-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add a note about implicit temporaries on &mut (fn or const) #104857
Add a note about implicit temporaries on &mut (fn or const) #104857
Conversation
It probably makes sense to add a test for this. |
3d9895a
to
8bcbfef
Compare
Rebased, removed "implicitly" from the error message(s), and added some tests. |
☔ The latest upstream changes (presumably #99798) made this pull request unmergeable. Please resolve the merge conflicts. |
8bcbfef
to
30e7429
Compare
Rebased |
☔ The latest upstream changes (presumably #104975) made this pull request unmergeable. Please resolve the merge conflicts. |
30e7429
to
2450ccb
Compare
Rebased |
r? @oli-obk |
The tests directory moved from |
// note about this. | ||
match &self.body.local_decls[local].local_info { | ||
Some(box LocalInfo::FnDefRef) => { | ||
implicit_temporary = Some(("function", "function pointer")); |
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.
it actually doesn't put the function pointer into a temporary, but creates a temporary of the function item type (a zst). Maybe it could literally mention the zero sized nature, as that should make it obvious that you get no data to mutate (in case someone expected a function pointer).
_ => {} | ||
} | ||
} | ||
match local_kind { | ||
LocalKind::ReturnPointer | LocalKind::Temp => { | ||
("temporary value".to_string(), "temporary value created here".to_string()) |
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.
As you already mentioned, this message is the misleading part. Maybe pick a different message here for ConstRef and FnDefRef instead of adding a new note?
2450ccb
to
3818536
Compare
Some changes occured in cc @BoxyUwU |
@sharnoff any updates to this? |
@Dylan-DPC Hey! Sorry, meant to reply, but have been overwhelmed with other stuff for the past couple months. No code updates - will get on that this weekend. |
☔ The latest upstream changes (presumably #108944) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks |
Ran into a confusing error message and thought I'd open a PR to improve it.
My confusion came about because something like
is valid, but
is not. The error message didn't help much:
"why is it creating a temporary only for
&mut
and not&
?"A similar case is true of constants (although they have the
const_item_mutation
lint).Changes to error messages
This PR adds a note to the error message for borrowck failures when a constants or functions are mutably borrowed and a referenece to the temporary is returned (at least, that's what it should do - I've only superficially tested it).
The note is:
The text of the notes can be improved; I just wanted to get something here for feedback :)
I'm also not sure that just having it in a "note" is sufficient, but I don't know what the ideal error construction would be. Maybe changing the "temporary value created here" line?
Other changes
mir::LocalInfo::FnDefRef
to accompanyConstRef
- required for detecting this (otherwiselocal_info = None
)thir::ExprKind::ZstLiteral
toNamedFn
, because it was only used for functions (and now it's used to set `local_info = FnDefRef``)Self
constructors, which might not really be considered "named" functionsr? rust-lang/diagnostics