Skip to content

Commit

Permalink
Address the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 12, 2015
1 parent e3ed7b0 commit 105bd15
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 62 deletions.
63 changes: 4 additions & 59 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

Expand Down Expand Up @@ -687,68 +680,20 @@ pub fn lookup_deprecation<'tcx>(tcx: &ty::ctxt<'tcx>, id: DefId) -> Option<Depre

fn lookup_stability_uncached<'tcx>(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<Deprecation> {
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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
3 changes: 3 additions & 0 deletions src/test/auxiliary/deprecation-lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
6 changes: 6 additions & 0 deletions src/test/auxiliary/lint_stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/deprecation-lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/lint-stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down

0 comments on commit 105bd15

Please sign in to comment.