From 0b5204f55efd9e25425055264d44f28501c0439b Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Mon, 11 Aug 2014 16:39:34 -0700 Subject: [PATCH] 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] --- src/librustc/lint/builtin.rs | 20 +++++++------- src/test/compile-fail/lint-stability.rs | 35 ++++++++++++------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index bde0992dabe..f929860c686 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -1479,20 +1479,20 @@ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { _ => 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 }; diff --git a/src/test/compile-fail/lint-stability.rs b/src/test/compile-fail/lint-stability.rs index 3a9380befbc..f5cee22ac2c 100644 --- a/src/test/compile-fail/lint-stability.rs +++ b/src/test/compile-fail/lint-stability.rs @@ -329,19 +329,19 @@ pub enum Enum { 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(); @@ -387,8 +387,7 @@ fn test() { 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 }; @@ -396,7 +395,7 @@ fn test() { let _ = FrozenStruct { i: 0 }; let _ = LockedStruct { i: 0 }; - let _ = DeprecatedUnitStruct; + let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item let _ = ExperimentalUnitStruct; let _ = UnstableUnitStruct; let _ = UnmarkedUnitStruct; @@ -404,7 +403,7 @@ fn test() { let _ = FrozenUnitStruct; let _ = LockedUnitStruct; - let _ = DeprecatedVariant; + let _ = DeprecatedVariant; //~ ERROR use of deprecated item let _ = ExperimentalVariant; let _ = UnstableVariant; let _ = UnmarkedVariant; @@ -412,7 +411,7 @@ fn test() { let _ = FrozenVariant; let _ = LockedVariant; - let _ = DeprecatedTupleStruct (1); + let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item let _ = ExperimentalTupleStruct (1); let _ = UnstableTupleStruct (1); let _ = UnmarkedTupleStruct (1); @@ -422,8 +421,8 @@ fn test() { } fn test_method_param(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(); @@ -433,8 +432,8 @@ fn test_method_param(foo: F) { } 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();