Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shrinking the deprecated method span #85018

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,13 @@ impl<'tcx> TyCtxt<'tcx> {
/// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
/// `id`.
pub fn eval_stability(self, def_id: DefId, id: Option<HirId>, span: Span) -> EvalResult {
pub fn eval_stability(
self,
def_id: DefId,
id: Option<HirId>,
span: Span,
method_span: Option<Span>,
) -> EvalResult {
// Deprecated attributes apply in-crate and cross-crate.
if let Some(id) = id {
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
Expand All @@ -300,6 +306,7 @@ impl<'tcx> TyCtxt<'tcx> {
let path = &with_no_trimmed_paths(|| self.def_path_str(def_id));
let kind = self.def_kind(def_id).descr(def_id);
let (message, lint) = deprecation_message(&depr_entry.attr, kind, path);
let span = method_span.unwrap_or(span);
late_report_deprecation(
self,
&message,
Expand Down Expand Up @@ -382,8 +389,14 @@ impl<'tcx> TyCtxt<'tcx> {
///
/// This function will also check if the item is deprecated.
/// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) {
self.check_optional_stability(def_id, id, span, |span, def_id| {
pub fn check_stability(
self,
def_id: DefId,
id: Option<HirId>,
span: Span,
method_span: Option<Span>,
) {
self.check_optional_stability(def_id, id, span, method_span, |span, def_id| {
// The API could be uncallable for other reasons, for example when a private module
// was referenced.
self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id));
Expand All @@ -399,14 +412,15 @@ impl<'tcx> TyCtxt<'tcx> {
def_id: DefId,
id: Option<HirId>,
span: Span,
method_span: Option<Span>,
unmarked: impl FnOnce(Span, DefId),
) {
let soft_handler = |lint, span, msg: &_| {
self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
lint.build(msg).emit()
})
};
match self.eval_stability(def_id, id, span) {
match self.eval_stability(def_id, id, span, method_span) {
EvalResult::Allow => {}
EvalResult::Deny { feature, reason, issue, is_soft } => {
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
None => return,
};
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span);
self.tcx.check_stability(def_id, Some(item.hir_id()), item.span, None);
}

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

fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
if let Some(def_id) = path.res.opt_def_id() {
self.tcx.check_stability(def_id, Some(id), path.span)
self.tcx.check_stability(def_id, Some(id), path.span, None)
}
intravisit::walk_path(self, path)
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
param.def_id,
Some(arg.id()),
arg.span(),
None,
|_, _| {
// Default generic parameters may not be marked
// with stability attributes, i.e. when the
Expand Down Expand Up @@ -1053,7 +1054,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.span_label(binding.span, "private associated type")
.emit();
}
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span);
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span, None);

if !speculative {
dup_bindings
Expand Down Expand Up @@ -1659,7 +1660,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.find(|vd| tcx.hygienic_eq(assoc_ident, vd.ident, adt_def.did));
if let Some(variant_def) = variant_def {
if permit_variants {
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span);
tcx.check_stability(variant_def.def_id, Some(hir_ref_id), span, None);
self.prohibit_generics(slice::from_ref(assoc_segment));
return Ok((qself_ty, DefKind::Variant, variant_def.def_id));
} else {
Expand Down Expand Up @@ -1779,7 +1780,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.span_label(span, &format!("private {}", kind))
.emit();
}
tcx.check_stability(item.def_id, Some(hir_ref_id), span);
tcx.check_stability(item.def_id, Some(hir_ref_id), span, None);

if let Some(variant_def_id) = variant_resolution {
tcx.struct_span_lint_hir(AMBIGUOUS_ASSOCIATED_ITEMS, hir_ref_id, span, |lint| {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// struct-like enums (yet...), but it's definitely not
// a bug to have constructed one.
if adt_kind != AdtKind::Enum {
tcx.check_stability(v_field.did, Some(expr_id), field.span);
tcx.check_stability(v_field.did, Some(expr_id), field.span, None);
}

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

self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span);
self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span, None);
return field_ty;
}
private_candidate = Some((base_def.did, field_ty));
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.insert(*import_id);
}

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

let result =
self.confirm_method(span, self_expr, call_expr, self_ty, pick.clone(), segment);
Expand Down Expand Up @@ -445,7 +445,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// them as well. It's ok to use the variant's id as a ctor id since an
// error will be reported on any use of such resolution anyway.
let ctor_def_id = variant_def.ctor_def_id.unwrap_or(variant_def.def_id);
tcx.check_stability(ctor_def_id, Some(expr_id), span);
tcx.check_stability(ctor_def_id, Some(expr_id), span, Some(method_name.span));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you change this and the change below to pass method_name.span on the already existing span parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will get an error:

error[E0658]: use of unstable library feature 'fmt_internals': internal to format_args!
   --> /Users/rustin/ClionProjects/rust/library/core/src/macros/mod.rs:473:49
    |
473 |     ($dst:expr, $($arg:tt)*) => ($dst.write_fmt($crate::format_args!($($arg)*)))
    |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: add `#![feature(fmt_internals)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
error: could not compile `rustc-demangle`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub fn allows_unstable(&self, feature: Symbol) -> bool {

It looks like this is because allow_internal_unstable is not recognized when we use method_span.

return Ok((
DefKind::Ctor(CtorOf::Variant, variant_def.ctor_kind),
ctor_def_id,
Expand Down Expand Up @@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let def_kind = pick.item.kind.as_def_kind();
debug!("resolve_ufcs: def_kind={:?}, def_id={:?}", def_kind, pick.item.def_id);
tcx.check_stability(pick.item.def_id, Some(expr_id), span);
tcx.check_stability(pick.item.def_id, Some(expr_id), span, Some(method_name.span));
Ok((def_kind, pick.item.def_id))
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
if let Some(uc) = unstable_candidates {
applicable_candidates.retain(|&(p, _)| {
if let stability::EvalResult::Deny { feature, .. } =
self.tcx.eval_stability(p.item.def_id, None, self.span)
self.tcx.eval_stability(p.item.def_id, None, self.span, None)
{
uc.push((p, feature));
return false;
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_typeck/src/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let field_ty = self.field_ty(subpat.span, &variant.fields[i], substs);
self.check_pat(&subpat, field_ty, def_bm, TopInfo { parent_pat: Some(&pat), ..ti });

self.tcx.check_stability(variant.fields[i].did, Some(pat.hir_id), subpat.span);
self.tcx.check_stability(
variant.fields[i].did,
Some(pat.hir_id),
subpat.span,
None,
);
}
} else {
// Pattern has wrong number of fields.
Expand Down Expand Up @@ -1192,7 +1197,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.get(&ident)
.map(|(i, f)| {
self.write_field_index(field.hir_id, *i);
self.tcx.check_stability(f.did, Some(pat.hir_id), span);
self.tcx.check_stability(f.did, Some(pat.hir_id), span, None);
self.field_ty(span, f, substs)
})
.unwrap_or_else(|| {
Expand Down
64 changes: 32 additions & 32 deletions src/test/ui/deprecation/deprecation-lint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,16 @@ LL | foo.method_deprecated();
| ^^^^^^^^^^^^^^^^^

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

error: use of deprecated associated function `this_crate::Trait::trait_deprecated`: text
--> $DIR/deprecation-lint.rs:302:13
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-rustfix

#![deny(deprecated)]

fn main() {
let _foo = str::trim_start(" aoeu"); //~ ERROR use of deprecated associated function `core::str::<impl str>::trim_left`: superseded by `trim_start` [deprecated]

let _bar = " aoeu".trim_start(); //~ ERROR use of deprecated associated function `core::str::<impl str>::trim_left`: superseded by `trim_start` [deprecated]
}
Loading