Skip to content

Commit cc77ba4

Browse files
committed
Auto merge of #85617 - hi-rustin:rustin-patch-fix, r=estebank
shrinking the deprecated method span part of #85403 r? `@estebank`
2 parents 2577825 + 957e2ef commit cc77ba4

File tree

7 files changed

+163
-131
lines changed

7 files changed

+163
-131
lines changed

compiler/rustc_passes/src/stability.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,11 @@ impl Visitor<'tcx> for Checker<'tcx> {
828828

829829
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
830830
if let Some(def_id) = path.res.opt_def_id() {
831-
self.tcx.check_stability(def_id, Some(id), path.span, None)
831+
let method_span = match path.segments {
832+
[.., _, last] => Some(last.ident.span),
833+
_ => None,
834+
};
835+
self.tcx.check_stability(def_id, Some(id), path.span, method_span)
832836
}
833837
intravisit::walk_path(self, path)
834838
}

src/test/ui/deprecation/deprecation-lint.stderr

+54-54
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ LL | #![deny(deprecated)]
1111
| ^^^^^^^^^^
1212

1313
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
14-
--> $DIR/deprecation-lint.rs:21:9
14+
--> $DIR/deprecation-lint.rs:21:16
1515
|
1616
LL | Trait::trait_deprecated(&foo);
17-
| ^^^^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^^^^^^^^^^^^^
1818

1919
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
20-
--> $DIR/deprecation-lint.rs:23:9
20+
--> $DIR/deprecation-lint.rs:23:25
2121
|
2222
LL | <Foo as Trait>::trait_deprecated(&foo);
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
| ^^^^^^^^^^^^^^^^
2424

2525
error: use of deprecated function `deprecation_lint::deprecated_text`: text
2626
--> $DIR/deprecation-lint.rs:25:9
@@ -29,16 +29,16 @@ LL | deprecated_text();
2929
| ^^^^^^^^^^^^^^^
3030

3131
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
32-
--> $DIR/deprecation-lint.rs:30:9
32+
--> $DIR/deprecation-lint.rs:30:16
3333
|
3434
LL | ... Trait::trait_deprecated_text(&foo);
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35+
| ^^^^^^^^^^^^^^^^^^^^^
3636

3737
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
38-
--> $DIR/deprecation-lint.rs:32:9
38+
--> $DIR/deprecation-lint.rs:32:25
3939
|
4040
LL | ... <Foo as Trait>::trait_deprecated_text(&foo);
41-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
| ^^^^^^^^^^^^^^^^^^^^^
4242

4343
error: use of deprecated struct `deprecation_lint::DeprecatedStruct`: text
4444
--> $DIR/deprecation-lint.rs:34:17
@@ -53,10 +53,10 @@ LL | let _ = DeprecatedUnitStruct;
5353
| ^^^^^^^^^^^^^^^^^^^^
5454

5555
error: use of deprecated variant `deprecation_lint::Enum::DeprecatedVariant`: text
56-
--> $DIR/deprecation-lint.rs:40:17
56+
--> $DIR/deprecation-lint.rs:40:23
5757
|
5858
LL | let _ = Enum::DeprecatedVariant;
59-
| ^^^^^^^^^^^^^^^^^^^^^^^
59+
| ^^^^^^^^^^^^^^^^^
6060

6161
error: use of deprecated struct `deprecation_lint::DeprecatedTupleStruct`: text
6262
--> $DIR/deprecation-lint.rs:42:17
@@ -65,28 +65,28 @@ LL | let _ = DeprecatedTupleStruct (1);
6565
| ^^^^^^^^^^^^^^^^^^^^^
6666

