Skip to content

Commit d442c01

Browse files
Don't ICE in ExprUseVisitor on FRU for non-existent struct
1 parent 26b24cd commit d442c01

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
523523
// Consume the expressions supplying values for each field.
524524
for field in fields {
525525
self.consume_expr(field.expr);
526+
527+
// The struct path probably didn't resolve
528+
if self.mc.typeck_results.opt_field_index(field.hir_id).is_none() {
529+
self.tcx().sess.delay_span_bug(field.span, "couldn't resolve index for field");
530+
}
526531
}
527532

528533
let with_expr = match *opt_with {
@@ -542,7 +547,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
542547
for (f_index, with_field) in adt.non_enum_variant().fields.iter().enumerate() {
543548
let is_mentioned = fields
544549
.iter()
545-
.any(|f| self.mc.typeck_results.field_index(f.hir_id) == f_index);
550+
.any(|f| self.mc.typeck_results.opt_field_index(f.hir_id) == Some(f_index));
546551
if !is_mentioned {
547552
let field_place = self.mc.cat_projection(
548553
&*with_expr,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
struct S {
2+
a: u32,
3+
}
4+
5+
fn main() {
6+
let s1 = S { a: 1 };
7+
8+
let _ = || {
9+
let s2 = Oops { a: 2, ..s1 };
10+
//~^ ERROR cannot find struct, variant or union type `Oops` in this scope
11+
};
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0422]: cannot find struct, variant or union type `Oops` in this scope
2+
--> $DIR/unresolved-struct-with-fru.rs:9:18
3+
|
4+
LL | let s2 = Oops { a: 2, ..s1 };
5+
| ^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0422`.

0 commit comments

Comments
 (0)