-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(match_as_ref): also suggest downcasting references #15935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9cde98a to
7a6f20a
Compare
| } | ||
|
|
||
| fn issue15932() { | ||
| let _: Option<&i32> = Some(0).as_mut().map(|x| x as _); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not Some(0).as_ref()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #15934 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, I'm not opposed to that solution (though I did end up liking this one more) -- I explicitly opened two PRs so that you could compare the outputs and see which one you prefer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that we not clear to me, I get a lot of notifications from GitHub.
tests/ui/match_as_ref.fixed
Outdated
| fn issue15932() { | ||
| let _: Option<&i32> = Some(0).as_mut().map(|x| x as _); | ||
|
|
||
| let _: Option<&dyn std::fmt::Debug> = Some(0).as_mut().map(|x| x as &mut _ as &_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the double cast necessary here, or even useful? Some(0).as_mut().map(|x| x as &_) would work, and Some(0).as_ref().map(|x| x as &_) would be even better. Why not even Some(0).as_ref().map(|x| x as _)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To the double-cast part: it's because when I first tried that I got a type ambiguity error. Though now that I think about it, the error was actually caused by me trying to cast &mut u32 as &i32 (note that the types change as well). Fixed that.
As to why I don't use as_ref, see the reply above.
7a6f20a to
789d36f
Compare
|
#15934 will be merged |
v2 of #15934
changelog: [
match_as_ref]: also suggest downcasting referencesr? @samueltardieu