6767
error: use of deprecated struct `deprecation_lint::nested::DeprecatedStruct`: text
68-
--> $DIR/deprecation-lint.rs:44:17
68+
--> $DIR/deprecation-lint.rs:44:25
6969
|
7070
LL | let _ = nested::DeprecatedStruct {
71-
| ^^^^^^^^^^^^^^^^^^^^^^^^
71+
| ^^^^^^^^^^^^^^^^
7272

7373
error: use of deprecated struct `deprecation_lint::nested::DeprecatedUnitStruct`: text
74-
--> $DIR/deprecation-lint.rs:48:17
74+
--> $DIR/deprecation-lint.rs:48:25
7575
|
7676
LL | let _ = nested::DeprecatedUnitStruct;
77-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77+
| ^^^^^^^^^^^^^^^^^^^^
7878

7979
error: use of deprecated variant `deprecation_lint::nested::Enum::DeprecatedVariant`: text
80-
--> $DIR/deprecation-lint.rs:50:17
80+
--> $DIR/deprecation-lint.rs:50:31
8181
|
8282
LL | ... let _ = nested::Enum::DeprecatedVariant;
83-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83+
| ^^^^^^^^^^^^^^^^^
8484

8585
error: use of deprecated struct `deprecation_lint::nested::DeprecatedTupleStruct`: text
86-
--> $DIR/deprecation-lint.rs:52:17
86+
--> $DIR/deprecation-lint.rs:52:25
8787
|
8888
LL | ... let _ = nested::DeprecatedTupleStruct (1);
89-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
89+
| ^^^^^^^^^^^^^^^^^^^^^
9090

9191
error: use of deprecated function `deprecation_lint::deprecated_text`: text
9292
--> $DIR/deprecation-lint.rs:59:25
@@ -101,28 +101,28 @@ LL | macro_test_arg!(macro_test_arg!(deprecated_text()));
101101
| ^^^^^^^^^^^^^^^
102102

103103
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
104-
--> $DIR/deprecation-lint.rs:65:9
104+
--> $DIR/deprecation-lint.rs:65:16
105105
|
106106
LL | Trait::trait_deprecated(&foo);
107-
| ^^^^^^^^^^^^^^^^^^^^^^^
107+
| ^^^^^^^^^^^^^^^^
108108

109109
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
110-
--> $DIR/deprecation-lint.rs:67:9
110+
--> $DIR/deprecation-lint.rs:67:25
111111
|
112112
LL | <Foo as Trait>::trait_deprecated(&foo);
113-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
113+
| ^^^^^^^^^^^^^^^^
114114

115115
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
116-
--> $DIR/deprecation-lint.rs:69:9
116+
--> $DIR/deprecation-lint.rs:69:16
117117
|
118118
LL | ... Trait::trait_deprecated_text(&foo);
119-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119+
| ^^^^^^^^^^^^^^^^^^^^^
120120

121121
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
122-
--> $DIR/deprecation-lint.rs:71:9
122+
--> $DIR/deprecation-lint.rs:71:25
123123
|
124124
LL | ... <Foo as Trait>::trait_deprecated_text(&foo);
125-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125+
| ^^^^^^^^^^^^^^^^^^^^^
126126

127127
error: use of deprecated trait `deprecation_lint::DeprecatedTrait`: text
128128
--> $DIR/deprecation-lint.rs:81:10
@@ -173,10 +173,10 @@ LL | let Deprecated2
173173
| ^^^^^^^^^^^
174174

175175
error: use of deprecated function `deprecation_lint::deprecated_mod::deprecated`: text
176-
--> $DIR/deprecation-lint.rs:162:9
176+
--> $DIR/deprecation-lint.rs:162:25
177177
|
178178
LL | deprecated_mod::deprecated();
179-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
179+
| ^^^^^^^^^^
180180

181181
error: use of deprecated function `this_crate::deprecated`: text
182182
--> $DIR/deprecation-lint.rs:245:9
@@ -185,16 +185,16 @@ LL | deprecated();
185185
| ^^^^^^^^^^
186186

187187
error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
188-
--> $DIR/deprecation-lint.rs:250:9
188+
--> $DIR/deprecation-lint.rs:250:16
189189
|
190190
LL | Trait::trait_deprecated(&foo);
191-
| ^^^^^^^^^^^^^^^^^^^^^^^
191+
| ^^^^^^^^^^^^^^^^
192192

193193
error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
194-
--> $DIR/deprecation-lint.rs:252:9
194+
--> $DIR/deprecation-lint.rs:252:25
195195
|
196196
LL | <Foo as Trait>::trait_deprecated(&foo);
197-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197+
| ^^^^^^^^^^^^^^^^
198198

199199
error: use of deprecated function `this_crate::deprecated_text`: text
200200
--> $DIR/deprecation-lint.rs:254:9
@@ -203,16 +203,16 @@ LL | deprecated_text();
203203
| ^^^^^^^^^^^^^^^
204204

205205
error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
206-
--> $DIR/deprecation-lint.rs:259:9
206+
--> $DIR/deprecation-lint.rs:259:16
207207
|
208208
LL | Trait::trait_deprecated_text(&foo);
209-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
209+
| ^^^^^^^^^^^^^^^^^^^^^
210210

211211
error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
212-
--> $DIR/deprecation-lint.rs:261:9
212+
--> $DIR/deprecation-lint.rs:261:25
213213
|
214214
LL | ... <Foo as Trait>::trait_deprecated_text(&foo);
215-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
215+
| ^^^^^^^^^^^^^^^^^^^^^
216216

217217
error: use of deprecated function `this_crate::deprecated_future`: text
218218
--> $DIR/deprecation-lint.rs:264:9
@@ -239,10 +239,10 @@ LL | let _ = DeprecatedUnitStruct;
239239
| ^^^^^^^^^^^^^^^^^^^^
240240

241241
error: use of deprecated unit variant `this_crate::Enum::DeprecatedVariant`: text
242-
--> $DIR/deprecation-lint.rs:274:17
242+
--> $DIR/deprecation-lint.rs:274:23
243243
|
244244
LL | let _ = Enum::DeprecatedVariant;
245-
| ^^^^^^^^^^^^^^^^^^^^^^^
245+
| ^^^^^^^^^^^^^^^^^
246246

247247
error: use of deprecated tuple struct `this_crate::DeprecatedTupleStruct`: text
248248
--> $DIR/deprecation-lint.rs:276:17
@@ -251,52 +251,52 @@ LL | let _ = DeprecatedTupleStruct (1);
251251
| ^^^^^^^^^^^^^^^^^^^^^
252252

253253
error: use of deprecated struct `this_crate::nested::DeprecatedStruct`: text
254-
--> $DIR/deprecation-lint.rs:278:17
254+
--> $DIR/deprecation-lint.rs:278:25
255255
|
256256
LL | let _ = nested::DeprecatedStruct {
257-
| ^^^^^^^^^^^^^^^^^^^^^^^^
257+
| ^^^^^^^^^^^^^^^^
258258

259259
error: use of deprecated unit struct `this_crate::nested::DeprecatedUnitStruct`: text
260-
--> $DIR/deprecation-lint.rs:283:17
260+
--> $DIR/deprecation-lint.rs:283:25
261261
|
262262
LL | let _ = nested::DeprecatedUnitStruct;
263-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
263+
| ^^^^^^^^^^^^^^^^^^^^
264264

265265
error: use of deprecated unit variant `this_crate::nested::Enum::DeprecatedVariant`: text
266-
--> $DIR/deprecation-lint.rs:285:17
266+
--> $DIR/deprecation-lint.rs:285:31
267267
|
268268
LL | ... let _ = nested::Enum::DeprecatedVariant;
269-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
269+
| ^^^^^^^^^^^^^^^^^
270270

271271
error: use of deprecated tuple struct `this_crate::nested::DeprecatedTupleStruct`: text
272-
--> $DIR/deprecation-lint.rs:287:17
272+
--> $DIR/deprecation-lint.rs:287:25
273273
|
274274
LL | ... let _ = nested::DeprecatedTupleStruct (1);
275-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275+
| ^^^^^^^^^^^^^^^^^^^^^
276276

277277
error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
278-
--> $DIR/deprecation-lint.rs:292:9
278+
--> $DIR/deprecation-lint.rs:292:16
279279
|
280280
LL | Trait::trait_deprecated(&foo);
281-
| ^^^^^^^^^^^^^^^^^^^^^^^
281+
| ^^^^^^^^^^^^^^^^
282282

283283
error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
284-
--> $DIR/deprecation-lint.rs:294:9
284+
--> $DIR/deprecation-lint.rs:294:25
285285
|
286286
LL | <Foo as Trait>::trait_deprecated(&foo);
287-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287+
| ^^^^^^^^^^^^^^^^
288288

289289
error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
290-
--> $DIR/deprecation-lint.rs:296:9
290+
--> $DIR/deprecation-lint.rs:296:16
291291
|
292292
LL | Trait::trait_deprecated_text(&foo);
293-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
293+
| ^^^^^^^^^^^^^^^^^^^^^
294294

295295
error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
296-
--> $DIR/deprecation-lint.rs:298:9
296+
--> $DIR/deprecation-lint.rs:298:25
297297
|
298298
LL | ... <Foo as Trait>::trait_deprecated_text(&foo);
299-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
299+
| ^^^^^^^^^^^^^^^^^^^^^
300300

301301
error: use of deprecated function `this_crate::test_fn_closure_body::{closure#0}::bar`
302302
--> $DIR/deprecation-lint.rs:316:13

src/test/ui/deprecation/suggestion.fixed

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// run-rustfix
22

33
#![feature(staged_api)]
4-
54
#![stable(since = "1.0.0", feature = "test")]
6-
75
#![deny(deprecated)]
86
#![allow(dead_code)]
97

@@ -21,8 +19,21 @@ impl Foo {
2119
fn replacement(&self) {}
2220
}
2321

22+
mod bar {
23+
#[rustc_deprecated(
24+
since = "1.0.0",
25+
reason = "replaced by `replacement`",
26+
suggestion = "replacement",
27+
)]
28+
#[stable(since = "1.0.0", feature = "test")]
29+
pub fn deprecated() {}
30+
31+
pub fn replacement() {}
32+
}
33+
2434
fn main() {
2535
let foo = Foo;
26-
2736
foo.replacement(); //~ ERROR use of deprecated
37+
38+
bar::replacement(); //~ ERROR use of deprecated
2839
}

