Skip to content

Commit 649b385

Browse files
authored
Rollup merge of #85018 - hi-rustin:rustin-patch-84637, r=estebank
shrinking the deprecated method span close #84637
2 parents 40be1d3 + 7c5bc20 commit 649b385

12 files changed

+156
-98
lines changed

compiler/rustc_middle/src/middle/stability.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,13 @@ impl<'tcx> TyCtxt<'tcx> {
281281
/// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
282282
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
283283
/// `id`.
284-
pub fn eval_stability(self, def_id: DefId, id: Option<HirId>, span: Span) -> EvalResult {
284+
pub fn eval_stability(
285+
self,
286+
def_id: DefId,
287+
id: Option<HirId>,
288+
span: Span,
289+
method_span: Option<Span>,
290+
) -> EvalResult {
285291
// Deprecated attributes apply in-crate and cross-crate.
286292
if let Some(id) = id {
287293
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
@@ -300,6 +306,7 @@ impl<'tcx> TyCtxt<'tcx> {
300306
let path = &with_no_trimmed_paths(|| self.def_path_str(def_id));
301307
let kind = self.def_kind(def_id).descr(def_id);
302308
let (message, lint) = deprecation_message(&depr_entry.attr, kind, path);
309+
let span = method_span.unwrap_or(span);
303310
late_report_deprecation(
304311
self,
305312
&message,
@@ -382,8 +389,14 @@ impl<'tcx> TyCtxt<'tcx> {
382389
///
383390
/// This function will also check if the item is deprecated.
384391
/// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
385-
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) {
386-
self.check_optional_stability(def_id, id, span, |span, def_id| {
392+
pub fn check_stability(
393+
self,
394+
def_id: DefId,
395+
id: Option<HirId>,
396+
span: Span,
397+
method_span: Option<Span>,
398+
) {
399+
self.check_optional_stability(def_id, id, span, method_span, |span, def_id| {
387400
// The API could be uncallable for other reasons, for example when a private module
388401
// was referenced.
389402
self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id));
@@ -399,14 +412,15 @@ impl<'tcx> TyCtxt<'tcx> {
399412
def_id: DefId,
400413
id: Option<HirId>,
401414
span: Span,
415+
method_span: Option<Span>,
402416
unmarked: impl FnOnce(Span, DefId),
403417
) {
404418
let soft_handler = |lint, span, msg: &_| {
405419
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
406420
lint.build(msg).emit()
407421
})
408422
};
409-
match self.eval_stability(def_id, id, span) {
423+
match self.eval_stability(def_id, id, span, method_span) {
410424
EvalResult::Allow => {}
411425
EvalResult::Deny { feature, reason, issue, is_soft } => {
412426
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler)

compiler/rustc_passes/src/stability.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
739739
None => return,
740740
};
741741
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
742-
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span);
742+
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span, None);
743743
}
744744

745745
// For implementations of traits, check the stability of each item
@@ -783,7 +783,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
783783
.map(|item| item.def_id);
784784
if let Some(def_id) = trait_item_def_id {
785785
// Pass `None` to skip deprecation warnings.
786-
self.tcx.check_stability(def_id, None, impl_item.span);
786+
self.tcx.check_stability(def_id, None, impl_item.span, None);
787787
}
788788
}
789789
}
@@ -832,7 +832,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
832832

833833
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
834834
if let Some(def_id) = path.res.opt_def_id() {
835-
self.tcx.check_stability(def_id, Some(id), path.span)
835+
self.tcx.check_stability(def_id, Some(id), path.span, None)
836836
}
837837
intravisit::walk_path(self, path)
838838
}

compiler/rustc_typeck/src/astconv/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
432432
param.def_id,
433433
Some(arg.id()),
434434
arg.span(),
435+
None,
435436
|_, _| {
436437
// Default generic parameters may not be marked
437438
// with stability attributes, i.e. when the
@@ -1059,7 +1060,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10591060
.span_label(binding.span, "private associated type")
10601061
.emit();
10611062
}
1062-
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span);
1063+
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span, None);
10631064

10641065
if !speculative {
10651066
dup_bindings
@@ -1666,7 +1667,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16661667
.find(|vd| tcx.hygienic_eq(assoc_ident, vd.ident, adt_def.did));
16671668
if let Some(variant_def) = variant_def {
16681669
if permit_variants {
1669-
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span);
1670+
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None);
16701671
self.prohibit_generics(slice::from_ref(assoc_segment));
16711672
return Ok((qself_ty, DefKind::Variant, variant_def.def_id));
16721673
} else {
@@ -1786,7 +1787,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
17861787
.span_label(span, &format!("private {}", kind))
17871788
.emit();
17881789
}
1789-
tcx.check_stability(item.def_id, Some(hir_ref_id), span);
1790+
tcx.check_stability(item.def_id, Some(hir_ref_id), span, None);
17901791

17911792
if let Some(variant_def_id) = variant_resolution {
17921793
tcx.struct_span_lint_hir(AMBIGUOUS_ASSOCIATED_ITEMS, hir_ref_id, span, |lint| {

compiler/rustc_typeck/src/check/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12301230
// struct-like enums (yet...), but it's definitely not
12311231
// a bug to have constructed one.
12321232
if adt_kind != AdtKind::Enum {
1233-
tcx.check_stability(v_field.did, Some(expr_id), field.span);
1233+
tcx.check_stability(v_field.did, Some(expr_id), field.span, None);
12341234
}
12351235

12361236
self.field_ty(field.span, v_field, substs)
@@ -1571,7 +1571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15711571
self.apply_adjustments(base, adjustments);
15721572
self.register_predicates(autoderef.into_obligations());
15731573

1574-
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span);
1574+
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
15751575
return field_ty;
15761576
}
15771577
private_candidate = Some((base_def.did, field_ty));

compiler/rustc_typeck/src/check/method/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
205205
.insert(*import_id);
206206
}
207207

208-
self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span);
208+
self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span, None);
209209

