From 153ed09fb3a0e7ed8d42749720e8a0b4fac50d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 6 Jan 2023 19:21:47 +0000 Subject: [PATCH] Tweak use of trimmed paths --- .../rustc_hir_typeck/src/method/suggest.rs | 36 +++++++++++++++---- tests/ui/associated-types/issue-43924.stderr | 2 +- .../issue-33784.stderr | 4 +-- .../ui/empty/empty-struct-braces-expr.stderr | 4 +-- .../fn-help-with-err.stderr | 2 +- .../higher-rank-trait-bounds/issue-30786.rs | 2 ++ .../issue-30786.stderr | 27 +++++++------- .../no-method-suggested-traits.stderr | 16 ++++----- tests/ui/issues/issue-19521.stderr | 2 +- tests/ui/issues/issue-30123.stderr | 2 +- .../issue-57642-higher-ranked-subtype.stderr | 2 +- tests/ui/object-pointer-types.stderr | 2 +- tests/ui/suggestions/remove-as_str.stderr | 2 +- tests/ui/suggestions/suggest-using-chars.rs | 4 +-- .../ui/suggestions/suggest-using-chars.stderr | 4 +-- ...ed-closures-static-call-wrong-trait.stderr | 2 +- 16 files changed, 69 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 31d55a41d8a..54890489f8b 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -259,7 +259,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mode = no_match_data.mode; let tcx = self.tcx; let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty); - let ty_str = with_forced_trimmed_paths!(self.ty_to_string(rcvr_ty)); + let (ty_str, ty_file) = tcx.short_ty_string(rcvr_ty); + let short_ty_str = with_forced_trimmed_paths!(rcvr_ty.to_string()); let is_method = mode == Mode::MethodCall; let unsatisfied_predicates = &no_match_data.unsatisfied_predicates; let similar_candidate = no_match_data.similar_candidate; @@ -276,11 +277,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }; - if self.suggest_wrapping_range_with_parens(tcx, rcvr_ty, source, span, item_name, &ty_str) - || self.suggest_constraining_numerical_ty( - tcx, rcvr_ty, source, span, item_kind, item_name, &ty_str, - ) - { + // We could pass the file for long types into these two, but it isn't strictly necessary + // given how targetted they are. + if self.suggest_wrapping_range_with_parens( + tcx, + rcvr_ty, + source, + span, + item_name, + &short_ty_str, + ) || self.suggest_constraining_numerical_ty( + tcx, + rcvr_ty, + source, + span, + item_kind, + item_name, + &short_ty_str, + ) { return None; } span = item_name.span; @@ -319,6 +333,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { rcvr_ty.prefix_string(self.tcx), ty_str_reported, ); + let ty_str = if short_ty_str.len() < ty_str.len() && ty_str.len() > 10 { + short_ty_str + } else { + ty_str + }; + if let Some(file) = ty_file { + err.note(&format!("the full type name has been written to '{}'", file.display(),)); + } if rcvr_ty.references_error() { err.downgrade_to_delayed_bug(); } @@ -826,7 +848,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let primary_message = primary_message.unwrap_or_else(|| { format!( "the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, \ - but its trait bounds were not satisfied" + but its trait bounds were not satisfied" ) }); err.set_primary_message(&primary_message); diff --git a/tests/ui/associated-types/issue-43924.stderr b/tests/ui/associated-types/issue-43924.stderr index 9046170d7c9..ab1a9511ec6 100644 --- a/tests/ui/associated-types/issue-43924.stderr +++ b/tests/ui/associated-types/issue-43924.stderr @@ -10,7 +10,7 @@ note: required by a bound in `Foo::Out` LL | type Out: Default + ToString + ?Sized = dyn ToString; | ^^^^^^^ required by this bound in `Foo::Out` -error[E0599]: no function or associated item named `default` found for trait object `dyn ToString` in the current scope +error[E0599]: no function or associated item named `default` found for trait object `(dyn ToString + 'static)` in the current scope --> $DIR/issue-43924.rs:14:39 | LL | assert_eq!(<() as Foo>::Out::default().to_string(), "false"); diff --git a/tests/ui/confuse-field-and-method/issue-33784.stderr b/tests/ui/confuse-field-and-method/issue-33784.stderr index 3906d64c946..34debb68317 100644 --- a/tests/ui/confuse-field-and-method/issue-33784.stderr +++ b/tests/ui/confuse-field-and-method/issue-33784.stderr @@ -1,4 +1,4 @@ -error[E0599]: no method named `closure` found for reference `&Obj<[closure@issue-33784.rs:25:43]>` in the current scope +error[E0599]: no method named `closure` found for reference `&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope --> $DIR/issue-33784.rs:27:7 | LL | p.closure(); @@ -9,7 +9,7 @@ help: to call the function stored in `closure`, surround the field access with p LL | (p.closure)(); | + + -error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[closure@issue-33784.rs:25:43]>` in the current scope +error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope --> $DIR/issue-33784.rs:29:7 | LL | q.fn_ptr(); diff --git a/tests/ui/empty/empty-struct-braces-expr.stderr b/tests/ui/empty/empty-struct-braces-expr.stderr index 0e580aedeaa..4604ebeaa8b 100644 --- a/tests/ui/empty/empty-struct-braces-expr.stderr +++ b/tests/ui/empty/empty-struct-braces-expr.stderr @@ -100,7 +100,7 @@ help: a unit struct with a similar name exists LL | let xe1 = XEmpty2(); | ~~~~~~~ -error[E0599]: no variant or associated item named `Empty3` found for enum `XE` in the current scope +error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope --> $DIR/empty-struct-braces-expr.rs:25:19 | LL | let xe3 = XE::Empty3; @@ -109,7 +109,7 @@ LL | let xe3 = XE::Empty3; | variant or associated item not found in `XE` | help: there is a variant with a similar name: `XEmpty3` -error[E0599]: no variant or associated item named `Empty3` found for enum `XE` in the current scope +error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope --> $DIR/empty-struct-braces-expr.rs:26:19 | LL | let xe3 = XE::Empty3(); diff --git a/tests/ui/functions-closures/fn-help-with-err.stderr b/tests/ui/functions-closures/fn-help-with-err.stderr index 83a2b1f58f9..da081eb4355 100644 --- a/tests/ui/functions-closures/fn-help-with-err.stderr +++ b/tests/ui/functions-closures/fn-help-with-err.stderr @@ -4,7 +4,7 @@ error[E0425]: cannot find value `oops` in this scope LL | let arc = std::sync::Arc::new(oops); | ^^^^ not found in this scope -error[E0599]: no method named `bar` found for struct `Arc<[closure@fn-help-with-err.rs:18:36]>` in the current scope +error[E0599]: no method named `bar` found for struct `Arc<[closure@$DIR/fn-help-with-err.rs:18:36: 18:38]>` in the current scope --> $DIR/fn-help-with-err.rs:19:10 | LL | arc2.bar(); diff --git a/tests/ui/higher-rank-trait-bounds/issue-30786.rs b/tests/ui/higher-rank-trait-bounds/issue-30786.rs index e5f46f711c2..4a6399c8f62 100644 --- a/tests/ui/higher-rank-trait-bounds/issue-30786.rs +++ b/tests/ui/higher-rank-trait-bounds/issue-30786.rs @@ -1,3 +1,5 @@ +// normalize-stderr-test: "long-type-\d+" -> "long-type-hash" + // rust-lang/rust#30786: the use of `for<'b> &'b mut A: Stream`, but its trait bounds were not satisfied - --> $DIR/issue-30786.rs:118:22 +error[E0599]: the method `filterx` exists for struct `Map`, but its trait bounds were not satisfied + --> $DIR/issue-30786.rs:120:22 | LL | pub struct Map { | -------------------- @@ -8,19 +8,19 @@ LL | pub struct Map { | doesn't satisfy `_: StreamExt` ... LL | let filter = map.filterx(|x: &_| true); - | ^^^^^^^ method cannot be called on `Map` due to unsatisfied trait bounds + | ^^^^^^^ method cannot be called on `Map` due to unsatisfied trait bounds | note: the following trait bounds were not satisfied: - `&'a mut &Map: Stream` - `&'a mut &mut Map: Stream` - `&'a mut Map: Stream` - --> $DIR/issue-30786.rs:96:50 + `&'a mut &Map: Stream` + `&'a mut &mut Map: Stream` + `&'a mut Map: Stream` + --> $DIR/issue-30786.rs:98:50 | LL | impl StreamExt for T where for<'a> &'a mut T: Stream {} | --------- - ^^^^^^ unsatisfied trait bound introduced here -error[E0599]: the method `countx` exists for struct `Filter &u64 {identity::}>, [closure@issue-30786.rs:129:30]>`, but its trait bounds were not satisfied - --> $DIR/issue-30786.rs:130:24 +error[E0599]: the method `countx` exists for struct `Filter &u64 {identity::}>, [closure@issue-30786.rs:131:30]>`, but its trait bounds were not satisfied + --> $DIR/issue-30786.rs:132:24 | LL | pub struct Filter { | ----------------------- @@ -31,11 +31,12 @@ LL | pub struct Filter { LL | let count = filter.countx(); | ^^^^^^ method cannot be called due to unsatisfied trait bounds | + = note: the full type name has been written to '$TEST_BUILD_DIR/higher-rank-trait-bounds/issue-30786/issue-30786.long-type-hash.txt' note: the following trait bounds were not satisfied: - `&'a mut &Filter fn(&'a u64) -> &'a u64 {identity::}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream` - `&'a mut &mut Filter fn(&'a u64) -> &'a u64 {identity::}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream` - `&'a mut Filter fn(&'a u64) -> &'a u64 {identity::}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream` - --> $DIR/issue-30786.rs:96:50 + `&'a mut &Filter fn(&'a u64) -> &'a u64 {identity::}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream` + `&'a mut &mut Filter fn(&'a u64) -> &'a u64 {identity::}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream` + `&'a mut Filter fn(&'a u64) -> &'a u64 {identity::}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream` + --> $DIR/issue-30786.rs:98:50 | LL | impl StreamExt for T where for<'a> &'a mut T: Stream {} | --------- - ^^^^^^ unsatisfied trait bound introduced here diff --git a/tests/ui/impl-trait/no-method-suggested-traits.stderr b/tests/ui/impl-trait/no-method-suggested-traits.stderr index 548c89d0a38..3c2c01dc227 100644 --- a/tests/ui/impl-trait/no-method-suggested-traits.stderr +++ b/tests/ui/impl-trait/no-method-suggested-traits.stderr @@ -145,7 +145,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it LL | pub trait Bar { | ^^^^^^^^^^^^^ -error[E0599]: no method named `method2` found for struct `Foo` in the current scope +error[E0599]: no method named `method2` found for struct `no_method_suggested_traits::Foo` in the current scope --> $DIR/no-method-suggested-traits.rs:50:37 | LL | no_method_suggested_traits::Foo.method2(); @@ -158,7 +158,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it LL | pub trait Bar { | ^^^^^^^^^^^^^ -error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&Foo>>` in the current scope +error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope --> $DIR/no-method-suggested-traits.rs:52:71 | LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2(); @@ -171,7 +171,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it LL | pub trait Bar { | ^^^^^^^^^^^^^ -error[E0599]: no method named `method2` found for enum `Bar` in the current scope +error[E0599]: no method named `method2` found for enum `no_method_suggested_traits::Bar` in the current scope --> $DIR/no-method-suggested-traits.rs:54:40 | LL | no_method_suggested_traits::Bar::X.method2(); @@ -184,7 +184,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it LL | pub trait Bar { | ^^^^^^^^^^^^^ -error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&Bar>>` in the current scope +error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope --> $DIR/no-method-suggested-traits.rs:56:74 | LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2(); @@ -255,25 +255,25 @@ error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&usize>>` LL | std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); | ^^^^^^^ method not found in `Rc<&mut Box<&usize>>` -error[E0599]: no method named `method3` found for struct `Foo` in the current scope +error[E0599]: no method named `method3` found for struct `no_method_suggested_traits::Foo` in the current scope --> $DIR/no-method-suggested-traits.rs:71:37 | LL | no_method_suggested_traits::Foo.method3(); | ^^^^^^^ method not found in `Foo` -error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&Foo>>` in the current scope +error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope --> $DIR/no-method-suggested-traits.rs:72:71 | LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3(); | ^^^^^^^ method not found in `Rc<&mut Box<&Foo>>` -error[E0599]: no method named `method3` found for enum `Bar` in the current scope +error[E0599]: no method named `method3` found for enum `no_method_suggested_traits::Bar` in the current scope --> $DIR/no-method-suggested-traits.rs:74:40 | LL | no_method_suggested_traits::Bar::X.method3(); | ^^^^^^^ method not found in `Bar` -error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&Bar>>` in the current scope +error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope --> $DIR/no-method-suggested-traits.rs:75:74 | LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3(); diff --git a/tests/ui/issues/issue-19521.stderr b/tests/ui/issues/issue-19521.stderr index 89936374085..13a12acb360 100644 --- a/tests/ui/issues/issue-19521.stderr +++ b/tests/ui/issues/issue-19521.stderr @@ -1,4 +1,4 @@ -error[E0599]: no method named `homura` found for reference `&str` in the current scope +error[E0599]: no method named `homura` found for reference `&'static str` in the current scope --> $DIR/issue-19521.rs:2:8 | LL | "".homura()(); diff --git a/tests/ui/issues/issue-30123.stderr b/tests/ui/issues/issue-30123.stderr index 7808cbf8aa1..a00a1dbb884 100644 --- a/tests/ui/issues/issue-30123.stderr +++ b/tests/ui/issues/issue-30123.stderr @@ -1,4 +1,4 @@ -error[E0599]: no function or associated item named `new_undirected` found for struct `Graph` in the current scope +error[E0599]: no function or associated item named `new_undirected` found for struct `issue_30123_aux::Graph` in the current scope --> $DIR/issue-30123.rs:7:33 | LL | let ug = Graph::::new_undirected(); diff --git a/tests/ui/nll/issue-57642-higher-ranked-subtype.stderr b/tests/ui/nll/issue-57642-higher-ranked-subtype.stderr index cab5898259f..d1e94bc702c 100644 --- a/tests/ui/nll/issue-57642-higher-ranked-subtype.stderr +++ b/tests/ui/nll/issue-57642-higher-ranked-subtype.stderr @@ -13,7 +13,7 @@ note: `X` defines an item `make_g`, perhaps you need to implement it LL | trait X { | ^^^^^^^ -error[E0599]: no function or associated item named `make_f` found for fn pointer `fn(&())` in the current scope +error[E0599]: no function or associated item named `make_f` found for fn pointer `for<'a> fn(&'a ())` in the current scope --> $DIR/issue-57642-higher-ranked-subtype.rs:35:25 | LL | let x = ::make_f(); diff --git a/tests/ui/object-pointer-types.stderr b/tests/ui/object-pointer-types.stderr index 7133f8ae194..2c8df3b616f 100644 --- a/tests/ui/object-pointer-types.stderr +++ b/tests/ui/object-pointer-types.stderr @@ -16,7 +16,7 @@ LL | fn owned(self: Box); LL | x.owned(); | ^^^^^ method not found in `&mut dyn Foo` -error[E0599]: no method named `managed` found for struct `Box` in the current scope +error[E0599]: no method named `managed` found for struct `Box<(dyn Foo + 'static)>` in the current scope --> $DIR/object-pointer-types.rs:23:7 | LL | x.managed(); diff --git a/tests/ui/suggestions/remove-as_str.stderr b/tests/ui/suggestions/remove-as_str.stderr index cb618db704d..534c497780a 100644 --- a/tests/ui/suggestions/remove-as_str.stderr +++ b/tests/ui/suggestions/remove-as_str.stderr @@ -4,7 +4,7 @@ error[E0599]: no method named `as_str` found for reference `&str` in the current LL | s.as_str(); | -^^^^^^-- help: remove this method call -error[E0599]: no method named `as_str` found for reference `&str` in the current scope +error[E0599]: no method named `as_str` found for reference `&'a str` in the current scope --> $DIR/remove-as_str.rs:7:7 | LL | s.as_str(); diff --git a/tests/ui/suggestions/suggest-using-chars.rs b/tests/ui/suggestions/suggest-using-chars.rs index 29750a20199..95732881baf 100644 --- a/tests/ui/suggestions/suggest-using-chars.rs +++ b/tests/ui/suggestions/suggest-using-chars.rs @@ -1,6 +1,6 @@ pub fn main() { - let _ = "foo".iter(); //~ ERROR no method named `iter` found for reference `&str` in the current scope - let _ = "foo".foo(); //~ ERROR no method named `foo` found for reference `&str` in the current scope + let _ = "foo".iter(); //~ ERROR no method named `iter` found for reference `&'static str` in the current scope + let _ = "foo".foo(); //~ ERROR no method named `foo` found for reference `&'static str` in the current scope let _ = String::from("bar").iter(); //~ ERROR no method named `iter` found for struct `String` in the current scope let _ = (&String::from("bar")).iter(); //~ ERROR no method named `iter` found for reference `&String` in the current scope let _ = 0.iter(); //~ ERROR no method named `iter` found for type `{integer}` in the current scope diff --git a/tests/ui/suggestions/suggest-using-chars.stderr b/tests/ui/suggestions/suggest-using-chars.stderr index 57b0e866f84..ba80ec6a201 100644 --- a/tests/ui/suggestions/suggest-using-chars.stderr +++ b/tests/ui/suggestions/suggest-using-chars.stderr @@ -1,4 +1,4 @@ -error[E0599]: no method named `iter` found for reference `&str` in the current scope +error[E0599]: no method named `iter` found for reference `&'static str` in the current scope --> $DIR/suggest-using-chars.rs:2:19 | LL | let _ = "foo".iter(); @@ -9,7 +9,7 @@ help: because of the in-memory representation of `&str`, to obtain an `Iterator` LL | let _ = "foo".chars(); | ~~~~~ -error[E0599]: no method named `foo` found for reference `&str` in the current scope +error[E0599]: no method named `foo` found for reference `&'static str` in the current scope --> $DIR/suggest-using-chars.rs:3:19 | LL | let _ = "foo".foo(); diff --git a/tests/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr b/tests/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr index 99ec5178340..482fd3cb44d 100644 --- a/tests/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr +++ b/tests/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr @@ -1,4 +1,4 @@ -error[E0599]: no method named `call` found for closure `[closure@unboxed-closures-static-call-wrong-trait.rs:6:26]` in the current scope +error[E0599]: no method named `call` found for closure `[closure@$DIR/unboxed-closures-static-call-wrong-trait.rs:6:26: 6:29]` in the current scope --> $DIR/unboxed-closures-static-call-wrong-trait.rs:7:10 | LL | mut_.call((0, ));