From da023c0c6f3cdc72d72ef047c2dadb1a59c646df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Esteban=20K=C3=BCber?= Date: Wed, 11 Dec 2019 17:06:24 -0800 Subject: [PATCH] Add more context for type parameters --- .../infer/error_reporting/need_type_info.rs | 42 ++++++++++++------- ...associated-types-overridden-binding.stderr | 4 +- .../ui/async-await/unresolved_type_param.rs | 2 +- .../async-await/unresolved_type_param.stderr | 2 +- .../cannot-infer-const-args.stderr | 2 +- .../fn-const-param-infer.stderr | 2 +- src/test/ui/consts/issue-64662.stderr | 4 +- src/test/ui/error-codes/E0401.stderr | 2 +- src/test/ui/issues/issue-12028.stderr | 2 +- src/test/ui/issues/issue-16966.stderr | 2 +- src/test/ui/issues/issue-17551.stderr | 2 +- src/test/ui/issues/issue-21974.stderr | 2 +- src/test/ui/issues/issue-24424.stderr | 2 +- src/test/ui/issues/issue-25368.stderr | 2 +- src/test/ui/issues/issue-29147.stderr | 2 +- src/test/ui/issues/issue-5062.stderr | 2 +- src/test/ui/issues/issue-6458-2.stderr | 2 +- src/test/ui/issues/issue-6458-3.stderr | 2 +- src/test/ui/issues/issue-6458.stderr | 2 +- src/test/ui/issues/issue-65611.stderr | 2 +- ...od-ambig-one-trait-unknown-int-type.stderr | 2 +- .../missing-type-parameter.stderr | 2 +- .../issue-42234-unknown-receiver-type.stderr | 2 +- .../span/type-annotations-needed-expr.stderr | 2 +- ...ts-multidispatch-convert-ambig-dest.stderr | 2 +- .../or_else-multiple-type-params.stderr | 2 +- src/test/ui/type-inference/sort_by_key.stderr | 2 +- .../unbounded-associated-type.rs | 16 +++++++ .../unbounded-associated-type.stderr | 15 +++++++ ...ounded-type-param-in-fn-with-assoc-type.rs | 9 ++++ ...ed-type-param-in-fn-with-assoc-type.stderr | 9 ++++ .../unbounded-type-param-in-fn.rs | 7 ++++ .../unbounded-type-param-in-fn.stderr | 9 ++++ .../ui/type/type-annotation-needed.stderr | 2 +- .../cannot_infer_local_or_vec.stderr | 2 +- ...cannot_infer_local_or_vec_in_tuples.stderr | 2 +- .../ui/type/type-check/issue-22897.stderr | 2 +- .../ui/type/type-check/issue-40294.stderr | 2 +- src/test/ui/unconstrained-none.stderr | 2 +- src/test/ui/unconstrained-ref.stderr | 2 +- src/test/ui/vector-no-ann.stderr | 2 +- 41 files changed, 128 insertions(+), 51 deletions(-) create mode 100644 src/test/ui/type-inference/unbounded-associated-type.rs create mode 100644 src/test/ui/type-inference/unbounded-associated-type.stderr create mode 100644 src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.rs create mode 100644 src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr create mode 100644 src/test/ui/type-inference/unbounded-type-param-in-fn.rs create mode 100644 src/test/ui/type-inference/unbounded-type-param-in-fn.stderr diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 4baab0492a5..8878683f3a7 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -9,6 +9,7 @@ use syntax::symbol::kw; use syntax_pos::Span; use errors::{Applicability, DiagnosticBuilder}; +use std::borrow::Cow; use rustc_error_codes::*; @@ -113,6 +114,7 @@ fn closure_return_type_suggestion( err: &mut DiagnosticBuilder<'_>, output: &FunctionRetTy, body: &Body, + descr: &str, name: &str, ret: &str, ) { @@ -136,7 +138,7 @@ fn closure_return_type_suggestion( suggestion, Applicability::HasPlaceholders, ); - err.span_label(span, InferCtxt::missing_type_msg(&name)); + err.span_label(span, InferCtxt::missing_type_msg(&name, &descr)); } /// Given a closure signature, return a `String` containing a list of all its argument types. @@ -175,13 +177,17 @@ pub fn extract_type_name( &self, ty: Ty<'tcx>, highlight: Option, - ) -> (String, Option) { + ) -> (String, Option, Cow<'static, str>) { if let ty::Infer(ty::TyVar(ty_vid)) = ty.kind { let ty_vars = self.type_variables.borrow(); let var_origin = ty_vars.var_origin(ty_vid); if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind { if name != kw::SelfUpper { - return (name.to_string(), Some(var_origin.span)); + return ( + name.to_string(), + Some(var_origin.span), + "type parameter".into(), + ); } } } @@ -192,7 +198,7 @@ pub fn extract_type_name( printer.region_highlight_mode = highlight; } let _ = ty.print(printer); - (s, None) + (s, None, ty.prefix_string()) } pub fn need_type_info_err( @@ -203,7 +209,7 @@ pub fn need_type_info_err( error_code: TypeAnnotationNeeded, ) -> DiagnosticBuilder<'tcx> { let ty = self.resolve_vars_if_possible(&ty); - let (name, name_sp) = self.extract_type_name(&ty, None); + let (name, name_sp, descr) = self.extract_type_name(&ty, None); let mut local_visitor = FindLocalByTypeVisitor::new(&self, ty, &self.tcx.hir()); let ty_to_string = |ty: Ty<'tcx>| -> String { @@ -308,6 +314,7 @@ pub fn need_type_info_err( &mut err, &decl.output, &body, + &descr, &name, &ret, ); @@ -427,7 +434,7 @@ pub fn need_type_info_err( span_label.label.is_some() && span_label.span == span }) && local_visitor.found_arg_pattern.is_none() { // Avoid multiple labels pointing at `span`. - err.span_label(span, InferCtxt::missing_type_msg(&name)); + err.span_label(span, InferCtxt::missing_type_msg(&name, &descr)); } err @@ -468,10 +475,15 @@ fn annotate_method_call( ); } else { let sig = self.tcx.fn_sig(did); - err.span_label(e.span, &format!( - "this method call resolves to `{:?}`", - sig.output().skip_binder(), - )); + let bound_output = sig.output(); + let output = bound_output.skip_binder(); + err.span_label(e.span, &format!("this method call resolves to `{:?}`", output)); + let kind = &output.kind; + if let ty::Projection(proj) | ty::UnnormalizedProjection(proj) = kind { + if let Some(span) = self.tcx.hir().span_if_local(proj.item_def_id) { + err.span_label(span, &format!("`{:?}` defined here", output)); + } + } } } } @@ -484,19 +496,19 @@ pub fn need_type_info_err_in_generator( ty: Ty<'tcx>, ) -> DiagnosticBuilder<'tcx> { let ty = self.resolve_vars_if_possible(&ty); - let name = self.extract_type_name(&ty, None).0; + let (name, _, descr) = self.extract_type_name(&ty, None); let mut err = struct_span_err!( self.tcx.sess, span, E0698, "type inside {} must be known in this context", kind, ); - err.span_label(span, InferCtxt::missing_type_msg(&name)); + err.span_label(span, InferCtxt::missing_type_msg(&name, &descr)); err } - fn missing_type_msg(type_name: &str) -> String { + fn missing_type_msg(type_name: &str, descr: &str) -> Cow<'static, str>{ if type_name == "_" { - "cannot infer type".to_owned() + "cannot infer type".into() } else { - format!("cannot infer type for `{}`", type_name) + format!("cannot infer type for {} `{}`", descr, type_name).into() } } } diff --git a/src/test/ui/associated-types/associated-types-overridden-binding.stderr b/src/test/ui/associated-types/associated-types-overridden-binding.stderr index dd6bde0c14d..069da955b67 100644 --- a/src/test/ui/associated-types/associated-types-overridden-binding.stderr +++ b/src/test/ui/associated-types/associated-types-overridden-binding.stderr @@ -4,7 +4,7 @@ error[E0284]: type annotations needed LL | trait Foo: Iterator {} | ------------------------------- required by `Foo` LL | trait Bar: Foo {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `Self` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` | = note: cannot resolve `::Item == i32` @@ -14,7 +14,7 @@ error[E0284]: type annotations needed LL | trait I32Iterator = Iterator; | ----------------------------------------- required by `I32Iterator` LL | trait U32Iterator = I32Iterator; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `Self` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` | = note: cannot resolve `::Item == i32` diff --git a/src/test/ui/async-await/unresolved_type_param.rs b/src/test/ui/async-await/unresolved_type_param.rs index 2876f9fea0e..79c043b701d 100644 --- a/src/test/ui/async-await/unresolved_type_param.rs +++ b/src/test/ui/async-await/unresolved_type_param.rs @@ -8,7 +8,7 @@ async fn bar() -> () {} async fn foo() { bar().await; //~^ ERROR type inside `async fn` body must be known in this context - //~| NOTE cannot infer type for `T` + //~| NOTE cannot infer type for type parameter `T` //~| NOTE the type is part of the `async fn` body because of this `await` //~| NOTE in this expansion of desugaring of `await` } diff --git a/src/test/ui/async-await/unresolved_type_param.stderr b/src/test/ui/async-await/unresolved_type_param.stderr index c7866fc7744..b9b4f5133b9 100644 --- a/src/test/ui/async-await/unresolved_type_param.stderr +++ b/src/test/ui/async-await/unresolved_type_param.stderr @@ -2,7 +2,7 @@ error[E0698]: type inside `async fn` body must be known in this context --> $DIR/unresolved_type_param.rs:9:5 | LL | bar().await; - | ^^^ cannot infer type for `T` + | ^^^ cannot infer type for type parameter `T` | note: the type is part of the `async fn` body because of this `await` --> $DIR/unresolved_type_param.rs:9:5 diff --git a/src/test/ui/const-generics/cannot-infer-const-args.stderr b/src/test/ui/const-generics/cannot-infer-const-args.stderr index 32adc63156a..8379cbd4908 100644 --- a/src/test/ui/const-generics/cannot-infer-const-args.stderr +++ b/src/test/ui/const-generics/cannot-infer-const-args.stderr @@ -10,7 +10,7 @@ error[E0282]: type annotations needed --> $DIR/cannot-infer-const-args.rs:9:5 | LL | foo(); - | ^^^ cannot infer type for `fn() -> usize {foo::<_: usize>}` + | ^^^ cannot infer type for fn item `fn() -> usize {foo::<_: usize>}` error: aborting due to previous error diff --git a/src/test/ui/const-generics/fn-const-param-infer.stderr b/src/test/ui/const-generics/fn-const-param-infer.stderr index 2d9b6edb8a2..9ccad7bcdd7 100644 --- a/src/test/ui/const-generics/fn-const-param-infer.stderr +++ b/src/test/ui/const-generics/fn-const-param-infer.stderr @@ -30,7 +30,7 @@ error[E0282]: type annotations needed --> $DIR/fn-const-param-infer.rs:22:23 | LL | let _ = Checked::; - | ^^^^^^^ cannot infer type for `T` + | ^^^^^^^ cannot infer type for type parameter `T` error[E0308]: mismatched types --> $DIR/fn-const-param-infer.rs:25:40 diff --git a/src/test/ui/consts/issue-64662.stderr b/src/test/ui/consts/issue-64662.stderr index b81daae330b..b3c673ec027 100644 --- a/src/test/ui/consts/issue-64662.stderr +++ b/src/test/ui/consts/issue-64662.stderr @@ -2,13 +2,13 @@ error[E0282]: type annotations needed --> $DIR/issue-64662.rs:2:9 | LL | A = foo(), - | ^^^ cannot infer type for `T` + | ^^^ cannot infer type for type parameter `T` error[E0282]: type annotations needed --> $DIR/issue-64662.rs:3:9 | LL | B = foo(), - | ^^^ cannot infer type for `T` + | ^^^ cannot infer type for type parameter `T` error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0401.stderr b/src/test/ui/error-codes/E0401.stderr index 485b76a09a3..0adf982d71c 100644 --- a/src/test/ui/error-codes/E0401.stderr +++ b/src/test/ui/error-codes/E0401.stderr @@ -36,7 +36,7 @@ error[E0282]: type annotations needed --> $DIR/E0401.rs:11:5 | LL | bfnr(x); - | ^^^^ cannot infer type for `U` + | ^^^^ cannot infer type for type parameter `U` error: aborting due to 4 previous errors diff --git a/src/test/ui/issues/issue-12028.stderr b/src/test/ui/issues/issue-12028.stderr index 5f23b4f559f..5f2dd729c73 100644 --- a/src/test/ui/issues/issue-12028.stderr +++ b/src/test/ui/issues/issue-12028.stderr @@ -2,7 +2,7 @@ error[E0284]: type annotations needed --> $DIR/issue-12028.rs:27:14 | LL | self.input_stream(&mut stream); - | ^^^^^^^^^^^^ cannot infer type for `H` + | ^^^^^^^^^^^^ cannot infer type for type parameter `H` | = note: cannot resolve `<_ as StreamHasher>::S == ::S` diff --git a/src/test/ui/issues/issue-16966.stderr b/src/test/ui/issues/issue-16966.stderr index 13e77fe3073..0d565af79b5 100644 --- a/src/test/ui/issues/issue-16966.stderr +++ b/src/test/ui/issues/issue-16966.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-16966.rs:2:5 | LL | panic!(std::default::Default::default()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `M` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `M` | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/src/test/ui/issues/issue-17551.stderr b/src/test/ui/issues/issue-17551.stderr index ce16f0f58ea..5468268e7de 100644 --- a/src/test/ui/issues/issue-17551.stderr +++ b/src/test/ui/issues/issue-17551.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `B` --> $DIR/issue-17551.rs:6:15 | LL | let foo = B(marker::PhantomData); - | --- ^ cannot infer type for `T` + | --- ^ cannot infer type for type parameter `T` | | | consider giving `foo` the explicit type `B`, where the type parameter `T` is specified diff --git a/src/test/ui/issues/issue-21974.stderr b/src/test/ui/issues/issue-21974.stderr index 4002c1eac2e..b1536bd8ddb 100644 --- a/src/test/ui/issues/issue-21974.stderr +++ b/src/test/ui/issues/issue-21974.stderr @@ -11,7 +11,7 @@ LL | | { LL | | x.foo(); LL | | y.foo(); LL | | } - | |_^ cannot infer type for `&'a T` + | |_^ cannot infer type for reference `&'a T` | = note: cannot resolve `&'a T: Foo` diff --git a/src/test/ui/issues/issue-24424.stderr b/src/test/ui/issues/issue-24424.stderr index 87214f56a1b..8f0850328b4 100644 --- a/src/test/ui/issues/issue-24424.stderr +++ b/src/test/ui/issues/issue-24424.stderr @@ -5,7 +5,7 @@ LL | trait Trait0<'l0> {} | ----------------- required by `Trait0` LL | LL | impl <'l0, 'l1, T0> Trait1<'l0, T0> for bool where T0 : Trait0<'l0>, T0 : Trait0<'l1> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `T0` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T0` | = note: cannot resolve `T0: Trait0<'l0>` diff --git a/src/test/ui/issues/issue-25368.stderr b/src/test/ui/issues/issue-25368.stderr index 0b890b573da..de020d4b56b 100644 --- a/src/test/ui/issues/issue-25368.stderr +++ b/src/test/ui/issues/issue-25368.stderr @@ -5,7 +5,7 @@ LL | let (tx, rx) = channel(); | -------- consider giving this pattern the explicit type `(std::sync::mpsc::Sender>, std::sync::mpsc::Receiver>)`, where the type parameter `T` is specified ... LL | tx.send(Foo{ foo: PhantomData }); - | ^^^ cannot infer type for `T` + | ^^^ cannot infer type for type parameter `T` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-29147.stderr b/src/test/ui/issues/issue-29147.stderr index 4de6a7c8514..1efedb45cac 100644 --- a/src/test/ui/issues/issue-29147.stderr +++ b/src/test/ui/issues/issue-29147.stderr @@ -5,7 +5,7 @@ LL | trait Foo { fn xxx(&self); } | -------------- required by `Foo::xxx` ... LL | let _ = >::xxx; - | ^^^^^^^^^^^^ cannot infer type for `S5<_>` + | ^^^^^^^^^^^^ cannot infer type for struct `S5<_>` | = note: cannot resolve `S5<_>: Foo` diff --git a/src/test/ui/issues/issue-5062.stderr b/src/test/ui/issues/issue-5062.stderr index 0f5c6d8d4bf..a20118d6911 100644 --- a/src/test/ui/issues/issue-5062.stderr +++ b/src/test/ui/issues/issue-5062.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-5062.rs:1:29 | LL | fn main() { format!("{:?}", None); } - | ^^^^ cannot infer type for `T` + | ^^^^ cannot infer type for type parameter `T` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-6458-2.stderr b/src/test/ui/issues/issue-6458-2.stderr index b5da2bf096c..d538a69045f 100644 --- a/src/test/ui/issues/issue-6458-2.stderr +++ b/src/test/ui/issues/issue-6458-2.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-6458-2.rs:3:21 | LL | format!("{:?}", None); - | ^^^^ cannot infer type for `T` + | ^^^^ cannot infer type for type parameter `T` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-6458-3.stderr b/src/test/ui/issues/issue-6458-3.stderr index 784497c959d..6b3f469ee37 100644 --- a/src/test/ui/issues/issue-6458-3.stderr +++ b/src/test/ui/issues/issue-6458-3.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-6458-3.rs:4:5 | LL | mem::transmute(0); - | ^^^^^^^^^^^^^^ cannot infer type for `U` + | ^^^^^^^^^^^^^^ cannot infer type for type parameter `U` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-6458.stderr b/src/test/ui/issues/issue-6458.stderr index d59d872ba93..de315659b6d 100644 --- a/src/test/ui/issues/issue-6458.stderr +++ b/src/test/ui/issues/issue-6458.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-6458.rs:9:4 | LL | foo(TypeWithState(marker::PhantomData)); - | ^^^ cannot infer type for `State` + | ^^^ cannot infer type for type parameter `State` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-65611.stderr b/src/test/ui/issues/issue-65611.stderr index 3be08b233e4..20e2ba144d9 100644 --- a/src/test/ui/issues/issue-65611.stderr +++ b/src/test/ui/issues/issue-65611.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | let x = buffer.last().unwrap().0.clone(); | -------^^^^-- | | | - | | cannot infer type for `T` + | | cannot infer type for type parameter `T` | this method call resolves to `std::option::Option<&T>` | = note: type must be known at this point diff --git a/src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr b/src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr index fcd97647568..f3f3c476809 100644 --- a/src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr +++ b/src/test/ui/methods/method-ambig-one-trait-unknown-int-type.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `std::vec::Vec` --> $DIR/method-ambig-one-trait-unknown-int-type.rs:24:17 | LL | let mut x = Vec::new(); - | ----- ^^^^^^^^ cannot infer type for `T` + | ----- ^^^^^^^^ cannot infer type for type parameter `T` | | | consider giving `x` the explicit type `std::vec::Vec`, where the type parameter `T` is specified diff --git a/src/test/ui/missing/missing-items/missing-type-parameter.stderr b/src/test/ui/missing/missing-items/missing-type-parameter.stderr index dbb467d60f9..be97f2373c3 100644 --- a/src/test/ui/missing/missing-items/missing-type-parameter.stderr +++ b/src/test/ui/missing/missing-items/missing-type-parameter.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/missing-type-parameter.rs:4:5 | LL | foo(); - | ^^^ cannot infer type for `X` + | ^^^ cannot infer type for type parameter `X` error: aborting due to previous error diff --git a/src/test/ui/span/issue-42234-unknown-receiver-type.stderr b/src/test/ui/span/issue-42234-unknown-receiver-type.stderr index 093a6f6f3eb..9824d879dbd 100644 --- a/src/test/ui/span/issue-42234-unknown-receiver-type.stderr +++ b/src/test/ui/span/issue-42234-unknown-receiver-type.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `std::option::Option<_>` LL | let x: Option<_> = None; | - consider giving `x` the explicit type `std::option::Option<_>`, where the type parameter `T` is specified LL | x.unwrap().method_that_could_exist_on_some_type(); - | ^^^^^^ cannot infer type for `T` + | ^^^^^^ cannot infer type for type parameter `T` | = note: type must be known at this point diff --git a/src/test/ui/span/type-annotations-needed-expr.stderr b/src/test/ui/span/type-annotations-needed-expr.stderr index bc1c2f6164b..8366285edcd 100644 --- a/src/test/ui/span/type-annotations-needed-expr.stderr +++ b/src/test/ui/span/type-annotations-needed-expr.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | let _ = (vec![1,2,3]).into_iter().sum() as f64; | ^^^ | | - | cannot infer type for `S` + | cannot infer type for type parameter `S` | help: consider specifying the type argument in the method call: `sum::` | = note: type must be known at this point diff --git a/src/test/ui/traits/traits-multidispatch-convert-ambig-dest.stderr b/src/test/ui/traits/traits-multidispatch-convert-ambig-dest.stderr index d7d27049f43..7bcda234c4b 100644 --- a/src/test/ui/traits/traits-multidispatch-convert-ambig-dest.stderr +++ b/src/test/ui/traits/traits-multidispatch-convert-ambig-dest.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/traits-multidispatch-convert-ambig-dest.rs:26:5 | LL | test(22, std::default::Default::default()); - | ^^^^ cannot infer type for `U` + | ^^^^ cannot infer type for type parameter `U` error: aborting due to previous error diff --git a/src/test/ui/type-inference/or_else-multiple-type-params.stderr b/src/test/ui/type-inference/or_else-multiple-type-params.stderr index a15904d01f6..141cc25ffe2 100644 --- a/src/test/ui/type-inference/or_else-multiple-type-params.stderr +++ b/src/test/ui/type-inference/or_else-multiple-type-params.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | .or_else(|err| { | ^^^^^^^ | | - | cannot infer type for `F` + | cannot infer type for type parameter `F` | help: consider specifying the type arguments in the method call: `or_else::` error: aborting due to previous error diff --git a/src/test/ui/type-inference/sort_by_key.stderr b/src/test/ui/type-inference/sort_by_key.stderr index 76b49ee1f23..1d386bd1f42 100644 --- a/src/test/ui/type-inference/sort_by_key.stderr +++ b/src/test/ui/type-inference/sort_by_key.stderr @@ -4,7 +4,7 @@ error[E0282]: type annotations needed LL | lst.sort_by_key(|&(v, _)| v.iter().sum()); | ^^^^^^^^^^^ --- help: consider specifying the type argument in the method call: `sum::` | | - | cannot infer type for `K` + | cannot infer type for type parameter `K` error: aborting due to previous error diff --git a/src/test/ui/type-inference/unbounded-associated-type.rs b/src/test/ui/type-inference/unbounded-associated-type.rs new file mode 100644 index 00000000000..0167e943612 --- /dev/null +++ b/src/test/ui/type-inference/unbounded-associated-type.rs @@ -0,0 +1,16 @@ +trait T { + type A; + fn foo(&self) -> Self::A { + panic!() + } +} + +struct S(std::marker::PhantomData); + +impl T for S { + type A = X; +} + +fn main() { + S(std::marker::PhantomData).foo(); //~ ERROR type annotations needed +} diff --git a/src/test/ui/type-inference/unbounded-associated-type.stderr b/src/test/ui/type-inference/unbounded-associated-type.stderr new file mode 100644 index 00000000000..726dd4b4758 --- /dev/null +++ b/src/test/ui/type-inference/unbounded-associated-type.stderr @@ -0,0 +1,15 @@ +error[E0282]: type annotations needed + --> $DIR/unbounded-associated-type.rs:15:5 + | +LL | type A; + | ------- `::A` defined here +... +LL | S(std::marker::PhantomData).foo(); + | ^-------------------------------- + | | + | this method call resolves to `::A` + | cannot infer type for type parameter `X` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.rs b/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.rs new file mode 100644 index 00000000000..81d054b3a1e --- /dev/null +++ b/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.rs @@ -0,0 +1,9 @@ +#[allow(invalid_type_param_default)] + +fn foo() -> (T, U) { + panic!() +} + +fn main() { + foo(); //~ ERROR type annotations needed +} diff --git a/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr b/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr new file mode 100644 index 00000000000..52039d0e934 --- /dev/null +++ b/src/test/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr @@ -0,0 +1,9 @@ +error[E0282]: type annotations needed + --> $DIR/unbounded-type-param-in-fn-with-assoc-type.rs:8:5 + | +LL | foo(); + | ^^^ cannot infer type for type parameter `T` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type-inference/unbounded-type-param-in-fn.rs b/src/test/ui/type-inference/unbounded-type-param-in-fn.rs new file mode 100644 index 00000000000..1f336ed59a6 --- /dev/null +++ b/src/test/ui/type-inference/unbounded-type-param-in-fn.rs @@ -0,0 +1,7 @@ +fn foo() -> T { + panic!() +} + +fn main() { + foo(); //~ ERROR type annotations needed +} diff --git a/src/test/ui/type-inference/unbounded-type-param-in-fn.stderr b/src/test/ui/type-inference/unbounded-type-param-in-fn.stderr new file mode 100644 index 00000000000..8d317df6ce9 --- /dev/null +++ b/src/test/ui/type-inference/unbounded-type-param-in-fn.stderr @@ -0,0 +1,9 @@ +error[E0282]: type annotations needed + --> $DIR/unbounded-type-param-in-fn.rs:6:5 + | +LL | foo(); + | ^^^ cannot infer type for type parameter `T` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type/type-annotation-needed.stderr b/src/test/ui/type/type-annotation-needed.stderr index 5b7d6ba16d0..94425440d33 100644 --- a/src/test/ui/type/type-annotation-needed.stderr +++ b/src/test/ui/type/type-annotation-needed.stderr @@ -7,7 +7,7 @@ LL | fn foo>(x: i32) {} LL | foo(42); | ^^^ | | - | cannot infer type for `T` + | cannot infer type for type parameter `T` | help: consider specifying the type argument in the function call: `foo::` | = note: cannot resolve `_: std::convert::Into` diff --git a/src/test/ui/type/type-check/cannot_infer_local_or_vec.stderr b/src/test/ui/type/type-check/cannot_infer_local_or_vec.stderr index 6524bf5dd2b..53cc769bae3 100644 --- a/src/test/ui/type/type-check/cannot_infer_local_or_vec.stderr +++ b/src/test/ui/type/type-check/cannot_infer_local_or_vec.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `std::vec::Vec` --> $DIR/cannot_infer_local_or_vec.rs:2:13 | LL | let x = vec![]; - | - ^^^^^^ cannot infer type for `T` + | - ^^^^^^ cannot infer type for type parameter `T` | | | consider giving `x` the explicit type `std::vec::Vec`, where the type parameter `T` is specified | diff --git a/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr b/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr index 6d1ef240da6..df7228ce9f2 100644 --- a/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr +++ b/src/test/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `(std::vec::Vec,)` --> $DIR/cannot_infer_local_or_vec_in_tuples.rs:2:18 | LL | let (x, ) = (vec![], ); - | ----- ^^^^^^ cannot infer type for `T` + | ----- ^^^^^^ cannot infer type for type parameter `T` | | | consider giving this pattern the explicit type `(std::vec::Vec,)`, where the type parameter `T` is specified | diff --git a/src/test/ui/type/type-check/issue-22897.stderr b/src/test/ui/type/type-check/issue-22897.stderr index 2b3f0696f3c..fae7b79269b 100644 --- a/src/test/ui/type/type-check/issue-22897.stderr +++ b/src/test/ui/type/type-check/issue-22897.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-22897.rs:4:5 | LL | []; - | ^^ cannot infer type for `[_; 0]` + | ^^ cannot infer type for array `[_; 0]` error: aborting due to previous error diff --git a/src/test/ui/type/type-check/issue-40294.stderr b/src/test/ui/type/type-check/issue-40294.stderr index f2bfd9ba541..4fc02855091 100644 --- a/src/test/ui/type/type-check/issue-40294.stderr +++ b/src/test/ui/type/type-check/issue-40294.stderr @@ -11,7 +11,7 @@ LL | | { LL | | x.foo(); LL | | y.foo(); LL | | } - | |_^ cannot infer type for `&'a T` + | |_^ cannot infer type for reference `&'a T` | = note: cannot resolve `&'a T: Foo` diff --git a/src/test/ui/unconstrained-none.stderr b/src/test/ui/unconstrained-none.stderr index eb918b25d2b..6c4fde94a61 100644 --- a/src/test/ui/unconstrained-none.stderr +++ b/src/test/ui/unconstrained-none.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/unconstrained-none.rs:4:5 | LL | None; - | ^^^^ cannot infer type for `T` + | ^^^^ cannot infer type for type parameter `T` error: aborting due to previous error diff --git a/src/test/ui/unconstrained-ref.stderr b/src/test/ui/unconstrained-ref.stderr index d9a129a2d7b..d6985a61daf 100644 --- a/src/test/ui/unconstrained-ref.stderr +++ b/src/test/ui/unconstrained-ref.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/unconstrained-ref.rs:6:5 | LL | S { o: &None }; - | ^ cannot infer type for `T` + | ^ cannot infer type for type parameter `T` error: aborting due to previous error diff --git a/src/test/ui/vector-no-ann.stderr b/src/test/ui/vector-no-ann.stderr index 28100d7c89e..62fc42fbae4 100644 --- a/src/test/ui/vector-no-ann.stderr +++ b/src/test/ui/vector-no-ann.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed for `std::vec::Vec` --> $DIR/vector-no-ann.rs:2:16 | LL | let _foo = Vec::new(); - | ---- ^^^^^^^^ cannot infer type for `T` + | ---- ^^^^^^^^ cannot infer type for type parameter `T` | | | consider giving `_foo` the explicit type `std::vec::Vec`, where the type parameter `T` is specified -- 2.44.0