diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 159af485ba4..aaab89ace0a 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -166,14 +166,14 @@ impl UseDiagnostic<'_> { /// Return a descriptor of the value at the use site fn descr(&self) -> &'static str { match self { - Self::TryConversion { .. } => "`?` error", + Self::TryConversion { .. } => "error for `?` operator", } } /// Return a descriptor of the type at the use site fn type_descr(&self) -> &'static str { match self { - Self::TryConversion { .. } => "`?` error type", + Self::TryConversion { .. } => "error type for `?` operator", } } @@ -188,20 +188,17 @@ impl UseDiagnostic<'_> { fn attach_note(&self, err: &mut DiagnosticBuilder<'_>) { match *self { Self::TryConversion { pre_ty, post_ty, .. } => { - let pre_ty = pre_ty.to_string(); - let post_ty = post_ty.to_string(); + let intro = "`?` implicitly converts the error value"; - let intro = "the `?` operation implicitly converts the error value"; - - let msg = match (pre_ty.as_str(), post_ty.as_str()) { - ("_", "_") => format!("{} using the `From` trait", intro), - (_, "_") => { + let msg = match (pre_ty.is_ty_infer(), post_ty.is_ty_infer()) { + (true, true) => format!("{} using the `From` trait", intro), + (false, true) => { format!("{} into a type implementing `From<{}>`", intro, pre_ty) } - ("_", _) => { + (true, false) => { format!("{} into `{}` using the `From` trait", intro, post_ty) } - (_, _) => { + (false, false) => { format!( "{} into `{}` using its implementation of `From<{}>`", intro, post_ty, pre_ty diff --git a/src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr b/src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr index de15d472d05..2875cef6801 100644 --- a/src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr +++ b/src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr @@ -13,9 +13,9 @@ error[E0282]: type annotations needed for `impl Future` LL | let fut = async { | --- consider giving `fut` the explicit type `impl Future`, with the type parameters specified LL | make_unit()?; - | ^ cannot infer type of `?` error + | ^ cannot infer type of error for `?` operator | - = note: the `?` operation implicitly converts the error value into a type implementing `From` + = note: `?` implicitly converts the error value into a type implementing `From` error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/inference/cannot-infer-async.stderr b/src/test/ui/inference/cannot-infer-async.stderr index d5cccc7a948..282bc13e9e7 100644 --- a/src/test/ui/inference/cannot-infer-async.stderr +++ b/src/test/ui/inference/cannot-infer-async.stderr @@ -4,9 +4,9 @@ error[E0282]: type annotations needed LL | let fut = async { | --- consider giving `fut` a type LL | make_unit()?; - | ^ cannot infer type of `?` error + | ^ cannot infer type of error for `?` operator | - = note: the `?` operation implicitly converts the error value into a type implementing `From` + = note: `?` implicitly converts the error value into a type implementing `From` error: aborting due to previous error diff --git a/src/test/ui/inference/cannot-infer-closure.stderr b/src/test/ui/inference/cannot-infer-closure.stderr index c083f2b686e..475ed00d107 100644 --- a/src/test/ui/inference/cannot-infer-closure.stderr +++ b/src/test/ui/inference/cannot-infer-closure.stderr @@ -2,9 +2,9 @@ error[E0282]: type annotations needed for the closure `fn((), ()) -> std::result --> $DIR/cannot-infer-closure.rs:3:15 | LL | Err(a)?; - | ^ cannot infer type of `?` error + | ^ cannot infer type of error for `?` operator | - = note: the `?` operation implicitly converts the error value into a type implementing `From<()>` + = note: `?` implicitly converts the error value into a type implementing `From<()>` help: give this closure an explicit return type without `_` placeholders | LL | let x = |a: (), b: ()| -> std::result::Result<(), _> { diff --git a/src/test/ui/inference/cannot-infer-partial-try-return.stderr b/src/test/ui/inference/cannot-infer-partial-try-return.stderr index d4223bfc155..a64503fa667 100644 --- a/src/test/ui/inference/cannot-infer-partial-try-return.stderr +++ b/src/test/ui/inference/cannot-infer-partial-try-return.stderr @@ -2,9 +2,9 @@ error[E0282]: type annotations needed for the closure `fn() -> std::result::Resu --> $DIR/cannot-infer-partial-try-return.rs:19:9 | LL | infallible()?; - | ^^^^^^^^^^^^^ cannot infer type of `?` error + | ^^^^^^^^^^^^^ cannot infer type of error for `?` operator | - = note: the `?` operation implicitly converts the error value into `QualifiedError<_>` using its implementation of `From` + = note: `?` implicitly converts the error value into `QualifiedError<_>` using its implementation of `From` help: give this closure an explicit return type without `_` placeholders | LL | let x = || -> std::result::Result<(), QualifiedError<_>> {