From 12a833acfd963beeabbc17bf000783168a0a032b Mon Sep 17 00:00:00 2001 From: Kailan Blanks Date: Tue, 22 Oct 2024 15:49:58 +0100 Subject: [PATCH 1/2] Add lint rule for `#[deprecated]` on `use` --- compiler/rustc_passes/src/stability.rs | 3 +++ library/core/src/alloc/mod.rs | 5 ----- library/std/src/collections/mod.rs | 3 +-- tests/ui/deprecation/deprecated_use.fixed | 10 ++++++++++ tests/ui/deprecation/deprecated_use.rs | 11 +++++++++++ tests/ui/deprecation/deprecated_use.stderr | 10 ++++++++++ tests/ui/imports/unused-import-issue-87973.fixed | 1 + tests/ui/imports/unused-import-issue-87973.rs | 1 + tests/ui/imports/unused-import-issue-87973.stderr | 2 +- 9 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 tests/ui/deprecation/deprecated_use.fixed create mode 100644 tests/ui/deprecation/deprecated_use.rs create mode 100644 tests/ui/deprecation/deprecated_use.stderr diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 751c87a9fe519..9296907465810 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -366,6 +366,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { kind = AnnotationKind::DeprecationProhibited; const_stab_inherit = InheritConstStability::Yes; } + hir::ItemKind::Use(_, _) => { + kind = AnnotationKind::DeprecationProhibited; + } hir::ItemKind::Struct(ref sd, _) => { if let Some(ctor_def_id) = sd.ctor_def_id() { self.annotate( diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index aa841db045ce7..f17687ed6e41b 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -10,11 +10,6 @@ pub use self::global::GlobalAlloc; #[stable(feature = "alloc_layout", since = "1.28.0")] pub use self::layout::Layout; #[stable(feature = "alloc_layout", since = "1.28.0")] -#[deprecated( - since = "1.52.0", - note = "Name does not follow std convention, use LayoutError", - suggestion = "LayoutError" -)] #[allow(deprecated, deprecated_in_future)] pub use self::layout::LayoutErr; #[stable(feature = "alloc_layout_error", since = "1.50.0")] diff --git a/library/std/src/collections/mod.rs b/library/std/src/collections/mod.rs index 889ed3c538035..ba57c5eb3530d 100644 --- a/library/std/src/collections/mod.rs +++ b/library/std/src/collections/mod.rs @@ -433,8 +433,7 @@ pub use self::hash_map::HashMap; #[doc(inline)] pub use self::hash_set::HashSet; #[stable(feature = "rust1", since = "1.0.0")] -// FIXME(#82080) The deprecation here is only theoretical, and does not actually produce a warning. -#[deprecated(note = "moved to `std::ops::Bound`", since = "1.26.0")] +// FIXME(#82080) This has moved but #[deprecated] on `use` is unsupported. #[doc(hidden)] pub use crate::ops::Bound; diff --git a/tests/ui/deprecation/deprecated_use.fixed b/tests/ui/deprecation/deprecated_use.fixed new file mode 100644 index 0000000000000..09d6869fd1a20 --- /dev/null +++ b/tests/ui/deprecation/deprecated_use.fixed @@ -0,0 +1,10 @@ +//@ run-rustfix +mod a_module { + pub struct ActiveType; +} + +//~^ ERROR this `#[deprecated]` annotation has no effect +pub use a_module::ActiveType; + +fn main() { +} diff --git a/tests/ui/deprecation/deprecated_use.rs b/tests/ui/deprecation/deprecated_use.rs new file mode 100644 index 0000000000000..1712b40675988 --- /dev/null +++ b/tests/ui/deprecation/deprecated_use.rs @@ -0,0 +1,11 @@ +//@ run-rustfix +mod a_module { + pub struct ActiveType; +} + +#[deprecated] +//~^ ERROR this `#[deprecated]` annotation has no effect +pub use a_module::ActiveType; + +fn main() { +} diff --git a/tests/ui/deprecation/deprecated_use.stderr b/tests/ui/deprecation/deprecated_use.stderr new file mode 100644 index 0000000000000..31f75237902ba --- /dev/null +++ b/tests/ui/deprecation/deprecated_use.stderr @@ -0,0 +1,10 @@ +error: this `#[deprecated]` annotation has no effect + --> $DIR/deprecated_use.rs:6:1 + | +LL | #[deprecated] + | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute + | + = note: `#[deny(useless_deprecated)]` on by default + +error: aborting due to 1 previous error + diff --git a/tests/ui/imports/unused-import-issue-87973.fixed b/tests/ui/imports/unused-import-issue-87973.fixed index d1167d7d4861a..402655e4fbc88 100644 --- a/tests/ui/imports/unused-import-issue-87973.fixed +++ b/tests/ui/imports/unused-import-issue-87973.fixed @@ -1,5 +1,6 @@ //@ run-rustfix #![deny(unused_imports)] +#![allow(useless_deprecated)] // Check that attributes get removed too. See #87973. //~^ ERROR unused import diff --git a/tests/ui/imports/unused-import-issue-87973.rs b/tests/ui/imports/unused-import-issue-87973.rs index 1b016ff814c6b..0186ddd5ec75f 100644 --- a/tests/ui/imports/unused-import-issue-87973.rs +++ b/tests/ui/imports/unused-import-issue-87973.rs @@ -1,5 +1,6 @@ //@ run-rustfix #![deny(unused_imports)] +#![allow(useless_deprecated)] // Check that attributes get removed too. See #87973. #[deprecated] diff --git a/tests/ui/imports/unused-import-issue-87973.stderr b/tests/ui/imports/unused-import-issue-87973.stderr index a43e92b145802..3628f319411ca 100644 --- a/tests/ui/imports/unused-import-issue-87973.stderr +++ b/tests/ui/imports/unused-import-issue-87973.stderr @@ -1,5 +1,5 @@ error: unused import: `std::fs` - --> $DIR/unused-import-issue-87973.rs:8:5 + --> $DIR/unused-import-issue-87973.rs:9:5 | LL | use std::fs; | ^^^^^^^ From ca664bb95dfaa13c2f2a5ce90898a992b050d511 Mon Sep 17 00:00:00 2001 From: Kailan Blanks Date: Tue, 22 Oct 2024 16:10:55 +0100 Subject: [PATCH 2/2] Merge `#[deprecated]` on `use` test with existing `deprecation-sanity` UI test --- tests/ui/deprecation/deprecated_use.fixed | 10 ---------- tests/ui/deprecation/deprecated_use.rs | 11 ----------- tests/ui/deprecation/deprecated_use.stderr | 10 ---------- tests/ui/deprecation/deprecation-sanity.rs | 7 +++++++ tests/ui/deprecation/deprecation-sanity.stderr | 8 +++++++- 5 files changed, 14 insertions(+), 32 deletions(-) delete mode 100644 tests/ui/deprecation/deprecated_use.fixed delete mode 100644 tests/ui/deprecation/deprecated_use.rs delete mode 100644 tests/ui/deprecation/deprecated_use.stderr diff --git a/tests/ui/deprecation/deprecated_use.fixed b/tests/ui/deprecation/deprecated_use.fixed deleted file mode 100644 index 09d6869fd1a20..0000000000000 --- a/tests/ui/deprecation/deprecated_use.fixed +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-rustfix -mod a_module { - pub struct ActiveType; -} - -//~^ ERROR this `#[deprecated]` annotation has no effect -pub use a_module::ActiveType; - -fn main() { -} diff --git a/tests/ui/deprecation/deprecated_use.rs b/tests/ui/deprecation/deprecated_use.rs deleted file mode 100644 index 1712b40675988..0000000000000 --- a/tests/ui/deprecation/deprecated_use.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ run-rustfix -mod a_module { - pub struct ActiveType; -} - -#[deprecated] -//~^ ERROR this `#[deprecated]` annotation has no effect -pub use a_module::ActiveType; - -fn main() { -} diff --git a/tests/ui/deprecation/deprecated_use.stderr b/tests/ui/deprecation/deprecated_use.stderr deleted file mode 100644 index 31f75237902ba..0000000000000 --- a/tests/ui/deprecation/deprecated_use.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: this `#[deprecated]` annotation has no effect - --> $DIR/deprecated_use.rs:6:1 - | -LL | #[deprecated] - | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute - | - = note: `#[deny(useless_deprecated)]` on by default - -error: aborting due to 1 previous error - diff --git a/tests/ui/deprecation/deprecation-sanity.rs b/tests/ui/deprecation/deprecation-sanity.rs index 9ea75b68f81ce..27a8fc3580ae0 100644 --- a/tests/ui/deprecation/deprecation-sanity.rs +++ b/tests/ui/deprecation/deprecation-sanity.rs @@ -39,4 +39,11 @@ impl Default for X { } } +mod inner { + pub struct Y; +} + +#[deprecated] //~ ERROR this `#[deprecated]` annotation has no effect +pub use inner::Y; + fn main() { } diff --git a/tests/ui/deprecation/deprecation-sanity.stderr b/tests/ui/deprecation/deprecation-sanity.stderr index 383212ad9b4b8..e05fbc0aa14cd 100644 --- a/tests/ui/deprecation/deprecation-sanity.stderr +++ b/tests/ui/deprecation/deprecation-sanity.stderr @@ -68,7 +68,13 @@ LL | #[deprecated = "hello"] | = note: `#[deny(useless_deprecated)]` on by default -error: aborting due to 10 previous errors +error: this `#[deprecated]` annotation has no effect + --> $DIR/deprecation-sanity.rs:46:1 + | +LL | #[deprecated] + | ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute + +error: aborting due to 11 previous errors Some errors have detailed explanations: E0538, E0539, E0541, E0565. For more information about an error, try `rustc --explain E0538`.