-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove the unhelpful let binding diag comes from FormatArguments #114511
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![allow(dead_code)] | ||
|
||
fn bar<'a>(_: std::fmt::Arguments<'a>) {} | ||
fn main() { | ||
let x = format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3); | ||
//~^ ERROR temporary value dropped while borrowed | ||
|
||
bar(x); | ||
|
||
let foo = format_args!("{}", "hi"); | ||
//~^ ERROR temporary value dropped while borrowed | ||
bar(foo); | ||
|
||
let foo = format_args!("hi"); // no placeholder in arguments, so no error | ||
bar(foo); | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/ui/borrowck/issue-114374-invalid-help-fmt-args.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/issue-114374-invalid-help-fmt-args.rs:5:13 | ||
| | ||
LL | let x = format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement | ||
| | | ||
| creates a temporary value which is freed while still in use | ||
... | ||
LL | bar(x); | ||
| - borrow later used here | ||
| | ||
= note: the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used | ||
= note: to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html> | ||
= note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0716]: temporary value dropped while borrowed | ||
--> $DIR/issue-114374-invalid-help-fmt-args.rs:10:15 | ||
| | ||
LL | let foo = format_args!("{}", "hi"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement | ||
| | | ||
| creates a temporary value which is freed while still in use | ||
LL | | ||
LL | bar(foo); | ||
| --- borrow later used here | ||
| | ||
= note: the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used | ||
= note: to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html> | ||
= note: this error originates in the macro `format_args` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0716`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What if we have nested
format_args
expressions?Do we only care about the case where we assign the result of
format_args!
? If so, why can't we just check forstmt
being an assignment where the rhs expris_format_args_item
?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.
the
if self.span == expr.span.source_callsite()
guarantee we find out the expr we're intrested in, the code goes here means a borrow(mostly binding) happens, I think use span to find expr is mostly enough for suggestions.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.
What does your branch output on something like this:
let x = format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3)
? Can you maybe add this to your test?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.
The output is:
I added it to the test case.