]> git.lizzy.rs Git - rust.git/commitdiff
Tweak use of trimmed paths
authorEsteban Küber <esteban@kuber.com.ar>
Fri, 6 Jan 2023 19:21:47 +0000 (19:21 +0000)
committerEsteban Küber <esteban@kuber.com.ar>
Mon, 30 Jan 2023 20:12:21 +0000 (20:12 +0000)
16 files changed:
compiler/rustc_hir_typeck/src/method/suggest.rs
tests/ui/associated-types/issue-43924.stderr
tests/ui/confuse-field-and-method/issue-33784.stderr
tests/ui/empty/empty-struct-braces-expr.stderr
tests/ui/functions-closures/fn-help-with-err.stderr
tests/ui/higher-rank-trait-bounds/issue-30786.rs
tests/ui/higher-rank-trait-bounds/issue-30786.stderr
tests/ui/impl-trait/no-method-suggested-traits.stderr
tests/ui/issues/issue-19521.stderr
tests/ui/issues/issue-30123.stderr
tests/ui/nll/issue-57642-higher-ranked-subtype.stderr
tests/ui/object-pointer-types.stderr
tests/ui/suggestions/remove-as_str.stderr
tests/ui/suggestions/suggest-using-chars.rs
tests/ui/suggestions/suggest-using-chars.stderr
tests/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr

index 31d55a41d8a31b6d91b3d533d95a2008ab0b87ad..54890489f8b8f7c08132d62469a04ccd46b4b3e5 100644 (file)
@@ -259,7 +259,8 @@ pub fn report_no_match_method_error(
         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 @@ pub fn report_no_match_method_error(
             }
         };
 
-        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 @@ pub fn report_no_match_method_error(
             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 @@ trait bound{s}",
                 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);
index 9046170d7c995accdc8723105c90ac87396766e9..ab1a9511ec6c7e041488a8c94fa362278b6341d6 100644 (file)
@@ -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<u32>>::Out::default().to_string(), "false");
index 3906d64c9462453682f8edf42d47332c5619b14f..34debb6831734568330e7b6d8ccfaa32ae753e3f 100644 (file)
@@ -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();
index 0e580aedeaa921e7fd548624dc075a660864600d..4604ebeaa8b987f8b01cd1a75b9a1d5349dadab9 100644 (file)
@@ -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();
index 83a2b1f58f9c58ddc1305d48a213f8ca43439b98..da081eb435584455f42eaba2abf7e3d8d0e726c5 100644 (file)
@@ -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();
index e5f46f711c2fbf73721f792ed9e1d6903a82c178..4a6399c8f62468da8df6562ddcabec733ae10557 100644 (file)
@@ -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<Item=T`
 // should act as assertion that item does not borrow from its stream;
 // but an earlier buggy rustc allowed `.map(|x: &_| x)` which does
index 2ded5ae56cdbcfb5381bb305495d25e96238df0d..6ec34d11a7e9ea8e78ff4c73b6d326bcc07f1407 100644 (file)
@@ -1,5 +1,5 @@
-error[E0599]: the method `filterx` exists for struct `Map<Repeat, [closure@issue-30786.rs:117:27]>`, but its trait bounds were not satisfied
-  --> $DIR/issue-30786.rs:118:22
+error[E0599]: the method `filterx` exists for struct `Map<Repeat, [closure@issue-30786.rs:119:27]>`, but its trait bounds were not satisfied
+  --> $DIR/issue-30786.rs:120:22
    |
 LL | pub struct Map<S, F> {
    | --------------------
@@ -8,19 +8,19 @@ LL | pub struct Map<S, F> {
    | doesn't satisfy `_: StreamExt`
 ...
 LL |     let filter = map.filterx(|x: &_| true);
-   |                      ^^^^^^^ method cannot be called on `Map<Repeat, [closure@issue-30786.rs:117:27]>` due to unsatisfied trait bounds
+   |                      ^^^^^^^ method cannot be called on `Map<Repeat, [closure@issue-30786.rs:119:27]>` due to unsatisfied trait bounds
    |
 note: the following trait bounds were not satisfied:
-      `&'a mut &Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream`
-      `&'a mut &mut Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream`
-      `&'a mut Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream`
-  --> $DIR/issue-30786.rs:96:50
+      `&'a mut &Map<Repeat, [closure@$DIR/issue-30786.rs:119:27: 119:34]>: Stream`
+      `&'a mut &mut Map<Repeat, [closure@$DIR/issue-30786.rs:119:27: 119:34]>: Stream`
+      `&'a mut Map<Repeat, [closure@$DIR/issue-30786.rs:119:27: 119:34]>: Stream`
+  --> $DIR/issue-30786.rs:98:50
    |
 LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
    |         ---------     -                          ^^^^^^ unsatisfied trait bound introduced here
 
