Skip to content

Commit 153ed09

Browse files
committed
Tweak use of trimmed paths
1 parent ab8dc9a commit 153ed09

16 files changed

+69
-44
lines changed

Diff for: compiler/rustc_hir_typeck/src/method/suggest.rs

+29-7
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
259259
let mode = no_match_data.mode;
260260
let tcx = self.tcx;
261261
let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty);
262-
let ty_str = with_forced_trimmed_paths!(self.ty_to_string(rcvr_ty));
262+
let (ty_str, ty_file) = tcx.short_ty_string(rcvr_ty);
263+
let short_ty_str = with_forced_trimmed_paths!(rcvr_ty.to_string());
263264
let is_method = mode == Mode::MethodCall;
264265
let unsatisfied_predicates = &no_match_data.unsatisfied_predicates;
265266
let similar_candidate = no_match_data.similar_candidate;
@@ -276,11 +277,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
276277
}
277278
};
278279

279-
if self.suggest_wrapping_range_with_parens(tcx, rcvr_ty, source, span, item_name, &ty_str)
280-
|| self.suggest_constraining_numerical_ty(
281-
tcx, rcvr_ty, source, span, item_kind, item_name, &ty_str,
282-
)
283-
{
280+
// We could pass the file for long types into these two, but it isn't strictly necessary
281+
// given how targetted they are.
282+
if self.suggest_wrapping_range_with_parens(
283+
tcx,
284+
rcvr_ty,
285+
source,
286+
span,
287+
item_name,
288+
&short_ty_str,
289+
) || self.suggest_constraining_numerical_ty(
290+
tcx,
291+
rcvr_ty,
292+
source,
293+
span,
294+
item_kind,
295+
item_name,
296+
&short_ty_str,
297+
) {
284298
return None;
285299
}
286300
span = item_name.span;
@@ -319,6 +333,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
319333
rcvr_ty.prefix_string(self.tcx),
320334
ty_str_reported,
321335
);
336+
let ty_str = if short_ty_str.len() < ty_str.len() && ty_str.len() > 10 {
337+
short_ty_str
338+
} else {
339+
ty_str
340+
};
341+
if let Some(file) = ty_file {
342+
err.note(&format!("the full type name has been written to '{}'", file.display(),));
343+
}
322344
if rcvr_ty.references_error() {
323345
err.downgrade_to_delayed_bug();
324346
}
@@ -826,7 +848,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
826848
let primary_message = primary_message.unwrap_or_else(|| {
827849
format!(
828850
"the {item_kind} `{item_name}` exists for {actual_prefix} `{ty_str}`, \
829-
but its trait bounds were not satisfied"
851+
but its trait bounds were not satisfied"
830852
)
831853
});
832854
err.set_primary_message(&primary_message);

Diff for: tests/ui/associated-types/issue-43924.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: required by a bound in `Foo::Out`
1010
LL | type Out: Default + ToString + ?Sized = dyn ToString;
1111
| ^^^^^^^ required by this bound in `Foo::Out`
1212

13-
error[E0599]: no function or associated item named `default` found for trait object `dyn ToString` in the current scope
13+
error[E0599]: no function or associated item named `default` found for trait object `(dyn ToString + 'static)` in the current scope
1414
--> $DIR/issue-43924.rs:14:39
1515
|
1616
LL | assert_eq!(<() as Foo<u32>>::Out::default().to_string(), "false");

Diff for: tests/ui/confuse-field-and-method/issue-33784.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `closure` found for reference `&Obj<[closure@issue-33784.rs:25:43]>` in the current scope
1+
error[E0599]: no method named `closure` found for reference `&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope
22
--> $DIR/issue-33784.rs:27:7
33
|
44
LL | p.closure();
@@ -9,7 +9,7 @@ help: to call the function stored in `closure`, surround the field access with p
99
LL | (p.closure)();
1010
| + +
1111

12-
error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[closure@issue-33784.rs:25:43]>` in the current scope
12+
error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope
1313
--> $DIR/issue-33784.rs:29:7
1414
|
1515
LL | q.fn_ptr();

