Skip to content

Commit 955b9c0

Browse files
committed
Auto merge of #86320 - hi-rustin:rustin-patch-fix-span, r=estebank
shrinking the deprecated span ref: #85617 (comment) part of #85403 r? `@estebank` The reason is that if we use method_span directly, it will cause the in_derive_expansion judgment to fail.
2 parents b5a2cce + 8c5938d commit 955b9c0

File tree

10 files changed

+186
-152
lines changed

10 files changed

+186
-152
lines changed

compiler/rustc_middle/src/middle/stability.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,19 @@ fn late_report_deprecation(
226226
suggestion: Option<Symbol>,
227227
lint: &'static Lint,
228228
span: Span,
229+
method_span: Option<Span>,
229230
hir_id: HirId,
230231
def_id: DefId,
231232
) {
232233
if span.in_derive_expansion() {
233234
return;
234235
}
235-
236-
tcx.struct_span_lint_hir(lint, hir_id, span, |lint| {
236+
let method_span = method_span.unwrap_or(span);
237+
tcx.struct_span_lint_hir(lint, hir_id, method_span, |lint| {
237238
let mut diag = lint.build(message);
238239
if let hir::Node::Expr(_) = tcx.hir().get(hir_id) {
239240
let kind = tcx.def_kind(def_id).descr(def_id);
240-
deprecation_suggestion(&mut diag, kind, suggestion, span);
241+
deprecation_suggestion(&mut diag, kind, suggestion, method_span);
241242
}
242243
diag.emit()
243244
});
@@ -306,13 +307,13 @@ impl<'tcx> TyCtxt<'tcx> {
306307
let path = &with_no_trimmed_paths(|| self.def_path_str(def_id));
307308
let kind = self.def_kind(def_id).descr(def_id);
308309
let (message, lint) = deprecation_message(&depr_entry.attr, kind, path);
309-
let span = method_span.unwrap_or(span);
310310
late_report_deprecation(
311311
self,
312312
&message,
313313
depr_entry.attr.suggestion,
314314
lint,
315315
span,
316+
method_span,
316317
id,
317318
def_id,
318319
);

compiler/rustc_passes/src/stability.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,8 @@ impl Visitor<'tcx> for Checker<'tcx> {
875875

876876
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
877877
if let Some(def_id) = path.res.opt_def_id() {
878-
self.tcx.check_stability(def_id, Some(id), path.span, None)
878+
let method_span = path.segments.last().map(|s| s.ident.span);
879+
self.tcx.check_stability(def_id, Some(id), path.span, method_span)
879880
}
880881
intravisit::walk_path(self, path)
881882
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
error: use of deprecated function `deprecation_lint::deprecated_text`: text
2-
--> $DIR/deprecation-lint-3.rs:13:5
2+
--> $DIR/deprecation-lint-3.rs:13:28
33
|
44
LL | macro_test_arg_nested!(deprecated_text);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
88
--> $DIR/deprecation-lint-3.rs:4:9
99
|
1010
LL | #![deny(deprecated)]
1111
| ^^^^^^^^^^
12-
= note: this error originates in the macro `macro_test_arg_nested` (in Nightly builds, run with -Z macro-backtrace for more info)
1312

1413
error: aborting due to previous error
1514

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
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@ impl Foo {
2121
fn replacement(&self) {}
2222
}
2323

24+
mod bar {
25+
#[rustc_deprecated(
26+
since = "1.0.0",
27+
reason = "replaced by `replacement`",
28+
suggestion = "replacement",
29+
)]
30+
#[stable(since = "1.0.0", feature = "test")]
31+
pub fn deprecated() {}
32+
33+
pub fn replacement() {}
34+
}
35+
2436
fn main() {
2537
let foo = Foo;
2638

2739
foo.replacement(); //~ ERROR use of deprecated
40+
41+
bar::replacement(); //~ ERROR use of deprecated
2842
}

src/test/ui/deprecation/suggestion.rs

+14
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,22 @@ impl Foo {
2121
fn replacement(&self) {}
2222
}
2323

24+
mod bar {
25+
#[rustc_deprecated(
26+
since = "1.0.0",
27+
reason = "replaced by `replacement`",
28+
suggestion = "replacement",
29+
)]
30+
#[stable(since = "1.0.0", feature = "test")]
31+
pub fn deprecated() {}
32+
33+
pub fn replacement() {}
34+
}
35+
2436
fn main() {
2537
let foo = Foo;
2638

2739
foo.deprecated(); //~ ERROR use of deprecated
40+
41+
bar::deprecated(); //~ ERROR use of deprecated
2842
}

0 commit comments

Comments
 (0)