-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest adding semicolon in user code rather than macro impl details #142543
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
|
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.
Thanks! r=me with two nits addressed in one way or another
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
ac875a1
to
6ff3713
Compare
@bors r=fmease |
Rollup of 10 pull requests Successful merges: - #133952 (Remove wasm legacy abi) - #134661 (Reduce precedence of expressions that have an outer attr) - #141769 (Move metadata object generation for dylibs to the linker code ) - #141937 (Report never type lints in dependencies) - #142347 (Async drop - fix for StorageLive/StorageDead codegen for pinned future) - #142389 (Apply ABI attributes on return types in `rustc_codegen_cranelift`) - #142470 (Add some missing mailmap entries) - #142481 (Add `f16` inline asm support for LoongArch) - #142499 (Remove check run bootstrap) - #142543 (Suggest adding semicolon in user code rather than macro impl details) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #142543 - Urgau:span-borrowck-semicolon, r=fmease Suggest adding semicolon in user code rather than macro impl details This PR tries to find the right span (by peeling expansion) so that the suggestion for adding a semicolon is suggested in user code rather than in the expanded code (in the example a macro impl). Fixes #139049 r? `@fmease`
let _write = { | ||
let mutex = Mutex; | ||
write!(Out, "{}", mutex.lock()) | ||
//~^ ERROR `mutex` does not live long enough | ||
//~| SUGGESTION ; | ||
}; |
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.
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.
I just noticed that this test passes in Rust 2024, due to the new rules for temporaries in tail expressions.
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.
I just noticed that this test passes in Rust 2024
Sure, but we still want to provide non-butchered / good diagnostics in older editions, they have "long-term support".
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.
We could replace that test with the following one:
// Make sure the generated suggestion suggest editing the user code instead of
// the macro implementation (which might come from an external crate).
// issue: <https://github.com/rust-lang/rust/issues/139049>
// You could assume that this comes from an extern crate (it doesn't
// because an aux crate would be overkill for this test).
macro_rules! perform { ($e:expr) => { D(&$e).end() } }
fn main() {
{ let l = (); perform!(l) }; //~ ERROR does not live long enough
//~^ SUGGESTION ;
let _x = { let l = (); perform!(l) }; //~ ERROR does not live long enough
//~| SUGGESTION let x
}
struct D<T>(T);
impl<T> Drop for D<T> { fn drop(&mut self) {} }
impl<T> D<T> { fn end(&self) -> String { String::new()} }
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.
Or modify tests/ui/nll/issue-54556-used-vs-unused-tails.rs
and add it there
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.
@fmease That test doesn't work. Then it just suggests to add the ;
inside the macro definition.
Handle same-crate macro for borrowck semicolon suggestion Handles rust-lang#142543 (comment) cc `@m-ou-se` r? `@fmease`
Handle same-crate macro for borrowck semicolon suggestion Handles rust-lang#142543 (comment) cc ``@m-ou-se`` r? ``@fmease``
Handle same-crate macro for borrowck semicolon suggestion Handles rust-lang#142543 (comment) cc ```@m-ou-se``` r? ```@fmease```
Rollup merge of #142584 - Urgau:span-borrowck-139049, r=fmease Handle same-crate macro for borrowck semicolon suggestion Handles #142543 (comment) cc ``@m-ou-se`` r? ``@fmease``
This PR tries to find the right span (by peeling expansion) so that the suggestion for adding a semicolon is suggested in user code rather than in the expanded code (in the example a macro impl).
Fixes #139049
r? @fmease