Diff for: tests/ui/empty/empty-struct-braces-expr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ help: a unit struct with a similar name exists
100100
LL | let xe1 = XEmpty2();
101101
| ~~~~~~~
102102

103-
error[E0599]: no variant or associated item named `Empty3` found for enum `XE` in the current scope
103+
error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope
104104
--> $DIR/empty-struct-braces-expr.rs:25:19
105105
|
106106
LL | let xe3 = XE::Empty3;
@@ -109,7 +109,7 @@ LL | let xe3 = XE::Empty3;
109109
| variant or associated item not found in `XE`
110110
| help: there is a variant with a similar name: `XEmpty3`
111111

112-
error[E0599]: no variant or associated item named `Empty3` found for enum `XE` in the current scope
112+
error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope
113113
--> $DIR/empty-struct-braces-expr.rs:26:19
114114
|
115115
LL | let xe3 = XE::Empty3();

Diff for: tests/ui/functions-closures/fn-help-with-err.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0425]: cannot find value `oops` in this scope
44
LL | let arc = std::sync::Arc::new(oops);
55
| ^^^^ not found in this scope
66

7-
error[E0599]: no method named `bar` found for struct `Arc<[closure@fn-help-with-err.rs:18:36]>` in the current scope
7+
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
88
--> $DIR/fn-help-with-err.rs:19:10
99
|
1010
LL | arc2.bar();

Diff for: tests/ui/higher-rank-trait-bounds/issue-30786.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
2+
13
// rust-lang/rust#30786: the use of `for<'b> &'b mut A: Stream<Item=T`
24
// should act as assertion that item does not borrow from its stream;
35
// but an earlier buggy rustc allowed `.map(|x: &_| x)` which does

