about summary refs log tree commit diff
path: root/compiler/rustc_passes
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-11-01 12:29:57 +0100
committerMara Bos <m-ou.se@m-ou.se>2020-11-01 20:48:58 +0100
commit706bc336515581c7559a5ccdfae0a7d93b0508fa (patch)
tree6f2e516a4fc3a172dc78e87c67771aea30a913ec /compiler/rustc_passes
parent0e2337a5d683c04004226502d2243ceb89cf4c22 (diff)
downloadrust-706bc336515581c7559a5ccdfae0a7d93b0508fa.tar.gz
rust-706bc336515581c7559a5ccdfae0a7d93b0508fa.zip
Use the right span for errors about #[deprecated] attributes.
Diffstat (limited to 'compiler/rustc_passes')
-rw-r--r--compiler/rustc_passes/src/stability.rs26
1 files changed, 17 insertions, 9 deletions
diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs
index 18d9e9f78d6..bacbab1a4f4 100644
--- a/compiler/rustc_passes/src/stability.rs
+++ b/compiler/rustc_passes/src/stability.rs
@@ -85,14 +85,22 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
             did_error = self.forbid_staged_api_attrs(hir_id, attrs, inherit_deprecation.clone());
         }
 
-        let depr =
-            if did_error { None } else { attr::find_deprecation(&self.tcx.sess, attrs, item_sp) };
+        let depr = if did_error { None } else { attr::find_deprecation(&self.tcx.sess, attrs) };
         let mut is_deprecated = false;
-        if let Some(depr) = &depr {
+        if let Some((depr, span)) = &depr {
             is_deprecated = true;
 
             if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited {
-                self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless");
+                self.tcx
+                    .sess
+                    .struct_span_err(*span, "this deprecation annotation is useless")
+                    .span_suggestion(
+                        *span,
+                        "try removing the deprecation attribute",
+                        String::new(),
+                        rustc_errors::Applicability::MachineApplicable,
+                    )
+                    .emit();
             }
 
             // `Deprecation` is just two pointers, no need to intern it
@@ -116,7 +124,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
             }
         } else {
             self.recurse_with_stability_attrs(
-                depr.map(|d| DeprecationEntry::local(d, hir_id)),
+                depr.map(|(d, _)| DeprecationEntry::local(d, hir_id)),
                 None,
                 None,
                 visit_children,
@@ -141,11 +149,11 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
             }
         }
 
-        if depr.as_ref().map_or(false, |d| d.is_since_rustc_version) {
+        if let Some((rustc_attr::Deprecation { is_since_rustc_version: true, .. }, span)) = &depr {
             if stab.is_none() {
                 struct_span_err!(
                     self.tcx.sess,
-                    item_sp,
+                    *span,
                     E0549,
                     "rustc_deprecated attribute must be paired with \
                     either stable or unstable attribute"
@@ -168,7 +176,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
             // Check if deprecated_since < stable_since. If it is,
             // this is *almost surely* an accident.
             if let (&Some(dep_since), &attr::Stable { since: stab_since }) =
-                (&depr.as_ref().and_then(|d| d.since), &stab.level)
+                (&depr.as_ref().and_then(|(d, _)| d.since), &stab.level)
             {
                 // Explicit version of iter::order::lt to handle parse errors properly
                 for (dep_v, stab_v) in
@@ -214,7 +222,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
         }
 
         self.recurse_with_stability_attrs(
-            depr.map(|d| DeprecationEntry::local(d, hir_id)),
+            depr.map(|(d, _)| DeprecationEntry::local(d, hir_id)),
             stab,
             const_stab,
             visit_children,