diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 58c1498faa9de..c9d57706d55ea 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -70,6 +70,7 @@ use std::{cmp, fmt}; mod note; mod need_type_info; +pub use need_type_info::TypeAnnotationNeeded; pub mod nice_region_error; diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 32eecdf01a31f..8878683f3a7a4 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -1,4 +1,4 @@ -use crate::hir::def::Namespace; +use crate::hir::def::{DefKind, Namespace}; use crate::hir::{self, Body, FunctionRetTy, Expr, ExprKind, HirId, Local, Pat}; use crate::hir::intravisit::{self, Visitor, NestedVisitorMap}; use crate::infer::InferCtxt; @@ -6,8 +6,10 @@ use crate::infer::type_variable::TypeVariableOriginKind; use crate::ty::{self, Ty, Infer, TyVar}; use crate::ty::print::Print; use syntax::source_map::DesugaringKind; +use syntax::symbol::kw; use syntax_pos::Span; use errors::{Applicability, DiagnosticBuilder}; +use std::borrow::Cow; use rustc_error_codes::*; @@ -19,6 +21,7 @@ struct FindLocalByTypeVisitor<'a, 'tcx> { found_arg_pattern: Option<&'tcx Pat>, found_ty: Option>, found_closure: Option<&'tcx ExprKind>, + found_method_call: Option<&'tcx Expr>, } impl<'a, 'tcx> FindLocalByTypeVisitor<'a, 'tcx> { @@ -35,6 +38,7 @@ impl<'a, 'tcx> FindLocalByTypeVisitor<'a, 'tcx> { found_arg_pattern: None, found_ty: None, found_closure: None, + found_method_call: None, } } @@ -93,11 +97,12 @@ impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> { } fn visit_expr(&mut self, expr: &'tcx Expr) { - if let (ExprKind::Closure(_, _fn_decl, _id, _sp, _), Some(_)) = ( - &expr.kind, - self.node_matches_type(expr.hir_id), - ) { - self.found_closure = Some(&expr.kind); + if self.node_matches_type(expr.hir_id).is_some() { + match expr.kind { + ExprKind::Closure(..) => self.found_closure = Some(&expr.kind), + ExprKind::MethodCall(..) => self.found_method_call = Some(&expr), + _ => {} + } } intravisit::walk_expr(self, expr); } @@ -109,6 +114,7 @@ fn closure_return_type_suggestion( err: &mut DiagnosticBuilder<'_>, output: &FunctionRetTy, body: &Body, + descr: &str, name: &str, ret: &str, ) { @@ -132,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. @@ -147,17 +153,42 @@ fn closure_args(fn_sig: &ty::PolyFnSig<'_>) -> String { .unwrap_or_default() } +pub enum TypeAnnotationNeeded { + E0282, + E0283, + E0284, +} + +impl Into for TypeAnnotationNeeded { + fn into(self) -> errors::DiagnosticId { + syntax::diagnostic_used!(E0282); + syntax::diagnostic_used!(E0283); + syntax::diagnostic_used!(E0284); + errors::DiagnosticId::Error(match self { + Self::E0282 => "E0282".to_string(), + Self::E0283 => "E0283".to_string(), + Self::E0284 => "E0284".to_string(), + }) + } +} + impl<'a, 'tcx> InferCtxt<'a, 'tcx> { 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 { - return (name.to_string(), Some(var_origin.span)); + if name != kw::SelfUpper { + return ( + name.to_string(), + Some(var_origin.span), + "type parameter".into(), + ); + } } } @@ -167,7 +198,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { printer.region_highlight_mode = highlight; } let _ = ty.print(printer); - (s, None) + (s, None, ty.prefix_string()) } pub fn need_type_info_err( @@ -175,9 +206,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { body_id: Option, span: Span, ty: Ty<'tcx>, + 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 { @@ -185,8 +217,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let mut printer = ty::print::FmtPrinter::new(self.tcx, &mut s, Namespace::TypeNS); let ty_vars = self.type_variables.borrow(); let getter = move |ty_vid| { - if let TypeVariableOriginKind::TypeParameterDefinition(name) = - ty_vars.var_origin(ty_vid).kind { + let var_origin = ty_vars.var_origin(ty_vid); + if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind { return Some(name.to_string()); } None @@ -210,6 +242,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // 3 | let _ = x.sum() as f64; // | ^^^ cannot infer type for `S` span + } else if let Some( + ExprKind::MethodCall(_, call_span, _), + ) = local_visitor.found_method_call.map(|e| &e.kind) { + // Point at the call instead of the whole expression: + // error[E0284]: type annotations needed + // --> file.rs:2:5 + // | + // 2 | vec![Ok(2)].into_iter().collect()?; + // | ^^^^^^^ cannot infer type + // | + // = note: cannot resolve `<_ as std::ops::Try>::Ok == _` + if span.contains(*call_span) { + *call_span + } else { + span + } } else { span }; @@ -247,12 +295,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // | consider giving `b` the explicit type `std::result::Result`, where // | the type parameter `E` is specified // ``` - let mut err = struct_span_err!( - self.tcx.sess, + let error_code = error_code.into(); + let mut err = self.tcx.sess.struct_span_err_with_code( err_span, - E0282, - "type annotations needed{}", - ty_msg, + &format!("type annotations needed{}", ty_msg), + error_code, ); let suffix = match local_visitor.found_ty { @@ -267,6 +314,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { &mut err, &decl.output, &body, + &descr, &name, &ret, ); @@ -334,6 +382,36 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { format!("consider giving this pattern {}", suffix) }; err.span_label(pattern.span, msg); + } else if let Some(e) = local_visitor.found_method_call { + if let ExprKind::MethodCall(segment, ..) = &e.kind { + // Suggest specifiying type params or point out the return type of the call: + // + // error[E0282]: type annotations needed + // --> $DIR/type-annotations-needed-expr.rs:2:39 + // | + // LL | let _ = x.into_iter().sum() as f64; + // | ^^^ + // | | + // | cannot infer type for `S` + // | help: consider specifying the type argument in + // | the method call: `sum::` + // | + // = note: type must be known at this point + // + // or + // + // error[E0282]: type annotations needed + // --> $DIR/issue-65611.rs:59:20 + // | + // LL | let x = buffer.last().unwrap().0.clone(); + // | -------^^^^-- + // | | | + // | | cannot infer type for `T` + // | this method call resolves to `std::option::Option<&T>` + // | + // = note: type must be known at this point + self.annotate_method_call(segment, e, &mut err); + } } // Instead of the following: // error[E0282]: type annotations needed @@ -351,17 +429,66 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // | ^^^ cannot infer type for `S` // | // = note: type must be known at this point - let span = name_sp.unwrap_or(span); + let span = name_sp.unwrap_or(err_span); if !err.span.span_labels().iter().any(|span_label| { 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 } + /// If the `FnSig` for the method call can be found and type arguments are identified as + /// needed, suggest annotating the call, otherwise point out the resulting type of the call. + fn annotate_method_call( + &self, + segment: &hir::ptr::P, + e: &Expr, + err: &mut DiagnosticBuilder<'_>, + ) { + if let (Ok(snippet), Some(tables), None) = ( + self.tcx.sess.source_map().span_to_snippet(segment.ident.span), + self.in_progress_tables, + &segment.args, + ) { + let borrow = tables.borrow(); + if let Some((DefKind::Method, did)) = borrow.type_dependent_def(e.hir_id) { + let generics = self.tcx.generics_of(did); + if !generics.params.is_empty() { + err.span_suggestion( + segment.ident.span, + &format!( + "consider specifying the type argument{} in the method call", + if generics.params.len() > 1 { + "s" + } else { + "" + }, + ), + format!("{}::<{}>", snippet, generics.params.iter() + .map(|p| p.name.to_string()) + .collect::>() + .join(", ")), + Applicability::HasPlaceholders, + ); + } else { + let sig = self.tcx.fn_sig(did); + 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)); + } + } + } + } + } + } + pub fn need_type_info_err_in_generator( &self, kind: hir::GeneratorKind, @@ -369,19 +496,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { 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/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 35017d6330da3..233d195766fe6 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -22,6 +22,7 @@ use crate::hir; use crate::hir::Node; use crate::hir::def_id::DefId; use crate::infer::{self, InferCtxt}; +use crate::infer::error_reporting::TypeAnnotationNeeded as ErrorCode; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::session::DiagnosticMessageId; use crate::ty::{self, AdtKind, DefIdTree, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable}; @@ -1951,7 +1952,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { return; } - match predicate { + let mut err = match predicate { ty::Predicate::Trait(ref data) => { let trait_ref = data.to_poly_trait_ref(); let self_ty = trait_ref.self_ty(); @@ -1985,59 +1986,109 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // avoid inundating the user with unnecessary errors, but we now // check upstream for type errors and dont add the obligations to // begin with in those cases. - if - self.tcx.lang_items().sized_trait() + if self.tcx.lang_items().sized_trait() .map_or(false, |sized_id| sized_id == trait_ref.def_id()) { - self.need_type_info_err(body_id, span, self_ty).emit(); - } else { - let mut err = struct_span_err!( - self.tcx.sess, - span, - E0283, - "type annotations needed: cannot resolve `{}`", - predicate, - ); - self.note_obligation_cause(&mut err, obligation); - err.emit(); + self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0282).emit(); + return; + } + let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0283); + err.note(&format!("cannot resolve `{}`", predicate)); + if let (Ok(ref snippet), ObligationCauseCode::BindingObligation(ref def_id, _)) = ( + self.tcx.sess.source_map().span_to_snippet(span), + &obligation.cause.code, + ) { + let generics = self.tcx.generics_of(*def_id); + if !generics.params.is_empty() && !snippet.ends_with('>'){ + // FIXME: To avoid spurious suggestions in functions where type arguments + // where already supplied, we check the snippet to make sure it doesn't + // end with a turbofish. Ideally we would have access to a `PathSegment` + // instead. Otherwise we would produce the following output: + // + // error[E0283]: type annotations needed + // --> $DIR/issue-54954.rs:3:24 + // | + // LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); + // | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + // | | + // | cannot infer type + // | help: consider specifying the type argument + // | in the function call: + // | `Tt::const_val::<[i8; 123]>::` + // ... + // LL | const fn const_val() -> usize { + // | --------- - required by this bound in `Tt::const_val` + // | + // = note: cannot resolve `_: Tt` + + err.span_suggestion( + span, + &format!( + "consider specifying the type argument{} in the function call", + if generics.params.len() > 1 { + "s" + } else { + "" + }, + ), + format!("{}::<{}>", snippet, generics.params.iter() + .map(|p| p.name.to_string()) + .collect::>() + .join(", ")), + Applicability::HasPlaceholders, + ); + } } + err } ty::Predicate::WellFormed(ty) => { // Same hacky approach as above to avoid deluging user // with error messages. - if !ty.references_error() && !self.tcx.sess.has_errors() { - self.need_type_info_err(body_id, span, ty).emit(); + if ty.references_error() || self.tcx.sess.has_errors() { + return; } + self.need_type_info_err(body_id, span, ty, ErrorCode::E0282) } ty::Predicate::Subtype(ref data) => { if data.references_error() || self.tcx.sess.has_errors() { // no need to overload user in such cases - } else { - let &SubtypePredicate { a_is_expected: _, a, b } = data.skip_binder(); - // both must be type variables, or the other would've been instantiated - assert!(a.is_ty_var() && b.is_ty_var()); - self.need_type_info_err(body_id, - obligation.cause.span, - a).emit(); + return } + let &SubtypePredicate { a_is_expected: _, a, b } = data.skip_binder(); + // both must be type variables, or the other would've been instantiated + assert!(a.is_ty_var() && b.is_ty_var()); + self.need_type_info_err(body_id, span, a, ErrorCode::E0282) + } + ty::Predicate::Projection(ref data) => { + let trait_ref = data.to_poly_trait_ref(self.tcx); + let self_ty = trait_ref.self_ty(); + if predicate.references_error() { + return; + } + let mut err = self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0284); + err.note(&format!("cannot resolve `{}`", predicate)); + err } _ => { - if !self.tcx.sess.has_errors() { - let mut err = struct_span_err!( - self.tcx.sess, - obligation.cause.span, - E0284, - "type annotations needed: cannot resolve `{}`", - predicate, - ); - self.note_obligation_cause(&mut err, obligation); - err.emit(); + if self.tcx.sess.has_errors() { + return; } + let mut err = struct_span_err!( + self.tcx.sess, + span, + E0284, + "type annotations needed: cannot resolve `{}`", + predicate, + ); + err.span_label(span, &format!("cannot resolve `{}`", predicate)); + err } - } + }; + self.note_obligation_cause(&mut err, obligation); + err.emit(); } /// Returns `true` if the trait predicate may apply for *some* assignment diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 5bfc60c754067..fc7d19766373a 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -871,6 +871,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr) { Ok(method) => { + // We could add a "consider `foo::`" suggestion here, but I wasn't able to + // trigger this codepath causing `structuraly_resolved_type` to emit an error. + self.write_method_call(expr.hir_id, method); Ok(method) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a956aba4f62b9..43e7bbcf0c0dc 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -103,6 +103,7 @@ use rustc_index::vec::Idx; use rustc_target::spec::abi::Abi; use rustc::infer::opaque_types::OpaqueTypeDecl; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; +use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc::middle::region; use rustc::mir::interpret::{ConstValue, GlobalId}; @@ -5359,7 +5360,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty } else { if !self.is_tainted_by_errors() { - self.need_type_info_err((**self).body_id, sp, ty) + self.need_type_info_err((**self).body_id, sp, ty, E0282) .note("type must be known at this point") .emit(); } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 3113e9b241daa..35f25b322e053 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -8,6 +8,7 @@ use rustc::hir; use rustc::hir::def_id::{DefId, DefIndex}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc::infer::InferCtxt; +use rustc::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc::ty::adjustment::{Adjust, Adjustment, PointerCast}; use rustc::ty::fold::{TypeFoldable, TypeFolder}; use rustc::ty::{self, Ty, TyCtxt}; @@ -717,7 +718,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> { fn report_error(&self, t: Ty<'tcx>) { if !self.tcx.sess.has_errors() { self.infcx - .need_type_info_err(Some(self.body.id()), self.span.to_span(self.tcx), t) + .need_type_info_err(Some(self.body.id()), self.span.to_span(self.tcx), t, E0282) .emit(); } } diff --git a/src/test/ui/associated-const/issue-63496.rs b/src/test/ui/associated-const/issue-63496.rs index 311c48b5e48c5..f9f663af5e265 100644 --- a/src/test/ui/associated-const/issue-63496.rs +++ b/src/test/ui/associated-const/issue-63496.rs @@ -2,8 +2,8 @@ trait A { const C: usize; fn f() -> ([u8; A::C], [u8; A::C]); - //~^ ERROR: type annotations needed: cannot resolve - //~| ERROR: type annotations needed: cannot resolve + //~^ ERROR: type annotations needed + //~| ERROR: type annotations needed } fn main() {} diff --git a/src/test/ui/associated-const/issue-63496.stderr b/src/test/ui/associated-const/issue-63496.stderr index 70bb12de1fb72..23916a3ba440c 100644 --- a/src/test/ui/associated-const/issue-63496.stderr +++ b/src/test/ui/associated-const/issue-63496.stderr @@ -1,20 +1,24 @@ -error[E0283]: type annotations needed: cannot resolve `_: A` +error[E0283]: type annotations needed --> $DIR/issue-63496.rs:4:21 | LL | const C: usize; | --------------- required by `A::C` LL | LL | fn f() -> ([u8; A::C], [u8; A::C]); - | ^^^^ + | ^^^^ cannot infer type + | + = note: cannot resolve `_: A` -error[E0283]: type annotations needed: cannot resolve `_: A` +error[E0283]: type annotations needed --> $DIR/issue-63496.rs:4:33 | LL | const C: usize; | --------------- required by `A::C` LL | LL | fn f() -> ([u8; A::C], [u8; A::C]); - | ^^^^ + | ^^^^ cannot infer type + | + = note: cannot resolve `_: A` error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-item/issue-48027.stderr b/src/test/ui/associated-item/issue-48027.stderr index 562146a426d23..9c825d593d3e4 100644 --- a/src/test/ui/associated-item/issue-48027.stderr +++ b/src/test/ui/associated-item/issue-48027.stderr @@ -7,13 +7,15 @@ LL | const X: usize; LL | impl dyn Bar {} | ^^^^^^^ the trait `Bar` cannot be made into an object -error[E0283]: type annotations needed: cannot resolve `_: Bar` +error[E0283]: type annotations needed --> $DIR/issue-48027.rs:3:32 | LL | const X: usize; | --------------- required by `Bar::X` LL | fn return_n(&self) -> [u8; Bar::X]; - | ^^^^^^ + | ^^^^^^ cannot infer type + | + = note: cannot resolve `_: Bar` error: aborting due to 2 previous errors 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 5ef1b23cbcd21..069da955b674e 100644 --- a/src/test/ui/associated-types/associated-types-overridden-binding.stderr +++ b/src/test/ui/associated-types/associated-types-overridden-binding.stderr @@ -1,18 +1,23 @@ -error[E0284]: type annotations needed: cannot resolve `::Item == i32` +error[E0284]: type annotations needed --> $DIR/associated-types-overridden-binding.rs:4:1 | LL | trait Foo: Iterator {} | ------------------------------- required by `Foo` LL | trait Bar: Foo {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` + | + = note: cannot resolve `::Item == i32` -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> $DIR/associated-types-overridden-binding.rs:7:1 | +LL | trait I32Iterator = Iterator; + | ----------------------------------------- required by `I32Iterator` LL | trait U32Iterator = I32Iterator; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self` + | + = note: cannot resolve `::Item == i32` error: aborting due to 2 previous errors -Some errors have detailed explanations: E0282, E0284. -For more information about an error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0284`. diff --git a/src/test/ui/associated-types/associated-types-unconstrained.stderr b/src/test/ui/associated-types/associated-types-unconstrained.stderr index 4e9e54d368805..14ce4836f97f8 100644 --- a/src/test/ui/associated-types/associated-types-unconstrained.stderr +++ b/src/test/ui/associated-types/associated-types-unconstrained.stderr @@ -1,8 +1,10 @@ -error[E0284]: type annotations needed: cannot resolve `<_ as Foo>::A == _` +error[E0284]: type annotations needed --> $DIR/associated-types-unconstrained.rs:14:20 | LL | let x: isize = Foo::bar(); - | ^^^^^^^^ + | ^^^^^^^^ cannot infer type + | + = note: cannot resolve `<_ as Foo>::A == _` error: aborting due to previous error diff --git a/src/test/ui/async-await/unresolved_type_param.rs b/src/test/ui/async-await/unresolved_type_param.rs index 2876f9fea0e00..79c043b701ddb 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 c7866fc774415..b9b4f5133b9a7 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 32adc63156a37..8379cbd4908e9 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 2d9b6edb8a26a..9ccad7bcdd7e6 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 b81daae330bfa..b3c673ec027ef 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/E0283.stderr b/src/test/ui/error-codes/E0283.stderr index aba649d83ec01..ae5b7c3ae8f67 100644 --- a/src/test/ui/error-codes/E0283.stderr +++ b/src/test/ui/error-codes/E0283.stderr @@ -1,11 +1,13 @@ -error[E0283]: type annotations needed: cannot resolve `_: Generator` +error[E0283]: type annotations needed --> $DIR/E0283.rs:18:21 | LL | fn create() -> u32; | ------------------- required by `Generator::create` ... LL | let cont: u32 = Generator::create(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: cannot resolve `_: Generator` error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0401.stderr b/src/test/ui/error-codes/E0401.stderr index 485b76a09a3c4..0adf982d71c90 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 ff92d01a69ed2..5f2dd729c739f 100644 --- a/src/test/ui/issues/issue-12028.stderr +++ b/src/test/ui/issues/issue-12028.stderr @@ -1,8 +1,10 @@ -error[E0284]: type annotations needed: cannot resolve `<_ as StreamHasher>::S == ::S` +error[E0284]: type annotations needed --> $DIR/issue-12028.rs:27:14 | LL | self.input_stream(&mut stream); - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ cannot infer type for type parameter `H` + | + = note: cannot resolve `<_ as StreamHasher>::S == ::S` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-16966.stderr b/src/test/ui/issues/issue-16966.stderr index 13e77fe3073ca..0d565af79b5de 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 ce16f0f58eaf0..5468268e7de94 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 7ceb2bd23f6cd..b1536bd8ddb0a 100644 --- a/src/test/ui/issues/issue-21974.stderr +++ b/src/test/ui/issues/issue-21974.stderr @@ -1,4 +1,4 @@ -error[E0283]: type annotations needed: cannot resolve `&'a T: Foo` +error[E0283]: type annotations needed --> $DIR/issue-21974.rs:10:1 | LL | trait Foo { @@ -11,7 +11,9 @@ LL | | { LL | | x.foo(); LL | | y.foo(); LL | | } - | |_^ + | |_^ cannot infer type for reference `&'a T` + | + = note: cannot resolve `&'a T: Foo` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-24424.rs b/src/test/ui/issues/issue-24424.rs index 9b74cd1230e8a..22bf513afe891 100644 --- a/src/test/ui/issues/issue-24424.rs +++ b/src/test/ui/issues/issue-24424.rs @@ -2,6 +2,6 @@ trait Trait1<'l0, T0> {} trait Trait0<'l0> {} impl <'l0, 'l1, T0> Trait1<'l0, T0> for bool where T0 : Trait0<'l0>, T0 : Trait0<'l1> {} -//~^ ERROR type annotations needed: cannot resolve `T0: Trait0<'l0>` +//~^ ERROR type annotations needed fn main() {} diff --git a/src/test/ui/issues/issue-24424.stderr b/src/test/ui/issues/issue-24424.stderr index 8c539f7cedd19..8f0850328b446 100644 --- a/src/test/ui/issues/issue-24424.stderr +++ b/src/test/ui/issues/issue-24424.stderr @@ -1,11 +1,13 @@ -error[E0283]: type annotations needed: cannot resolve `T0: Trait0<'l0>` +error[E0283]: type annotations needed --> $DIR/issue-24424.rs:4:1 | 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 type parameter `T0` + | + = note: cannot resolve `T0: Trait0<'l0>` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-25368.stderr b/src/test/ui/issues/issue-25368.stderr index 0b890b573da13..de020d4b56ba1 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.rs b/src/test/ui/issues/issue-29147.rs index 7ec96b97eef07..271bc526033d4 100644 --- a/src/test/ui/issues/issue-29147.rs +++ b/src/test/ui/issues/issue-29147.rs @@ -18,5 +18,5 @@ impl Foo for S5 { fn xxx(&self) {} } impl Foo for S5 { fn xxx(&self) {} } fn main() { - let _ = >::xxx; //~ ERROR cannot resolve `S5<_>: Foo` + let _ = >::xxx; //~ ERROR type annotations needed } diff --git a/src/test/ui/issues/issue-29147.stderr b/src/test/ui/issues/issue-29147.stderr index c9dd92fca7dc8..1efedb45cace7 100644 --- a/src/test/ui/issues/issue-29147.stderr +++ b/src/test/ui/issues/issue-29147.stderr @@ -1,11 +1,13 @@ -error[E0283]: type annotations needed: cannot resolve `S5<_>: Foo` +error[E0283]: type annotations needed --> $DIR/issue-29147.rs:21:13 | LL | trait Foo { fn xxx(&self); } | -------------- required by `Foo::xxx` ... LL | let _ = >::xxx; - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ cannot infer type for struct `S5<_>` + | + = note: cannot resolve `S5<_>: Foo` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-5062.stderr b/src/test/ui/issues/issue-5062.stderr index 0f5c6d8d4bf9a..a20118d691170 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-54954.stderr b/src/test/ui/issues/issue-54954.stderr index 56ccdaf7aac40..d99a5772e8a4c 100644 --- a/src/test/ui/issues/issue-54954.stderr +++ b/src/test/ui/issues/issue-54954.stderr @@ -4,14 +4,16 @@ error[E0379]: trait fns cannot be declared const LL | const fn const_val() -> usize { | ^^^^^ trait fns cannot be const -error[E0283]: type annotations needed: cannot resolve `_: Tt` +error[E0283]: type annotations needed --> $DIR/issue-54954.rs:3:24 | LL | const ARR_LEN: usize = Tt::const_val::<[i8; 123]>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type ... LL | const fn const_val() -> usize { | --------- - required by this bound in `Tt::const_val` + | + = note: cannot resolve `_: Tt` error[E0080]: evaluation of constant value failed --> $DIR/issue-54954.rs:13:15 diff --git a/src/test/ui/issues/issue-58022.rs b/src/test/ui/issues/issue-58022.rs index 30527903ed0f2..e4b9b3b53a69e 100644 --- a/src/test/ui/issues/issue-58022.rs +++ b/src/test/ui/issues/issue-58022.rs @@ -2,7 +2,7 @@ pub trait Foo: Sized { const SIZE: usize; fn new(slice: &[u8; Foo::SIZE]) -> Self; - //~^ ERROR: type annotations needed: cannot resolve `_: Foo` + //~^ ERROR: type annotations needed } pub struct Bar(T); diff --git a/src/test/ui/issues/issue-58022.stderr b/src/test/ui/issues/issue-58022.stderr index a3e4cb6320240..ef0d66d7ad6d1 100644 --- a/src/test/ui/issues/issue-58022.stderr +++ b/src/test/ui/issues/issue-58022.stderr @@ -4,14 +4,16 @@ error[E0423]: expected function, tuple struct or tuple variant, found trait `Foo LL | Foo(Box::new(*slice)) | ^^^ not a function, tuple struct or tuple variant -error[E0283]: type annotations needed: cannot resolve `_: Foo` +error[E0283]: type annotations needed --> $DIR/issue-58022.rs:4:25 | LL | const SIZE: usize; | ------------------ required by `Foo::SIZE` LL | LL | fn new(slice: &[u8; Foo::SIZE]) -> Self; - | ^^^^^^^^^ + | ^^^^^^^^^ cannot infer type + | + = note: cannot resolve `_: Foo` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-6458-2.stderr b/src/test/ui/issues/issue-6458-2.stderr index b5da2bf096cb3..d538a69045f32 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 784497c959d6c..6b3f469ee3789 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 d59d872ba93b0..de315659b6df9 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 cb441c13c6b9e..20e2ba144d926 100644 --- a/src/test/ui/issues/issue-65611.stderr +++ b/src/test/ui/issues/issue-65611.stderr @@ -2,7 +2,10 @@ error[E0282]: type annotations needed --> $DIR/issue-65611.rs:59:20 | 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 fcd976475686f..f3f3c4768095c 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 dbb467d60f9ec..be97f2373c313 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/question-mark-type-infer.rs b/src/test/ui/question-mark-type-infer.rs index 95ee01a70cead..2ef8618192f6b 100644 --- a/src/test/ui/question-mark-type-infer.rs +++ b/src/test/ui/question-mark-type-infer.rs @@ -9,7 +9,7 @@ fn f(x: &i32) -> Result { fn g() -> Result, ()> { let l = [1, 2, 3, 4]; - l.iter().map(f).collect()? //~ ERROR type annotations needed: cannot resolve + l.iter().map(f).collect()? //~ ERROR type annotations needed } fn main() { diff --git a/src/test/ui/question-mark-type-infer.stderr b/src/test/ui/question-mark-type-infer.stderr index 53a170e7d431c..7911701946cd3 100644 --- a/src/test/ui/question-mark-type-infer.stderr +++ b/src/test/ui/question-mark-type-infer.stderr @@ -1,8 +1,13 @@ -error[E0284]: type annotations needed: cannot resolve `<_ as std::ops::Try>::Ok == _` - --> $DIR/question-mark-type-infer.rs:12:5 +error[E0284]: type annotations needed + --> $DIR/question-mark-type-infer.rs:12:21 | LL | l.iter().map(f).collect()? - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ + | | + | cannot infer type + | help: consider specifying the type argument in the method call: `collect::` + | + = note: cannot resolve `<_ as std::ops::Try>::Ok == _` error: aborting due to previous error diff --git a/src/test/ui/span/issue-42234-unknown-receiver-type.rs b/src/test/ui/span/issue-42234-unknown-receiver-type.rs index 58138e21bc097..d3292bbecbaaa 100644 --- a/src/test/ui/span/issue-42234-unknown-receiver-type.rs +++ b/src/test/ui/span/issue-42234-unknown-receiver-type.rs @@ -9,8 +9,8 @@ fn shines_a_beacon_through_the_darkness() { } fn courier_to_des_moines_and_points_west(data: &[u32]) -> String { - data.iter() //~ ERROR type annotations needed - .sum::<_>() + data.iter() + .sum::<_>() //~ ERROR type annotations needed .to_string() } 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 30c9adb1dce72..9824d879dbdd2 100644 --- a/src/test/ui/span/issue-42234-unknown-receiver-type.stderr +++ b/src/test/ui/span/issue-42234-unknown-receiver-type.stderr @@ -4,16 +4,15 @@ 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 error[E0282]: type annotations needed - --> $DIR/issue-42234-unknown-receiver-type.rs:12:5 + --> $DIR/issue-42234-unknown-receiver-type.rs:13:10 | -LL | / data.iter() -LL | | .sum::<_>() - | |___________________^ cannot infer type +LL | .sum::<_>() + | ^^^ cannot infer type | = 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 e32a542bb7a8c..8366285edcda8 100644 --- a/src/test/ui/span/type-annotations-needed-expr.stderr +++ b/src/test/ui/span/type-annotations-needed-expr.stderr @@ -2,7 +2,10 @@ error[E0282]: type annotations needed --> $DIR/type-annotations-needed-expr.rs:2:39 | 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/trait-static-method-generic-inference.stderr b/src/test/ui/traits/trait-static-method-generic-inference.stderr index 22931c5ba32e9..f9718dac3547d 100644 --- a/src/test/ui/traits/trait-static-method-generic-inference.stderr +++ b/src/test/ui/traits/trait-static-method-generic-inference.stderr @@ -1,11 +1,13 @@ -error[E0283]: type annotations needed: cannot resolve `_: base::HasNew` +error[E0283]: type annotations needed --> $DIR/trait-static-method-generic-inference.rs:24:25 | LL | fn new() -> T; | -------------- required by `base::HasNew::new` ... LL | let _f: base::Foo = base::HasNew::new(); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: cannot resolve `_: base::HasNew` error: aborting due to previous error 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 d7d27049f431b..7bcda234c4b0d 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.rs b/src/test/ui/type-inference/or_else-multiple-type-params.rs new file mode 100644 index 0000000000000..b15de2a4559d5 --- /dev/null +++ b/src/test/ui/type-inference/or_else-multiple-type-params.rs @@ -0,0 +1,10 @@ +use std::process::{Command, Stdio}; + +fn main() { + let process = Command::new("wc") + .stdout(Stdio::piped()) + .spawn() + .or_else(|err| { //~ ERROR type annotations needed + panic!("oh no: {:?}", err); + }).unwrap(); +} 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 new file mode 100644 index 0000000000000..141cc25ffe22d --- /dev/null +++ b/src/test/ui/type-inference/or_else-multiple-type-params.stderr @@ -0,0 +1,12 @@ +error[E0282]: type annotations needed + --> $DIR/or_else-multiple-type-params.rs:7:10 + | +LL | .or_else(|err| { + | ^^^^^^^ + | | + | 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 + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/type-inference/sort_by_key.rs b/src/test/ui/type-inference/sort_by_key.rs new file mode 100644 index 0000000000000..afc4d90b8650f --- /dev/null +++ b/src/test/ui/type-inference/sort_by_key.rs @@ -0,0 +1,5 @@ +fn main() { + let mut lst: [([i32; 10], bool); 10] = [([0; 10], false); 10]; + lst.sort_by_key(|&(v, _)| v.iter().sum()); //~ ERROR type annotations needed + println!("{:?}", lst); +} diff --git a/src/test/ui/type-inference/sort_by_key.stderr b/src/test/ui/type-inference/sort_by_key.stderr new file mode 100644 index 0000000000000..1d386bd1f42c9 --- /dev/null +++ b/src/test/ui/type-inference/sort_by_key.stderr @@ -0,0 +1,11 @@ +error[E0282]: type annotations needed + --> $DIR/sort_by_key.rs:3:9 + | +LL | lst.sort_by_key(|&(v, _)| v.iter().sum()); + | ^^^^^^^^^^^ --- help: consider specifying the type argument in the method call: `sum::` + | | + | cannot infer type for type parameter `K` + +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-associated-type.rs b/src/test/ui/type-inference/unbounded-associated-type.rs new file mode 100644 index 0000000000000..0167e943612d0 --- /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 0000000000000..726dd4b475817 --- /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 0000000000000..81d054b3a1e07 --- /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 0000000000000..52039d0e934e6 --- /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 0000000000000..1f336ed59a6dd --- /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 0000000000000..8d317df6ce95a --- /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.rs b/src/test/ui/type/type-annotation-needed.rs index 3b1521d5c028b..a420515be496d 100644 --- a/src/test/ui/type/type-annotation-needed.rs +++ b/src/test/ui/type/type-annotation-needed.rs @@ -5,4 +5,6 @@ fn foo>(x: i32) {} fn main() { foo(42); //~^ ERROR type annotations needed + //~| NOTE cannot infer type + //~| NOTE cannot resolve } diff --git a/src/test/ui/type/type-annotation-needed.stderr b/src/test/ui/type/type-annotation-needed.stderr index 460bbe9dbc4f9..94425440d333c 100644 --- a/src/test/ui/type/type-annotation-needed.stderr +++ b/src/test/ui/type/type-annotation-needed.stderr @@ -1,4 +1,4 @@ -error[E0283]: type annotations needed: cannot resolve `_: std::convert::Into` +error[E0283]: type annotations needed --> $DIR/type-annotation-needed.rs:6:5 | LL | fn foo>(x: i32) {} @@ -6,6 +6,11 @@ LL | fn foo>(x: i32) {} ... LL | foo(42); | ^^^ + | | + | cannot infer type for type parameter `T` + | help: consider specifying the type argument in the function call: `foo::` + | + = note: cannot resolve `_: std::convert::Into` error: aborting due to previous error 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 6524bf5dd2bc5..53cc769bae3cf 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 6d1ef240da60c..df7228ce9f2a8 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 2b3f0696f3c22..fae7b79269bec 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 508783aaf2b0e..4fc0285509149 100644 --- a/src/test/ui/type/type-check/issue-40294.stderr +++ b/src/test/ui/type/type-check/issue-40294.stderr @@ -1,4 +1,4 @@ -error[E0283]: type annotations needed: cannot resolve `&'a T: Foo` +error[E0283]: type annotations needed --> $DIR/issue-40294.rs:5:1 | LL | trait Foo: Sized { @@ -11,7 +11,9 @@ LL | | { LL | | x.foo(); LL | | y.foo(); LL | | } - | |_^ + | |_^ cannot infer type for reference `&'a T` + | + = note: cannot resolve `&'a T: Foo` error: aborting due to previous error diff --git a/src/test/ui/unconstrained-none.stderr b/src/test/ui/unconstrained-none.stderr index eb918b25d2bef..6c4fde94a6199 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 d9a129a2d7b22..d6985a61daf0b 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 28100d7c89e71..62fc42fbae463 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