-
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
Unused braces lint triggers on partial move into ref pattern. #70717
Comments
Hello, thanks for the report! Are the braces not unused? What you have here is let ref _b = {
a.0
}; ie, assigning ref binding
The unused braces lint was added in b3d744c, which was after the current beta (4c587bb). |
The braces cause the fn main(){
let a = (String::new(),0);
let ref _b = {a.0};
// Can't print a partially moved value
println!("{:?}",a);
}
While this does: fn main(){
let a = (String::new(),0);
let ref _b = a.0;
println!("{:?}",a);
} |
Oh, I see - very true! Thanks for clarifying. |
For let a = 0;
let ref mut b = {a};
*b += 1;
assert_eq!(a, 0); vs. // `mut` qualifier is necessary, also not observed by the lint.
let mut a = 0;
let ref mut b = a;
*b += 1;
assert_eq!(a, 1); |
This may also be triggered by a (IMO common) usage of the quote crate, but it only appears when running rustdoc: [package]
name = "repro"
version = "0.1.0"
edition = "2018"
[dependencies]
quote = "=1.0.3" use quote::quote;
pub fn repro() {
let many = [1, 2, 3];
let _together = quote! {
#(#many),*
};
}
|
Ping @lcnr (author of the lint) |
Are borrows and "pattern-matching contexts" the only ones where we need to silence the lint? |
The issue with quote was actually mentioned in the original PR but somehow forgotten. @eddyb unused_braces currently only warns on top lvl exprs afaik. So I should probably stop linting for "pattern-matching contexts". I don't think that a lint based on syntax should know about types. i.e. changing types should not suddenly cause a warning because of unused braces (this is a personal preference though). |
It's not about types, it's about implicit borrows, e.g. |
@shepmaster I fixed the issue concerning ref patterns for now, but don't yet have a good idea on how to fix the issue with Can you please open a new issue for this? |
Opened as #70814 |
Fixes unused_braces regression rust-lang/rust#70717
I tried this code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=4b8d234e04e2d77ab45ecf3c41d59d58
I expected the code to compile without warnings.
Instead, the
unused_braces
lint was triggered:Meta
This bug happens in 1.44.0-nightly (2020-04-01 76b1198),not in Rust beta nor stable.
The text was updated successfully, but these errors were encountered: