Skip to content
Open
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
6 changes: 5 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
};
self.typeck_results.borrow_mut().fru_field_types_mut().insert(expr.hir_id, fru_tys);
} else if adt_kind != AdtKind::Union && !remaining_fields.is_empty() {
} else if adt_kind != AdtKind::Union
&& !remaining_fields.is_empty()
//~ non_exhaustive already reported, which will only happen for extern modules
&& !variant.field_list_has_applicable_non_exhaustive()
{
debug!(?remaining_fields);
let private_fields: Vec<&ty::FieldDef> = variant
.fields
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/privacy/auxiliary/non_exhaustive_with_private.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Auxiliary crate for testing non-exhaustive struct with private fields

#[non_exhaustive]
pub struct Foo {
pub my_field: u32,
private_field: i32,
}

#[non_exhaustive]
pub struct Bar {
pub my_field: u32,
pub missing_field: i32,
}
17 changes: 17 additions & 0 deletions tests/ui/privacy/non-exhaustive-with-private-fields-147513.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ aux-build:non_exhaustive_with_private.rs

extern crate non_exhaustive_with_private;

use non_exhaustive_with_private::{Bar, Foo};

fn main() {
let foo = Foo {
//~^ ERROR cannot create non-exhaustive struct using struct expression
my_field: 10,
};

let bar = Bar {
//~^ ERROR cannot create non-exhaustive struct using struct expression
my_field: 10,
};
}
23 changes: 23 additions & 0 deletions tests/ui/privacy/non-exhaustive-with-private-fields-147513.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0639]: cannot create non-exhaustive struct using struct expression
--> $DIR/non-exhaustive-with-private-fields-147513.rs:8:15
|
LL | let foo = Foo {
| _______________^
LL | |
LL | | my_field: 10,
LL | | };
| |_____^

error[E0639]: cannot create non-exhaustive struct using struct expression
--> $DIR/non-exhaustive-with-private-fields-147513.rs:13:15
|
LL | let bar = Bar {
| _______________^
LL | |
LL | | my_field: 10,
LL | | };
| |_____^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0639`.
Loading