Rollup merge of #82789 - csmoe:issue-82772, r=estebank
Get with field index from pattern slice instead of directly indexing Closes #82772 r? ``@estebank`` https://github.com/rust-lang/rust/pull/82789#issuecomment-796921977 > ``@estebank`` So the real cause is we only generate single pattern for Box here615b03aeaa/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs (L1130-L1132)
But in the replacing function, it tries to index on the 1-length pattern slice with field 1, thus out of bounds.615b03aeaa/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs (L1346)
This commit is contained in:
commit
0d9a6edb50
|
@ -1343,7 +1343,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
|
|||
match &mut fields {
|
||||
Fields::Vec(pats) => {
|
||||
for (i, pat) in new_pats {
|
||||
pats[i] = pat
|
||||
if let Some(p) = pats.get_mut(i) {
|
||||
*p = pat;
|
||||
}
|
||||
}
|
||||
}
|
||||
Fields::Filtered { fields, .. } => {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// aux-build:struct_variant_privacy.rs
|
||||
extern crate struct_variant_privacy;
|
||||
|
||||
fn f(b: struct_variant_privacy::Bar) { //~ ERROR enum `Bar` is private
|
||||
fn f(b: struct_variant_privacy::Bar) {
|
||||
//~^ ERROR enum `Bar` is private
|
||||
match b {
|
||||
struct_variant_privacy::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ LL | enum Bar {
|
|||
| ^^^^^^^^
|
||||
|
||||
error[E0603]: enum `Bar` is private
|
||||
--> $DIR/struct-variant-privacy-xc.rs:6:33
|
||||
--> $DIR/struct-variant-privacy-xc.rs:7:33
|
||||
|
|
||||
LL | struct_variant_privacy::Bar::Baz { a: _a } => {}
|
||||
| ^^^ private enum
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
mod foo {
|
||||
enum Bar {
|
||||
Baz { a: isize }
|
||||
Baz { a: isize },
|
||||
}
|
||||
}
|
||||
|
||||
fn f(b: foo::Bar) { //~ ERROR enum `Bar` is private
|
||||
fn f(b: foo::Bar) {
|
||||
//~^ ERROR enum `Bar` is private
|
||||
match b {
|
||||
foo::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ LL | enum Bar {
|
|||
| ^^^^^^^^
|
||||
|
||||
error[E0603]: enum `Bar` is private
|
||||
--> $DIR/struct-variant-privacy.rs:9:14
|
||||
--> $DIR/struct-variant-privacy.rs:10:14
|
||||
|
|
||||
LL | foo::Bar::Baz { a: _a } => {}
|
||||
| ^^^ private enum
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// edition:2018
|
||||
|
||||
fn main() {
|
||||
use a::ModPrivateStruct;
|
||||
let Box { 0: _, .. }: Box<()>; //~ ERROR field `0` of
|
||||
let Box { 1: _, .. }: Box<()>; //~ ERROR field `1` of
|
||||
let ModPrivateStruct { 1: _, .. } = ModPrivateStruct::default(); //~ ERROR field `1` of
|
||||
}
|
||||
|
||||
mod a {
|
||||
#[derive(Default)]
|
||||
pub struct ModPrivateStruct(u8, u8);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
error[E0451]: field `0` of struct `Box` is private
|
||||
--> $DIR/issue-82772.rs:5:15
|
||||
|
|
||||
LL | let Box { 0: _, .. }: Box<()>;
|
||||
| ^^^^ private field
|
||||
|
||||
error[E0451]: field `1` of struct `Box` is private
|
||||
--> $DIR/issue-82772.rs:6:15
|
||||
|
|
||||
LL | let Box { 1: _, .. }: Box<()>;
|
||||
| ^^^^ private field
|
||||
|
||||
error[E0451]: field `1` of struct `ModPrivateStruct` is private
|
||||
--> $DIR/issue-82772.rs:7:28
|
||||
|
|
||||
LL | let ModPrivateStruct { 1: _, .. } = ModPrivateStruct::default();
|
||||
| ^^^^ private field
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0451`.
|
Loading…
Reference in New Issue