Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove erroneous error message when checking impl trait params #48709

Merged
merged 2 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
// variables.
let method_generics = self.tcx.generics_of(pick.item.def_id);
let mut fn_segment = Some((segment, method_generics));
self.fcx.check_path_parameter_count(self.span, &mut fn_segment, true);
self.fcx.check_path_parameter_count(self.span, &mut fn_segment, true, false);

// Create subst for early-bound lifetime parameters, combining
// parameters from the type and those from the method.
Expand Down
20 changes: 13 additions & 7 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4764,9 +4764,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// variables. If the user provided some types, we may still need
// to add defaults. If the user provided *too many* types, that's
// a problem.
self.check_path_parameter_count(span, &mut type_segment, false);
self.check_path_parameter_count(span, &mut fn_segment, false);
self.check_impl_trait(span, &mut fn_segment);
let supress_mismatch = self.check_impl_trait(span, &mut fn_segment);
self.check_path_parameter_count(span, &mut type_segment, false, supress_mismatch);
self.check_path_parameter_count(span, &mut fn_segment, false, supress_mismatch);

let (fn_start, has_self) = match (type_segment, fn_segment) {
(_, Some((_, generics))) => {
Expand Down Expand Up @@ -4919,7 +4919,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn check_path_parameter_count(&self,
span: Span,
segment: &mut Option<(&hir::PathSegment, &ty::Generics)>,
is_method_call: bool) {
is_method_call: bool,
supress_mismatch_error: bool) {
let (lifetimes, types, infer_types, bindings) = segment.map_or(
(&[][..], &[][..], true, &[][..]),
|(s, _)| s.parameters.as_ref().map_or(
Expand Down Expand Up @@ -4959,7 +4960,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// type parameters, we force instantiate_value_path to
// use inference variables instead of the provided types.
*segment = None;
} else if types.len() < required_len && !infer_types {
} else if types.len() < required_len && !infer_types && !supress_mismatch_error {
let expected_text = count_type_params(required_len);
let actual_text = count_type_params(types.len());
struct_span_err!(self.tcx.sess, span, E0089,
Expand Down Expand Up @@ -5026,10 +5027,11 @@ 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: &mut Option<(&hir::PathSegment, &ty::Generics)>) {
segment: &mut Option<(&hir::PathSegment, &ty::Generics)>)
-> bool {
use hir::SyntheticTyParamKind::*;

segment.map(|(path_segment, generics)| {
let segment = segment.map(|(path_segment, generics)| {
let explicit = !path_segment.infer_types;
let impl_trait = generics.types.iter()
.any(|ty_param| {
Expand All @@ -5050,7 +5052,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {

err.emit();
}

impl_trait
});

segment.unwrap_or(false)
}

// Resolves `typ` by a single level if `typ` is a type variable.
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/impl-trait/universal-issue-48703.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(universal_impl_trait)]

use std::fmt::Debug;

fn foo<T>(x: impl Debug) { }

fn main() {
foo::<String>('a'); //~ ERROR cannot provide explicit type parameters
}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/universal-issue-48703.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0632]: cannot provide explicit type parameters when `impl Trait` is used in argument position.
--> $DIR/universal-issue-48703.rs:18:5
|
LL | foo::<String>('a'); //~ ERROR cannot provide explicit type parameters
| ^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0632`.