From 7617fb98827585bfe592973b8c9314f99d902dd4 Mon Sep 17 00:00:00 2001 From: albab-hasan Date: Mon, 20 Jul 2026 14:41:38 +0600 Subject: [PATCH 1/3] merge ambiguity errors that blame the same inference variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit multiple `FulfillmentErrorCode::Ambiguity` obligations on the same inference variable only ever reported the first — the rest got dropped after `set_tainted_by_errors` fired. grouped them by sub-unification-table root and fold Trait/Projection predicates from the group into notes on the primary. uses the sub root not the raw TyVid so variables unified by a pending Coerce obligation correctly land in the same group. fixes https://github.com/rust-lang/rust/issues/103911 --- .../src/error_reporting/traits/ambiguity.rs | 105 +++++++++-- .../src/error_reporting/traits/mod.rs | 96 +++++++++- compiler/rustc_type_ir/src/solve/mod.rs | 7 +- .../duplicate-bound-err.stderr | 3 + .../unique-closure-type-mismatch.stderr | 3 + ...-on-failed-eval-with-vars-fail.next.stderr | 1 + tests/ui/error-codes/E0283.stderr | 2 + .../span-format_args-issue-140578.stderr | 10 ++ ...ambig-hr-projection-issue-93340.old.stderr | 2 + .../bugs/issue-88382.stderr | 1 + .../bugs/issue-91762.stderr | 1 + ...eck-in-selection-6-ambig-unify.next.stderr | 1 + ...heck-in-selection-6-ambig-unify.old.stderr | 1 + ...-in-higher-ranked-fn-signature.next.stderr | 1 + .../auto-trait-selection-freeze.old.stderr | 1 + .../auto-trait-selection.old.stderr | 1 + .../cross-return-site-inference.stderr | 4 + .../opaque-cast-field-access-in-future.stderr | 1 + tests/ui/impl-trait/where-allowed.stderr | 1 + .../ambiguity-errors-single-diagnostic.rs | 25 +++ .../ambiguity-errors-single-diagnostic.stderr | 60 +++++++ tests/ui/inference/cannot-infer-async.stderr | 1 + .../cannot-infer-closure-circular.stderr | 1 + .../ui/inference/cannot-infer-closure.stderr | 1 + ...nnot-infer-iterator-sum-return-type.stderr | 1 + .../cannot-infer-partial-try-return.stderr | 1 + tests/ui/inference/issue-12028.stderr | 1 + tests/ui/inference/issue-70082.stderr | 2 + tests/ui/inference/issue-71584.stderr | 2 + tests/ui/inference/issue-71732.stderr | 3 + tests/ui/inference/issue-72616.stderr | 2 + tests/ui/inference/issue-72690.rs | 8 - tests/ui/inference/issue-72690.stderr | 170 ++---------------- tests/ui/inference/issue-80816.rs | 1 + tests/ui/inference/issue-80816.stderr | 1 + ...745-avoid-expr-from-macro-expansion.stderr | 2 + .../single-type-generic-suggestion.stderr | 1 + .../inference/question-mark-type-infer.stderr | 9 + .../question-mark-type-inference-in-chain.rs | 3 + ...estion-mark-type-inference-in-chain.stderr | 15 +- ...method-ambig-one-trait-unknown-int-type.rs | 2 +- ...od-ambig-one-trait-unknown-int-type.stderr | 25 +-- .../infer-unwrap-none-issue-120786.rs | 8 - .../infer-unwrap-none-issue-120786.stderr | 170 ++---------------- .../pattern/slice-patterns-irrefutable.stderr | 1 + .../types/into-inference-needs-type.stderr | 3 + ...gument-with-unnecessary-method-call.stderr | 1 + ...rojection-predicate-not-satisfied-69455.rs | 1 - ...ction-predicate-not-satisfied-69455.stderr | 28 +-- tests/ui/traits/issue-77982.rs | 1 - tests/ui/traits/issue-77982.stderr | 34 ++-- .../multidispatch-convert-ambig-dest.stderr | 1 + .../runaway-impl-candidate-selection.stderr | 1 + ...to_ignores_unnormalizable_candidate.stderr | 1 + ...expected-pointer-deref-issue-154568.stderr | 2 + .../next-solver/well-formed-in-relate.stderr | 1 + .../index-expr-ambiguous-type.stderr | 7 + .../or_else-multiple-type-params.stderr | 1 + .../panic-with-unspecified-type.stderr | 2 + .../send-with-unspecified-type.stderr | 1 + tests/ui/type-inference/sort_by_key.stderr | 1 + ...pe-inference-for-associated-types-69683.rs | 1 - ...nference-for-associated-types-69683.stderr | 34 +--- 63 files changed, 421 insertions(+), 458 deletions(-) create mode 100644 tests/ui/inference/ambiguity-errors-single-diagnostic.rs create mode 100644 tests/ui/inference/ambiguity-errors-single-diagnostic.stderr diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index ec855b4debd04..43b337d005bbe 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -20,8 +20,8 @@ use tracing::{debug, instrument}; use crate::error_reporting::TypeErrCtxt; use crate::error_reporting::infer::need_type_info::TypeAnnotationNeeded; use crate::error_reporting::traits::{FindExprBySpan, to_pretty_impl_header}; -use crate::traits::ObligationCtxt; use crate::traits::query::evaluate_obligation::InferCtxtExt; +use crate::traits::{FulfillmentError, ObligationCtxt}; #[derive(Debug)] pub enum CandidateSource { @@ -174,10 +174,43 @@ pub fn compute_applicable_impls_for_diagnostics<'tcx>( } impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { + /// The term of an ambiguous obligation's predicate that gets blamed for the + /// missing type annotation: the first one still containing inference variables. + /// + /// Besides `maybe_report_ambiguity` pointing its diagnostics at this term, + /// `report_fulfillment_errors` merges the ambiguity errors whose blamed terms + /// share an inference variable into a single diagnostic. + pub(super) fn ambiguity_term(&self, predicate: ty::Predicate<'tcx>) -> Option> { + match predicate.kind().skip_binder() { + ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => data + .trait_ref + .args + .iter() + .filter_map(ty::GenericArg::as_term) + .find(|term| term.has_non_region_infer()), + ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => data + .projection_term + .args + .iter() + .filter_map(ty::GenericArg::as_term) + .chain([data.term]) + .find(|term| term.has_non_region_infer()), + ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) => Some(term), + ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(data)) => { + data.walk().filter_map(ty::GenericArg::as_term).find(|term| term.is_infer()) + } + ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, _)) => Some(ct.into()), + ty::PredicateKind::Subtype(data) => Some(data.a.into()), + ty::PredicateKind::NormalizesTo(data) if data.term.is_infer() => Some(data.term), + _ => None, + } + } + #[instrument(skip(self), level = "debug")] pub(super) fn maybe_report_ambiguity( &self, obligation: &PredicateObligation<'tcx>, + related: &[&FulfillmentError<'tcx>], ) -> ErrorGuaranteed { // Unable to successfully determine, probably means // insufficient type information, but could mean @@ -255,12 +288,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // Pick the first generic parameter that still contains inference variables as the one // we're going to emit an error for. If there are none (see above), fall back to // a more general error. - let term = data - .trait_ref - .args - .iter() - .filter_map(ty::GenericArg::as_term) - .find(|s| s.has_non_region_infer()); + let term = self.ambiguity_term(predicate); let mut err = if let Some(term) = term { let candidates: Vec<_> = self @@ -590,13 +618,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // other `Foo` impls are incoherent. return guar; } - let term = data - .projection_term - .args - .iter() - .filter_map(ty::GenericArg::as_term) - .chain([data.term]) - .find(|g| g.has_non_region_infer()); + let term = self.ambiguity_term(predicate); let predicate = self.tcx.short_string(predicate, &mut long_ty_path); if let Some(term) = term { self.emit_inference_failure_err( @@ -621,16 +643,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } - ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(data)) => { + ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(_)) => { if let Err(e) = predicate.error_reported() { return e; } if let Some(e) = self.tainted_by_errors() { return e; } - let term = - data.walk().filter_map(ty::GenericArg::as_term).find(|term| term.is_infer()); - if let Some(term) = term { + if let Some(term) = self.ambiguity_term(predicate) { self.emit_inference_failure_err( obligation.cause.body_def_id, span, @@ -713,6 +733,55 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .with_long_ty_path(long_ty_path) } }; + + // The related obligations are ambiguous because of the same inference variable, + // so they belong to this diagnostic: annotating the variable has to satisfy all + // of them at once. Mention their requirements, except for bookkeeping predicates + // (`WellFormed`, sizedness, ...) whose mention wouldn't be actionable. + let mut mentioned = vec![predicate]; + let mut mentioned_strs: Vec = vec![]; + for &error in related { + let related_pred = self.resolve_vars_if_possible(error.obligation.predicate); + if mentioned.contains(&related_pred) { + continue; + } + let note = match related_pred.kind().skip_binder() { + ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) + if !matches!( + self.tcx.as_lang_item(data.def_id()), + Some(LangItem::Sized | LangItem::MetaSized | LangItem::PointeeSized) + ) => + { + let clause = related_pred.kind().rebind(data); + if let ty::Infer(_) = clause.self_ty().skip_binder().kind() { + let tr = self.tcx.short_string( + clause.print_modifiers_and_trait_path(), + &mut err.long_ty_path(), + ); + format!("the type must also implement `{tr}`") + } else { + let pred = self.tcx.short_string(related_pred, &mut err.long_ty_path()); + format!("cannot satisfy `{pred}`") + } + } + ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => { + let pred = self.tcx.short_string(related_pred, &mut err.long_ty_path()); + format!("cannot satisfy `{pred}`") + } + _ => { + mentioned.push(related_pred); + continue; + } + }; + // Two predicates can print identically (e.g. `From` and `From` both show as + // `From<_>`); only emit each unique note string once. + if !mentioned_strs.contains(¬e) { + err.note(note.clone()); + mentioned_strs.push(note); + } + mentioned.push(related_pred); + } + self.note_obligation_cause(&mut err, obligation); err.emit() } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index 76b4900367bde..1b67314a95b45 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -11,6 +11,7 @@ use rustc_crate_store::{ExternCrate, ExternCrateSource}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::unord::UnordSet; use rustc_errors::{Applicability, Diag, E0038, E0276, MultiSpan, struct_span_code_err}; +use rustc_hir::attrs::lang_items::LangItem; use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::intravisit::Visitor; use rustc_hir::{self as hir, AmbigArg}; @@ -21,6 +22,7 @@ use rustc_infer::traits::{ }; use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt as _}; +use rustc_next_trait_solver::solve::TyOrConstInferVar; use rustc_span::{DesugaringKind, ErrorGuaranteed, ExpnKind, Span}; use thin_vec::ThinVec; use tracing::{info, instrument}; @@ -250,12 +252,94 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } + // Ambiguity errors blaming the same inference variable describe a single problem: + // annotating that one variable has to satisfy all of them at once. Reporting them + // separately loses all but the first, as the rest get canceled as duplicates once + // the `infcx` is tainted (see `maybe_report_ambiguity`), hiding their requirements + // from the user. Instead, report the first one (the sort above placed the most + // informative obligation first) and mention the requirements of the others in it. + // + // Type variables that are only related through a pending `Coerce` or `Subtype` + // obligation still concern the same annotation, so compare their sub-unification + // roots, like `need_type_info` does when looking for the annotation source. + let ambiguity_infer_var = |error: &FulfillmentError<'tcx>| match error.code { + FulfillmentErrorCode::Ambiguity { overflow: None } => self + .ambiguity_term(self.resolve_vars_if_possible(error.obligation.predicate)) + .and_then(|term| { + ty::GenericArg::from(term) + .walk() + .find_map(TyOrConstInferVar::maybe_from_generic_arg::>) + }) + .map(|var| match var { + TyOrConstInferVar::Ty(vid) => { + TyOrConstInferVar::Ty(self.sub_unification_table_root_var(vid)) + } + other => other, + }), + _ => None, + }; + let infer_vars: Vec<_> = errors.iter().map(ambiguity_infer_var).collect(); + let mut reported = None; + let mut merged = vec![None; errors.len()]; + let mut reported_as_primary = vec![false; errors.len()]; for from_expansion in [false, true] { - for (error, suppressed) in iter::zip(&errors, &is_suppressed) { + for (index, (error, suppressed)) in iter::zip(&errors, &is_suppressed).enumerate() { if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion { if !error.references_error() { - let guar = self.report_fulfillment_error(error); + let guar = if let Some(guar) = merged[index] { + guar + } else { + let group: Vec = match infer_vars[index] { + Some(var) => (0..errors.len()) + .filter(|&other| { + other != index && infer_vars[other] == Some(var) + }) + .collect(), + None => vec![], + }; + let related: Vec<_> = group + .iter() + .filter(|&&other| { + // Exclude already-reported primaries: they were their own + // canonical error and adding them as notes here would + // produce duplicate information. + !is_suppressed[other] + && !errors[other].references_error() + && !reported_as_primary[other] + }) + .map(|&other| &errors[other]) + .collect(); + let guar = self.report_fulfillment_error(error, &related); + for &other in &group { + // Only suppress related errors whose predicates produce + // informative notes in maybe_report_ambiguity (Trait, + // Projection). Predicates we can't represent as notes + // (e.g. const evaluatability) still report separately. + let pred = errors[other].obligation.predicate; + let suppresses = match pred.kind().skip_binder() { + ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => { + !matches!( + self.tcx.as_lang_item(data.def_id()), + Some( + LangItem::Sized + | LangItem::MetaSized + | LangItem::PointeeSized + ) + ) + } + ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => { + true + } + _ => false, + }; + if suppresses { + merged[other] = Some(guar); + } + } + reported_as_primary[index] = true; + guar + }; self.infcx.set_tainted_by_errors(guar); reported = Some(guar); // We want to ignore desugarings here: spans are equivalent even @@ -286,7 +370,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } #[instrument(skip(self), level = "debug")] - fn report_fulfillment_error(&self, error: &FulfillmentError<'tcx>) -> ErrorGuaranteed { + fn report_fulfillment_error( + &self, + error: &FulfillmentError<'tcx>, + related: &[&FulfillmentError<'tcx>], + ) -> ErrorGuaranteed { let mut error = FulfillmentError { obligation: error.obligation.clone(), code: error.code.clone(), @@ -311,7 +399,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { self.report_projection_error(&error.obligation, e) } FulfillmentErrorCode::Ambiguity { overflow: None } => { - self.maybe_report_ambiguity(&error.obligation) + self.maybe_report_ambiguity(&error.obligation, related) } FulfillmentErrorCode::Ambiguity { overflow: Some(suggest_increasing_limit) } => { self.report_overflow_no_abort(error.obligation.clone(), suggest_increasing_limit) diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs index 3f5ad1ed9a8f5..5905d6172c2da 100644 --- a/compiler/rustc_type_ir/src/solve/mod.rs +++ b/compiler/rustc_type_ir/src/solve/mod.rs @@ -1012,9 +1012,10 @@ pub enum ComputeGoalFastPathOutcome { TriviallyStalled { stalled_on: GoalStalledOn }, } -/// Helper for `InferCtxt::ty_or_const_infer_var_changed` (see comment on that), currently -/// used only for `traits::fulfill`'s list of `stalled_on` inference variables. -#[derive(Copy, Clone, Debug)] +/// Helper for `InferCtxt::ty_or_const_infer_var_changed` (see comment on that), used +/// for `traits::fulfill`'s list of `stalled_on` inference variables and for merging +/// ambiguity errors caused by the same inference variable during error reporting. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum TyOrConstInferVar { /// Equivalent to `ty::Infer(ty::TyVar(_))`. Ty(TyVid), diff --git a/tests/ui/associated-type-bounds/duplicate-bound-err.stderr b/tests/ui/associated-type-bounds/duplicate-bound-err.stderr index f685b01cd8cc3..65d132cc50224 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound-err.stderr +++ b/tests/ui/associated-type-bounds/duplicate-bound-err.stderr @@ -4,6 +4,8 @@ error[E0282]: type annotations needed LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` | + = note: the type must also implement `Copy` + = note: the type must also implement `Send` help: consider specifying a concrete type for the type parameter `T` | LL | iter::empty::() @@ -15,6 +17,7 @@ error[E0282]: type annotations needed LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` | + = note: the type must also implement `Copy` help: consider specifying a concrete type for the type parameter `T` | LL | iter::empty::() diff --git a/tests/ui/closures/unique-closure-type-mismatch.stderr b/tests/ui/closures/unique-closure-type-mismatch.stderr index 3a31b6db4f62b..54bafa9af524b 100644 --- a/tests/ui/closures/unique-closure-type-mismatch.stderr +++ b/tests/ui/closures/unique-closure-type-mismatch.stderr @@ -18,6 +18,9 @@ LL | 1 => |c| c + 1, | ^ - type must be known at this point | = note: cannot satisfy `<_ as Add>::Output == _` + = note: the type must also implement `Add` + = note: cannot satisfy `<_ as Sub>::Output == _` + = note: the type must also implement `Sub` help: consider giving this closure parameter an explicit type | LL | 1 => |c: /* Type */| c + 1, diff --git a/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.next.stderr b/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.next.stderr index e0bf63f4b066d..366711e6d43c7 100644 --- a/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.next.stderr +++ b/tests/ui/const-generics/gca/ambiguous-on-failed-eval-with-vars-fail.next.stderr @@ -29,6 +29,7 @@ error[E0284]: type annotations needed for `([(); _], [(); 10])` LL | let (mut arr, mut arr_with_weird_len) = proj(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------ type must be known at this point | + = note: cannot satisfy `::PROJ<_> == 10` note: required by a const generic parameter in `proj` --> $DIR/ambiguous-on-failed-eval-with-vars-fail.rs:44:9 | diff --git a/tests/ui/error-codes/E0283.stderr b/tests/ui/error-codes/E0283.stderr index 29baae5f133a2..a8bd34b9a2d40 100644 --- a/tests/ui/error-codes/E0283.stderr +++ b/tests/ui/error-codes/E0283.stderr @@ -28,6 +28,8 @@ LL | impl Into for Impl { = note: and another `impl` found in the `core` crate: - impl Into for T where U: From; + = note: cannot satisfy `<_ as Mul>::Output == u32` + = note: the type must also implement `Mul` help: try using a fully qualified path to specify the expected types | LL - let bar = foo_impl.into() * 1u32; diff --git a/tests/ui/errors/span-format_args-issue-140578.stderr b/tests/ui/errors/span-format_args-issue-140578.stderr index b5394b6c33afc..a514fdd0ef630 100644 --- a/tests/ui/errors/span-format_args-issue-140578.stderr +++ b/tests/ui/errors/span-format_args-issue-140578.stderr @@ -3,30 +3,40 @@ error[E0282]: type annotations needed | LL | print!("{:?} {a} {a:?}", [], a = 1 + 1); | ^^ cannot infer type + | + = note: the type must also implement `Debug` error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:7:30 | LL | println!("{:?} {a} {a:?}", [], a = 1 + 1); | ^^ cannot infer type + | + = note: the type must also implement `Debug` error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:12:35 | LL | println!("{:?} {:?} {a} {a:?}", [], [], a = 1 + 1); | ^^ cannot infer type + | + = note: the type must also implement `Debug` error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:17:41 | LL | println!("{:?} {:?} {a} {a:?} {b:?}", [], [], a = 1 + 1, b = []); | ^^ cannot infer type + | + = note: the type must also implement `Debug` error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:26:9 | LL | [], | ^^ cannot infer type + | + = note: the type must also implement `Debug` error: aborting due to 5 previous errors diff --git a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr index 58ed71fad4a66..bb0ebbc723ff4 100644 --- a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr +++ b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr @@ -5,6 +5,8 @@ LL | cmp_eq | ^^^^^^ cannot infer type of the type parameter `A` declared on the function `cmp_eq` | = note: the type must implement `Scalar` + = note: cannot satisfy `for<'a> ::RefType<'_> == ::RefType<'a>` + = note: cannot satisfy `::RefType<'_> == _` note: required by a bound in `cmp_eq` --> $DIR/ambig-hr-projection-issue-93340.rs:10:22 | diff --git a/tests/ui/generic-associated-types/bugs/issue-88382.stderr b/tests/ui/generic-associated-types/bugs/issue-88382.stderr index 0567e1c55a96f..c1a6ca0f4d0d7 100644 --- a/tests/ui/generic-associated-types/bugs/issue-88382.stderr +++ b/tests/ui/generic-associated-types/bugs/issue-88382.stderr @@ -10,6 +10,7 @@ help: the trait `Iterable` is implemented for `SomeImplementation` | LL | impl Iterable for SomeImplementation { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: cannot satisfy `<_ as Iterable>::Iterator<'_> == std::iter::Empty` note: required by a bound in `test` --> $DIR/issue-88382.rs:29:16 | diff --git a/tests/ui/generic-associated-types/bugs/issue-91762.stderr b/tests/ui/generic-associated-types/bugs/issue-91762.stderr index b4ca65889ada0..498f3eada7bf8 100644 --- a/tests/ui/generic-associated-types/bugs/issue-91762.stderr +++ b/tests/ui/generic-associated-types/bugs/issue-91762.stderr @@ -5,6 +5,7 @@ LL | ret = ::fmap(arg); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the associated function `fmap` | = note: cannot satisfy `<>::Base as Functor>::With<_> == Self` + = note: cannot satisfy `<>::Base as Functor>::With<_> == _` help: consider specifying the generic arguments | LL | ret = ::fmap::(arg); diff --git a/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr b/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr index 77dec93d0617a..0474b2c36c6d4 100644 --- a/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr +++ b/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr @@ -11,6 +11,7 @@ LL | impl Trait for () where for<'b> ((),): LeakCheckFailure<'static, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | impl Trait for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: the type must also implement `Id<_>` note: required by a bound in `impls_trait` --> $DIR/leak-check-in-selection-6-ambig-unify.rs:30:19 | diff --git a/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr b/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr index 77dec93d0617a..0474b2c36c6d4 100644 --- a/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr +++ b/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr @@ -11,6 +11,7 @@ LL | impl Trait for () where for<'b> ((),): LeakCheckFailure<'static, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | impl Trait for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: the type must also implement `Id<_>` note: required by a bound in `impls_trait` --> $DIR/leak-check-in-selection-6-ambig-unify.rs:30:19 | diff --git a/tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr b/tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr index a917c34b52ae5..47ef70993237b 100644 --- a/tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr +++ b/tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr @@ -5,6 +5,7 @@ LL | let _: for<'a> fn(<_ as Trait<'a>>::Assoc) = foo::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type | = note: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc == _` + = note: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc == >::Assoc` error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr b/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr index b6c6e74f26052..513b28099e384 100644 --- a/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr @@ -13,6 +13,7 @@ LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: the type must also implement `Default` note: required by a bound in `is_trait` --> $DIR/auto-trait-selection-freeze.rs:11:16 | diff --git a/tests/ui/impl-trait/auto-trait-selection.old.stderr b/tests/ui/impl-trait/auto-trait-selection.old.stderr index 8e44100177154..1da41350ce452 100644 --- a/tests/ui/impl-trait/auto-trait-selection.old.stderr +++ b/tests/ui/impl-trait/auto-trait-selection.old.stderr @@ -13,6 +13,7 @@ LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: the type must also implement `Default` note: required by a bound in `is_trait` --> $DIR/auto-trait-selection.rs:7:16 | diff --git a/tests/ui/impl-trait/cross-return-site-inference.stderr b/tests/ui/impl-trait/cross-return-site-inference.stderr index 5512c234af985..758b7fb245d68 100644 --- a/tests/ui/impl-trait/cross-return-site-inference.stderr +++ b/tests/ui/impl-trait/cross-return-site-inference.stderr @@ -4,6 +4,8 @@ error[E0282]: type annotations needed LL | Ok(()) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | + = note: the type must also implement `Debug` + = note: the type must also implement `From<&str>` help: consider specifying the generic arguments | LL | Ok::<(), E>(()) @@ -15,6 +17,7 @@ error[E0790]: cannot call associated function on trait without specifying the co LL | return Err(From::from("foo")); | ^^^^^^^^^^^^^^^^^ cannot call associated function of trait | + = note: the type must also implement `Debug` help: use a fully-qualified path to a specific available implementation | LL | return Err(::from("foo")); @@ -26,6 +29,7 @@ error[E0790]: cannot call associated function on trait without specifying the co LL | Err(From::from("foo")) | ^^^^^^^^^^^^^^^^^ cannot call associated function of trait | + = note: the type must also implement `Debug` help: use a fully-qualified path to a specific available implementation | LL | Err(::from("foo")) diff --git a/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr b/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr index 8abced84ab86b..edef7a5e0a2c7 100644 --- a/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr +++ b/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr @@ -8,6 +8,7 @@ LL | loop {} | ------- return type was inferred to be `!` here | = note: the type must implement `Future` + = note: cannot satisfy `<_ as Future>::Output == ()` error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/where-allowed.stderr b/tests/ui/impl-trait/where-allowed.stderr index 52b63ae8177ea..a0cdc8ee89382 100644 --- a/tests/ui/impl-trait/where-allowed.stderr +++ b/tests/ui/impl-trait/where-allowed.stderr @@ -389,6 +389,7 @@ LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { pani where Args: std::marker::Tuple, F: Fn, A: Allocator, F: ?Sized; - impl Fn for SyncView where F: Sync, F: Fn, Args: std::marker::Tuple; + = note: cannot satisfy `<_ as FnOnce<()>>::Output == impl Debug` error: unconstrained opaque type --> $DIR/where-allowed.rs:122:16 diff --git a/tests/ui/inference/ambiguity-errors-single-diagnostic.rs b/tests/ui/inference/ambiguity-errors-single-diagnostic.rs new file mode 100644 index 0000000000000..7e8403b217ec4 --- /dev/null +++ b/tests/ui/inference/ambiguity-errors-single-diagnostic.rs @@ -0,0 +1,25 @@ +//! Ambiguity errors blaming the same inference variable are merged into a single +//! diagnostic that mentions every unsatisfied requirement, instead of only the +//! first one while the others get canceled as tainted-by-error duplicates. +//! +//! Regression test for . + +trait Trait {} +impl Trait for String {} +struct NotDefault; +impl Trait for NotDefault {} + +fn as_input(_: T) {} +fn constrained(_: T) {} + +fn two_bounds() { + as_input(Default::default()); + //~^ ERROR type annotations needed +} + +fn three_bounds() { + constrained(Default::default()); + //~^ ERROR type annotations needed +} + +fn main() {} diff --git a/tests/ui/inference/ambiguity-errors-single-diagnostic.stderr b/tests/ui/inference/ambiguity-errors-single-diagnostic.stderr new file mode 100644 index 0000000000000..f0013e957b6f9 --- /dev/null +++ b/tests/ui/inference/ambiguity-errors-single-diagnostic.stderr @@ -0,0 +1,60 @@ +error[E0283]: type annotations needed + --> $DIR/ambiguity-errors-single-diagnostic.rs:16:5 + | +LL | as_input(Default::default()); + | ^^^^^^^^ ------------------ type must be known at this point + | | + | cannot infer type of the type parameter `T` declared on the function `as_input` + | + = note: the type must implement `Trait` +help: the following types implement trait `Trait` + --> $DIR/ambiguity-errors-single-diagnostic.rs:8:1 + | +LL | impl Trait for String {} + | ^^^^^^^^^^^^^^^^^^^^^ `String` +LL | struct NotDefault; +LL | impl Trait for NotDefault {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ `NotDefault` + = note: the type must also implement `Default` +note: required by a bound in `as_input` + --> $DIR/ambiguity-errors-single-diagnostic.rs:12:16 + | +LL | fn as_input(_: T) {} + | ^^^^^ required by this bound in `as_input` +help: consider specifying a concrete type for the type parameter `T` + | +LL | as_input::(Default::default()); + | ++++++++++++++ + +error[E0283]: type annotations needed + --> $DIR/ambiguity-errors-single-diagnostic.rs:21:5 + | +LL | constrained(Default::default()); + | ^^^^^^^^^^^ ------------------ type must be known at this point + | | + | cannot infer type of the type parameter `T` declared on the function `constrained` + | + = note: the type must implement `Trait` +help: the following types implement trait `Trait` + --> $DIR/ambiguity-errors-single-diagnostic.rs:8:1 + | +LL | impl Trait for String {} + | ^^^^^^^^^^^^^^^^^^^^^ `String` +LL | struct NotDefault; +LL | impl Trait for NotDefault {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ `NotDefault` + = note: the type must also implement `Clone` + = note: the type must also implement `Default` +note: required by a bound in `constrained` + --> $DIR/ambiguity-errors-single-diagnostic.rs:13:19 + | +LL | fn constrained(_: T) {} + | ^^^^^ required by this bound in `constrained` +help: consider specifying a concrete type for the type parameter `T` + | +LL | constrained::(Default::default()); + | ++++++++++++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/inference/cannot-infer-async.stderr b/tests/ui/inference/cannot-infer-async.stderr index 346109fd5c018..1629ee416ba2b 100644 --- a/tests/ui/inference/cannot-infer-async.stderr +++ b/tests/ui/inference/cannot-infer-async.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed LL | Ok(()) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | + = note: the type must also implement `From` help: consider specifying the generic arguments | LL | Ok::<(), E>(()) diff --git a/tests/ui/inference/cannot-infer-closure-circular.stderr b/tests/ui/inference/cannot-infer-closure-circular.stderr index ee17f7737cf30..6caf02b0e2f55 100644 --- a/tests/ui/inference/cannot-infer-closure-circular.stderr +++ b/tests/ui/inference/cannot-infer-closure-circular.stderr @@ -7,6 +7,7 @@ LL | let v = r?; LL | Ok(v) | ----- type must be known at this point | + = note: the type must also implement `From<_>` help: consider giving this closure parameter an explicit type, where the type for type parameter `E` is specified | LL | let x = |r: Result<_, E>| { diff --git a/tests/ui/inference/cannot-infer-closure.stderr b/tests/ui/inference/cannot-infer-closure.stderr index 507a70c1bac46..1835edf35d61c 100644 --- a/tests/ui/inference/cannot-infer-closure.stderr +++ b/tests/ui/inference/cannot-infer-closure.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed LL | Ok(b) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | + = note: the type must also implement `From<()>` help: consider specifying the generic arguments | LL | Ok::<(), E>(b) diff --git a/tests/ui/inference/cannot-infer-iterator-sum-return-type.stderr b/tests/ui/inference/cannot-infer-iterator-sum-return-type.stderr index 594b6f0181db0..a7d9b0335e584 100644 --- a/tests/ui/inference/cannot-infer-iterator-sum-return-type.stderr +++ b/tests/ui/inference/cannot-infer-iterator-sum-return-type.stderr @@ -13,6 +13,7 @@ help: the trait `Sum` is implemented for `i32` ::: $SRC_DIR/core/src/iter/traits/accum.rs:LL:COL | = note: in this macro invocation + = note: the type must also implement `PartialOrd` note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL = note: this error originates in the macro `integer_sum_product` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/inference/cannot-infer-partial-try-return.stderr b/tests/ui/inference/cannot-infer-partial-try-return.stderr index ff4d7418a63af..255e1b93fb04a 100644 --- a/tests/ui/inference/cannot-infer-partial-try-return.stderr +++ b/tests/ui/inference/cannot-infer-partial-try-return.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed LL | Ok(()) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | + = note: the type must also implement `From` help: consider specifying the generic arguments | LL | Ok::<(), QualifiedError<_>>(()) diff --git a/tests/ui/inference/issue-12028.stderr b/tests/ui/inference/issue-12028.stderr index 0d8ef1c938d4c..68bacac0fbbd0 100644 --- a/tests/ui/inference/issue-12028.stderr +++ b/tests/ui/inference/issue-12028.stderr @@ -5,6 +5,7 @@ LL | self.input_stream(&mut stream); | ^^^^^^^^^^^^ | = note: cannot satisfy `<_ as StreamHasher>::S == ::S` + = note: the type must also implement `StreamHasher` help: try using a fully qualified path to specify the expected types | LL - self.input_stream(&mut stream); diff --git a/tests/ui/inference/issue-70082.stderr b/tests/ui/inference/issue-70082.stderr index 926ecff4a4fb5..bf115aab8506b 100644 --- a/tests/ui/inference/issue-70082.stderr +++ b/tests/ui/inference/issue-70082.stderr @@ -7,6 +7,8 @@ LL | let y: f64 = 0.01f64 * 1i16.into(); | type must be known at this point | = note: cannot satisfy `>::Output == f64` + = note: cannot satisfy `f64: Mul<_>` + = note: the type must also implement `From` help: try using a fully qualified path to specify the expected types | LL - let y: f64 = 0.01f64 * 1i16.into(); diff --git a/tests/ui/inference/issue-71584.stderr b/tests/ui/inference/issue-71584.stderr index 4bbfef6c44afa..7c6f211ec8b7b 100644 --- a/tests/ui/inference/issue-71584.stderr +++ b/tests/ui/inference/issue-71584.stderr @@ -7,6 +7,8 @@ LL | d = d % n.into(); | type must be known at this point | = note: cannot satisfy `>::Output == u64` + = note: cannot satisfy `u64: Rem<_>` + = note: the type must also implement `From` help: try using a fully qualified path to specify the expected types | LL - d = d % n.into(); diff --git a/tests/ui/inference/issue-71732.stderr b/tests/ui/inference/issue-71732.stderr index 3b46a24e01088..e3e28865ef4be 100644 --- a/tests/ui/inference/issue-71732.stderr +++ b/tests/ui/inference/issue-71732.stderr @@ -10,6 +10,9 @@ LL | .get(&"key".into()) - impl Borrow for String; - impl Borrow for T where T: ?Sized; + = note: the type must also implement `Hash` + = note: the type must also implement `Eq` + = note: the type must also implement `From<&str>` note: required by a bound in `HashMap::::get` --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL help: consider specifying a concrete type for the type parameter `Q` diff --git a/tests/ui/inference/issue-72616.stderr b/tests/ui/inference/issue-72616.stderr index 8eba3216a8464..0f7fd9223b1eb 100644 --- a/tests/ui/inference/issue-72616.stderr +++ b/tests/ui/inference/issue-72616.stderr @@ -13,6 +13,8 @@ LL | if String::from("a") == "a".try_into().unwrap() {} - impl PartialEq for String; - impl PartialEq for String; - impl PartialEq for String; + = note: the type must also implement `TryFrom<&str>` + = note: cannot satisfy `<_ as TryFrom<&str>>::Error == _` help: try using a fully qualified path to specify the expected types | LL - if String::from("a") == "a".try_into().unwrap() {} diff --git a/tests/ui/inference/issue-72690.rs b/tests/ui/inference/issue-72690.rs index 8c0a0f51a2157..4edbd9ca15de7 100644 --- a/tests/ui/inference/issue-72690.rs +++ b/tests/ui/inference/issue-72690.rs @@ -5,12 +5,10 @@ fn no_err() { fn err() { String::from("x".as_ref()); //~ ERROR type annotations needed - //~^ ERROR type annotations needed } fn arg_pat_closure_err() { |x| String::from("x".as_ref()); //~ ERROR type annotations needed - //~| ERROR type annotations needed } fn local_pat_closure_err() { @@ -19,14 +17,12 @@ fn local_pat_closure_err() { fn err_first_arg_pat() { String::from("x".as_ref()); //~ ERROR type annotations needed - //~^ ERROR type annotations needed |x: String| x; } fn err_second_arg_pat() { |x: String| x; String::from("x".as_ref()); //~ ERROR type annotations needed - //~^ ERROR type annotations needed } fn err_mid_arg_pat() { @@ -35,7 +31,6 @@ fn err_mid_arg_pat() { |x: String| x; |x: String| x; String::from("x".as_ref()); //~ ERROR type annotations needed - //~^ ERROR type annotations needed |x: String| x; |x: String| x; |x: String| x; @@ -44,14 +39,12 @@ fn err_mid_arg_pat() { fn err_first_local_pat() { String::from("x".as_ref()); //~ ERROR type annotations needed - //~^ ERROR type annotations needed let _ = String::from("x"); } fn err_second_local_pat() { let _ = String::from("x"); String::from("x".as_ref()); //~ ERROR type annotations needed - //~^ ERROR type annotations needed } fn err_mid_local_pat() { @@ -60,7 +53,6 @@ fn err_mid_local_pat() { let _ = String::from("x"); let _ = String::from("x"); String::from("x".as_ref()); //~ ERROR type annotations needed - //~^ ERROR type annotations needed let _ = String::from("x"); let _ = String::from("x"); let _ = String::from("x"); diff --git a/tests/ui/inference/issue-72690.stderr b/tests/ui/inference/issue-72690.stderr index 4926cf9e981ba..3b7c4514ac999 100644 --- a/tests/ui/inference/issue-72690.stderr +++ b/tests/ui/inference/issue-72690.stderr @@ -7,27 +7,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:7:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:12:9 + --> $DIR/issue-72690.rs:11:9 | LL | |x| String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -35,27 +18,10 @@ LL | |x| String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - -error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:12:26 - | -LL | |x| String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - |x| String::from("x".as_ref()); -LL + |x| String::from(>::as_ref("x")); - | + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed for `&_` - --> $DIR/issue-72690.rs:17:9 + --> $DIR/issue-72690.rs:15:9 | LL | let _ = "x".as_ref(); | ^ ------ type must be known at this point @@ -72,7 +38,7 @@ LL | let _: &T = "x".as_ref(); | ++++ error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:21:5 + --> $DIR/issue-72690.rs:19:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -80,27 +46,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:21:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:28:5 + --> $DIR/issue-72690.rs:25:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -108,27 +57,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:28:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:37:5 + --> $DIR/issue-72690.rs:33:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -136,27 +68,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:37:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:46:5 + --> $DIR/issue-72690.rs:41:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -164,27 +79,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:46:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:53:5 + --> $DIR/issue-72690.rs:47:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -192,27 +90,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:53:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:62:5 + --> $DIR/issue-72690.rs:55:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -220,25 +101,8 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` -error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:62:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error: aborting due to 17 previous errors +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/inference/issue-80816.rs b/tests/ui/inference/issue-80816.rs index 4d319b44987e2..e5aae3abcb973 100644 --- a/tests/ui/inference/issue-80816.rs +++ b/tests/ui/inference/issue-80816.rs @@ -49,6 +49,7 @@ pub fn foo() { let s: Arc>> = unimplemented!(); let guard: Guard> = s.load(); //~^ ERROR: type annotations needed + //~| NOTE: cannot satisfy `> as Access<_>>::Guard == Guard>` //~| HELP: try using a fully qualified path to specify the expected types } diff --git a/tests/ui/inference/issue-80816.stderr b/tests/ui/inference/issue-80816.stderr index bca7cd4c3adbb..7230fd042df0f 100644 --- a/tests/ui/inference/issue-80816.stderr +++ b/tests/ui/inference/issue-80816.stderr @@ -12,6 +12,7 @@ LL | impl Access for ArcSwapAny { ... LL | impl Access for ArcSwapAny> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: cannot satisfy `> as Access<_>>::Guard == Guard>` note: required for `Arc>>` to implement `Access<_>` --> $DIR/issue-80816.rs:31:45 | diff --git a/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr index ff668f88d4d15..dc33482010243 100644 --- a/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr +++ b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr @@ -3,6 +3,8 @@ error[E0282]: type annotations needed | LL | println!("{:?}", []); | ^^ cannot infer type + | + = note: the type must also implement `Debug` error: aborting due to 1 previous error diff --git a/tests/ui/inference/need_type_info/single-type-generic-suggestion.stderr b/tests/ui/inference/need_type_info/single-type-generic-suggestion.stderr index fe696847eab7a..7a69f4291c284 100644 --- a/tests/ui/inference/need_type_info/single-type-generic-suggestion.stderr +++ b/tests/ui/inference/need_type_info/single-type-generic-suggestion.stderr @@ -5,6 +5,7 @@ LL | "".parse(); | ^^^^^ cannot infer type of the type parameter `F` declared on the method `parse` | = note: cannot satisfy `<_ as FromStr>::Err == _` + = note: the type must also implement `FromStr` help: consider specifying a concrete type for the type parameter `F` | LL | "".parse::(); diff --git a/tests/ui/inference/question-mark-type-infer.stderr b/tests/ui/inference/question-mark-type-infer.stderr index b531d42ff93cf..eb092a6f5d69c 100644 --- a/tests/ui/inference/question-mark-type-infer.stderr +++ b/tests/ui/inference/question-mark-type-infer.stderr @@ -5,6 +5,9 @@ LL | l.iter().map(f).collect()? | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | = note: the type must implement `FromIterator>` + = note: cannot satisfy `<_ as Try>::Residual == _` + = note: the type must also implement `Try` + = note: cannot satisfy `<_ as Try>::Output == Result, ()>` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider specifying the generic argument @@ -19,6 +22,9 @@ LL | let x = l.iter().map(f).collect()?; | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | = note: the type must implement `FromIterator>` + = note: cannot satisfy `<_ as Try>::Residual == _` + = note: the type must also implement `Try` + = note: cannot satisfy `<_ as Try>::Output == ()` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider specifying the generic argument @@ -33,6 +39,9 @@ LL | let x: Vec = l.iter().map(f).collect()?; | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | = note: the type must implement `FromIterator>` + = note: cannot satisfy `<_ as Try>::Residual == _` + = note: the type must also implement `Try` + = note: cannot satisfy `<_ as Try>::Output == Vec` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider specifying the generic argument diff --git a/tests/ui/inference/question-mark-type-inference-in-chain.rs b/tests/ui/inference/question-mark-type-inference-in-chain.rs index 68960ec466dd3..23ebe1ae9d2c5 100644 --- a/tests/ui/inference/question-mark-type-inference-in-chain.rs +++ b/tests/ui/inference/question-mark-type-inference-in-chain.rs @@ -49,6 +49,9 @@ pub fn error2(lines: &[&str]) -> Result> { //~^ ERROR: type annotations needed //~| NOTE: cannot infer type of the type parameter `B` //~| NOTE: the type must implement `FromIterator>` + //~| NOTE: cannot satisfy `<_ as Try>::Residual == _` + //~| NOTE: the type must also implement `Try` + //~| NOTE: cannot satisfy `<_ as Try>::Output == Vec` //~| NOTE: required by a bound in `collect` //~| HELP: consider specifying the generic argument tags.sort(); diff --git a/tests/ui/inference/question-mark-type-inference-in-chain.stderr b/tests/ui/inference/question-mark-type-inference-in-chain.stderr index 5c0a739f4e6b0..bac168b938449 100644 --- a/tests/ui/inference/question-mark-type-inference-in-chain.stderr +++ b/tests/ui/inference/question-mark-type-inference-in-chain.stderr @@ -22,6 +22,9 @@ LL | let mut tags: Vec = lines.iter().map(|e| parse(e)).collect()?; | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | = note: the type must implement `FromIterator>` + = note: cannot satisfy `<_ as Try>::Residual == _` + = note: the type must also implement `Try` + = note: cannot satisfy `<_ as Try>::Output == Vec` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider specifying the generic argument @@ -30,7 +33,7 @@ LL | let mut tags: Vec = lines.iter().map(|e| parse(e)).collect:: $DIR/question-mark-type-inference-in-chain.rs:60:20 + --> $DIR/question-mark-type-inference-in-chain.rs:63:20 | LL | let mut tags = lines.iter().map(|e| parse(e)).collect::>()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `Vec>` @@ -38,7 +41,7 @@ LL | let mut tags = lines.iter().map(|e| parse(e)).collect::>()?; = help: the nightly-only, unstable trait `Try` is not implemented for `Vec>` warning: method call on a diverging inference variable - --> $DIR/question-mark-type-inference-in-chain.rs:66:10 + --> $DIR/question-mark-type-inference-in-chain.rs:69:10 | LL | tags.sort(); | ^^^^ @@ -48,13 +51,13 @@ LL | tags.sort(); = note: for more information, see issue #156047 error[E0599]: no method named `sort` found for type `!` in the current scope - --> $DIR/question-mark-type-inference-in-chain.rs:66:10 + --> $DIR/question-mark-type-inference-in-chain.rs:69:10 | LL | tags.sort(); | ^^^^ method not found in `!` error[E0277]: a value of type `std::result::Result, AnotherError>` cannot be built from an iterator over elements of type `std::result::Result` - --> $DIR/question-mark-type-inference-in-chain.rs:85:20 + --> $DIR/question-mark-type-inference-in-chain.rs:88:20 | LL | .collect::>>()?; | ------- ^^^^^^^^^^^^^^^^^^^^ value of type `std::result::Result, AnotherError>` cannot be built from `std::iter::Iterator>` @@ -66,7 +69,7 @@ help: the trait `FromIterator>` is not implemented for `std::re --> $SRC_DIR/core/src/result.rs:LL:COL = help: for that trait implementation, expected `AnotherError`, found `Error` note: the method call chain might not have had the expected associated types - --> $DIR/question-mark-type-inference-in-chain.rs:82:10 + --> $DIR/question-mark-type-inference-in-chain.rs:85:10 | LL | let mut tags = lines | ----- this expression has type `&[&str]` @@ -97,7 +100,7 @@ LL | tags.sort(); Future breakage diagnostic: warning: method call on a diverging inference variable - --> $DIR/question-mark-type-inference-in-chain.rs:66:10 + --> $DIR/question-mark-type-inference-in-chain.rs:69:10 | LL | tags.sort(); | ^^^^ diff --git a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.rs b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.rs index 7b2fc34e1af12..49fe7d1324ca8 100644 --- a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.rs +++ b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.rs @@ -23,7 +23,7 @@ fn m1() { // we couldn't infer the type of the vector just based on calling foo()... let mut x = Vec::new(); //~^ ERROR type annotations needed - x.foo(); //~ ERROR type annotations needed + x.foo(); } fn m2() { diff --git a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr index a5f1b76702f57..5bb8d0ea3fb2c 100644 --- a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr +++ b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr @@ -4,31 +4,12 @@ error[E0282]: type annotations needed for `Vec<_>` LL | let mut x = Vec::new(); | ^^^^^ ---------- type must be known at this point | + = note: cannot satisfy `Vec<_>: Foo` help: consider giving `x` an explicit type, where the type for type parameter `T` is specified | LL | let mut x: Vec = Vec::new(); | ++++++++ -error[E0283]: type annotations needed - --> $DIR/method-ambig-one-trait-unknown-int-type.rs:26:7 - | -LL | x.foo(); - | ^^^ - | -note: multiple `impl`s satisfying `Vec<_>: Foo` found - --> $DIR/method-ambig-one-trait-unknown-int-type.rs:9:1 - | -LL | impl Foo for Vec { - | ^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | impl Foo for Vec { - | ^^^^^^^^^^^^^^^^^^^^^^^ -help: try using a fully qualified path to specify the expected types - | -LL - x.foo(); -LL + as Foo>::foo(&x); - | - error[E0308]: mismatched types --> $DIR/method-ambig-one-trait-unknown-int-type.rs:33:20 | @@ -42,7 +23,7 @@ help: you can convert an `isize` to a `usize` and panic if the converted value d LL | let y: usize = x.foo().try_into().unwrap(); | ++++++++++++++++++++ -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0282, E0283, E0308. +Some errors have detailed explanations: E0282, E0308. For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.rs b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.rs index f617e20804a2e..a8b209b736b3e 100644 --- a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.rs +++ b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.rs @@ -9,13 +9,11 @@ fn no_err() { fn err() { String::from("x".as_ref()); //~^ ERROR type annotations needed - //~| ERROR type annotations needed } fn arg_pat_closure_err() { |x| String::from("x".as_ref()); //~^ ERROR type annotations needed - //~| ERROR type annotations needed } fn local_pat_closure_err() { @@ -26,7 +24,6 @@ fn local_pat_closure_err() { fn err_first_arg_pat() { String::from("x".as_ref()); //~^ ERROR type annotations needed - //~| ERROR type annotations needed |x: String| x; } @@ -34,7 +31,6 @@ fn err_second_arg_pat() { |x: String| x; String::from("x".as_ref()); //~^ ERROR type annotations needed - //~| ERROR type annotations needed } fn err_mid_arg_pat() { @@ -44,7 +40,6 @@ fn err_mid_arg_pat() { |x: String| x; String::from("x".as_ref()); //~^ ERROR type annotations needed - //~| ERROR type annotations needed |x: String| x; |x: String| x; |x: String| x; @@ -54,7 +49,6 @@ fn err_mid_arg_pat() { fn err_first_local_pat() { String::from("x".as_ref()); //~^ ERROR type annotations needed - //~| ERROR type annotations needed let _ = String::from("x"); } @@ -62,7 +56,6 @@ fn err_second_local_pat() { let _ = String::from("x"); String::from("x".as_ref()); //~^ ERROR type annotations needed - //~| ERROR type annotations needed } fn err_mid_local_pat() { @@ -72,7 +65,6 @@ fn err_mid_local_pat() { let _ = String::from("x"); String::from("x".as_ref()); //~^ ERROR type annotations needed - //~| ERROR type annotations needed let _ = String::from("x"); let _ = String::from("x"); let _ = String::from("x"); diff --git a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr index 3be18fc59e737..4c4bfe5db4351 100644 --- a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr +++ b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr @@ -18,27 +18,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:10:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:16:9 + --> $DIR/infer-unwrap-none-issue-120786.rs:15:9 | LL | |x| String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -46,27 +29,10 @@ LL | |x| String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - -error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:16:26 - | -LL | |x| String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - |x| String::from("x".as_ref()); -LL + |x| String::from(>::as_ref("x")); - | + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed for `&_` - --> $DIR/infer-unwrap-none-issue-120786.rs:22:9 + --> $DIR/infer-unwrap-none-issue-120786.rs:20:9 | LL | let _ = "x".as_ref(); | ^ ------ type must be known at this point @@ -83,7 +49,7 @@ LL | let _: &T = "x".as_ref(); | ++++ error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:27:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:25:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -91,27 +57,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:27:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:35:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:32:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -119,27 +68,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:35:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:45:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:41:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -147,27 +79,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:45:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:55:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:50:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -175,27 +90,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:55:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:63:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:57:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -203,27 +101,10 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:63:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:73:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:66:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -231,26 +112,9 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + = note: cannot satisfy `str: AsRef<_>` -error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:73:22 - | -LL | String::from("x".as_ref()); - | ^^^^^^ - | - = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef for str; - - impl AsRef<[u8]> for str; - - impl AsRef for str; -help: try using a fully qualified path to specify the expected types - | -LL - String::from("x".as_ref()); -LL + String::from(>::as_ref("x")); - | - -error: aborting due to 18 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0282, E0283. For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/pattern/slice-patterns-irrefutable.stderr b/tests/ui/pattern/slice-patterns-irrefutable.stderr index 4619a0d798d4b..ba1643a7c9096 100644 --- a/tests/ui/pattern/slice-patterns-irrefutable.stderr +++ b/tests/ui/pattern/slice-patterns-irrefutable.stderr @@ -7,6 +7,7 @@ LL | LL | [a, b] = Default::default(); | - type must be known at this point | + = note: the type must also implement `Default` help: consider giving `b` an explicit type, where the placeholder `_` is specified | LL | let b: [_; 3]; diff --git a/tests/ui/suggestions/types/into-inference-needs-type.stderr b/tests/ui/suggestions/types/into-inference-needs-type.stderr index 5fbc281072047..89fb9405cbe56 100644 --- a/tests/ui/suggestions/types/into-inference-needs-type.stderr +++ b/tests/ui/suggestions/types/into-inference-needs-type.stderr @@ -5,6 +5,9 @@ LL | .into()?; | ^^^^ | = note: the type must implement `From, {closure@$DIR/into-inference-needs-type.rs:10:14: 10:17}>, fn(Option<&str>) -> Option> {Option::>::Some}>>` + = note: cannot satisfy `<_ as Try>::Residual == _` + = note: the type must also implement `Try` + = note: cannot satisfy `<_ as Try>::Output == ()` = note: required for `FilterMap, {closure@$DIR/into-inference-needs-type.rs:10:14: 10:17}>, fn(Option<&str>) -> Option> {Option::>::Some}>` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | diff --git a/tests/ui/trait-bounds/argument-with-unnecessary-method-call.stderr b/tests/ui/trait-bounds/argument-with-unnecessary-method-call.stderr index 870a865f02dd6..094c4a5516035 100644 --- a/tests/ui/trait-bounds/argument-with-unnecessary-method-call.stderr +++ b/tests/ui/trait-bounds/argument-with-unnecessary-method-call.stderr @@ -7,6 +7,7 @@ LL | qux(Bar.into()); | required by a bound introduced by this call | = note: the type must implement `From` + = note: the type must also implement `From` note: required by a bound in `qux` --> $DIR/argument-with-unnecessary-method-call.rs:6:16 | diff --git a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.rs b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.rs index a53aadcfad024..f1935ae253463 100644 --- a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.rs +++ b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.rs @@ -27,5 +27,4 @@ impl Test for u64 { fn main() { let xs: Vec = vec![1, 2, 3]; println!("{}", 23u64.test(xs.iter().sum())); //~ ERROR: type annotations needed - //~^ ERROR type annotations needed } diff --git a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr index 58e56ea45a8c1..27d6efee8bcee 100644 --- a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr +++ b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr @@ -7,33 +7,13 @@ LL | println!("{}", 23u64.test(xs.iter().sum())); | type must be known at this point | = note: cannot satisfy `>::Output == _` + = note: cannot satisfy `u64: Test<_>` + = note: the type must also implement `Sum<&u64>` help: consider specifying a concrete type for the type parameter `S` | LL | println!("{}", 23u64.test(xs.iter().sum::())); | ++++++++++++++ -error[E0283]: type annotations needed - --> $DIR/projection-predicate-not-satisfied-69455.rs:29:41 - | -LL | println!("{}", 23u64.test(xs.iter().sum())); - | ---- ^^^ cannot infer type of the type parameter `S` declared on the method `sum` - | | - | required by a bound introduced by this call - | -note: multiple `impl`s satisfying `u64: Test<_>` found - --> $DIR/projection-predicate-not-satisfied-69455.rs:11:1 - | -LL | impl Test for u64 { - | ^^^^^^^^^^^^^^^^^^^^^^ -... -LL | impl Test for u64 { - | ^^^^^^^^^^^^^^^^^^^^^^ -help: consider specifying a concrete type for the type parameter `S` - | -LL | println!("{}", 23u64.test(xs.iter().sum::())); - | ++++++++++++++ - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0283, E0284. -For more information about an error, try `rustc --explain E0283`. +For more information about this error, try `rustc --explain E0284`. diff --git a/tests/ui/traits/issue-77982.rs b/tests/ui/traits/issue-77982.rs index b2a488e18e828..e82ffaf4caca1 100644 --- a/tests/ui/traits/issue-77982.rs +++ b/tests/ui/traits/issue-77982.rs @@ -9,7 +9,6 @@ fn what() { let opt = String::new(); opts.get(opt.as_ref()); //~ ERROR type annotations needed - //~^ ERROR type annotations needed } fn main() { diff --git a/tests/ui/traits/issue-77982.stderr b/tests/ui/traits/issue-77982.stderr index 22f3a258e6986..9f5375992b960 100644 --- a/tests/ui/traits/issue-77982.stderr +++ b/tests/ui/traits/issue-77982.stderr @@ -10,6 +10,9 @@ LL | opts.get(opt.as_ref()); - impl Borrow for String; - impl Borrow for T where T: ?Sized; + = note: the type must also implement `Hash` + = note: the type must also implement `Eq` + = note: cannot satisfy `String: AsRef<_>` note: required by a bound in `HashMap::::get` --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL help: consider specifying a concrete type for the type parameter `Q` @@ -18,25 +21,7 @@ LL | opts.get::(opt.as_ref()); | ++++++++++++++ error[E0283]: type annotations needed - --> $DIR/issue-77982.rs:11:10 - | -LL | opts.get(opt.as_ref()); - | ^^^ ------ type must be known at this point - | | - | cannot infer type of the type parameter `Q` declared on the method `get` - | - = note: multiple `impl`s satisfying `String: AsRef<_>` found in the following crates: `alloc`, `std`: - - impl AsRef for String; - - impl AsRef for String; - - impl AsRef<[u8]> for String; - - impl AsRef for String; -help: consider specifying a concrete type for the type parameter `Q` - | -LL | opts.get::(opt.as_ref()); - | ++++++++++++++ - -error[E0283]: type annotations needed - --> $DIR/issue-77982.rs:16:59 + --> $DIR/issue-77982.rs:15:59 | LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect(); | --- ^^^^ @@ -50,6 +35,7 @@ LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect( - impl From for u32; - impl From for u32; - impl From for u32; + = note: the type must also implement `From` help: try using a fully qualified path to specify the expected types | LL - let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect(); @@ -57,13 +43,13 @@ LL + let ips: Vec<_> = (0..100_000).map(|_| u32::from(>::into | error[E0283]: type annotations needed for `Box<_>` - --> $DIR/issue-77982.rs:39:9 + --> $DIR/issue-77982.rs:38:9 | LL | let _ = ().foo(); | ^ --- type must be known at this point | note: multiple `impl`s satisfying `(): Foo<'_, _>` found - --> $DIR/issue-77982.rs:32:1 + --> $DIR/issue-77982.rs:31:1 | LL | impl Foo<'static, u32> for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,13 +61,13 @@ LL | let _: Box = ().foo(); | ++++++++ error[E0283]: type annotations needed for `Box<_>` - --> $DIR/issue-77982.rs:43:9 + --> $DIR/issue-77982.rs:42:9 | LL | let _ = (&()).bar(); | ^ --- type must be known at this point | note: multiple `impl`s satisfying `&(): Bar<'_, _>` found - --> $DIR/issue-77982.rs:35:1 + --> $DIR/issue-77982.rs:34:1 | LL | impl<'a> Bar<'static, u32> for &'a () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -92,6 +78,6 @@ help: consider giving this pattern a type, where the type for type parameter `T` LL | let _: Box = (&()).bar(); | ++++++++ -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/traits/multidispatch-convert-ambig-dest.stderr b/tests/ui/traits/multidispatch-convert-ambig-dest.stderr index 12984c7936c9a..8a38376d91b62 100644 --- a/tests/ui/traits/multidispatch-convert-ambig-dest.stderr +++ b/tests/ui/traits/multidispatch-convert-ambig-dest.stderr @@ -14,6 +14,7 @@ LL | impl Convert for i32 { ... LL | impl Convert for i32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: the type must also implement `Default` note: required by a bound in `test` --> $DIR/multidispatch-convert-ambig-dest.rs:21:11 | diff --git a/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr b/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr index ac427c8f0cba7..95ac5d64a869c 100644 --- a/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr +++ b/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr @@ -5,6 +5,7 @@ LL | println!("{:?}", iter::<_>()); | ^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `iter` | = note: the type must implement `Iterator` + = note: cannot satisfy `<_ as Iterator>::Item == _` note: required by a bound in `iter` --> $DIR/runaway-impl-candidate-selection.rs:8:12 | diff --git a/tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.stderr b/tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.stderr index 5c1910546872e..b85dbc5613e3a 100644 --- a/tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.stderr +++ b/tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.stderr @@ -7,6 +7,7 @@ LL | foo(unconstrained()) | cannot infer type of the type parameter `T` declared on the function `foo` | = note: cannot satisfy `Vec<_>: Trait` + = note: cannot satisfy ` as Trait>::Assoc == u8` note: required by a bound in `foo` --> $DIR/normalizes_to_ignores_unnormalizable_candidate.rs:14:11 | diff --git a/tests/ui/traits/next-solver/unexpected-pointer-deref-issue-154568.stderr b/tests/ui/traits/next-solver/unexpected-pointer-deref-issue-154568.stderr index 3c5a00744a636..f26ba396b9db6 100644 --- a/tests/ui/traits/next-solver/unexpected-pointer-deref-issue-154568.stderr +++ b/tests/ui/traits/next-solver/unexpected-pointer-deref-issue-154568.stderr @@ -5,6 +5,8 @@ LL | let handshake = Handshake(callback.0.clone()); | ^^^^^^^^^ ----------------------------- type must be known at this point | = note: the type must implement `Role` + = note: cannot satisfy `<_ as Role>::Inner == ()` + = note: cannot satisfy `<_ as Role>::Inner == _` note: required by a bound in `Handshake` --> $DIR/unexpected-pointer-deref-issue-154568.rs:9:21 | diff --git a/tests/ui/traits/next-solver/well-formed-in-relate.stderr b/tests/ui/traits/next-solver/well-formed-in-relate.stderr index dbe8a656812a5..12a3589c87a55 100644 --- a/tests/ui/traits/next-solver/well-formed-in-relate.stderr +++ b/tests/ui/traits/next-solver/well-formed-in-relate.stderr @@ -14,6 +14,7 @@ LL | x = unconstrained_map(); where Args: std::marker::Tuple, F: Fn, A: Allocator, F: ?Sized; - impl Fn for SyncView where F: Sync, F: Fn, Args: std::marker::Tuple; + = note: cannot satisfy `<_ as FnOnce<()>>::Output == _` note: required by a bound in `unconstrained_map` --> $DIR/well-formed-in-relate.rs:21:25 | diff --git a/tests/ui/type-inference/index-expr-ambiguous-type.stderr b/tests/ui/type-inference/index-expr-ambiguous-type.stderr index 83de98d80cae6..3c5e4c7c951f7 100644 --- a/tests/ui/type-inference/index-expr-ambiguous-type.stderr +++ b/tests/ui/type-inference/index-expr-ambiguous-type.stderr @@ -11,6 +11,7 @@ LL | let _foo = 0 + [1, 2, 3][bad_idx.into()]; | ^^^^ cannot infer type | = note: cannot satisfy `>::Output == _` + = note: cannot satisfy `i32: Add<_>` error[E0283]: type annotations needed --> $DIR/index-expr-ambiguous-type.rs:21:34 @@ -19,6 +20,8 @@ LL | let _foo = [1, 2, 3][bad_idx.into()]; | ^^^^ | = note: the type must implement `From` + = note: the type must also implement `SliceIndex<[i32]>` + = note: cannot satisfy `<_ as SliceIndex<[i32]>>::Output == _` = note: required for `u8` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | @@ -41,6 +44,7 @@ LL | let _foo = 0u64 + [1i32, 2, 3][bad_idx.into()]; | ^ cannot infer type | = note: cannot satisfy `>::Output == _` + = note: cannot satisfy `u64: Add<_>` error[E0284]: type annotations needed --> $DIR/index-expr-ambiguous-type.rs:44:38 @@ -49,6 +53,7 @@ LL | let _foo = 1u32 << [0u8][bad_idx.into()]; | ^^^^ cannot infer type | = note: cannot satisfy `>::Output == _` + = note: cannot satisfy `u32: Shl<_>` error[E0283]: type annotations needed --> $DIR/index-expr-ambiguous-type.rs:50:45 @@ -57,6 +62,8 @@ LL | let _foo = String::new() + [""][bad_idx.into()]; | ^^^^ | = note: the type must implement `From` + = note: the type must also implement `SliceIndex<[&str]>` + = note: cannot satisfy `<_ as SliceIndex<[&str]>>::Output == &str` = note: required for `u8` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | diff --git a/tests/ui/type-inference/or_else-multiple-type-params.stderr b/tests/ui/type-inference/or_else-multiple-type-params.stderr index 9bcd07f8bf164..eb8fa8610dca4 100644 --- a/tests/ui/type-inference/or_else-multiple-type-params.stderr +++ b/tests/ui/type-inference/or_else-multiple-type-params.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed for `Result` LL | .or_else(|err| { | ^^^^^ | + = note: the type must also implement `Debug` help: try giving this closure an explicit return type | LL | .or_else(|err| -> Result<_, F> { diff --git a/tests/ui/type-inference/panic-with-unspecified-type.stderr b/tests/ui/type-inference/panic-with-unspecified-type.stderr index 99c6e83ef3225..e0f92334afd34 100644 --- a/tests/ui/type-inference/panic-with-unspecified-type.stderr +++ b/tests/ui/type-inference/panic-with-unspecified-type.stderr @@ -8,6 +8,8 @@ LL | panic!(std::default::Default::default()); | required by a bound introduced by this call | = note: the type must implement `Any` + = note: the type must also implement `Send` + = note: the type must also implement `Default` note: required by a bound in `std::rt::begin_panic` --> $SRC_DIR/std/src/panicking.rs:LL:COL diff --git a/tests/ui/type-inference/send-with-unspecified-type.stderr b/tests/ui/type-inference/send-with-unspecified-type.stderr index 0d7daed44c0d9..1025f9d0bb2ff 100644 --- a/tests/ui/type-inference/send-with-unspecified-type.stderr +++ b/tests/ui/type-inference/send-with-unspecified-type.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed LL | tx.send(Foo{ foo: PhantomData }); | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `PhantomData` | + = note: the type must also implement `Send` help: consider specifying a concrete type for the type parameter `T` | LL | tx.send(Foo{ foo: PhantomData:: }); diff --git a/tests/ui/type-inference/sort_by_key.stderr b/tests/ui/type-inference/sort_by_key.stderr index d191d50b203af..80da5f6a0c7ad 100644 --- a/tests/ui/type-inference/sort_by_key.stderr +++ b/tests/ui/type-inference/sort_by_key.stderr @@ -7,6 +7,7 @@ LL | lst.sort_by_key(|&(v, _)| v.iter().sum()); | type must be known at this point | = note: the type must implement `Ord` + = note: the type must also implement `Sum<&i32>` note: required by a bound in `slice::::sort_by_key` --> $SRC_DIR/alloc/src/slice.rs:LL:COL help: consider specifying a concrete type for the type parameter `S` diff --git a/tests/ui/typeck/type-inference-for-associated-types-69683.rs b/tests/ui/typeck/type-inference-for-associated-types-69683.rs index f18adcae23b05..756a0112710d9 100644 --- a/tests/ui/typeck/type-inference-for-associated-types-69683.rs +++ b/tests/ui/typeck/type-inference-for-associated-types-69683.rs @@ -29,6 +29,5 @@ fn main() { let b: [u8; 3] = [0u8; 3]; 0u16.foo(b); //~ ERROR type annotations needed - //~^ ERROR type annotations needed //>::foo(0u16, b); } diff --git a/tests/ui/typeck/type-inference-for-associated-types-69683.stderr b/tests/ui/typeck/type-inference-for-associated-types-69683.stderr index 5d49d442c55d0..60a3131f5863d 100644 --- a/tests/ui/typeck/type-inference-for-associated-types-69683.stderr +++ b/tests/ui/typeck/type-inference-for-associated-types-69683.stderr @@ -5,41 +5,13 @@ LL | 0u16.foo(b); | ^^^ | = note: cannot satisfy `>::Array == [u8; 3]` + = note: cannot satisfy `u8: Element<_>` help: try using a fully qualified path to specify the expected types | LL - 0u16.foo(b); LL + >::foo(0u16, b); | -error[E0283]: type annotations needed - --> $DIR/type-inference-for-associated-types-69683.rs:31:10 - | -LL | 0u16.foo(b); - | ^^^ - | -note: multiple `impl`s satisfying `u8: Element<_>` found - --> $DIR/type-inference-for-associated-types-69683.rs:6:1 - | -LL | impl Element<()> for T { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | impl, S> Element<[S; 3]> for T { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: required by a bound in `Foo::foo` - --> $DIR/type-inference-for-associated-types-69683.rs:16:9 - | -LL | u8: Element, - | ^^^^^^^^^^ required by this bound in `Foo::foo` -LL | { -LL | fn foo(self, x: >::Array); - | --- required by a bound in this associated function -help: try using a fully qualified path to specify the expected types - | -LL - 0u16.foo(b); -LL + >::foo(0u16, b); - | - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0283, E0284. -For more information about an error, try `rustc --explain E0283`. +For more information about this error, try `rustc --explain E0284`. From e27cb9b425939b806667c7aa521b1f51aac034af Mon Sep 17 00:00:00 2001 From: albab-hasan Date: Thu, 6 Aug 2026 14:38:53 +0600 Subject: [PATCH 2/3] point at the applicable impls in merged ambiguity errors --- .../src/error_reporting/traits/ambiguity.rs | 84 ++++++++++++------- tests/ui/inference/issue-70082.stderr | 4 +- tests/ui/inference/issue-71584.stderr | 5 +- tests/ui/inference/issue-72690.stderr | 56 +++++++++++-- ...od-ambig-one-trait-unknown-int-type.stderr | 9 +- .../infer-unwrap-none-issue-120786.stderr | 56 +++++++++++-- ...ction-predicate-not-satisfied-69455.stderr | 9 +- tests/ui/traits/issue-77982.stderr | 6 +- .../index-expr-ambiguous-type.stderr | 8 +- ...nference-for-associated-types-69683.stderr | 9 +- 10 files changed, 193 insertions(+), 53 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index 43b337d005bbe..a76758ebf089e 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -334,34 +334,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .with_long_ty_path(long_ty_path) }; - let mut ambiguities = compute_applicable_impls_for_diagnostics( - self.infcx, - &obligation.with(self.tcx, trait_pred), - false, - ); - let has_non_region_infer = trait_pred - .skip_binder() - .trait_ref - .args - .types() - .any(|t| !t.is_ty_or_numeric_infer()); - // It doesn't make sense to talk about applicable impls if there are more than a - // handful of them. If there are a lot of them, but only a few of them have no type - // params, we only show those, as they are more likely to be useful/intended. - if ambiguities.len() > 5 { - let infcx = self.infcx; - if !ambiguities.iter().all(|option| match option { - CandidateSource::DefId(did) => infcx.tcx.generics_of(*did).count() == 0, - CandidateSource::ParamEnv(_) => true, - }) { - // If not all are blanket impls, we filter blanked impls out. - ambiguities.retain(|option| match option { - CandidateSource::DefId(did) => infcx.tcx.generics_of(*did).count() == 0, - CandidateSource::ParamEnv(_) => true, - }); - } - } - if ambiguities.len() > 1 && ambiguities.len() < 10 && has_non_region_infer { + if let Some(ambiguities) = self.applicable_impls_to_mention(obligation, trait_pred) + { if let Some(e) = self.tainted_by_errors() && term.is_none() { @@ -761,7 +735,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { format!("the type must also implement `{tr}`") } else { let pred = self.tcx.short_string(related_pred, &mut err.long_ty_path()); - format!("cannot satisfy `{pred}`") + let note = format!("cannot satisfy `{pred}`"); + // The self type is known, so the `impl`s that could have applied to it are + // few and worth pointing at, like the blamed bound does. When it is still + // an inference variable the list is every `impl` of the trait, which is + // why the branch above only names the trait. + // + // `tainted_by_errors` is checked because `annotate_source_of_ambiguity` + // downgrades the whole diagnostic once an error was already emitted. + if !mentioned_strs.contains(¬e) + && self.tainted_by_errors().is_none() + && let Some(ambiguities) = + self.applicable_impls_to_mention(&error.obligation, clause) + { + self.annotate_source_of_ambiguity(&mut err, &ambiguities, related_pred); + mentioned_strs.push(note); + mentioned.push(related_pred); + continue; + } + note } } ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => { @@ -786,6 +778,40 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { err.emit() } + /// The `impl`s and `where` clauses that could have satisfied `trait_pred`, when listing them + /// is likely to help. `None` means the caller should describe the bound some other way. + fn applicable_impls_to_mention( + &self, + obligation: &PredicateObligation<'tcx>, + trait_pred: ty::PolyTraitPredicate<'tcx>, + ) -> Option> { + let mut ambiguities = compute_applicable_impls_for_diagnostics( + self.infcx, + &obligation.with(self.tcx, trait_pred), + false, + ); + let has_non_region_infer = + trait_pred.skip_binder().trait_ref.args.types().any(|t| !t.is_ty_or_numeric_infer()); + // It doesn't make sense to talk about applicable impls if there are more than a + // handful of them. If there are a lot of them, but only a few of them have no type + // params, we only show those, as they are more likely to be useful/intended. + if ambiguities.len() > 5 { + let infcx = self.infcx; + if !ambiguities.iter().all(|option| match option { + CandidateSource::DefId(did) => infcx.tcx.generics_of(*did).count() == 0, + CandidateSource::ParamEnv(_) => true, + }) { + // If not all are blanket impls, we filter blanked impls out. + ambiguities.retain(|option| match option { + CandidateSource::DefId(did) => infcx.tcx.generics_of(*did).count() == 0, + CandidateSource::ParamEnv(_) => true, + }); + } + } + (ambiguities.len() > 1 && ambiguities.len() < 10 && has_non_region_infer) + .then_some(ambiguities) + } + fn annotate_source_of_ambiguity( &self, err: &mut Diag<'_>, diff --git a/tests/ui/inference/issue-70082.stderr b/tests/ui/inference/issue-70082.stderr index bf115aab8506b..cce1a5ee6a6bc 100644 --- a/tests/ui/inference/issue-70082.stderr +++ b/tests/ui/inference/issue-70082.stderr @@ -7,7 +7,9 @@ LL | let y: f64 = 0.01f64 * 1i16.into(); | type must be known at this point | = note: cannot satisfy `>::Output == f64` - = note: cannot satisfy `f64: Mul<_>` + = note: multiple `impl`s satisfying `f64: Mul<_>` found in the `core` crate: + - impl Mul for f64; + - impl Mul<&f64> for f64; = note: the type must also implement `From` help: try using a fully qualified path to specify the expected types | diff --git a/tests/ui/inference/issue-71584.stderr b/tests/ui/inference/issue-71584.stderr index 7c6f211ec8b7b..813473c969eb2 100644 --- a/tests/ui/inference/issue-71584.stderr +++ b/tests/ui/inference/issue-71584.stderr @@ -7,7 +7,10 @@ LL | d = d % n.into(); | type must be known at this point | = note: cannot satisfy `>::Output == u64` - = note: cannot satisfy `u64: Rem<_>` + = note: multiple `impl`s satisfying `u64: Rem<_>` found in the `core` crate: + - impl Rem for u64; + - impl Rem<&u64> for u64; + - impl Rem> for u64; = note: the type must also implement `From` help: try using a fully qualified path to specify the expected types | diff --git a/tests/ui/inference/issue-72690.stderr b/tests/ui/inference/issue-72690.stderr index 3b7c4514ac999..113df0c792beb 100644 --- a/tests/ui/inference/issue-72690.stderr +++ b/tests/ui/inference/issue-72690.stderr @@ -7,7 +7,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/issue-72690.rs:11:9 @@ -18,7 +23,12 @@ LL | |x| String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed for `&_` --> $DIR/issue-72690.rs:15:9 @@ -46,7 +56,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/issue-72690.rs:25:5 @@ -57,7 +72,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/issue-72690.rs:33:5 @@ -68,7 +88,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/issue-72690.rs:41:5 @@ -79,7 +104,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/issue-72690.rs:47:5 @@ -90,7 +120,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/issue-72690.rs:55:5 @@ -101,7 +136,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error: aborting due to 9 previous errors diff --git a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr index 5bb8d0ea3fb2c..910ce3fe9ad36 100644 --- a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr +++ b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr @@ -4,7 +4,14 @@ error[E0282]: type annotations needed for `Vec<_>` LL | let mut x = Vec::new(); | ^^^^^ ---------- type must be known at this point | - = note: cannot satisfy `Vec<_>: Foo` +note: multiple `impl`s satisfying `Vec<_>: Foo` found + --> $DIR/method-ambig-one-trait-unknown-int-type.rs:9:1 + | +LL | impl Foo for Vec { + | ^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | impl Foo for Vec { + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider giving `x` an explicit type, where the type for type parameter `T` is specified | LL | let mut x: Vec = Vec::new(); diff --git a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr index 4c4bfe5db4351..18a823323587d 100644 --- a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr +++ b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr @@ -18,7 +18,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/infer-unwrap-none-issue-120786.rs:15:9 @@ -29,7 +34,12 @@ LL | |x| String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed for `&_` --> $DIR/infer-unwrap-none-issue-120786.rs:20:9 @@ -57,7 +67,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/infer-unwrap-none-issue-120786.rs:32:5 @@ -68,7 +83,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/infer-unwrap-none-issue-120786.rs:41:5 @@ -79,7 +99,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/infer-unwrap-none-issue-120786.rs:50:5 @@ -90,7 +115,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/infer-unwrap-none-issue-120786.rs:57:5 @@ -101,7 +131,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error[E0283]: type annotations needed --> $DIR/infer-unwrap-none-issue-120786.rs:66:5 @@ -112,7 +147,12 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; - = note: cannot satisfy `str: AsRef<_>` + = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef for str; + - impl AsRef<[u8]> for str; + - impl AsRef for str; error: aborting due to 10 previous errors diff --git a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr index 27d6efee8bcee..76affa7e29f48 100644 --- a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr +++ b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr @@ -7,7 +7,14 @@ LL | println!("{}", 23u64.test(xs.iter().sum())); | type must be known at this point | = note: cannot satisfy `>::Output == _` - = note: cannot satisfy `u64: Test<_>` +note: multiple `impl`s satisfying `u64: Test<_>` found + --> $DIR/projection-predicate-not-satisfied-69455.rs:11:1 + | +LL | impl Test for u64 { + | ^^^^^^^^^^^^^^^^^^^^^^ +... +LL | impl Test for u64 { + | ^^^^^^^^^^^^^^^^^^^^^^ = note: the type must also implement `Sum<&u64>` help: consider specifying a concrete type for the type parameter `S` | diff --git a/tests/ui/traits/issue-77982.stderr b/tests/ui/traits/issue-77982.stderr index 9f5375992b960..c46b297c9ad5d 100644 --- a/tests/ui/traits/issue-77982.stderr +++ b/tests/ui/traits/issue-77982.stderr @@ -12,7 +12,11 @@ LL | opts.get(opt.as_ref()); where T: ?Sized; = note: the type must also implement `Hash` = note: the type must also implement `Eq` - = note: cannot satisfy `String: AsRef<_>` + = note: multiple `impl`s satisfying `String: AsRef<_>` found in the following crates: `alloc`, `std`: + - impl AsRef for String; + - impl AsRef for String; + - impl AsRef<[u8]> for String; + - impl AsRef for String; note: required by a bound in `HashMap::::get` --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL help: consider specifying a concrete type for the type parameter `Q` diff --git a/tests/ui/type-inference/index-expr-ambiguous-type.stderr b/tests/ui/type-inference/index-expr-ambiguous-type.stderr index 3c5e4c7c951f7..17a93bce976a8 100644 --- a/tests/ui/type-inference/index-expr-ambiguous-type.stderr +++ b/tests/ui/type-inference/index-expr-ambiguous-type.stderr @@ -11,7 +11,9 @@ LL | let _foo = 0 + [1, 2, 3][bad_idx.into()]; | ^^^^ cannot infer type | = note: cannot satisfy `>::Output == _` - = note: cannot satisfy `i32: Add<_>` + = note: multiple `impl`s satisfying `i32: Add<_>` found in the `core` crate: + - impl Add for i32; + - impl Add<&i32> for i32; error[E0283]: type annotations needed --> $DIR/index-expr-ambiguous-type.rs:21:34 @@ -44,7 +46,9 @@ LL | let _foo = 0u64 + [1i32, 2, 3][bad_idx.into()]; | ^ cannot infer type | = note: cannot satisfy `>::Output == _` - = note: cannot satisfy `u64: Add<_>` + = note: multiple `impl`s satisfying `u64: Add<_>` found in the `core` crate: + - impl Add for u64; + - impl Add<&u64> for u64; error[E0284]: type annotations needed --> $DIR/index-expr-ambiguous-type.rs:44:38 diff --git a/tests/ui/typeck/type-inference-for-associated-types-69683.stderr b/tests/ui/typeck/type-inference-for-associated-types-69683.stderr index 60a3131f5863d..44d68218b9924 100644 --- a/tests/ui/typeck/type-inference-for-associated-types-69683.stderr +++ b/tests/ui/typeck/type-inference-for-associated-types-69683.stderr @@ -5,7 +5,14 @@ LL | 0u16.foo(b); | ^^^ | = note: cannot satisfy `>::Array == [u8; 3]` - = note: cannot satisfy `u8: Element<_>` +note: multiple `impl`s satisfying `u8: Element<_>` found + --> $DIR/type-inference-for-associated-types-69683.rs:6:1 + | +LL | impl Element<()> for T { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | impl, S> Element<[S; 3]> for T { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using a fully qualified path to specify the expected types | LL - 0u16.foo(b); From 846d935393e262207fd2783fae0d9af0e607d6d3 Mon Sep 17 00:00:00 2001 From: albab-hasan Date: Wed, 12 Aug 2026 19:19:11 +0600 Subject: [PATCH 3/3] only merge ambiguity errors that blame the same expression an error pointing at a different expression labels that expression and suggests how to annotate it, and a note on the merged diagnostic carries none of that, so it kept getting dropped. such errors are reported on their own again, and the bounds behind the errors that do get merged are now explained on the merged diagnostic. --- .../src/error_reporting/traits/ambiguity.rs | 8 ++ .../src/error_reporting/traits/mod.rs | 51 ++++---- .../duplicate-bound-err.stderr | 3 - .../unique-closure-type-mismatch.stderr | 2 - tests/ui/error-codes/E0283.stderr | 2 - .../span-format_args-issue-140578.stderr | 24 +++- ...ambig-hr-projection-issue-93340.old.stderr | 1 - .../bugs/issue-88382.stderr | 9 +- .../bugs/issue-91762.stderr | 1 - ...eck-in-selection-6-ambig-unify.next.stderr | 1 - ...heck-in-selection-6-ambig-unify.old.stderr | 1 - ...-in-higher-ranked-fn-signature.next.stderr | 1 - .../auto-trait-selection-freeze.old.stderr | 1 - .../auto-trait-selection.old.stderr | 1 - .../cross-return-site-inference.stderr | 4 - .../ambiguity-errors-single-diagnostic.stderr | 5 + tests/ui/inference/cannot-infer-async.stderr | 1 - .../cannot-infer-closure-circular.stderr | 1 - .../ui/inference/cannot-infer-closure.stderr | 1 - ...nnot-infer-iterator-sum-return-type.stderr | 1 - .../cannot-infer-partial-try-return.stderr | 1 - tests/ui/inference/issue-12028.stderr | 7 ++ tests/ui/inference/issue-70082.stderr | 1 - tests/ui/inference/issue-71584.stderr | 1 - tests/ui/inference/issue-71732.stderr | 5 +- tests/ui/inference/issue-72616.stderr | 2 - tests/ui/inference/issue-72690.rs | 8 ++ tests/ui/inference/issue-72690.stderr | 114 ++++++++++++++++-- ...745-avoid-expr-from-macro-expansion.stderr | 5 +- .../single-type-generic-suggestion.stderr | 2 + .../inference/question-mark-type-infer.stderr | 9 -- .../question-mark-type-inference-in-chain.rs | 3 - ...estion-mark-type-inference-in-chain.stderr | 15 +-- ...method-ambig-one-trait-unknown-int-type.rs | 2 +- ...od-ambig-one-trait-unknown-int-type.stderr | 22 +++- .../infer-unwrap-none-issue-120786.rs | 8 ++ .../infer-unwrap-none-issue-120786.stderr | 114 ++++++++++++++++-- .../pattern/slice-patterns-irrefutable.stderr | 1 - .../types/into-inference-needs-type.stderr | 3 - ...gument-with-unnecessary-method-call.stderr | 1 - ...rojection-predicate-not-satisfied-69455.rs | 1 + ...ction-predicate-not-satisfied-69455.stderr | 19 ++- tests/ui/traits/issue-77982.rs | 1 + tests/ui/traits/issue-77982.stderr | 44 +++++-- .../multidispatch-convert-ambig-dest.stderr | 1 - .../runaway-impl-candidate-selection.stderr | 1 - ...to_ignores_unnormalizable_candidate.stderr | 1 - ...expected-pointer-deref-issue-154568.stderr | 1 - .../next-solver/well-formed-in-relate.stderr | 5 + .../index-expr-ambiguous-type.stderr | 4 - .../or_else-multiple-type-params.stderr | 5 + .../panic-with-unspecified-type.stderr | 3 + .../send-with-unspecified-type.stderr | 1 - tests/ui/type-inference/sort_by_key.stderr | 1 - ...nference-for-associated-types-69683.stderr | 8 ++ 55 files changed, 410 insertions(+), 129 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index a76758ebf089e..06d882a309489 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -775,6 +775,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } self.note_obligation_cause(&mut err, obligation); + // The merged errors are not reported on their own anymore, so the bounds they came from + // have to be explained here too. Causes shared with the blamed obligation are already + // described by the call above. + for &error in related { + if error.obligation.cause.code() != obligation.cause.code() { + self.note_obligation_cause(&mut err, &error.obligation); + } + } err.emit() } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index 1b67314a95b45..8bf5814b9fe13 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -298,13 +298,39 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .collect(), None => vec![], }; + // Only merge errors that a note on this diagnostic can fully + // represent. An error blaming a different expression labels that + // expression and suggests how to annotate it, and one whose + // predicate we can't phrase as a note (e.g. const evaluatability) + // says nothing here, so both keep their own error. + let merges = |other: usize| { + errors[other].obligation.cause.span == error.obligation.cause.span + && match errors[other].obligation.predicate.kind().skip_binder() + { + ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => { + !matches!( + self.tcx.as_lang_item(data.def_id()), + Some( + LangItem::Sized + | LangItem::MetaSized + | LangItem::PointeeSized + ) + ) + } + ty::PredicateKind::Clause(ty::ClauseKind::Projection( + _, + )) => true, + _ => false, + } + }; let related: Vec<_> = group .iter() .filter(|&&other| { // Exclude already-reported primaries: they were their own // canonical error and adding them as notes here would // produce duplicate information. - !is_suppressed[other] + merges(other) + && !is_suppressed[other] && !errors[other].references_error() && !reported_as_primary[other] }) @@ -312,28 +338,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .collect(); let guar = self.report_fulfillment_error(error, &related); for &other in &group { - // Only suppress related errors whose predicates produce - // informative notes in maybe_report_ambiguity (Trait, - // Projection). Predicates we can't represent as notes - // (e.g. const evaluatability) still report separately. - let pred = errors[other].obligation.predicate; - let suppresses = match pred.kind().skip_binder() { - ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => { - !matches!( - self.tcx.as_lang_item(data.def_id()), - Some( - LangItem::Sized - | LangItem::MetaSized - | LangItem::PointeeSized - ) - ) - } - ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => { - true - } - _ => false, - }; - if suppresses { + if merges(other) { merged[other] = Some(guar); } } diff --git a/tests/ui/associated-type-bounds/duplicate-bound-err.stderr b/tests/ui/associated-type-bounds/duplicate-bound-err.stderr index 65d132cc50224..f685b01cd8cc3 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound-err.stderr +++ b/tests/ui/associated-type-bounds/duplicate-bound-err.stderr @@ -4,8 +4,6 @@ error[E0282]: type annotations needed LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` | - = note: the type must also implement `Copy` - = note: the type must also implement `Send` help: consider specifying a concrete type for the type parameter `T` | LL | iter::empty::() @@ -17,7 +15,6 @@ error[E0282]: type annotations needed LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` | - = note: the type must also implement `Copy` help: consider specifying a concrete type for the type parameter `T` | LL | iter::empty::() diff --git a/tests/ui/closures/unique-closure-type-mismatch.stderr b/tests/ui/closures/unique-closure-type-mismatch.stderr index 54bafa9af524b..7d2a05b1d148b 100644 --- a/tests/ui/closures/unique-closure-type-mismatch.stderr +++ b/tests/ui/closures/unique-closure-type-mismatch.stderr @@ -19,8 +19,6 @@ LL | 1 => |c| c + 1, | = note: cannot satisfy `<_ as Add>::Output == _` = note: the type must also implement `Add` - = note: cannot satisfy `<_ as Sub>::Output == _` - = note: the type must also implement `Sub` help: consider giving this closure parameter an explicit type | LL | 1 => |c: /* Type */| c + 1, diff --git a/tests/ui/error-codes/E0283.stderr b/tests/ui/error-codes/E0283.stderr index a8bd34b9a2d40..29baae5f133a2 100644 --- a/tests/ui/error-codes/E0283.stderr +++ b/tests/ui/error-codes/E0283.stderr @@ -28,8 +28,6 @@ LL | impl Into for Impl { = note: and another `impl` found in the `core` crate: - impl Into for T where U: From; - = note: cannot satisfy `<_ as Mul>::Output == u32` - = note: the type must also implement `Mul` help: try using a fully qualified path to specify the expected types | LL - let bar = foo_impl.into() * 1u32; diff --git a/tests/ui/errors/span-format_args-issue-140578.stderr b/tests/ui/errors/span-format_args-issue-140578.stderr index a514fdd0ef630..c4a2911d3fb07 100644 --- a/tests/ui/errors/span-format_args-issue-140578.stderr +++ b/tests/ui/errors/span-format_args-issue-140578.stderr @@ -2,41 +2,57 @@ error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:2:28 | LL | print!("{:?} {a} {a:?}", [], a = 1 + 1); - | ^^ cannot infer type + | ---- ^^ cannot infer type + | | + | required by this formatting parameter | = note: the type must also implement `Debug` + = note: required for `[_; 0]` to implement `Debug` error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:7:30 | LL | println!("{:?} {a} {a:?}", [], a = 1 + 1); - | ^^ cannot infer type + | ---- ^^ cannot infer type + | | + | required by this formatting parameter | = note: the type must also implement `Debug` + = note: required for `[_; 0]` to implement `Debug` error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:12:35 | LL | println!("{:?} {:?} {a} {a:?}", [], [], a = 1 + 1); - | ^^ cannot infer type + | ---- ^^ cannot infer type + | | + | required by this formatting parameter | = note: the type must also implement `Debug` + = note: required for `[_; 0]` to implement `Debug` error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:17:41 | LL | println!("{:?} {:?} {a} {a:?} {b:?}", [], [], a = 1 + 1, b = []); - | ^^ cannot infer type + | ---- ^^ cannot infer type + | | + | required by this formatting parameter | = note: the type must also implement `Debug` + = note: required for `[_; 0]` to implement `Debug` error[E0282]: type annotations needed --> $DIR/span-format_args-issue-140578.rs:26:9 | +LL | {:?} {:?} + | ---- required by this formatting parameter +... LL | [], | ^^ cannot infer type | = note: the type must also implement `Debug` + = note: required for `[_; 0]` to implement `Debug` error: aborting due to 5 previous errors diff --git a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr index bb0ebbc723ff4..0dcc5f11d4861 100644 --- a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr +++ b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.old.stderr @@ -5,7 +5,6 @@ LL | cmp_eq | ^^^^^^ cannot infer type of the type parameter `A` declared on the function `cmp_eq` | = note: the type must implement `Scalar` - = note: cannot satisfy `for<'a> ::RefType<'_> == ::RefType<'a>` = note: cannot satisfy `::RefType<'_> == _` note: required by a bound in `cmp_eq` --> $DIR/ambig-hr-projection-issue-93340.rs:10:22 diff --git a/tests/ui/generic-associated-types/bugs/issue-88382.stderr b/tests/ui/generic-associated-types/bugs/issue-88382.stderr index c1a6ca0f4d0d7..8b6c8929dd608 100644 --- a/tests/ui/generic-associated-types/bugs/issue-88382.stderr +++ b/tests/ui/generic-associated-types/bugs/issue-88382.stderr @@ -2,7 +2,9 @@ error[E0283]: type annotations needed --> $DIR/issue-88382.rs:26:40 | LL | do_something(SomeImplementation(), test); - | ^^^^ cannot infer type of the type parameter `I` declared on the function `test` + | ------------ ^^^^ cannot infer type of the type parameter `I` declared on the function `test` + | | + | required by a bound introduced by this call | = note: the type must implement `Iterable` help: the trait `Iterable` is implemented for `SomeImplementation` @@ -16,6 +18,11 @@ note: required by a bound in `test` | LL | fn test<'a, I: Iterable>(_: &mut I::Iterator<'a>) {} | ^^^^^^^^ required by this bound in `test` +note: required by a bound in `do_something` + --> $DIR/issue-88382.rs:20:48 + | +LL | fn do_something(i: I, mut f: impl for<'a> Fn(&mut I::Iterator<'a>)) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `do_something` help: consider specifying a concrete type for the type parameter `I` | LL | do_something(SomeImplementation(), test::); diff --git a/tests/ui/generic-associated-types/bugs/issue-91762.stderr b/tests/ui/generic-associated-types/bugs/issue-91762.stderr index 498f3eada7bf8..b4ca65889ada0 100644 --- a/tests/ui/generic-associated-types/bugs/issue-91762.stderr +++ b/tests/ui/generic-associated-types/bugs/issue-91762.stderr @@ -5,7 +5,6 @@ LL | ret = ::fmap(arg); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the associated function `fmap` | = note: cannot satisfy `<>::Base as Functor>::With<_> == Self` - = note: cannot satisfy `<>::Base as Functor>::With<_> == _` help: consider specifying the generic arguments | LL | ret = ::fmap::(arg); diff --git a/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr b/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr index 0474b2c36c6d4..77dec93d0617a 100644 --- a/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr +++ b/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.next.stderr @@ -11,7 +11,6 @@ LL | impl Trait for () where for<'b> ((),): LeakCheckFailure<'static, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | impl Trait for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the type must also implement `Id<_>` note: required by a bound in `impls_trait` --> $DIR/leak-check-in-selection-6-ambig-unify.rs:30:19 | diff --git a/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr b/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr index 0474b2c36c6d4..77dec93d0617a 100644 --- a/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr +++ b/tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.old.stderr @@ -11,7 +11,6 @@ LL | impl Trait for () where for<'b> ((),): LeakCheckFailure<'static, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | impl Trait for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the type must also implement `Id<_>` note: required by a bound in `impls_trait` --> $DIR/leak-check-in-selection-6-ambig-unify.rs:30:19 | diff --git a/tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr b/tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr index 47ef70993237b..a917c34b52ae5 100644 --- a/tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr +++ b/tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr @@ -5,7 +5,6 @@ LL | let _: for<'a> fn(<_ as Trait<'a>>::Assoc) = foo::(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type | = note: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc == _` - = note: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc == >::Assoc` error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr b/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr index 513b28099e384..b6c6e74f26052 100644 --- a/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.old.stderr @@ -13,7 +13,6 @@ LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the type must also implement `Default` note: required by a bound in `is_trait` --> $DIR/auto-trait-selection-freeze.rs:11:16 | diff --git a/tests/ui/impl-trait/auto-trait-selection.old.stderr b/tests/ui/impl-trait/auto-trait-selection.old.stderr index 1da41350ce452..8e44100177154 100644 --- a/tests/ui/impl-trait/auto-trait-selection.old.stderr +++ b/tests/ui/impl-trait/auto-trait-selection.old.stderr @@ -13,7 +13,6 @@ LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | impl Trait for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the type must also implement `Default` note: required by a bound in `is_trait` --> $DIR/auto-trait-selection.rs:7:16 | diff --git a/tests/ui/impl-trait/cross-return-site-inference.stderr b/tests/ui/impl-trait/cross-return-site-inference.stderr index 758b7fb245d68..5512c234af985 100644 --- a/tests/ui/impl-trait/cross-return-site-inference.stderr +++ b/tests/ui/impl-trait/cross-return-site-inference.stderr @@ -4,8 +4,6 @@ error[E0282]: type annotations needed LL | Ok(()) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | - = note: the type must also implement `Debug` - = note: the type must also implement `From<&str>` help: consider specifying the generic arguments | LL | Ok::<(), E>(()) @@ -17,7 +15,6 @@ error[E0790]: cannot call associated function on trait without specifying the co LL | return Err(From::from("foo")); | ^^^^^^^^^^^^^^^^^ cannot call associated function of trait | - = note: the type must also implement `Debug` help: use a fully-qualified path to a specific available implementation | LL | return Err(::from("foo")); @@ -29,7 +26,6 @@ error[E0790]: cannot call associated function on trait without specifying the co LL | Err(From::from("foo")) | ^^^^^^^^^^^^^^^^^ cannot call associated function of trait | - = note: the type must also implement `Debug` help: use a fully-qualified path to a specific available implementation | LL | Err(::from("foo")) diff --git a/tests/ui/inference/ambiguity-errors-single-diagnostic.stderr b/tests/ui/inference/ambiguity-errors-single-diagnostic.stderr index f0013e957b6f9..4488032717ce2 100644 --- a/tests/ui/inference/ambiguity-errors-single-diagnostic.stderr +++ b/tests/ui/inference/ambiguity-errors-single-diagnostic.stderr @@ -50,6 +50,11 @@ note: required by a bound in `constrained` | LL | fn constrained(_: T) {} | ^^^^^ required by this bound in `constrained` +note: required by a bound in `constrained` + --> $DIR/ambiguity-errors-single-diagnostic.rs:13:27 + | +LL | fn constrained(_: T) {} + | ^^^^^ required by this bound in `constrained` help: consider specifying a concrete type for the type parameter `T` | LL | constrained::(Default::default()); diff --git a/tests/ui/inference/cannot-infer-async.stderr b/tests/ui/inference/cannot-infer-async.stderr index 1629ee416ba2b..346109fd5c018 100644 --- a/tests/ui/inference/cannot-infer-async.stderr +++ b/tests/ui/inference/cannot-infer-async.stderr @@ -4,7 +4,6 @@ error[E0282]: type annotations needed LL | Ok(()) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | - = note: the type must also implement `From` help: consider specifying the generic arguments | LL | Ok::<(), E>(()) diff --git a/tests/ui/inference/cannot-infer-closure-circular.stderr b/tests/ui/inference/cannot-infer-closure-circular.stderr index 6caf02b0e2f55..ee17f7737cf30 100644 --- a/tests/ui/inference/cannot-infer-closure-circular.stderr +++ b/tests/ui/inference/cannot-infer-closure-circular.stderr @@ -7,7 +7,6 @@ LL | let v = r?; LL | Ok(v) | ----- type must be known at this point | - = note: the type must also implement `From<_>` help: consider giving this closure parameter an explicit type, where the type for type parameter `E` is specified | LL | let x = |r: Result<_, E>| { diff --git a/tests/ui/inference/cannot-infer-closure.stderr b/tests/ui/inference/cannot-infer-closure.stderr index 1835edf35d61c..507a70c1bac46 100644 --- a/tests/ui/inference/cannot-infer-closure.stderr +++ b/tests/ui/inference/cannot-infer-closure.stderr @@ -4,7 +4,6 @@ error[E0282]: type annotations needed LL | Ok(b) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | - = note: the type must also implement `From<()>` help: consider specifying the generic arguments | LL | Ok::<(), E>(b) diff --git a/tests/ui/inference/cannot-infer-iterator-sum-return-type.stderr b/tests/ui/inference/cannot-infer-iterator-sum-return-type.stderr index a7d9b0335e584..594b6f0181db0 100644 --- a/tests/ui/inference/cannot-infer-iterator-sum-return-type.stderr +++ b/tests/ui/inference/cannot-infer-iterator-sum-return-type.stderr @@ -13,7 +13,6 @@ help: the trait `Sum` is implemented for `i32` ::: $SRC_DIR/core/src/iter/traits/accum.rs:LL:COL | = note: in this macro invocation - = note: the type must also implement `PartialOrd` note: required by a bound in `std::iter::Iterator::sum` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL = note: this error originates in the macro `integer_sum_product` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/inference/cannot-infer-partial-try-return.stderr b/tests/ui/inference/cannot-infer-partial-try-return.stderr index 255e1b93fb04a..ff4d7418a63af 100644 --- a/tests/ui/inference/cannot-infer-partial-try-return.stderr +++ b/tests/ui/inference/cannot-infer-partial-try-return.stderr @@ -4,7 +4,6 @@ error[E0282]: type annotations needed LL | Ok(()) | ^^ cannot infer type of the type parameter `E` declared on the enum `Result` | - = note: the type must also implement `From` help: consider specifying the generic arguments | LL | Ok::<(), QualifiedError<_>>(()) diff --git a/tests/ui/inference/issue-12028.stderr b/tests/ui/inference/issue-12028.stderr index 68bacac0fbbd0..92cfd85d96f85 100644 --- a/tests/ui/inference/issue-12028.stderr +++ b/tests/ui/inference/issue-12028.stderr @@ -6,6 +6,13 @@ LL | self.input_stream(&mut stream); | = note: cannot satisfy `<_ as StreamHasher>::S == ::S` = note: the type must also implement `StreamHasher` +note: required by a bound in `StreamHash::input_stream` + --> $DIR/issue-12028.rs:20:21 + | +LL | trait StreamHash: Hash { + | ^^^^^^^^^^^^ required by this bound in `StreamHash::input_stream` +LL | fn input_stream(&self, stream: &mut H::S); + | ------------ required by a bound in this associated function help: try using a fully qualified path to specify the expected types | LL - self.input_stream(&mut stream); diff --git a/tests/ui/inference/issue-70082.stderr b/tests/ui/inference/issue-70082.stderr index cce1a5ee6a6bc..5dc2311272e67 100644 --- a/tests/ui/inference/issue-70082.stderr +++ b/tests/ui/inference/issue-70082.stderr @@ -10,7 +10,6 @@ LL | let y: f64 = 0.01f64 * 1i16.into(); = note: multiple `impl`s satisfying `f64: Mul<_>` found in the `core` crate: - impl Mul for f64; - impl Mul<&f64> for f64; - = note: the type must also implement `From` help: try using a fully qualified path to specify the expected types | LL - let y: f64 = 0.01f64 * 1i16.into(); diff --git a/tests/ui/inference/issue-71584.stderr b/tests/ui/inference/issue-71584.stderr index 813473c969eb2..1439ae6a51583 100644 --- a/tests/ui/inference/issue-71584.stderr +++ b/tests/ui/inference/issue-71584.stderr @@ -11,7 +11,6 @@ LL | d = d % n.into(); - impl Rem for u64; - impl Rem<&u64> for u64; - impl Rem> for u64; - = note: the type must also implement `From` help: try using a fully qualified path to specify the expected types | LL - d = d % n.into(); diff --git a/tests/ui/inference/issue-71732.stderr b/tests/ui/inference/issue-71732.stderr index e3e28865ef4be..04be1ce6c07f4 100644 --- a/tests/ui/inference/issue-71732.stderr +++ b/tests/ui/inference/issue-71732.stderr @@ -12,7 +12,10 @@ LL | .get(&"key".into()) where T: ?Sized; = note: the type must also implement `Hash` = note: the type must also implement `Eq` - = note: the type must also implement `From<&str>` +note: required by a bound in `HashMap::::get` + --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL +note: required by a bound in `HashMap::::get` + --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL note: required by a bound in `HashMap::::get` --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL help: consider specifying a concrete type for the type parameter `Q` diff --git a/tests/ui/inference/issue-72616.stderr b/tests/ui/inference/issue-72616.stderr index 0f7fd9223b1eb..8eba3216a8464 100644 --- a/tests/ui/inference/issue-72616.stderr +++ b/tests/ui/inference/issue-72616.stderr @@ -13,8 +13,6 @@ LL | if String::from("a") == "a".try_into().unwrap() {} - impl PartialEq for String; - impl PartialEq for String; - impl PartialEq for String; - = note: the type must also implement `TryFrom<&str>` - = note: cannot satisfy `<_ as TryFrom<&str>>::Error == _` help: try using a fully qualified path to specify the expected types | LL - if String::from("a") == "a".try_into().unwrap() {} diff --git a/tests/ui/inference/issue-72690.rs b/tests/ui/inference/issue-72690.rs index 4edbd9ca15de7..8c0a0f51a2157 100644 --- a/tests/ui/inference/issue-72690.rs +++ b/tests/ui/inference/issue-72690.rs @@ -5,10 +5,12 @@ fn no_err() { fn err() { String::from("x".as_ref()); //~ ERROR type annotations needed + //~^ ERROR type annotations needed } fn arg_pat_closure_err() { |x| String::from("x".as_ref()); //~ ERROR type annotations needed + //~| ERROR type annotations needed } fn local_pat_closure_err() { @@ -17,12 +19,14 @@ fn local_pat_closure_err() { fn err_first_arg_pat() { String::from("x".as_ref()); //~ ERROR type annotations needed + //~^ ERROR type annotations needed |x: String| x; } fn err_second_arg_pat() { |x: String| x; String::from("x".as_ref()); //~ ERROR type annotations needed + //~^ ERROR type annotations needed } fn err_mid_arg_pat() { @@ -31,6 +35,7 @@ fn err_mid_arg_pat() { |x: String| x; |x: String| x; String::from("x".as_ref()); //~ ERROR type annotations needed + //~^ ERROR type annotations needed |x: String| x; |x: String| x; |x: String| x; @@ -39,12 +44,14 @@ fn err_mid_arg_pat() { fn err_first_local_pat() { String::from("x".as_ref()); //~ ERROR type annotations needed + //~^ ERROR type annotations needed let _ = String::from("x"); } fn err_second_local_pat() { let _ = String::from("x"); String::from("x".as_ref()); //~ ERROR type annotations needed + //~^ ERROR type annotations needed } fn err_mid_local_pat() { @@ -53,6 +60,7 @@ fn err_mid_local_pat() { let _ = String::from("x"); let _ = String::from("x"); String::from("x".as_ref()); //~ ERROR type annotations needed + //~^ ERROR type annotations needed let _ = String::from("x"); let _ = String::from("x"); let _ = String::from("x"); diff --git a/tests/ui/inference/issue-72690.stderr b/tests/ui/inference/issue-72690.stderr index 113df0c792beb..4926cf9e981ba 100644 --- a/tests/ui/inference/issue-72690.stderr +++ b/tests/ui/inference/issue-72690.stderr @@ -7,15 +7,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:7:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:11:9 + --> $DIR/issue-72690.rs:12:9 | LL | |x| String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -23,15 +35,27 @@ LL | |x| String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:12:26 + | +LL | |x| String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - |x| String::from("x".as_ref()); +LL + |x| String::from(>::as_ref("x")); + | error[E0283]: type annotations needed for `&_` - --> $DIR/issue-72690.rs:15:9 + --> $DIR/issue-72690.rs:17:9 | LL | let _ = "x".as_ref(); | ^ ------ type must be known at this point @@ -48,7 +72,7 @@ LL | let _: &T = "x".as_ref(); | ++++ error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:19:5 + --> $DIR/issue-72690.rs:21:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -56,15 +80,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:21:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:25:5 + --> $DIR/issue-72690.rs:28:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -72,15 +108,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:28:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:33:5 + --> $DIR/issue-72690.rs:37:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -88,15 +136,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:37:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:41:5 + --> $DIR/issue-72690.rs:46:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -104,15 +164,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:46:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:47:5 + --> $DIR/issue-72690.rs:53:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -120,15 +192,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:53:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/issue-72690.rs:55:5 + --> $DIR/issue-72690.rs:62:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -136,13 +220,25 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/issue-72690.rs:62:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | -error: aborting due to 9 previous errors +error: aborting due to 17 previous errors For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr index dc33482010243..14d671f80e095 100644 --- a/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr +++ b/tests/ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.stderr @@ -2,9 +2,12 @@ error[E0282]: type annotations needed --> $DIR/issue-107745-avoid-expr-from-macro-expansion.rs:17:22 | LL | println!("{:?}", []); - | ^^ cannot infer type + | ---- ^^ cannot infer type + | | + | required by this formatting parameter | = note: the type must also implement `Debug` + = note: required for `[_; 0]` to implement `Debug` error: aborting due to 1 previous error diff --git a/tests/ui/inference/need_type_info/single-type-generic-suggestion.stderr b/tests/ui/inference/need_type_info/single-type-generic-suggestion.stderr index 7a69f4291c284..d1dcafcbc1d4d 100644 --- a/tests/ui/inference/need_type_info/single-type-generic-suggestion.stderr +++ b/tests/ui/inference/need_type_info/single-type-generic-suggestion.stderr @@ -6,6 +6,8 @@ LL | "".parse(); | = note: cannot satisfy `<_ as FromStr>::Err == _` = note: the type must also implement `FromStr` +note: required by a bound in `core::str::::parse` + --> $SRC_DIR/core/src/str/mod.rs:LL:COL help: consider specifying a concrete type for the type parameter `F` | LL | "".parse::(); diff --git a/tests/ui/inference/question-mark-type-infer.stderr b/tests/ui/inference/question-mark-type-infer.stderr index eb092a6f5d69c..b531d42ff93cf 100644 --- a/tests/ui/inference/question-mark-type-infer.stderr +++ b/tests/ui/inference/question-mark-type-infer.stderr @@ -5,9 +5,6 @@ LL | l.iter().map(f).collect()? | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | = note: the type must implement `FromIterator>` - = note: cannot satisfy `<_ as Try>::Residual == _` - = note: the type must also implement `Try` - = note: cannot satisfy `<_ as Try>::Output == Result, ()>` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider specifying the generic argument @@ -22,9 +19,6 @@ LL | let x = l.iter().map(f).collect()?; | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | = note: the type must implement `FromIterator>` - = note: cannot satisfy `<_ as Try>::Residual == _` - = note: the type must also implement `Try` - = note: cannot satisfy `<_ as Try>::Output == ()` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider specifying the generic argument @@ -39,9 +33,6 @@ LL | let x: Vec = l.iter().map(f).collect()?; | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | = note: the type must implement `FromIterator>` - = note: cannot satisfy `<_ as Try>::Residual == _` - = note: the type must also implement `Try` - = note: cannot satisfy `<_ as Try>::Output == Vec` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider specifying the generic argument diff --git a/tests/ui/inference/question-mark-type-inference-in-chain.rs b/tests/ui/inference/question-mark-type-inference-in-chain.rs index 23ebe1ae9d2c5..68960ec466dd3 100644 --- a/tests/ui/inference/question-mark-type-inference-in-chain.rs +++ b/tests/ui/inference/question-mark-type-inference-in-chain.rs @@ -49,9 +49,6 @@ pub fn error2(lines: &[&str]) -> Result> { //~^ ERROR: type annotations needed //~| NOTE: cannot infer type of the type parameter `B` //~| NOTE: the type must implement `FromIterator>` - //~| NOTE: cannot satisfy `<_ as Try>::Residual == _` - //~| NOTE: the type must also implement `Try` - //~| NOTE: cannot satisfy `<_ as Try>::Output == Vec` //~| NOTE: required by a bound in `collect` //~| HELP: consider specifying the generic argument tags.sort(); diff --git a/tests/ui/inference/question-mark-type-inference-in-chain.stderr b/tests/ui/inference/question-mark-type-inference-in-chain.stderr index bac168b938449..5c0a739f4e6b0 100644 --- a/tests/ui/inference/question-mark-type-inference-in-chain.stderr +++ b/tests/ui/inference/question-mark-type-inference-in-chain.stderr @@ -22,9 +22,6 @@ LL | let mut tags: Vec = lines.iter().map(|e| parse(e)).collect()?; | ^^^^^^^ cannot infer type of the type parameter `B` declared on the method `collect` | = note: the type must implement `FromIterator>` - = note: cannot satisfy `<_ as Try>::Residual == _` - = note: the type must also implement `Try` - = note: cannot satisfy `<_ as Try>::Output == Vec` note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL help: consider specifying the generic argument @@ -33,7 +30,7 @@ LL | let mut tags: Vec = lines.iter().map(|e| parse(e)).collect:: $DIR/question-mark-type-inference-in-chain.rs:63:20 + --> $DIR/question-mark-type-inference-in-chain.rs:60:20 | LL | let mut tags = lines.iter().map(|e| parse(e)).collect::>()?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `Vec>` @@ -41,7 +38,7 @@ LL | let mut tags = lines.iter().map(|e| parse(e)).collect::>()?; = help: the nightly-only, unstable trait `Try` is not implemented for `Vec>` warning: method call on a diverging inference variable - --> $DIR/question-mark-type-inference-in-chain.rs:69:10 + --> $DIR/question-mark-type-inference-in-chain.rs:66:10 | LL | tags.sort(); | ^^^^ @@ -51,13 +48,13 @@ LL | tags.sort(); = note: for more information, see issue #156047 error[E0599]: no method named `sort` found for type `!` in the current scope - --> $DIR/question-mark-type-inference-in-chain.rs:69:10 + --> $DIR/question-mark-type-inference-in-chain.rs:66:10 | LL | tags.sort(); | ^^^^ method not found in `!` error[E0277]: a value of type `std::result::Result, AnotherError>` cannot be built from an iterator over elements of type `std::result::Result` - --> $DIR/question-mark-type-inference-in-chain.rs:88:20 + --> $DIR/question-mark-type-inference-in-chain.rs:85:20 | LL | .collect::>>()?; | ------- ^^^^^^^^^^^^^^^^^^^^ value of type `std::result::Result, AnotherError>` cannot be built from `std::iter::Iterator>` @@ -69,7 +66,7 @@ help: the trait `FromIterator>` is not implemented for `std::re --> $SRC_DIR/core/src/result.rs:LL:COL = help: for that trait implementation, expected `AnotherError`, found `Error` note: the method call chain might not have had the expected associated types - --> $DIR/question-mark-type-inference-in-chain.rs:85:10 + --> $DIR/question-mark-type-inference-in-chain.rs:82:10 | LL | let mut tags = lines | ----- this expression has type `&[&str]` @@ -100,7 +97,7 @@ LL | tags.sort(); Future breakage diagnostic: warning: method call on a diverging inference variable - --> $DIR/question-mark-type-inference-in-chain.rs:69:10 + --> $DIR/question-mark-type-inference-in-chain.rs:66:10 | LL | tags.sort(); | ^^^^ diff --git a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.rs b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.rs index 49fe7d1324ca8..7b2fc34e1af12 100644 --- a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.rs +++ b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.rs @@ -23,7 +23,7 @@ fn m1() { // we couldn't infer the type of the vector just based on calling foo()... let mut x = Vec::new(); //~^ ERROR type annotations needed - x.foo(); + x.foo(); //~ ERROR type annotations needed } fn m2() { diff --git a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr index 910ce3fe9ad36..a5f1b76702f57 100644 --- a/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr +++ b/tests/ui/methods/method-ambig-one-trait-unknown-int-type.stderr @@ -4,6 +4,17 @@ error[E0282]: type annotations needed for `Vec<_>` LL | let mut x = Vec::new(); | ^^^^^ ---------- type must be known at this point | +help: consider giving `x` an explicit type, where the type for type parameter `T` is specified + | +LL | let mut x: Vec = Vec::new(); + | ++++++++ + +error[E0283]: type annotations needed + --> $DIR/method-ambig-one-trait-unknown-int-type.rs:26:7 + | +LL | x.foo(); + | ^^^ + | note: multiple `impl`s satisfying `Vec<_>: Foo` found --> $DIR/method-ambig-one-trait-unknown-int-type.rs:9:1 | @@ -12,10 +23,11 @@ LL | impl Foo for Vec { ... LL | impl Foo for Vec { | ^^^^^^^^^^^^^^^^^^^^^^^ -help: consider giving `x` an explicit type, where the type for type parameter `T` is specified +help: try using a fully qualified path to specify the expected types + | +LL - x.foo(); +LL + as Foo>::foo(&x); | -LL | let mut x: Vec = Vec::new(); - | ++++++++ error[E0308]: mismatched types --> $DIR/method-ambig-one-trait-unknown-int-type.rs:33:20 @@ -30,7 +42,7 @@ help: you can convert an `isize` to a `usize` and panic if the converted value d LL | let y: usize = x.foo().try_into().unwrap(); | ++++++++++++++++++++ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0282, E0308. +Some errors have detailed explanations: E0282, E0283, E0308. For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.rs b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.rs index a8b209b736b3e..f617e20804a2e 100644 --- a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.rs +++ b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.rs @@ -9,11 +9,13 @@ fn no_err() { fn err() { String::from("x".as_ref()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed } fn arg_pat_closure_err() { |x| String::from("x".as_ref()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed } fn local_pat_closure_err() { @@ -24,6 +26,7 @@ fn local_pat_closure_err() { fn err_first_arg_pat() { String::from("x".as_ref()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed |x: String| x; } @@ -31,6 +34,7 @@ fn err_second_arg_pat() { |x: String| x; String::from("x".as_ref()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed } fn err_mid_arg_pat() { @@ -40,6 +44,7 @@ fn err_mid_arg_pat() { |x: String| x; String::from("x".as_ref()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed |x: String| x; |x: String| x; |x: String| x; @@ -49,6 +54,7 @@ fn err_mid_arg_pat() { fn err_first_local_pat() { String::from("x".as_ref()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed let _ = String::from("x"); } @@ -56,6 +62,7 @@ fn err_second_local_pat() { let _ = String::from("x"); String::from("x".as_ref()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed } fn err_mid_local_pat() { @@ -65,6 +72,7 @@ fn err_mid_local_pat() { let _ = String::from("x"); String::from("x".as_ref()); //~^ ERROR type annotations needed + //~| ERROR type annotations needed let _ = String::from("x"); let _ = String::from("x"); let _ = String::from("x"); diff --git a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr index 18a823323587d..3be18fc59e737 100644 --- a/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr +++ b/tests/ui/parallel-rustc/infer-unwrap-none-issue-120786.stderr @@ -18,15 +18,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/infer-unwrap-none-issue-120786.rs:10:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:15:9 + --> $DIR/infer-unwrap-none-issue-120786.rs:16:9 | LL | |x| String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -34,15 +46,27 @@ LL | |x| String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/infer-unwrap-none-issue-120786.rs:16:26 + | +LL | |x| String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - |x| String::from("x".as_ref()); +LL + |x| String::from(>::as_ref("x")); + | error[E0283]: type annotations needed for `&_` - --> $DIR/infer-unwrap-none-issue-120786.rs:20:9 + --> $DIR/infer-unwrap-none-issue-120786.rs:22:9 | LL | let _ = "x".as_ref(); | ^ ------ type must be known at this point @@ -59,7 +83,7 @@ LL | let _: &T = "x".as_ref(); | ++++ error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:25:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:27:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -67,15 +91,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/infer-unwrap-none-issue-120786.rs:27:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:32:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:35:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -83,15 +119,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/infer-unwrap-none-issue-120786.rs:35:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:41:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:45:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -99,15 +147,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/infer-unwrap-none-issue-120786.rs:45:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:50:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:55:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -115,15 +175,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/infer-unwrap-none-issue-120786.rs:55:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:57:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:63:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -131,15 +203,27 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/infer-unwrap-none-issue-120786.rs:63:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | error[E0283]: type annotations needed - --> $DIR/infer-unwrap-none-issue-120786.rs:66:5 + --> $DIR/infer-unwrap-none-issue-120786.rs:73:5 | LL | String::from("x".as_ref()); | ^^^^^^ cannot infer type for reference `&_` @@ -147,14 +231,26 @@ LL | String::from("x".as_ref()); = note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate: - impl From<&String> for String; - impl From<&str> for String; + +error[E0283]: type annotations needed + --> $DIR/infer-unwrap-none-issue-120786.rs:73:22 + | +LL | String::from("x".as_ref()); + | ^^^^^^ + | = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`: - impl AsRef for str; - impl AsRef for str; - impl AsRef for str; - impl AsRef<[u8]> for str; - impl AsRef for str; +help: try using a fully qualified path to specify the expected types + | +LL - String::from("x".as_ref()); +LL + String::from(>::as_ref("x")); + | -error: aborting due to 10 previous errors +error: aborting due to 18 previous errors Some errors have detailed explanations: E0282, E0283. For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/pattern/slice-patterns-irrefutable.stderr b/tests/ui/pattern/slice-patterns-irrefutable.stderr index ba1643a7c9096..4619a0d798d4b 100644 --- a/tests/ui/pattern/slice-patterns-irrefutable.stderr +++ b/tests/ui/pattern/slice-patterns-irrefutable.stderr @@ -7,7 +7,6 @@ LL | LL | [a, b] = Default::default(); | - type must be known at this point | - = note: the type must also implement `Default` help: consider giving `b` an explicit type, where the placeholder `_` is specified | LL | let b: [_; 3]; diff --git a/tests/ui/suggestions/types/into-inference-needs-type.stderr b/tests/ui/suggestions/types/into-inference-needs-type.stderr index 89fb9405cbe56..5fbc281072047 100644 --- a/tests/ui/suggestions/types/into-inference-needs-type.stderr +++ b/tests/ui/suggestions/types/into-inference-needs-type.stderr @@ -5,9 +5,6 @@ LL | .into()?; | ^^^^ | = note: the type must implement `From, {closure@$DIR/into-inference-needs-type.rs:10:14: 10:17}>, fn(Option<&str>) -> Option> {Option::>::Some}>>` - = note: cannot satisfy `<_ as Try>::Residual == _` - = note: the type must also implement `Try` - = note: cannot satisfy `<_ as Try>::Output == ()` = note: required for `FilterMap, {closure@$DIR/into-inference-needs-type.rs:10:14: 10:17}>, fn(Option<&str>) -> Option> {Option::>::Some}>` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | diff --git a/tests/ui/trait-bounds/argument-with-unnecessary-method-call.stderr b/tests/ui/trait-bounds/argument-with-unnecessary-method-call.stderr index 094c4a5516035..870a865f02dd6 100644 --- a/tests/ui/trait-bounds/argument-with-unnecessary-method-call.stderr +++ b/tests/ui/trait-bounds/argument-with-unnecessary-method-call.stderr @@ -7,7 +7,6 @@ LL | qux(Bar.into()); | required by a bound introduced by this call | = note: the type must implement `From` - = note: the type must also implement `From` note: required by a bound in `qux` --> $DIR/argument-with-unnecessary-method-call.rs:6:16 | diff --git a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.rs b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.rs index f1935ae253463..a53aadcfad024 100644 --- a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.rs +++ b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.rs @@ -27,4 +27,5 @@ impl Test for u64 { fn main() { let xs: Vec = vec![1, 2, 3]; println!("{}", 23u64.test(xs.iter().sum())); //~ ERROR: type annotations needed + //~^ ERROR type annotations needed } diff --git a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr index 76affa7e29f48..58e56ea45a8c1 100644 --- a/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr +++ b/tests/ui/trait-bounds/projection-predicate-not-satisfied-69455.stderr @@ -7,6 +7,19 @@ LL | println!("{}", 23u64.test(xs.iter().sum())); | type must be known at this point | = note: cannot satisfy `>::Output == _` +help: consider specifying a concrete type for the type parameter `S` + | +LL | println!("{}", 23u64.test(xs.iter().sum::())); + | ++++++++++++++ + +error[E0283]: type annotations needed + --> $DIR/projection-predicate-not-satisfied-69455.rs:29:41 + | +LL | println!("{}", 23u64.test(xs.iter().sum())); + | ---- ^^^ cannot infer type of the type parameter `S` declared on the method `sum` + | | + | required by a bound introduced by this call + | note: multiple `impl`s satisfying `u64: Test<_>` found --> $DIR/projection-predicate-not-satisfied-69455.rs:11:1 | @@ -15,12 +28,12 @@ LL | impl Test for u64 { ... LL | impl Test for u64 { | ^^^^^^^^^^^^^^^^^^^^^^ - = note: the type must also implement `Sum<&u64>` help: consider specifying a concrete type for the type parameter `S` | LL | println!("{}", 23u64.test(xs.iter().sum::())); | ++++++++++++++ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0284`. +Some errors have detailed explanations: E0283, E0284. +For more information about an error, try `rustc --explain E0283`. diff --git a/tests/ui/traits/issue-77982.rs b/tests/ui/traits/issue-77982.rs index e82ffaf4caca1..b2a488e18e828 100644 --- a/tests/ui/traits/issue-77982.rs +++ b/tests/ui/traits/issue-77982.rs @@ -9,6 +9,7 @@ fn what() { let opt = String::new(); opts.get(opt.as_ref()); //~ ERROR type annotations needed + //~^ ERROR type annotations needed } fn main() { diff --git a/tests/ui/traits/issue-77982.stderr b/tests/ui/traits/issue-77982.stderr index c46b297c9ad5d..429c4edcad339 100644 --- a/tests/ui/traits/issue-77982.stderr +++ b/tests/ui/traits/issue-77982.stderr @@ -12,20 +12,47 @@ LL | opts.get(opt.as_ref()); where T: ?Sized; = note: the type must also implement `Hash` = note: the type must also implement `Eq` +note: required by a bound in `HashMap::::get` + --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL +note: required by a bound in `HashMap::::get` + --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL +note: required by a bound in `HashMap::::get` + --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL +help: consider specifying a concrete type for the type parameter `Q` + | +LL | opts.get::(opt.as_ref()); + | ++++++++++++++ +help: consider removing this method call, as the receiver has type `String` and `String: Hash` trivially holds + | +LL - opts.get(opt.as_ref()); +LL + opts.get(opt); + | +help: consider removing this method call, as the receiver has type `String` and `String: Eq` trivially holds + | +LL - opts.get(opt.as_ref()); +LL + opts.get(opt); + | + +error[E0283]: type annotations needed + --> $DIR/issue-77982.rs:11:10 + | +LL | opts.get(opt.as_ref()); + | ^^^ ------ type must be known at this point + | | + | cannot infer type of the type parameter `Q` declared on the method `get` + | = note: multiple `impl`s satisfying `String: AsRef<_>` found in the following crates: `alloc`, `std`: - impl AsRef for String; - impl AsRef for String; - impl AsRef<[u8]> for String; - impl AsRef for String; -note: required by a bound in `HashMap::::get` - --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL help: consider specifying a concrete type for the type parameter `Q` | LL | opts.get::(opt.as_ref()); | ++++++++++++++ error[E0283]: type annotations needed - --> $DIR/issue-77982.rs:15:59 + --> $DIR/issue-77982.rs:16:59 | LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect(); | --- ^^^^ @@ -39,7 +66,6 @@ LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect( - impl From for u32; - impl From for u32; - impl From for u32; - = note: the type must also implement `From` help: try using a fully qualified path to specify the expected types | LL - let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect(); @@ -47,13 +73,13 @@ LL + let ips: Vec<_> = (0..100_000).map(|_| u32::from(>::into | error[E0283]: type annotations needed for `Box<_>` - --> $DIR/issue-77982.rs:38:9 + --> $DIR/issue-77982.rs:39:9 | LL | let _ = ().foo(); | ^ --- type must be known at this point | note: multiple `impl`s satisfying `(): Foo<'_, _>` found - --> $DIR/issue-77982.rs:31:1 + --> $DIR/issue-77982.rs:32:1 | LL | impl Foo<'static, u32> for () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -65,13 +91,13 @@ LL | let _: Box = ().foo(); | ++++++++ error[E0283]: type annotations needed for `Box<_>` - --> $DIR/issue-77982.rs:42:9 + --> $DIR/issue-77982.rs:43:9 | LL | let _ = (&()).bar(); | ^ --- type must be known at this point | note: multiple `impl`s satisfying `&(): Bar<'_, _>` found - --> $DIR/issue-77982.rs:34:1 + --> $DIR/issue-77982.rs:35:1 | LL | impl<'a> Bar<'static, u32> for &'a () {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -82,6 +108,6 @@ help: consider giving this pattern a type, where the type for type parameter `T` LL | let _: Box = (&()).bar(); | ++++++++ -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/traits/multidispatch-convert-ambig-dest.stderr b/tests/ui/traits/multidispatch-convert-ambig-dest.stderr index 8a38376d91b62..12984c7936c9a 100644 --- a/tests/ui/traits/multidispatch-convert-ambig-dest.stderr +++ b/tests/ui/traits/multidispatch-convert-ambig-dest.stderr @@ -14,7 +14,6 @@ LL | impl Convert for i32 { ... LL | impl Convert for i32 { | ^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: the type must also implement `Default` note: required by a bound in `test` --> $DIR/multidispatch-convert-ambig-dest.rs:21:11 | diff --git a/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr b/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr index 95ac5d64a869c..ac427c8f0cba7 100644 --- a/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr +++ b/tests/ui/traits/next-solver/assembly/runaway-impl-candidate-selection.stderr @@ -5,7 +5,6 @@ LL | println!("{:?}", iter::<_>()); | ^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `iter` | = note: the type must implement `Iterator` - = note: cannot satisfy `<_ as Iterator>::Item == _` note: required by a bound in `iter` --> $DIR/runaway-impl-candidate-selection.rs:8:12 | diff --git a/tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.stderr b/tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.stderr index b85dbc5613e3a..5c1910546872e 100644 --- a/tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.stderr +++ b/tests/ui/traits/next-solver/normalization-shadowing/normalizes_to_ignores_unnormalizable_candidate.stderr @@ -7,7 +7,6 @@ LL | foo(unconstrained()) | cannot infer type of the type parameter `T` declared on the function `foo` | = note: cannot satisfy `Vec<_>: Trait` - = note: cannot satisfy ` as Trait>::Assoc == u8` note: required by a bound in `foo` --> $DIR/normalizes_to_ignores_unnormalizable_candidate.rs:14:11 | diff --git a/tests/ui/traits/next-solver/unexpected-pointer-deref-issue-154568.stderr b/tests/ui/traits/next-solver/unexpected-pointer-deref-issue-154568.stderr index f26ba396b9db6..90cd6a36d9c0b 100644 --- a/tests/ui/traits/next-solver/unexpected-pointer-deref-issue-154568.stderr +++ b/tests/ui/traits/next-solver/unexpected-pointer-deref-issue-154568.stderr @@ -6,7 +6,6 @@ LL | let handshake = Handshake(callback.0.clone()); | = note: the type must implement `Role` = note: cannot satisfy `<_ as Role>::Inner == ()` - = note: cannot satisfy `<_ as Role>::Inner == _` note: required by a bound in `Handshake` --> $DIR/unexpected-pointer-deref-issue-154568.rs:9:21 | diff --git a/tests/ui/traits/next-solver/well-formed-in-relate.stderr b/tests/ui/traits/next-solver/well-formed-in-relate.stderr index 12a3589c87a55..d1113d0a3e6b6 100644 --- a/tests/ui/traits/next-solver/well-formed-in-relate.stderr +++ b/tests/ui/traits/next-solver/well-formed-in-relate.stderr @@ -20,6 +20,11 @@ note: required by a bound in `unconstrained_map` | LL | fn unconstrained_map U, U>() -> as Mirror>::Assoc { todo!() } | ^^^^^^^^^ required by this bound in `unconstrained_map` +note: required by a bound in `unconstrained_map` + --> $DIR/well-formed-in-relate.rs:21:33 + | +LL | fn unconstrained_map U, U>() -> as Mirror>::Assoc { todo!() } + | ^ required by this bound in `unconstrained_map` help: consider giving `x` an explicit type, where the type for type parameter `T` is specified | LL | let x: Map; diff --git a/tests/ui/type-inference/index-expr-ambiguous-type.stderr b/tests/ui/type-inference/index-expr-ambiguous-type.stderr index 17a93bce976a8..1e2ea9ab32215 100644 --- a/tests/ui/type-inference/index-expr-ambiguous-type.stderr +++ b/tests/ui/type-inference/index-expr-ambiguous-type.stderr @@ -22,8 +22,6 @@ LL | let _foo = [1, 2, 3][bad_idx.into()]; | ^^^^ | = note: the type must implement `From` - = note: the type must also implement `SliceIndex<[i32]>` - = note: cannot satisfy `<_ as SliceIndex<[i32]>>::Output == _` = note: required for `u8` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | @@ -66,8 +64,6 @@ LL | let _foo = String::new() + [""][bad_idx.into()]; | ^^^^ | = note: the type must implement `From` - = note: the type must also implement `SliceIndex<[&str]>` - = note: cannot satisfy `<_ as SliceIndex<[&str]>>::Output == &str` = note: required for `u8` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | diff --git a/tests/ui/type-inference/or_else-multiple-type-params.stderr b/tests/ui/type-inference/or_else-multiple-type-params.stderr index eb8fa8610dca4..ea64b91b726d7 100644 --- a/tests/ui/type-inference/or_else-multiple-type-params.stderr +++ b/tests/ui/type-inference/or_else-multiple-type-params.stderr @@ -3,8 +3,13 @@ error[E0282]: type annotations needed for `Result` | LL | .or_else(|err| { | ^^^^^ +LL | panic!("oh no: {:?}", err); +LL | }).unwrap(); + | ------ required by a bound introduced by this call | = note: the type must also implement `Debug` +note: required by a bound in `Result::::unwrap` + --> $SRC_DIR/core/src/result.rs:LL:COL help: try giving this closure an explicit return type | LL | .or_else(|err| -> Result<_, F> { diff --git a/tests/ui/type-inference/panic-with-unspecified-type.stderr b/tests/ui/type-inference/panic-with-unspecified-type.stderr index e0f92334afd34..99949d4901a4e 100644 --- a/tests/ui/type-inference/panic-with-unspecified-type.stderr +++ b/tests/ui/type-inference/panic-with-unspecified-type.stderr @@ -6,12 +6,15 @@ LL | panic!(std::default::Default::default()); | | | | | cannot infer type | required by a bound introduced by this call + | required by a bound introduced by this call | = note: the type must implement `Any` = note: the type must also implement `Send` = note: the type must also implement `Default` note: required by a bound in `std::rt::begin_panic` --> $SRC_DIR/std/src/panicking.rs:LL:COL +note: required by a bound in `std::rt::begin_panic` + --> $SRC_DIR/std/src/panicking.rs:LL:COL error: aborting due to 1 previous error diff --git a/tests/ui/type-inference/send-with-unspecified-type.stderr b/tests/ui/type-inference/send-with-unspecified-type.stderr index 1025f9d0bb2ff..0d7daed44c0d9 100644 --- a/tests/ui/type-inference/send-with-unspecified-type.stderr +++ b/tests/ui/type-inference/send-with-unspecified-type.stderr @@ -4,7 +4,6 @@ error[E0282]: type annotations needed LL | tx.send(Foo{ foo: PhantomData }); | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `PhantomData` | - = note: the type must also implement `Send` help: consider specifying a concrete type for the type parameter `T` | LL | tx.send(Foo{ foo: PhantomData:: }); diff --git a/tests/ui/type-inference/sort_by_key.stderr b/tests/ui/type-inference/sort_by_key.stderr index 80da5f6a0c7ad..d191d50b203af 100644 --- a/tests/ui/type-inference/sort_by_key.stderr +++ b/tests/ui/type-inference/sort_by_key.stderr @@ -7,7 +7,6 @@ LL | lst.sort_by_key(|&(v, _)| v.iter().sum()); | type must be known at this point | = note: the type must implement `Ord` - = note: the type must also implement `Sum<&i32>` note: required by a bound in `slice::::sort_by_key` --> $SRC_DIR/alloc/src/slice.rs:LL:COL help: consider specifying a concrete type for the type parameter `S` diff --git a/tests/ui/typeck/type-inference-for-associated-types-69683.stderr b/tests/ui/typeck/type-inference-for-associated-types-69683.stderr index 44d68218b9924..46ddd4556e96f 100644 --- a/tests/ui/typeck/type-inference-for-associated-types-69683.stderr +++ b/tests/ui/typeck/type-inference-for-associated-types-69683.stderr @@ -13,6 +13,14 @@ LL | impl Element<()> for T { ... LL | impl, S> Element<[S; 3]> for T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `Foo::foo` + --> $DIR/type-inference-for-associated-types-69683.rs:16:9 + | +LL | u8: Element, + | ^^^^^^^^^^ required by this bound in `Foo::foo` +LL | { +LL | fn foo(self, x: >::Array); + | --- required by a bound in this associated function help: try using a fully qualified path to specify the expected types | LL - 0u16.foo(b);