From 180ab161b025e62c4fd0f772c820f2621fca4a81 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 23 May 2025 15:02:56 +0200 Subject: [PATCH 1/8] make teach_help message for cast-before-pass-to-variadic more precise --- compiler/rustc_hir_typeck/messages.ftl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_hir_typeck/messages.ftl b/compiler/rustc_hir_typeck/messages.ftl index 23309102c4da5..034cec83299ae 100644 --- a/compiler/rustc_hir_typeck/messages.ftl +++ b/compiler/rustc_hir_typeck/messages.ftl @@ -169,7 +169,7 @@ hir_typeck_option_result_copied = use `{$def_path}::copied` to copy the value in hir_typeck_pass_to_variadic_function = can't pass `{$ty}` to variadic function .suggestion = cast the value to `{$cast_ty}` - .teach_help = certain types, like `{$ty}`, must be casted before passing them to a variadic function, because of arcane ABI rules dictated by the C standard + .teach_help = certain types, like `{$ty}`, must be cast before passing them to a variadic function to match the implicit cast that a C compiler would perform as part of C's integer promotion rules hir_typeck_ptr_cast_add_auto_to_object = cannot add {$traits_len -> [1] auto trait {$traits} From 01503d0c1e43a23de92ad1577cbdceb7afe47dab Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Sat, 24 May 2025 20:22:58 +0200 Subject: [PATCH 2/8] Avoid extra path trimming in method not found error Method errors have an extra check that force trim paths whenever the normal string is longer than 10 characters, which can be quite unhelpful when multiple items have the same name (for example an `Error`). A user reported this force trimming as being quite unhelpful when they had a method error where the precise path of the `Error` mattered. The code uses `tcx.short_string` already to get the normal path, which tries to be clever around trimming paths if necessary, so there is no reason for this extra force trimming. --- compiler/rustc_hir_typeck/src/method/suggest.rs | 6 +----- .../crate-loading/multiple-dep-versions.stderr | 4 ++-- tests/ui/associated-types/issue-43924.stderr | 2 +- tests/ui/attributes/rustc_confusables.stderr | 6 +++--- tests/ui/empty/empty-struct-braces-expr.stderr | 4 ++-- .../multiline-removal-suggestion.svg | 10 +++++----- .../functions-closures/fn-help-with-err.stderr | 2 +- .../hrtb-doesnt-borrow-self-1.stderr | 2 +- .../hrtb-doesnt-borrow-self-2.stderr | 2 +- .../impl-trait/no-method-suggested-traits.stderr | 16 ++++++++-------- tests/ui/issues/issue-30123.stderr | 2 +- tests/ui/issues/issue-41880.stderr | 2 +- tests/ui/macros/missing-writer.stderr | 4 ++-- tests/ui/methods/issue-19521.stderr | 2 +- .../method-not-found-generic-arg-elision.stderr | 2 +- tests/ui/methods/receiver-equality.stderr | 2 +- tests/ui/methods/untrimmed-path-type.rs | 11 +++++++++++ tests/ui/methods/untrimmed-path-type.stderr | 9 +++++++++ tests/ui/mismatched_types/issue-36053-2.stderr | 2 +- tests/ui/nll/issue-57362-2.stderr | 2 +- .../nll/issue-57642-higher-ranked-subtype.stderr | 4 ++-- tests/ui/object-pointer-types.stderr | 2 +- .../mut-borrow-needed-by-trait.stderr | 4 ++-- tests/ui/suggestions/suggest-using-chars.stderr | 4 ++-- tests/ui/typeck/issue-31173.stderr | 2 +- ...boxed-closures-static-call-wrong-trait.stderr | 2 +- 26 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 tests/ui/methods/untrimmed-path-type.rs create mode 100644 tests/ui/methods/untrimmed-path-type.stderr diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 342eed751a589..7b71f5de7569f 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -599,7 +599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let tcx = self.tcx; let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty); let mut ty_file = None; - let (mut ty_str, short_ty_str) = + let (ty_str, short_ty_str) = if trait_missing_method && let ty::Dynamic(predicates, _, _) = rcvr_ty.kind() { (predicates.to_string(), with_forced_trimmed_paths!(predicates.to_string())) } else { @@ -738,10 +738,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.span_label(within_macro_span, "due to this macro variable"); } - if short_ty_str.len() < ty_str.len() && ty_str.len() > 10 { - ty_str = short_ty_str; - } - if rcvr_ty.references_error() { err.downgrade_to_delayed_bug(); } diff --git a/tests/run-make/crate-loading/multiple-dep-versions.stderr b/tests/run-make/crate-loading/multiple-dep-versions.stderr index 6e1d6111b5810..dea08bb96c979 100644 --- a/tests/run-make/crate-loading/multiple-dep-versions.stderr +++ b/tests/run-make/crate-loading/multiple-dep-versions.stderr @@ -39,7 +39,7 @@ error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in t --> replaced | LL | Type.foo(); - | ^^^ method not found in `Type` + | ^^^ method not found in `dep_2_reexport::Type` | note: there are multiple different versions of crate `dependency` in the dependency graph --> replaced @@ -63,7 +63,7 @@ error[E0599]: no function or associated item named `bar` found for struct `dep_2 --> replaced | LL | Type::bar(); - | ^^^ function or associated item not found in `Type` + | ^^^ function or associated item not found in `dep_2_reexport::Type` | note: there are multiple different versions of crate `dependency` in the dependency graph --> replaced diff --git a/tests/ui/associated-types/issue-43924.stderr b/tests/ui/associated-types/issue-43924.stderr index ab1a9511ec6c7..526f425b21e71 100644 --- a/tests/ui/associated-types/issue-43924.stderr +++ b/tests/ui/associated-types/issue-43924.stderr @@ -14,7 +14,7 @@ error[E0599]: no function or associated item named `default` found for trait obj --> $DIR/issue-43924.rs:14:39 | LL | assert_eq!(<() as Foo>::Out::default().to_string(), "false"); - | ^^^^^^^ function or associated item not found in `dyn ToString` + | ^^^^^^^ function or associated item not found in `(dyn ToString + 'static)` error: aborting due to 2 previous errors diff --git a/tests/ui/attributes/rustc_confusables.stderr b/tests/ui/attributes/rustc_confusables.stderr index 55c9219a08a84..aba384ff8ac83 100644 --- a/tests/ui/attributes/rustc_confusables.stderr +++ b/tests/ui/attributes/rustc_confusables.stderr @@ -42,13 +42,13 @@ error[E0599]: no method named `foo` found for struct `rustc_confusables_across_c --> $DIR/rustc_confusables.rs:15:7 | LL | x.foo(); - | ^^^ method not found in `BTreeSet` + | ^^^ method not found in `rustc_confusables_across_crate::BTreeSet` error[E0599]: no method named `push` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope --> $DIR/rustc_confusables.rs:17:7 | LL | x.push(); - | ^^^^ method not found in `BTreeSet` + | ^^^^ method not found in `rustc_confusables_across_crate::BTreeSet` | help: you might have meant to use `insert` | @@ -60,7 +60,7 @@ error[E0599]: no method named `test` found for struct `rustc_confusables_across_ --> $DIR/rustc_confusables.rs:20:7 | LL | x.test(); - | ^^^^ method not found in `BTreeSet` + | ^^^^ method not found in `rustc_confusables_across_crate::BTreeSet` error[E0599]: no method named `pulled` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope --> $DIR/rustc_confusables.rs:22:7 diff --git a/tests/ui/empty/empty-struct-braces-expr.stderr b/tests/ui/empty/empty-struct-braces-expr.stderr index 8ec8ecf46bf06..a176107a06e24 100644 --- a/tests/ui/empty/empty-struct-braces-expr.stderr +++ b/tests/ui/empty/empty-struct-braces-expr.stderr @@ -121,7 +121,7 @@ error[E0599]: no variant or associated item named `Empty3` found for enum `empty --> $DIR/empty-struct-braces-expr.rs:25:19 | LL | let xe3 = XE::Empty3; - | ^^^^^^ variant or associated item not found in `XE` + | ^^^^^^ variant or associated item not found in `empty_struct::XE` | help: there is a variant with a similar name | @@ -132,7 +132,7 @@ error[E0599]: no variant or associated item named `Empty3` found for enum `empty --> $DIR/empty-struct-braces-expr.rs:26:19 | LL | let xe3 = XE::Empty3(); - | ^^^^^^ variant or associated item not found in `XE` + | ^^^^^^ variant or associated item not found in `empty_struct::XE` | help: there is a variant with a similar name | diff --git a/tests/ui/error-emitter/multiline-removal-suggestion.svg b/tests/ui/error-emitter/multiline-removal-suggestion.svg index 95c7740f6995d..9c9bd163ecd49 100644 --- a/tests/ui/error-emitter/multiline-removal-suggestion.svg +++ b/tests/ui/error-emitter/multiline-removal-suggestion.svg @@ -1,4 +1,4 @@ - +