-error[E0599]: the method `countx` exists for struct `Filter<Map<Repeat, fn(&u64) -> &u64 {identity::<u64>}>, [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<Map<Repeat, fn(&u64) -> &u64 {identity::<u64>}>, [closure@issue-30786.rs:131:30]>`, but its trait bounds were not satisfied
+  --> $DIR/issue-30786.rs:132:24
    |
 LL | pub struct Filter<S, F> {
    | -----------------------
@@ -31,11 +31,12 @@ LL | pub struct Filter<S, F> {
 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<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
-      `&'a mut &mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
-      `&'a mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
-  --> $DIR/issue-30786.rs:96:50
+      `&'a mut &Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream`
+      `&'a mut &mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream`
+      `&'a mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream`
+  --> $DIR/issue-30786.rs:98:50
    |
 LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
    |         ---------     -                          ^^^^^^ unsatisfied trait bound introduced here
index 548c89d0a3871372e87270fd08b5ad3b2e1421a4..3c2c01dc227b9d45f49081d716e68b0d3db338f8 100644 (file)
@@ -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();
index 8993637408539155e4cb5745f7e0b5957f88fd30..13a12acb3605b5e13b148a923a68892cd938412d 100644 (file)
@@ -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()();
index 7808cbf8aa10840644bb7e85e8c9a81045adb8fc..a00a1dbb8843d2a282b4fa9044c2ac518575c4fa 100644 (file)
@@ -1,4 +1,4 @@
-error[E0599]: no function or associated item named `new_undirected` found for struct `Graph<i32, i32>` in the current scope
+error[E0599]: no function or associated item named `new_undirected` found for struct `issue_30123_aux::Graph<i32, i32>` in the current scope
   --> $DIR/issue-30123.rs:7:33
    |
 LL |     let ug = Graph::<i32, i32>::new_undirected();
index cab5898259fbc5afc24c32ea011368ddc98992ea..d1e94bc702cae7e0225f6f22570492321d62fe12 100644 (file)
@@ -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 = <fn (&())>::make_f();
index 7133f8ae1947801d9fcad6bee07d49a47741d9bc..2c8df3b616fb8ac5c43b02aa07d16ba38d65703a 100644 (file)
@@ -16,7 +16,7 @@ LL |     fn owned(self: Box<Self>);
 LL |     x.owned();
    |       ^^^^^ method not found in `&mut dyn Foo`
 
-error[E0599]: no method named `managed` found for struct `Box<dyn Foo>` 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();
index cb618db704d1bca369371bd0ad03efe93b45133c..534c497780a95e959982113289f50a128fcc8629 100644 (file)
@@ -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();
index 29750a20199966108b0f62a0831ee6d0a97ae8ee..95732881baf09423d8a5aeeead5bb3d21a145464 100644 (file)
@@ -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
index 57b0e866f84535892537dedf4981a9e0758dd681..ba80ec6a2019cb35160698296e173298cd74ffa5 100644 (file)
@@ -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();
index 99ec5178340030d15ca4cac950f747182a9e36cc..482fd3cb44def7b215ae30ea6f3b46ca9e46ba79 100644 (file)
@@ -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, ));