]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_hir_typeck/src/expr_use_visitor.rs
Merge from rustc
[rust.git] / compiler / rustc_hir_typeck / src / expr_use_visitor.rs
index e5e798f4b933f2ec18ae1dc5bdc8c4e6bd411cbe..7774ffc9b9793ea8ac6a93a0e41b9ca196514a71 100644 (file)
@@ -523,6 +523,11 @@ fn walk_struct_expr<'hir>(
         // 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 {
@@ -540,9 +545,9 @@ fn walk_struct_expr<'hir>(
             ty::Adt(adt, substs) if adt.is_struct() => {
                 // Consume those fields of the with expression that are needed.
                 for (f_index, with_field) in adt.non_enum_variant().fields.iter().enumerate() {
-                    let is_mentioned = fields.iter().any(|f| {
-                        self.tcx().field_index(f.hir_id, self.mc.typeck_results) == f_index
-                    });
+                    let is_mentioned = fields
+                        .iter()
+                        .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,
@@ -751,8 +756,8 @@ fn walk_pat(
     /// - When reporting the Place back to the Delegate, ensure that the UpvarId uses the enclosing
     /// closure as the DefId.
     fn walk_captures(&mut self, closure_expr: &hir::Closure<'_>) {
-        fn upvar_is_local_variable<'tcx>(
-            upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
+        fn upvar_is_local_variable(
+            upvars: Option<&FxIndexMap<hir::HirId, hir::Upvar>>,
             upvar_id: hir::HirId,
             body_owner_is_closure: bool,
         ) -> bool {