Refactor mod/check (part v)

This commit is contained in:
varkor 2018-06-26 23:34:33 +01:00
parent e812b55d8f
commit c9941a8a85
2 changed files with 24 additions and 28 deletions

View File

@ -315,8 +315,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
// If they were not explicitly supplied, just construct fresh
// variables.
let method_generics = self.tcx.generics_of(pick.item.def_id);
let fn_segment = Some((segment, method_generics));
let supress_mismatch = self.fcx.check_impl_trait(self.span, fn_segment);
let supress_mismatch = self.fcx.check_impl_trait(self.span, segment, &method_generics);
self.fcx.check_generic_arg_count(self.span, &segment, &method_generics, true, supress_mismatch);
// Create subst for early-bound lifetime parameters, combining

View File

@ -4984,10 +4984,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// to add defaults. If the user provided *too many* types, that's
// a problem.
let mut infer_lifetimes = FxHashMap();
let supress_mismatch = self.check_impl_trait(span, fn_segment);
for &PathSeg(def_id, index) in &path_segs {
let generics = self.tcx.generics_of(def_id);
let seg = &segments[index];
let generics = self.tcx.generics_of(def_id);
let supress_mismatch = self.check_impl_trait(span, seg, &generics);
self.check_generic_arg_count(span, seg, &generics, false, supress_mismatch);
infer_lifetimes.insert(index, if let Some(ref data) = seg.args {
!data.args.iter().any(|arg| match arg {
@ -5284,33 +5284,30 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
/// Report error if there is an explicit type parameter when using `impl Trait`.
fn check_impl_trait(&self,
span: Span,
segment: Option<(&hir::PathSegment, &ty::Generics)>)
seg: &hir::PathSegment,
generics: &ty::Generics)
-> bool {
let segment = segment.map(|(path_segment, generics)| {
let explicit = !path_segment.infer_types;
let impl_trait = generics.params.iter().any(|param| match param.kind {
ty::GenericParamDefKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), ..
} => true,
_ => false,
});
if explicit && impl_trait {
let mut err = struct_span_err! {
self.tcx.sess,
span,
E0632,
"cannot provide explicit type parameters when `impl Trait` is \
used in argument position."
};
err.emit();
}
impl_trait
let explicit = !seg.infer_types;
let impl_trait = generics.params.iter().any(|param| match param.kind {
ty::GenericParamDefKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), ..
} => true,
_ => false,
});
segment.unwrap_or(false)
if explicit && impl_trait {
let mut err = struct_span_err! {
self.tcx.sess,
span,
E0632,
"cannot provide explicit type parameters when `impl Trait` is \
used in argument position."
};
err.emit();
}
impl_trait
}
// Resolves `typ` by a single level if `typ` is a type variable.