-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
RFC2229 Only compute place if upvars can be resolved #88039
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | |
suffix: &'pat [Pat<'tcx>], | ||
) { | ||
let tcx = self.tcx; | ||
let (min_length, exact_size) = match place | ||
.clone() | ||
.into_place(tcx, self.typeck_results) | ||
.ty(&self.local_decls, tcx) | ||
.ty | ||
.kind() | ||
let (min_length, exact_size) = if let Ok(place_resolved) = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. likewise here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
place.clone().try_upvars_resolved(tcx, self.typeck_results) | ||
{ | ||
ty::Array(_, length) => (length.eval_usize(tcx, self.param_env), true), | ||
_ => ((prefix.len() + suffix.len()).try_into().unwrap(), false), | ||
match place_resolved | ||
.into_place(tcx, self.typeck_results) | ||
.ty(&self.local_decls, tcx) | ||
.ty | ||
.kind() | ||
{ | ||
ty::Array(_, length) => (length.eval_usize(tcx, self.param_env), true), | ||
_ => ((prefix.len() + suffix.len()).try_into().unwrap(), false), | ||
} | ||
} else { | ||
((prefix.len() + suffix.len()).try_into().unwrap(), false) | ||
}; | ||
|
||
match_pairs.extend(prefix.iter().enumerate().map(|(idx, subpattern)| { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// run-pass | ||
// edition:2021 | ||
|
||
struct Props { | ||
field_1: u32, //~ WARNING: field is never read: `field_1` | ||
field_2: u32, //~ WARNING: field is never read: `field_2` | ||
} | ||
|
||
fn main() { | ||
// Test 1 | ||
let props_2 = Props { //~ WARNING: unused variable: `props_2` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This warning is inconsistent with what happens when |
||
field_1: 1, | ||
field_2: 1, | ||
}; | ||
|
||
let _ = || { | ||
let _: Props = props_2; | ||
}; | ||
|
||
// Test 2 | ||
let mut arr = [1, 3, 4, 5]; | ||
|
||
let mref = &mut arr; | ||
|
||
let _c = || match arr { | ||
[_, _, _, _] => println!("A") | ||
}; | ||
|
||
println!("{:#?}", mref); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
warning: unused variable: `props_2` | ||
--> $DIR/issue-87987.rs:11:9 | ||
| | ||
LL | let props_2 = Props { | ||
| ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_props_2` | ||
| | ||
= note: `#[warn(unused_variables)]` on by default | ||
|
||
warning: field is never read: `field_1` | ||
--> $DIR/issue-87987.rs:5:5 | ||
| | ||
LL | field_1: u32, | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(dead_code)]` on by default | ||
|
||
warning: field is never read: `field_2` | ||
--> $DIR/issue-87987.rs:6:5 | ||
| | ||
LL | field_2: u32, | ||
| ^^^^^^^^^^^^ | ||
|
||
warning: 3 warnings emitted | ||
|
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.
Under what conditions would this fail to succeed?
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.
in the case we dont capture the root variable