Diff for: tests/ui/higher-rank-trait-bounds/issue-30786.stderr

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0599]: the method `filterx` exists for struct `Map<Repeat, [closure@issue-30786.rs:117:27]>`, but its trait bounds were not satisfied
2-
--> $DIR/issue-30786.rs:118:22
1+
error[E0599]: the method `filterx` exists for struct `Map<Repeat, [closure@issue-30786.rs:119:27]>`, but its trait bounds were not satisfied
2+
--> $DIR/issue-30786.rs:120:22
33
|
44
LL | pub struct Map<S, F> {
55
| --------------------
@@ -8,19 +8,19 @@ LL | pub struct Map<S, F> {
88
| doesn't satisfy `_: StreamExt`
99
...
1010
LL | let filter = map.filterx(|x: &_| true);
11-
| ^^^^^^^ method cannot be called on `Map<Repeat, [closure@issue-30786.rs:117:27]>` due to unsatisfied trait bounds
11+
| ^^^^^^^ method cannot be called on `Map<Repeat, [closure@issue-30786.rs:119:27]>` due to unsatisfied trait bounds
1212
|
1313
note: the following trait bounds were not satisfied:
14-
`&'a mut &Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream`
15-
`&'a mut &mut Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream`
16-
`&'a mut Map<Repeat, [closure@$DIR/issue-30786.rs:117:27: 117:34]>: Stream`
17-
--> $DIR/issue-30786.rs:96:50
14+
`&'a mut &Map<Repeat, [closure@$DIR/issue-30786.rs:119:27: 119:34]>: Stream`
15+
`&'a mut &mut Map<Repeat, [closure@$DIR/issue-30786.rs:119:27: 119:34]>: Stream`
16+
`&'a mut Map<Repeat, [closure@$DIR/issue-30786.rs:119:27: 119:34]>: Stream`
17+
--> $DIR/issue-30786.rs:98:50
1818
|
1919
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
2020
| --------- - ^^^^^^ unsatisfied trait bound introduced here
2121

22-
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
23-
--> $DIR/issue-30786.rs:130:24
22+
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
23+
--> $DIR/issue-30786.rs:132:24
2424
|
2525
LL | pub struct Filter<S, F> {
2626
| -----------------------
@@ -31,11 +31,12 @@ LL | pub struct Filter<S, F> {
3131
LL | let count = filter.countx();
3232
| ^^^^^^ method cannot be called due to unsatisfied trait bounds
3333
|
34+
= note: the full type name has been written to '$TEST_BUILD_DIR/higher-rank-trait-bounds/issue-30786/issue-30786.long-type-hash.txt'
3435
note: the following trait bounds were not satisfied:
35-
`&'a mut &Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
36-
`&'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`
37-
`&'a mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:129:30: 129:37]>: Stream`
38-
--> $DIR/issue-30786.rs:96:50
36+
`&'a mut &Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream`
37+
`&'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`
38+
`&'a mut Filter<Map<Repeat, for<'a> fn(&'a u64) -> &'a u64 {identity::<u64>}>, [closure@$DIR/issue-30786.rs:131:30: 131:37]>: Stream`
39+
--> $DIR/issue-30786.rs:98:50
3940
|
4041
LL | impl<T> StreamExt for T where for<'a> &'a mut T: Stream {}
4142
| --------- - ^^^^^^ unsatisfied trait bound introduced here

Diff for: tests/ui/impl-trait/no-method-suggested-traits.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
145145
LL | pub trait Bar {
146146
| ^^^^^^^^^^^^^
147147

148-
error[E0599]: no method named `method2` found for struct `Foo` in the current scope
148+
error[E0599]: no method named `method2` found for struct `no_method_suggested_traits::Foo` in the current scope
149149
--> $DIR/no-method-suggested-traits.rs:50:37
150150
|
151151
LL | no_method_suggested_traits::Foo.method2();
@@ -158,7 +158,7 @@ note: `foo::Bar` defines an item `method2`, perhaps you need to implement it
158158
LL | pub trait Bar {
159159
| ^^^^^^^^^^^^^
160160

161-
error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&Foo>>` in the current scope
161+
error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope
162162
--> $DIR/no-method-suggested-traits.rs:52:71
163163
|
164164
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
171171
LL | pub trait Bar {
172172
| ^^^^^^^^^^^^^
173173

174-
error[E0599]: no method named `method2` found for enum `Bar` in the current scope
174+
error[E0599]: no method named `method2` found for enum `no_method_suggested_traits::Bar` in the current scope
175175
--> $DIR/no-method-suggested-traits.rs:54:40
176176
|
177177
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
184184
LL | pub trait Bar {
185185
| ^^^^^^^^^^^^^
186186

187-
error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&Bar>>` in the current scope
187+
error[E0599]: no method named `method2` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope
188188
--> $DIR/no-method-suggested-traits.rs:56:74
189189
|
190190
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>>`
255255
LL | std::rc::Rc::new(&mut Box::new(&1_usize)).method3();
256256
| ^^^^^^^ method not found in `Rc<&mut Box<&usize>>`
257257

258-
error[E0599]: no method named `method3` found for struct `Foo` in the current scope
258+
error[E0599]: no method named `method3` found for struct `no_method_suggested_traits::Foo` in the current scope
259259
--> $DIR/no-method-suggested-traits.rs:71:37
260260
|
261261
LL | no_method_suggested_traits::Foo.method3();
262262
| ^^^^^^^ method not found in `Foo`
263263

264-
error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&Foo>>` in the current scope
264+
error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&no_method_suggested_traits::Foo>>` in the current scope
265265
--> $DIR/no-method-suggested-traits.rs:72:71
266266
|
267267
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3();
268268
| ^^^^^^^ method not found in `Rc<&mut Box<&Foo>>`
269269

270-
error[E0599]: no method named `method3` found for enum `Bar` in the current scope
270+
error[E0599]: no method named `method3` found for enum `no_method_suggested_traits::Bar` in the current scope
271271
--> $DIR/no-method-suggested-traits.rs:74:40
272272
|
273273
LL | no_method_suggested_traits::Bar::X.method3();
274274
| ^^^^^^^ method not found in `Bar`
275275

276-
error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&Bar>>` in the current scope
276+
error[E0599]: no method named `method3` found for struct `Rc<&mut Box<&no_method_suggested_traits::Bar>>` in the current scope
277277
--> $DIR/no-method-suggested-traits.rs:75:74
278278
|
279279
LL | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3();

Diff for: tests/ui/issues/issue-19521.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `homura` found for reference `&str` in the current scope
1+
error[E0599]: no method named `homura` found for reference `&'static str` in the current scope
22
--> $DIR/issue-19521.rs:2:8
33
|
44
LL | "".homura()();

Diff for: tests/ui/issues/issue-30123.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no function or associated item named `new_undirected` found for struct `Graph<i32, i32>` in the current scope
1+
error[E0599]: no function or associated item named `new_undirected` found for struct `issue_30123_aux::Graph<i32, i32>` in the current scope
22
--> $DIR/issue-30123.rs:7:33
33
|
44
LL | let ug = Graph::<i32, i32>::new_undirected();

Diff for: tests/ui/nll/issue-57642-higher-ranked-subtype.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ note: `X` defines an item `make_g`, perhaps you need to implement it
1313
LL | trait X {
1414
| ^^^^^^^
1515

16-
error[E0599]: no function or associated item named `make_f` found for fn pointer `fn(&())` in the current scope
16+
error[E0599]: no function or associated item named `make_f` found for fn pointer `for<'a> fn(&'a ())` in the current scope
1717
--> $DIR/issue-57642-higher-ranked-subtype.rs:35:25
1818
|
1919
LL | let x = <fn (&())>::make_f();

Diff for: tests/ui/object-pointer-types.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | fn owned(self: Box<Self>);
1616
LL | x.owned();
1717
| ^^^^^ method not found in `&mut dyn Foo`
1818

19-
error[E0599]: no method named `managed` found for struct `Box<dyn Foo>` in the current scope
19+
error[E0599]: no method named `managed` found for struct `Box<(dyn Foo + 'static)>` in the current scope
2020
--> $DIR/object-pointer-types.rs:23:7
2121
|
2222
LL | x.managed();

Diff for: tests/ui/suggestions/remove-as_str.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0599]: no method named `as_str` found for reference `&str` in the current
44
LL | s.as_str();
55
| -^^^^^^-- help: remove this method call
66

7-
error[E0599]: no method named `as_str` found for reference `&str` in the current scope
7+
error[E0599]: no method named `as_str` found for reference `&'a str` in the current scope
88
--> $DIR/remove-as_str.rs:7:7
99
|
1010
LL | s.as_str();

Diff for: tests/ui/suggestions/suggest-using-chars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub fn main() {
2-
let _ = "foo".iter(); //~ ERROR no method named `iter` found for reference `&str` in the current scope
3-
let _ = "foo".foo(); //~ ERROR no method named `foo` found for reference `&str` in the current scope
2+
let _ = "foo".iter(); //~ ERROR no method named `iter` found for reference `&'static str` in the current scope
3+
let _ = "foo".foo(); //~ ERROR no method named `foo` found for reference `&'static str` in the current scope
44
let _ = String::from("bar").iter(); //~ ERROR no method named `iter` found for struct `String` in the current scope
55
let _ = (&String::from("bar")).iter(); //~ ERROR no method named `iter` found for reference `&String` in the current scope
66
let _ = 0.iter(); //~ ERROR no method named `iter` found for type `{integer}` in the current scope

Diff for: tests/ui/suggestions/suggest-using-chars.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `iter` found for reference `&str` in the current scope
1+
error[E0599]: no method named `iter` found for reference `&'static str` in the current scope
22
--> $DIR/suggest-using-chars.rs:2:19
33
|
44
LL | let _ = "foo".iter();
@@ -9,7 +9,7 @@ help: because of the in-memory representation of `&str`, to obtain an `Iterator`
99
LL | let _ = "foo".chars();
1010
| ~~~~~
1111

12-
error[E0599]: no method named `foo` found for reference `&str` in the current scope
12+
error[E0599]: no method named `foo` found for reference `&'static str` in the current scope
1313
--> $DIR/suggest-using-chars.rs:3:19
1414
|
1515
LL | let _ = "foo".foo();

Diff for: tests/ui/unboxed-closures/unboxed-closures-static-call-wrong-trait.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0599]: no method named `call` found for closure `[closure@unboxed-closures-static-call-wrong-trait.rs:6:26]` in the current scope
1+
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
22
--> $DIR/unboxed-closures-static-call-wrong-trait.rs:7:10
33
|
44
LL | mut_.call((0, ));

0 commit comments

Comments
 (0)