210210
let result =
211211
self.confirm_method(span, self_expr, call_expr, self_ty, pick.clone(), segment);
@@ -445,7 +445,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
445445
// them as well. It's ok to use the variant's id as a ctor id since an
446446
// error will be reported on any use of such resolution anyway.
447447
let ctor_def_id = variant_def.ctor_def_id.unwrap_or(variant_def.def_id);
448-
tcx.check_stability(ctor_def_id, Some(expr_id), span);
448+
tcx.check_stability(ctor_def_id, Some(expr_id), span, Some(method_name.span));
449449
return Ok((
450450
DefKind::Ctor(CtorOf::Variant, variant_def.ctor_kind),
451451
ctor_def_id,
@@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
475475

476476
let def_kind = pick.item.kind.as_def_kind();
477477
debug!("resolve_ufcs: def_kind={:?}, def_id={:?}", def_kind, pick.item.def_id);
478-
tcx.check_stability(pick.item.def_id, Some(expr_id), span);
478+
tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span));
479479
Ok((def_kind, pick.item.def_id))
480480
}
481481

compiler/rustc_typeck/src/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12861286
if let Some(uc) = unstable_candidates {
12871287
applicable_candidates.retain(|&(p, _)| {
12881288
if let stability::EvalResult::Deny { feature, .. } =
1289-
self.tcx.eval_stability(p.item.def_id, None, self.span)
1289+
self.tcx.eval_stability(p.item.def_id, None, self.span, None)
12901290
{
12911291
uc.push((p, feature));
12921292
return false;

compiler/rustc_typeck/src/check/pat.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
958958
let field_ty = self.field_ty(subpat.span, &variant.fields[i], substs);
959959
self.check_pat(&subpat, field_ty, def_bm, TopInfo { parent_pat: Some(&pat), ..ti });
960960

961-
self.tcx.check_stability(variant.fields[i].did, Some(pat.hir_id), subpat.span);
961+
self.tcx.check_stability(
962+
variant.fields[i].did,
963+
Some(pat.hir_id),
964+
subpat.span,
965+
None,
966+
);
962967
}
963968
} else {
964969
// Pattern has wrong number of fields.
@@ -1192,7 +1197,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11921197
.get(&ident)
11931198
.map(|(i, f)| {
11941199
self.write_field_index(field.hir_id, *i);
1195-
self.tcx.check_stability(f.did, Some(pat.hir_id), span);
1200+
self.tcx.check_stability(f.did, Some(pat.hir_id), span, None);
11961201
self.field_ty(span, f, substs)
11971202
})
11981203
.unwrap_or_else(|| {

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

+32-32
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,16 @@ LL | foo.method_deprecated();
359359
| ^^^^^^^^^^^^^^^^^
360360

361361
error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`: text
362-
--> $DIR/deprecation-lint.rs:18:9
362+
--> $DIR/deprecation-lint.rs:18:14
363363
|
364364
LL | Foo::method_deprecated(&foo);
365-
| ^^^^^^^^^^^^^^^^^^^^^^
365+
| ^^^^^^^^^^^^^^^^^
366366

367367
error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated`: text
368-
--> $DIR/deprecation-lint.rs:19:9
368+
--> $DIR/deprecation-lint.rs:19:16
369369
|
370370
LL | <Foo>::method_deprecated(&foo);
371-
| ^^^^^^^^^^^^^^^^^^^^^^^^
371+
| ^^^^^^^^^^^^^^^^^
372372

373373
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
374374
--> $DIR/deprecation-lint.rs:20:13
@@ -377,10 +377,10 @@ LL | foo.trait_deprecated();
377377
| ^^^^^^^^^^^^^^^^
378378

379379
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
380-
--> $DIR/deprecation-lint.rs:22:9
380+
--> $DIR/deprecation-lint.rs:22:16
381381
|
382382
LL | <Foo>::trait_deprecated(&foo);
383-
| ^^^^^^^^^^^^^^^^^^^^^^^
383+
| ^^^^^^^^^^^^^^^^
384384

385385
error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
386386
--> $DIR/deprecation-lint.rs:26:13
@@ -389,16 +389,16 @@ LL | ... foo.method_deprecated_text();
389389
| ^^^^^^^^^^^^^^^^^^^^^^
390390

391391
error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
392-
--> $DIR/deprecation-lint.rs:27:9
392+
--> $DIR/deprecation-lint.rs:27:14
393393
|
394394
LL | ... Foo::method_deprecated_text(&foo);
395-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
395+
| ^^^^^^^^^^^^^^^^^^^^^^
396396

397397
error: use of deprecated associated function `deprecation_lint::MethodTester::method_deprecated_text`: text
398-
--> $DIR/deprecation-lint.rs:28:9
398+
--> $DIR/deprecation-lint.rs:28:16
399399
|
400400
LL | ... <Foo>::method_deprecated_text(&foo);
401-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
401+
| ^^^^^^^^^^^^^^^^^^^^^^
402402

403403
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
404404
--> $DIR/deprecation-lint.rs:29:13
@@ -407,10 +407,10 @@ LL | foo.trait_deprecated_text();
407407
| ^^^^^^^^^^^^^^^^^^^^^
408408

409409
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
410-
--> $DIR/deprecation-lint.rs:31:9
410+
--> $DIR/deprecation-lint.rs:31:16
411411
|
412412
LL | ... <Foo>::trait_deprecated_text(&foo);
413-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
413+
| ^^^^^^^^^^^^^^^^^^^^^
414414

415415
error: use of deprecated field `deprecation_lint::DeprecatedStruct::i`: text
416416
--> $DIR/deprecation-lint.rs:35:13
@@ -431,10 +431,10 @@ LL | foo.trait_deprecated();
431431
| ^^^^^^^^^^^^^^^^
432432

433433
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
434-
--> $DIR/deprecation-lint.rs:66:9
434+
--> $DIR/deprecation-lint.rs:66:16
435435
|
436436
LL | <Foo>::trait_deprecated(&foo);
437-
| ^^^^^^^^^^^^^^^^^^^^^^^
437+
| ^^^^^^^^^^^^^^^^
438438

439439
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
440440
--> $DIR/deprecation-lint.rs:68:13
@@ -443,10 +443,10 @@ LL | foo.trait_deprecated_text();
443443
| ^^^^^^^^^^^^^^^^^^^^^
444444

445445
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated_text`: text
446-
--> $DIR/deprecation-lint.rs:70:9
446+
--> $DIR/deprecation-lint.rs:70:16
447447
|
448448
LL | ... <Foo>::trait_deprecated_text(&foo);
449-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
449+
| ^^^^^^^^^^^^^^^^^^^^^
450450

451451
error: use of deprecated associated function `deprecation_lint::Trait::trait_deprecated`: text
452452
--> $DIR/deprecation-lint.rs:75:13
@@ -551,16 +551,16 @@ LL | foo.method_deprecated();
551551
| ^^^^^^^^^^^^^^^^^
552552

553553
error: use of deprecated associated function `this_crate::MethodTester::method_deprecated`: text
554-
--> $DIR/deprecation-lint.rs:247:9
554+
--> $DIR/deprecation-lint.rs:247:14
555555
|
556556
LL | Foo::method_deprecated(&foo);
557-
| ^^^^^^^^^^^^^^^^^^^^^^
557+
| ^^^^^^^^^^^^^^^^^
558558

559559
error: use of deprecated associated function `this_crate::MethodTester::method_deprecated`: text
560-
--> $DIR/deprecation-lint.rs:248:9
560+
--> $DIR/deprecation-lint.rs:248:16
561561
|
562562
LL | <Foo>::method_deprecated(&foo);
563-
| ^^^^^^^^^^^^^^^^^^^^^^^^
563+
| ^^^^^^^^^^^^^^^^^
564564

565565
error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
566566
--> $DIR/deprecation-lint.rs:249:13
@@ -569,10 +569,10 @@ LL | foo.trait_deprecated();
569569
| ^^^^^^^^^^^^^^^^
570570

571571
error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
572-
--> $DIR/deprecation-lint.rs:251:9
572+
--> $DIR/deprecation-lint.rs:251:16
573573
|
574574
LL | <Foo>::trait_deprecated(&foo);
575-
| ^^^^^^^^^^^^^^^^^^^^^^^
575+
| ^^^^^^^^^^^^^^^^
576576

577577
error: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
578578
--> $DIR/deprecation-lint.rs:255:13
@@ -581,16 +581,16 @@ LL | ... foo.method_deprecated_text();
581581
| ^^^^^^^^^^^^^^^^^^^^^^
582582

583583
error: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
584-
--> $DIR/deprecation-lint.rs:256:9
584+
--> $DIR/deprecation-lint.rs:256:14
585585
|
586586
LL | ... Foo::method_deprecated_text(&foo);
587-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
587+
| ^^^^^^^^^^^^^^^^^^^^^^
588588

589589
error: use of deprecated associated function `this_crate::MethodTester::method_deprecated_text`: text
590-
--> $DIR/deprecation-lint.rs:257:9
590+
--> $DIR/deprecation-lint.rs:257:16
591591
|
592592
LL | ... <Foo>::method_deprecated_text(&foo);
593-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
593+
| ^^^^^^^^^^^^^^^^^^^^^^
594594

595595
error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
596596
--> $DIR/deprecation-lint.rs:258:13
@@ -599,10 +599,10 @@ LL | foo.trait_deprecated_text();
599599
| ^^^^^^^^^^^^^^^^^^^^^
600600

601601
error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
602-
--> $DIR/deprecation-lint.rs:260:9
602+
--> $DIR/deprecation-lint.rs:260:16
603603
|
604604
LL | <Foo>::trait_deprecated_text(&foo);
605-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
605+
| ^^^^^^^^^^^^^^^^^^^^^
606606

607607
error: use of deprecated field `this_crate::DeprecatedStruct::i`: text
608608
--> $DIR/deprecation-lint.rs:269:13
@@ -623,10 +623,10 @@ LL | foo.trait_deprecated();
623623
| ^^^^^^^^^^^^^^^^
624624

625625
error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
626-
--> $DIR/deprecation-lint.rs:293:9
626+
--> $DIR/deprecation-lint.rs:293:16
627627
|
628628
LL | <Foo>::trait_deprecated(&foo);
629-
| ^^^^^^^^^^^^^^^^^^^^^^^
629+
| ^^^^^^^^^^^^^^^^
630630

631631
error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
632632
--> $DIR/deprecation-lint.rs:295:13
@@ -635,10 +635,10 @@ LL | foo.trait_deprecated_text();
635635
| ^^^^^^^^^^^^^^^^^^^^^
636636

637637
error: use of deprecated associated function `this_crate::Trait::trait_deprecated_text`: text
638-
--> $DIR/deprecation-lint.rs:297:9
638+
--> $DIR/deprecation-lint.rs:297:16
639639
|
640640
LL | <Foo>::trait_deprecated_text(&foo);
641-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
641+
| ^^^^^^^^^^^^^^^^^^^^^
642642

643643
error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
644644
--> $DIR/deprecation-lint.rs:302:13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-rustfix
2+
3+
#![deny(deprecated)]
4+
5+
fn main() {
6+
let _foo = str::trim_start(" aoeu"); //~ ERROR use of deprecated associated function `core::str::<impl str>::trim_left`: superseded by `trim_start` [deprecated]
7+
8+
let _bar = " aoeu".trim_start(); //~ ERROR use of deprecated associated function `core::str::<impl str>::trim_left`: superseded by `trim_start` [deprecated]
9+
}

0 commit comments

Comments
 (0)