src/test/ui/deprecation/suggestion.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// run-rustfix
22

33
#![feature(staged_api)]
4-
54
#![stable(since = "1.0.0", feature = "test")]
6-
75
#![deny(deprecated)]
86
#![allow(dead_code)]
97

@@ -21,8 +19,21 @@ impl Foo {
2119
fn replacement(&self) {}
2220
}
2321

22+
mod bar {
23+
#[rustc_deprecated(
24+
since = "1.0.0",
25+
reason = "replaced by `replacement`",
26+
suggestion = "replacement",
27+
)]
28+
#[stable(since = "1.0.0", feature = "test")]
29+
pub fn deprecated() {}
30+
31+
pub fn replacement() {}
32+
}
33+
2434
fn main() {
2535
let foo = Foo;
26-
2736
foo.deprecated(); //~ ERROR use of deprecated
37+
38+
bar::deprecated(); //~ ERROR use of deprecated
2839
}
+12-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
error: use of deprecated associated function `Foo::deprecated`: replaced by `replacement`
2-
--> $DIR/suggestion.rs:27:9
1+
error: use of deprecated function `bar::deprecated`: replaced by `replacement`
2+
--> $DIR/suggestion.rs:38:10
33
|
4-
LL | foo.deprecated();
5-
| ^^^^^^^^^^ help: replace the use of the deprecated associated function: `replacement`
4+
LL | bar::deprecated();
5+
| ^^^^^^^^^^ help: replace the use of the deprecated function: `replacement`
66
|
77
note: the lint level is defined here
8-
--> $DIR/suggestion.rs:7:9
8+
--> $DIR/suggestion.rs:5:9
99
|
1010
LL | #![deny(deprecated)]
1111
| ^^^^^^^^^^
1212

13-
error: aborting due to previous error
13+
error: use of deprecated associated function `Foo::deprecated`: replaced by `replacement`
14+
--> $DIR/suggestion.rs:36:9
15+
|
16+
LL | foo.deprecated();
17+
| ^^^^^^^^^^ help: replace the use of the deprecated associated function: `replacement`
18+
19+
error: aborting due to 2 previous errors
1420

0 commit comments

Comments
 (0)