Skip to content

Get with field index from pattern slice instead of directly indexing #82789

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. } => {
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/structs/struct-variant-privacy-xc.rs
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/structs/struct-variant-privacy-xc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/structs/struct-variant-privacy.rs
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/structs/struct-variant-privacy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/typeck/issue-82772.rs
Original file line number Diff line number Diff line change
@@ -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);
}
21 changes: 21 additions & 0 deletions src/test/ui/typeck/issue-82772.stderr
Original file line number Diff line number Diff line change
@@ -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`.