diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index f819a5f642f..80583a58558 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -569,7 +569,7 @@ fn create_substs_for_ast_path(&self, let has_self = generic_params.has_self; let (_, potential_assoc_types) = Self::check_generic_arg_count( - self.tcx(), + tcx, span, &generic_params, &generic_args, @@ -594,7 +594,7 @@ fn create_substs_for_ast_path(&self, }; let substs = Self::create_substs_for_generic_args( - self.tcx(), + tcx, def_id, &[][..], self_ty.is_some(), @@ -1293,8 +1293,8 @@ pub fn associated_path_def_to_ty(&self, self.prohibit_generics(slice::from_ref(item_segment)); // Check if we have an enum variant here. - if let ty::Adt(adt_def, _) = ty.sty { - if adt_def.is_enum() { + match ty.sty { + ty::Adt(adt_def, _) if adt_def.is_enum() => { let variant_def = adt_def.variants.iter().find(|vd| { tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did) }); @@ -1305,7 +1305,8 @@ pub fn associated_path_def_to_ty(&self, tcx.check_stability(def.def_id(), Some(ref_id), span); return (ty, def); } - } + }, + _ => (), } // Find the type of the associated item, and the trait where the associated @@ -1339,7 +1340,7 @@ pub fn associated_path_def_to_ty(&self, } (&ty::Adt(adt_def, _substs), Def::Enum(_did)) => { let ty_str = ty.to_string(); - // Incorrect enum variant + // Incorrect enum variant. let mut err = tcx.sess.struct_span_err( span, &format!("no variant `{}` on enum `{}`", &assoc_name.as_str(), ty_str), @@ -1669,23 +1670,24 @@ pub fn def_to_ty(&self, tcx.mk_ty_param(index, tcx.hir().name(node_id).as_interned_str()) } Def::SelfTy(_, Some(def_id)) => { - // `Self` in impl (we know the concrete type) + // `Self` in impl (we know the concrete type). assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); tcx.at(span).type_of(def_id) } Def::SelfTy(Some(_), None) => { - // `Self` in trait + // `Self` in trait. assert_eq!(opt_self_ty, None); self.prohibit_generics(&path.segments); tcx.mk_self_type() } Def::AssociatedTy(def_id) => { - self.prohibit_generics(&path.segments[..path.segments.len()-2]); + debug_assert!(path.segments.len() >= 2); + self.prohibit_generics(&path.segments[..path.segments.len() - 2]); self.qpath_to_ty(span, opt_self_ty, def_id, - &path.segments[path.segments.len()-2], + &path.segments[path.segments.len() - 2], path.segments.last().unwrap()) } Def::PrimTy(prim_ty) => { diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 88814ae6a2d..a039835b88f 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -372,8 +372,8 @@ pub fn resolve_ufcs(&self, let tcx = self.tcx; // Check if we have an enum variant here. - if let ty::Adt(adt_def, _) = self_ty.sty { - if adt_def.is_enum() { + match self_ty.sty { + ty::Adt(adt_def, _) if adt_def.is_enum() => { let variant_def = adt_def.variants.iter().find(|vd| { tcx.hygienic_eq(method_name, vd.ident, adt_def.did) }); @@ -384,7 +384,8 @@ pub fn resolve_ufcs(&self, tcx.check_stability(def.def_id(), Some(expr_id), span); return Ok(def); } - } + }, + _ => (), } let mode = probe::Mode::Path;