Skip to content

Commit 0559107

Browse files
committed
Use local spans only
1 parent f796fcd commit 0559107

File tree

10 files changed

+100
-185
lines changed

10 files changed

+100
-185
lines changed

src/librustc_typeck/check/method/suggest.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
176176

177177
let actual = self.resolve_type_vars_if_possible(&rcvr_ty);
178178
let ty_string = self.ty_to_string(actual);
179-
let type_str = if mode == Mode::MethodCall {
179+
let is_method = mode == Mode::MethodCall;
180+
let type_str = if is_method {
180181
"method"
181182
} else if actual.is_enum() {
182183
"variant"
@@ -207,16 +208,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
207208
};
208209

209210
if let Some(def) = actual.ty_adt_def() {
210-
let full_sp = tcx.def_span(def.did);
211-
let def_sp = tcx.sess.codemap().def_span(full_sp);
212-
err.span_label(def_sp, format!("{} `{}` not found {}",
213-
type_str,
214-
item_name,
215-
if def.is_enum() {
216-
"here"
217-
} else {
218-
"for this"
219-
}));
211+
if let Some(full_sp) = tcx.hir.span_if_local(def.did) {
212+
let def_sp = tcx.sess.codemap().def_span(full_sp);
213+
err.span_label(def_sp, format!("{} `{}` not found {}",
214+
type_str,
215+
item_name,
216+
if def.is_enum() && !is_method {
217+
"here"
218+
} else {
219+
"for this"
220+
}));
221+
}
220222
}
221223

222224
// If the method name is the name of a field with a function or closure type,

src/test/compile-fail/bogus-tag.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ fn main() {
1616
let red: color = color::rgb(255, 0, 0);
1717
match red {
1818
color::rgb(r, g, b) => { println!("rgb"); }
19-
color::hsl(h, s, l) => { println!("hsl"); } //~ ERROR no variant
19+
color::hsl(h, s, l) => { println!("hsl"); }
20+
//~^ ERROR no variant
21+
//~| NOTE variant not found in `color`
2022
}
2123
}

src/test/compile-fail/issue-22933-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum Delicious { //~ NOTE variant `PIE` not found here
1313
Apple = 0x2,
1414
ApplePie = Delicious::Apple as isize | Delicious::PIE as isize,
1515
//~^ ERROR no variant named `PIE` found for type `Delicious`
16+
//~| NOTE variant not found in `Delicious`
1617
}
1718

1819
fn main() {}

src/test/compile-fail/issue-23173.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ enum Token { LeftParen, RightParen, Plus, Minus, /* etc */ }
1414
fn use_token(token: &Token) { unimplemented!() }
1515

1616
fn main() {
17-
use_token(&Token::Homura); //~ ERROR no variant named `Homura`
17+
use_token(&Token::Homura);
18+
//~^ ERROR no variant named `Homura`
19+
//~| NOTE variant not found in `Token`
1820
}

src/test/compile-fail/issue-23217.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
pub enum SomeEnum { //~ NOTE variant `A` not found here
1212
B = SomeEnum::A,
1313
//~^ ERROR no variant named `A` found for type `SomeEnum`
14+
//~| NOTE variant not found in `SomeEnum`
1415
}
1516

1617
fn main() {}

src/test/compile-fail/issue-28971.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn main(){
1818
match Foo::Bar(1) {
1919
Foo::Baz(..) => (),
2020
//~^ ERROR no variant named `Baz` found for type `Foo`
21+
//~| NOTE variant not found in `Foo`
2122
_ => (),
2223
}
2324
});

src/test/ui/impl-trait/no-method-suggested-traits.stderr

+57-136
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,17 @@ error[E0599]: no method named `method` found for type `u32` in the current scope
1212
candidate #4: `use no_method_suggested_traits::Reexported;`
1313

