Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable deprecation lint on crate-local items
Previously the lint considered cross-crate items only. That's
appropriate for unstable and experimental levels, but not for
deprecation.

Closes #16409

Due to deny(deprecation), this is a:

[breaking-change]
  • Loading branch information
aturon committed Aug 12, 2014
1 parent e2273d9 commit 0b5204f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
20 changes: 10 additions & 10 deletions src/librustc/lint/builtin.rs
Expand Up @@ -1479,20 +1479,20 @@ impl LintPass for Stability {
_ => return
};

// stability attributes are promises made across crates; do not
// check anything for crate-local usage.
if ast_util::is_local(id) { return }

let stability = stability::lookup(cx.tcx, id);
let cross_crate = !ast_util::is_local(id);

// stability attributes are promises made across crates; only
// check DEPRECATED for crate-local usage.
let (lint, label) = match stability {
// no stability attributes == Unstable
None => (UNSTABLE, "unmarked"),
Some(attr::Stability { level: attr::Unstable, .. }) =>
(UNSTABLE, "unstable"),
Some(attr::Stability { level: attr::Experimental, .. }) =>
(EXPERIMENTAL, "experimental"),
None if cross_crate => (UNSTABLE, "unmarked"),
Some(attr::Stability { level: attr::Unstable, .. }) if cross_crate =>
(UNSTABLE, "unstable"),
Some(attr::Stability { level: attr::Experimental, .. }) if cross_crate =>
(EXPERIMENTAL, "experimental"),
Some(attr::Stability { level: attr::Deprecated, .. }) =>
(DEPRECATED, "deprecated"),
(DEPRECATED, "deprecated"),
_ => return
};

Expand Down
35 changes: 17 additions & 18 deletions src/test/compile-fail/lint-stability.rs
Expand Up @@ -329,19 +329,19 @@ mod this_crate {
pub struct LockedTupleStruct(int);

fn test() {
// None of the following should generate errors, because
// stability attributes now have meaning only *across* crates,
// not within a single crate.
// Only the deprecated cases of the following should generate
// errors, because other stability attributes now have meaning
// only *across* crates, not within a single crate.

let foo = MethodTester;

deprecated();
foo.method_deprecated();
foo.trait_deprecated();
deprecated(); //~ ERROR use of deprecated item
foo.method_deprecated(); //~ ERROR use of deprecated item
foo.trait_deprecated(); //~ ERROR use of deprecated item

deprecated_text();
foo.method_deprecated_text();
foo.trait_deprecated_text();
deprecated_text(); //~ ERROR use of deprecated item: text
foo.method_deprecated_text(); //~ ERROR use of deprecated item: text
foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text

experimental();
foo.method_experimental();
Expand Down Expand Up @@ -387,32 +387,31 @@ mod this_crate {
foo.method_locked_text();
foo.trait_locked_text();


let _ = DeprecatedStruct { i: 0 };
let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
let _ = ExperimentalStruct { i: 0 };
let _ = UnstableStruct { i: 0 };
let _ = UnmarkedStruct { i: 0 };
let _ = StableStruct { i: 0 };
let _ = FrozenStruct { i: 0 };
let _ = LockedStruct { i: 0 };

let _ = DeprecatedUnitStruct;
let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
let _ = ExperimentalUnitStruct;
let _ = UnstableUnitStruct;
let _ = UnmarkedUnitStruct;
let _ = StableUnitStruct;
let _ = FrozenUnitStruct;
let _ = LockedUnitStruct;

let _ = DeprecatedVariant;
let _ = DeprecatedVariant; //~ ERROR use of deprecated item
let _ = ExperimentalVariant;
let _ = UnstableVariant;
let _ = UnmarkedVariant;
let _ = StableVariant;
let _ = FrozenVariant;
let _ = LockedVariant;

let _ = DeprecatedTupleStruct (1);
let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
let _ = ExperimentalTupleStruct (1);
let _ = UnstableTupleStruct (1);
let _ = UnmarkedTupleStruct (1);
Expand All @@ -422,8 +421,8 @@ mod this_crate {
}

fn test_method_param<F: Trait>(foo: F) {
foo.trait_deprecated();
foo.trait_deprecated_text();
foo.trait_deprecated(); //~ ERROR use of deprecated item
foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
foo.trait_experimental();
foo.trait_experimental_text();
foo.trait_unstable();
Expand All @@ -433,8 +432,8 @@ mod this_crate {
}

fn test_method_object(foo: &Trait) {
foo.trait_deprecated();
foo.trait_deprecated_text();
foo.trait_deprecated(); //~ ERROR use of deprecated item
foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
foo.trait_experimental();
foo.trait_experimental_text();
foo.trait_unstable();
Expand Down

0 comments on commit 0b5204f

Please sign in to comment.