Skip to content

Commit 875249e

Browse files
committed
Do not ICE on private type in field of unresolved struct
1 parent d9dba3a commit 875249e

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,9 +2179,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21792179
let ast::ExprKind::Struct(struct_expr) = &expr.kind else { return };
21802180
// We don't have to handle type-relative paths because they're forbidden in ADT
21812181
// expressions, but that would change with `#[feature(more_qualified_paths)]`.
2182-
let Some(Res::Def(_, def_id)) =
2183-
self.partial_res_map[&struct_expr.path.segments.iter().last().unwrap().id].full_res()
2184-
else {
2182+
let Some(segment) = struct_expr.path.segments.iter().last() else { return };
2183+
let Some(partial_res) = self.partial_res_map.get(&segment.id) else { return };
2184+
let Some(Res::Def(_, def_id)) = partial_res.full_res() else {
21852185
return;
21862186
};
21872187
let Some(default_fields) = self.field_defaults(def_id) else { return };
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/145367
2+
mod m {
3+
struct Priv2;
4+
}
5+
fn main() {
6+
WithUse { one: m::Priv2 } //~ ERROR: cannot find struct, variant or union type `WithUse` in this scope
7+
//~^ ERROR: unit struct `Priv2` is private
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0422]: cannot find struct, variant or union type `WithUse` in this scope
2+
--> $DIR/non-exhaustive-ctor-not-found.rs:6:5
3+
|
4+
LL | WithUse { one: m::Priv2 }
5+
| ^^^^^^^ not found in this scope
6+
7+
error[E0603]: unit struct `Priv2` is private
8+
--> $DIR/non-exhaustive-ctor-not-found.rs:6:23
9+
|
10+
LL | WithUse { one: m::Priv2 }
11+
| ^^^^^ private unit struct
12+
|
13+
note: the unit struct `Priv2` is defined here
14+
--> $DIR/non-exhaustive-ctor-not-found.rs:3:5
15+
|
16+
LL | struct Priv2;
17+
| ^^^^^^^^^^^^^
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0422, E0603.
22+
For more information about an error, try `rustc --explain E0422`.

0 commit comments

Comments
 (0)