1414
error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::boxed::Box<&u32>>` in the current scope
15-
--> $DIR/no-method-suggested-traits.rs:38:44
16-
|
17-
38 | std::rc::Rc::new(&mut Box::new(&1u32)).method();
18-
| ^^^^^^
19-
|
20-
::: /checkout/src/liballoc/rc.rs
21-
|
22-
284 | pub struct Rc<T: ?Sized> {
23-
| ------------------------ method `method` not found for this
24-
|
25-
= help: items from traits can only be used if the trait is in scope
26-
= note: the following traits are implemented but not in scope, perhaps add a `use` for one of them:
27-
candidate #1: `use foo::Bar;`
28-
candidate #2: `use no_method_suggested_traits::foo::PubPub;`
29-
candidate #3: `use no_method_suggested_traits::qux::PrivPub;`
30-
candidate #4: `use no_method_suggested_traits::Reexported;`
15+
--> $DIR/no-method-suggested-traits.rs:38:44
16+
|
17+
38 | std::rc::Rc::new(&mut Box::new(&1u32)).method();
18+
| ^^^^^^
19+
|
20+
= help: items from traits can only be used if the trait is in scope
21+
= note: the following traits are implemented but not in scope, perhaps add a `use` for one of them:
22+
candidate #1: `use foo::Bar;`
23+
candidate #2: `use no_method_suggested_traits::foo::PubPub;`
24+
candidate #3: `use no_method_suggested_traits::qux::PrivPub;`
25+
candidate #4: `use no_method_suggested_traits::Reexported;`
3126

3227
error[E0599]: no method named `method` found for type `char` in the current scope
3328
--> $DIR/no-method-suggested-traits.rs:44:9
@@ -40,19 +35,14 @@ error[E0599]: no method named `method` found for type `char` in the current scop
4035
candidate #1: `use foo::Bar;`
4136

4237
error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::boxed::Box<&char>>` in the current scope
43-
--> $DIR/no-method-suggested-traits.rs:48:43
44-
|
45-
48 | std::rc::Rc::new(&mut Box::new(&'a')).method();
46-
| ^^^^^^
47-
|
48-
::: /checkout/src/liballoc/rc.rs
49-
|
50-
284 | pub struct Rc<T: ?Sized> {
51-
| ------------------------ method `method` not found for this
52-
|
53-
= help: items from traits can only be used if the trait is in scope
54-
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:
55-
candidate #1: `use foo::Bar;`
38+
--> $DIR/no-method-suggested-traits.rs:48:43
39+
|
40+
48 | std::rc::Rc::new(&mut Box::new(&'a')).method();
41+
| ^^^^^^
42+
|
43+
= help: items from traits can only be used if the trait is in scope
44+
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:
45+
candidate #1: `use foo::Bar;`
5646

5747
error[E0599]: no method named `method` found for type `i32` in the current scope
5848
--> $DIR/no-method-suggested-traits.rs:53:10
@@ -65,18 +55,14 @@ error[E0599]: no method named `method` found for type `i32` in the current scope
6555
candidate #1: `use no_method_suggested_traits::foo::PubPub;`
6656

6757
error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::boxed::Box<&i32>>` in the current scope
68-
--> $DIR/no-method-suggested-traits.rs:57:44
69-
|
70-
57 | std::rc::Rc::new(&mut Box::new(&1i32)).method();
71-
|
72-
::: /checkout/src/liballoc/rc.rs
73-
|
74-
284 | pub struct Rc<T: ?Sized> {
75-
| ------------------------ method `method` not found for this
76-
|
77-
= help: items from traits can only be used if the trait is in scope
78-
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:
79-
candidate #1: `use no_method_suggested_traits::foo::PubPub;`
58+
--> $DIR/no-method-suggested-traits.rs:57:44
59+
|
60+
57 | std::rc::Rc::new(&mut Box::new(&1i32)).method();
61+
| ^^^^^^
62+
|
63+
= help: items from traits can only be used if the trait is in scope
64+
= note: the following trait is implemented but not in scope, perhaps add a `use` for it:
65+
candidate #1: `use no_method_suggested_traits::foo::PubPub;`
8066

8167
error[E0599]: no method named `method` found for type `Foo` in the current scope
8268
--> $DIR/no-method-suggested-traits.rs:62:9
@@ -97,24 +83,19 @@ error[E0599]: no method named `method` found for type `Foo` in the current scope
9783
candidate #6: `no_method_suggested_traits::Reexported`
9884

9985
error[E0599]: no method named `method` found for type `std::rc::Rc<&mut std::boxed::Box<&Foo>>` in the current scope
100-
--> $DIR/no-method-suggested-traits.rs:71:43
101-
|
102-
71 | std::rc::Rc::new(&mut Box::new(&Foo)).method();
103-
| ^^^^^^
104-
|
105-
::: /checkout/src/liballoc/rc.rs
106-
|
107-
284 | pub struct Rc<T: ?Sized> {
108-
| ------------------------ method `method` not found for this
109-
|
110-
= help: items from traits can only be used if the trait is implemented and in scope
111-
= note: the following traits define an item `method`, perhaps you need to implement one of them:
112-
candidate #1: `foo::Bar`
113-
candidate #2: `no_method_suggested_traits::foo::PubPub`
114-
candidate #3: `no_method_suggested_traits::bar::PubPriv`
115-
candidate #4: `no_method_suggested_traits::qux::PrivPub`
116-
candidate #5: `no_method_suggested_traits::quz::PrivPriv`
117-
candidate #6: `no_method_suggested_traits::Reexported`
86+
--> $DIR/no-method-suggested-traits.rs:71:43
87+
|
88+
71 | std::rc::Rc::new(&mut Box::new(&Foo)).method();
89+
| ^^^^^^
90+
|
91+
= help: items from traits can only be used if the trait is implemented and in scope
92+
= note: the following traits define an item `method`, perhaps you need to implement one of them:
93+
candidate #1: `foo::Bar`
94+
candidate #2: `no_method_suggested_traits::foo::PubPub`
95+
candidate #3: `no_method_suggested_traits::bar::PubPriv`
96+
candidate #4: `no_method_suggested_traits::qux::PrivPub`
97+
candidate #5: `no_method_suggested_traits::quz::PrivPriv`
98+
candidate #6: `no_method_suggested_traits::Reexported`
11899

119100
error[E0599]: no method named `method2` found for type `u64` in the current scope
120101
--> $DIR/no-method-suggested-traits.rs:81:10
@@ -127,60 +108,40 @@ error[E0599]: no method named `method2` found for type `u64` in the current scop
127108
candidate #1: `foo::Bar`
128109

129110
error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::boxed::Box<&u64>>` in the current scope
130-
--> $DIR/no-method-suggested-traits.rs:85:44
131-
|
132-
85 | std::rc::Rc::new(&mut Box::new(&1u64)).method2();
133-
| ^^^^^^^
134-
|
135-
::: /checkout/src/liballoc/rc.rs
136-
|
137-
284 | pub struct Rc<T: ?Sized> {
138-
| ------------------------ method `method2` not found for this
139-
|
140-
= help: items from traits can only be used if the trait is implemented and in scope
141-
= note: the following trait defines an item `method2`, perhaps you need to implement it:
142-
candidate #1: `foo::Bar`
111+
--> $DIR/no-method-suggested-traits.rs:85:44
112+
|
113+
85 | std::rc::Rc::new(&mut Box::new(&1u64)).method2();
114+
| ^^^^^^^
115+
|
116+
= help: items from traits can only be used if the trait is implemented and in scope
117+
= note: the following trait defines an item `method2`, perhaps you need to implement it:
118+
candidate #1: `foo::Bar`
143119

144120
error[E0599]: no method named `method2` found for type `no_method_suggested_traits::Foo` in the current scope
145121
--> $DIR/no-method-suggested-traits.rs:90:37
146122
|
147123
90 | no_method_suggested_traits::Foo.method2();
148124
| ^^^^^^^
149-
|
150-
::: $DIR/auxiliary/no_method_suggested_traits.rs
151-
|
152-
13 | pub struct Foo;
153-
| --------------- method `method2` not found for this
154125
|
155126
= help: items from traits can only be used if the trait is implemented and in scope
156127
= note: the following trait defines an item `method2`, perhaps you need to implement it:
157128
candidate #1: `foo::Bar`
158129

159130
error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>` in the current scope
160-
--> $DIR/no-method-suggested-traits.rs:94:71
161-
|
162-
94 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
163-
| ^^^^^^^
164-
|
165-
::: /checkout/src/liballoc/rc.rs
166-
|
167-
284 | pub struct Rc<T: ?Sized> {
168-
| ------------------------ method `method2` not found for this
169-
|
170-
= help: items from traits can only be used if the trait is implemented and in scope
171-
= note: the following trait defines an item `method2`, perhaps you need to implement it:
172-
candidate #1: `foo::Bar`
131+
--> $DIR/no-method-suggested-traits.rs:94:71
132+
|
133+
94 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
134+
| ^^^^^^^
135+
|
136+
= help: items from traits can only be used if the trait is implemented and in scope
137+
= note: the following trait defines an item `method2`, perhaps you need to implement it:
138+
candidate #1: `foo::Bar`
173139

174140
error[E0599]: no method named `method2` found for type `no_method_suggested_traits::Bar` in the current scope
175141
--> $DIR/no-method-suggested-traits.rs:98:40
176142
|
177143
98 | no_method_suggested_traits::Bar::X.method2();
178144
| ^^^^^^^
179-
|
180-
::: $DIR/auxiliary/no_method_suggested_traits.rs
181-
|
182-
14 | pub enum Bar { X }
183-
| ------------ method `method2` not found here
184145
|
185146
= help: items from traits can only be used if the trait is implemented and in scope
186147
= note: the following trait defines an item `method2`, perhaps you need to implement it:
@@ -191,11 +152,6 @@ error[E0599]: no method named `method2` found for type `std::rc::Rc<&mut std::bo
191152
|
192153
102 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
193154
| ^^^^^^^
194-
|
195-
::: /checkout/src/liballoc/rc.rs
196-
|
197-
284 | pub struct Rc<T: ?Sized> {
198-
| ------------------------ method `method2` not found for this
199155
|
200156
= help: items from traits can only be used if the trait is implemented and in scope
201157
= note: the following trait defines an item `method2`, perhaps you need to implement it:
@@ -219,11 +175,6 @@ error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::bo
219175
|
220176
111 | std::rc::Rc::new(&mut Box::new(&Foo)).method3();
221177
| ^^^^^^^
222-
|
223-
::: /checkout/src/liballoc/rc.rs
224-
|
225-
284 | pub struct Rc<T: ?Sized> {
226-
| ------------------------ method `method3` not found for this
227178
|
228179
= help: items from traits can only be used if the trait is implemented and in scope
229180
= note: the following trait defines an item `method3`, perhaps you need to implement it:
@@ -233,7 +184,7 @@ error[E0599]: no method named `method3` found for type `Bar` in the current scop
233184
--> $DIR/no-method-suggested-traits.rs:115:12
234185
|
235186
15 | enum Bar { X }
236-
| -------- method `method3` not found here
187+
| -------- method `method3` not found for this
237188
...
238189
115 | Bar::X.method3();
239190
| ^^^^^^^
@@ -247,11 +198,6 @@ error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::bo
247198
|
248199
119 | std::rc::Rc::new(&mut Box::new(&Bar::X)).method3();
249200
| ^^^^^^^
250-
|
251-
::: /checkout/src/liballoc/rc.rs
252-
|
253-
284 | pub struct Rc<T: ?Sized> {
254-
| ------------------------ method `method3` not found for this
255201
|
256202
= help: items from traits can only be used if the trait is implemented and in scope
257203
= note: the following trait defines an item `method3`, perhaps you need to implement it:
@@ -268,55 +214,30 @@ error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::bo
268214
|
269215
126 | std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR no method named
270216
| ^^^^^^^
271-
|
272-
::: /checkout/src/liballoc/rc.rs
273-
|
274-
284 | pub struct Rc<T: ?Sized> {
275-
| ------------------------ method `method3` not found for this
276217

277218
error[E0599]: no method named `method3` found for type `no_method_suggested_traits::Foo` in the current scope
278219
--> $DIR/no-method-suggested-traits.rs:127:37
279220
|
280221
127 | no_method_suggested_traits::Foo.method3(); //~ ERROR no method named
281222
| ^^^^^^^
282-
|
283-
::: $DIR/auxiliary/no_method_suggested_traits.rs
284-
|
285-
13 | pub struct Foo;
286-
| --------------- method `method3` not found for this
287223

288224
error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Foo>>` in the current scope
289225
--> $DIR/no-method-suggested-traits.rs:128:71
290226
|
291227
128 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3();
292228
| ^^^^^^^
293-
|
294-
::: /checkout/src/liballoc/rc.rs
295-
|
296-
284 | pub struct Rc<T: ?Sized> {
297-
| ------------------------ method `method3` not found for this
298229

299230
error[E0599]: no method named `method3` found for type `no_method_suggested_traits::Bar` in the current scope
300231
--> $DIR/no-method-suggested-traits.rs:130:40
301232
|
302233
130 | no_method_suggested_traits::Bar::X.method3(); //~ ERROR no method named
303234
| ^^^^^^^
304-
|
305-
::: $DIR/auxiliary/no_method_suggested_traits.rs
306-
|
307-
14 | pub enum Bar { X }
308-
| ------------ method `method3` not found here
309235

310236
error[E0599]: no method named `method3` found for type `std::rc::Rc<&mut std::boxed::Box<&no_method_suggested_traits::Bar>>` in the current scope
311237
--> $DIR/no-method-suggested-traits.rs:131:74
312238
|
313239
131 | std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3();
314240
| ^^^^^^^
315-
|
316-
::: /checkout/src/liballoc/rc.rs
317-
|
318-
284 | pub struct Rc<T: ?Sized> {
319-
| ------------------------ method `method3` not found for this
320241

321242
error: aborting due to 24 previous errors
322243

0 commit comments

Comments
 (0)