1
Fork 0

Minor clean-up

This commit is contained in:
Alexander Regueiro 2018-12-26 00:07:31 +00:00
parent 67a30d2d70
commit 87532e99e5
2 changed files with 16 additions and 13 deletions

View file

@ -569,7 +569,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
let has_self = generic_params.has_self; let has_self = generic_params.has_self;
let (_, potential_assoc_types) = Self::check_generic_arg_count( let (_, potential_assoc_types) = Self::check_generic_arg_count(
self.tcx(), tcx,
span, span,
&generic_params, &generic_params,
&generic_args, &generic_args,
@ -594,7 +594,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
}; };
let substs = Self::create_substs_for_generic_args( let substs = Self::create_substs_for_generic_args(
self.tcx(), tcx,
def_id, def_id,
&[][..], &[][..],
self_ty.is_some(), self_ty.is_some(),
@ -1293,8 +1293,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
self.prohibit_generics(slice::from_ref(item_segment)); self.prohibit_generics(slice::from_ref(item_segment));
// Check if we have an enum variant here. // Check if we have an enum variant here.
if let ty::Adt(adt_def, _) = ty.sty { match ty.sty {
if adt_def.is_enum() { ty::Adt(adt_def, _) if adt_def.is_enum() => {
let variant_def = adt_def.variants.iter().find(|vd| { let variant_def = adt_def.variants.iter().find(|vd| {
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did) tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
}); });
@ -1305,7 +1305,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
tcx.check_stability(def.def_id(), Some(ref_id), span); tcx.check_stability(def.def_id(), Some(ref_id), span);
return (ty, def); return (ty, def);
} }
} },
_ => (),
} }
// Find the type of the associated item, and the trait where the associated // Find the type of the associated item, and the trait where the associated
@ -1339,7 +1340,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
} }
(&ty::Adt(adt_def, _substs), Def::Enum(_did)) => { (&ty::Adt(adt_def, _substs), Def::Enum(_did)) => {
let ty_str = ty.to_string(); let ty_str = ty.to_string();
// Incorrect enum variant // Incorrect enum variant.
let mut err = tcx.sess.struct_span_err( let mut err = tcx.sess.struct_span_err(
span, span,
&format!("no variant `{}` on enum `{}`", &assoc_name.as_str(), ty_str), &format!("no variant `{}` on enum `{}`", &assoc_name.as_str(), ty_str),
@ -1669,23 +1670,24 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
tcx.mk_ty_param(index, tcx.hir().name(node_id).as_interned_str()) tcx.mk_ty_param(index, tcx.hir().name(node_id).as_interned_str())
} }
Def::SelfTy(_, Some(def_id)) => { 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); assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments); self.prohibit_generics(&path.segments);
tcx.at(span).type_of(def_id) tcx.at(span).type_of(def_id)
} }
Def::SelfTy(Some(_), None) => { Def::SelfTy(Some(_), None) => {
// `Self` in trait // `Self` in trait.
assert_eq!(opt_self_ty, None); assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments); self.prohibit_generics(&path.segments);
tcx.mk_self_type() tcx.mk_self_type()
} }
Def::AssociatedTy(def_id) => { 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, self.qpath_to_ty(span,
opt_self_ty, opt_self_ty,
def_id, def_id,
&path.segments[path.segments.len()-2], &path.segments[path.segments.len() - 2],
path.segments.last().unwrap()) path.segments.last().unwrap())
} }
Def::PrimTy(prim_ty) => { Def::PrimTy(prim_ty) => {

View file

@ -372,8 +372,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
// Check if we have an enum variant here. // Check if we have an enum variant here.
if let ty::Adt(adt_def, _) = self_ty.sty { match self_ty.sty {
if adt_def.is_enum() { ty::Adt(adt_def, _) if adt_def.is_enum() => {
let variant_def = adt_def.variants.iter().find(|vd| { let variant_def = adt_def.variants.iter().find(|vd| {
tcx.hygienic_eq(method_name, vd.ident, adt_def.did) tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
}); });
@ -384,7 +384,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.check_stability(def.def_id(), Some(expr_id), span); tcx.check_stability(def.def_id(), Some(expr_id), span);
return Ok(def); return Ok(def);
} }
} },
_ => (),
} }
let mode = probe::Mode::Path; let mode = probe::Mode::Path;