Refactor mod/check (part v)
This commit is contained in:
parent
e812b55d8f
commit
c9941a8a85
2 changed files with 24 additions and 28 deletions
|
@ -315,8 +315,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
||||||
// If they were not explicitly supplied, just construct fresh
|
// If they were not explicitly supplied, just construct fresh
|
||||||
// variables.
|
// variables.
|
||||||
let method_generics = self.tcx.generics_of(pick.item.def_id);
|
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, segment, &method_generics);
|
||||||
let supress_mismatch = self.fcx.check_impl_trait(self.span, fn_segment);
|
|
||||||
self.fcx.check_generic_arg_count(self.span, &segment, &method_generics, true, supress_mismatch);
|
self.fcx.check_generic_arg_count(self.span, &segment, &method_generics, true, supress_mismatch);
|
||||||
|
|
||||||
// Create subst for early-bound lifetime parameters, combining
|
// Create subst for early-bound lifetime parameters, combining
|
||||||
|
|
|
@ -4984,10 +4984,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
// to add defaults. If the user provided *too many* types, that's
|
// to add defaults. If the user provided *too many* types, that's
|
||||||
// a problem.
|
// a problem.
|
||||||
let mut infer_lifetimes = FxHashMap();
|
let mut infer_lifetimes = FxHashMap();
|
||||||
let supress_mismatch = self.check_impl_trait(span, fn_segment);
|
|
||||||
for &PathSeg(def_id, index) in &path_segs {
|
for &PathSeg(def_id, index) in &path_segs {
|
||||||
let generics = self.tcx.generics_of(def_id);
|
|
||||||
let seg = &segments[index];
|
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);
|
self.check_generic_arg_count(span, seg, &generics, false, supress_mismatch);
|
||||||
infer_lifetimes.insert(index, if let Some(ref data) = seg.args {
|
infer_lifetimes.insert(index, if let Some(ref data) = seg.args {
|
||||||
!data.args.iter().any(|arg| match arg {
|
!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`.
|
/// Report error if there is an explicit type parameter when using `impl Trait`.
|
||||||
fn check_impl_trait(&self,
|
fn check_impl_trait(&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
segment: Option<(&hir::PathSegment, &ty::Generics)>)
|
seg: &hir::PathSegment,
|
||||||
|
generics: &ty::Generics)
|
||||||
-> bool {
|
-> bool {
|
||||||
let segment = segment.map(|(path_segment, generics)| {
|
let explicit = !seg.infer_types;
|
||||||
let explicit = !path_segment.infer_types;
|
let impl_trait = generics.params.iter().any(|param| match param.kind {
|
||||||
let impl_trait = generics.params.iter().any(|param| match param.kind {
|
ty::GenericParamDefKind::Type {
|
||||||
ty::GenericParamDefKind::Type {
|
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), ..
|
||||||
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), ..
|
} => true,
|
||||||
} => true,
|
_ => false,
|
||||||
_ => 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
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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.
|
// Resolves `typ` by a single level if `typ` is a type variable.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue