diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index f7e2135d5a43..31158901775f 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -171,13 +171,6 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { attr::mark_used(attr); self.tcx.sess.span_err(attr.span(), "stability attributes may not be used \ outside of the standard library"); - } else if tag == "deprecated" { - if !self.tcx.sess.features.borrow().deprecated { - self.tcx.sess.span_err(attr.span(), - "`#[deprecated]` attribute is unstable"); - fileline_help!(self.tcx.sess, attr.span(), "add #![feature(deprecated)] to \ - the crate features to enable"); - } } } @@ -687,68 +680,20 @@ pub fn lookup_deprecation<'tcx>(tcx: &ty::ctxt<'tcx>, id: DefId) -> Option(tcx: &ty::ctxt<'tcx>, id: DefId) -> Option<&'tcx Stability> { debug!("lookup(id={:?})", id); - - // is this definition the implementation of a trait method? - match tcx.trait_item_of_item(id) { - Some(ty::MethodTraitItemId(trait_method_id)) if trait_method_id != id => { - debug!("lookup: trait_method_id={:?}", trait_method_id); - return lookup_stability(tcx, trait_method_id) - } - _ => {} - } - - let item_stab = if id.is_local() { + if id.is_local() { None // The stability cache is filled partially lazily } else { tcx.sess.cstore.stability(id).map(|st| tcx.intern_stability(st)) - }; - - item_stab.or_else(|| { - if tcx.is_impl(id) { - if let Some(trait_id) = tcx.trait_id_of_impl(id) { - // FIXME (#18969): for the time being, simply use the - // stability of the trait to determine the stability of any - // unmarked impls for it. See FIXME above for more details. - - debug!("lookup: trait_id={:?}", trait_id); - return lookup_stability(tcx, trait_id); - } - } - None - }) + } } fn lookup_deprecation_uncached<'tcx>(tcx: &ty::ctxt<'tcx>, id: DefId) -> Option { debug!("lookup(id={:?})", id); - - // is this definition the implementation of a trait method? - match tcx.trait_item_of_item(id) { - Some(ty::MethodTraitItemId(trait_method_id)) if trait_method_id != id => { - debug!("lookup: trait_method_id={:?}", trait_method_id); - return lookup_deprecation(tcx, trait_method_id) - } - _ => {} - } - - let item_depr = if id.is_local() { + if id.is_local() { None // The stability cache is filled partially lazily } else { tcx.sess.cstore.deprecation(id) - }; - - item_depr.or_else(|| { - if tcx.is_impl(id) { - if let Some(trait_id) = tcx.trait_id_of_impl(id) { - // FIXME (#18969): for the time being, simply use the - // stability of the trait to determine the stability of any - // unmarked impls for it. See FIXME above for more details. - - debug!("lookup: trait_id={:?}", trait_id); - return lookup_deprecation(tcx, trait_id); - } - } - None - }) + } } /// Given the list of enabled features that were not language features (i.e. that diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 249504cbd8dc..e403e6d067af 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -575,7 +575,7 @@ impl LateLintPass for MissingDebugImplementations { declare_lint! { DEPRECATED, Warn, - "detects use of `#[deprecated]` or `#[rustc_deprecated]` items" + "detects use of deprecated items" } /// Checks for use of items with `#[deprecated]` or `#[rustc_deprecated]` attributes diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6b138b50f038..f186aff6d363 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -380,7 +380,7 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeGat ("must_use", Whitelisted, Ungated), ("stable", Whitelisted, Ungated), ("unstable", Whitelisted, Ungated), - ("deprecated", Whitelisted, Ungated), + ("deprecated", Normal, Gated("deprecated", "`#[deprecated]` attribute is unstable")), ("rustc_paren_sugar", Normal, Gated("unboxed_closures", "unboxed_closures are still evolving")), diff --git a/src/test/auxiliary/deprecation-lint.rs b/src/test/auxiliary/deprecation-lint.rs index 61c91590b31f..ff872efb7bdb 100644 --- a/src/test/auxiliary/deprecation-lint.rs +++ b/src/test/auxiliary/deprecation-lint.rs @@ -31,6 +31,9 @@ pub trait Trait { fn trait_deprecated_text(&self) {} } +#[deprecated(since = "1.0.0", note = "text")] +pub trait DeprecatedTrait { fn dummy(&self) { } } + impl Trait for MethodTester {} #[deprecated(since = "1.0.0", note = "text")] diff --git a/src/test/auxiliary/lint_stability.rs b/src/test/auxiliary/lint_stability.rs index 09d8302095f3..3100aba4b72b 100644 --- a/src/test/auxiliary/lint_stability.rs +++ b/src/test/auxiliary/lint_stability.rs @@ -98,6 +98,12 @@ impl Trait for MethodTester {} #[unstable(feature = "test_feature", issue = "0")] pub trait UnstableTrait { fn dummy(&self) { } } +#[stable(feature = "test_feature", since = "1.0.0")] +#[rustc_deprecated(since = "1.0.0", reason = "text")] +pub trait DeprecatedTrait { + #[stable(feature = "test_feature", since = "1.0.0")] fn dummy(&self) { } +} + #[stable(feature = "test_feature", since = "1.0.0")] #[rustc_deprecated(since = "1.0.0", reason = "text")] pub struct DeprecatedStruct { diff --git a/src/test/compile-fail/deprecation-lint.rs b/src/test/compile-fail/deprecation-lint.rs index db6d5fd63e59..58fa00fb4108 100644 --- a/src/test/compile-fail/deprecation-lint.rs +++ b/src/test/compile-fail/deprecation-lint.rs @@ -78,6 +78,11 @@ mod cross_crate { foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text } + struct S; + + impl DeprecatedTrait for S {} //~ ERROR use of deprecated item: text + trait LocalTrait : DeprecatedTrait { } //~ ERROR use of deprecated item: text + pub fn foo() { let x = Stable { override2: 3, diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index f32d7db244bc..414d2a857acc 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -227,8 +227,9 @@ mod cross_crate { struct S; impl UnstableTrait for S { } //~ ERROR use of unstable library feature - + impl DeprecatedTrait for S {} //~ ERROR use of deprecated item: text trait LocalTrait : UnstableTrait { } //~ ERROR use of unstable library feature + trait LocalTrait2 : DeprecatedTrait { } //~ ERROR use of deprecated item: text impl Trait for S { fn trait_stable(&self) {}