mirror of https://github.com/rust-lang/rust.git
Don't ICE in ExprUseVisitor on FRU for non-existent struct
This commit is contained in:
parent
26b24cd755
commit
d442c015d6
|
@ -523,6 +523,11 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
// Consume the expressions supplying values for each field.
|
||||
for field in fields {
|
||||
self.consume_expr(field.expr);
|
||||
|
||||
// The struct path probably didn't resolve
|
||||
if self.mc.typeck_results.opt_field_index(field.hir_id).is_none() {
|
||||
self.tcx().sess.delay_span_bug(field.span, "couldn't resolve index for field");
|
||||
}
|
||||
}
|
||||
|
||||
let with_expr = match *opt_with {
|
||||
|
@ -542,7 +547,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
for (f_index, with_field) in adt.non_enum_variant().fields.iter().enumerate() {
|
||||
let is_mentioned = fields
|
||||
.iter()
|
||||
.any(|f| self.mc.typeck_results.field_index(f.hir_id) == f_index);
|
||||
.any(|f| self.mc.typeck_results.opt_field_index(f.hir_id) == Some(f_index));
|
||||
if !is_mentioned {
|
||||
let field_place = self.mc.cat_projection(
|
||||
&*with_expr,
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
struct S {
|
||||
a: u32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s1 = S { a: 1 };
|
||||
|
||||
let _ = || {
|
||||
let s2 = Oops { a: 2, ..s1 };
|
||||
//~^ ERROR cannot find struct, variant or union type `Oops` in this scope
|
||||
};
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
error[E0422]: cannot find struct, variant or union type `Oops` in this scope
|
||||
--> $DIR/unresolved-struct-with-fru.rs:9:18
|
||||
|
|
||||
LL | let s2 = Oops { a: 2, ..s1 };
|
||||
| ^^^^ not found in this scope
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0422`.
|
Loading…
Reference in New Issue