Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint rule for #[deprecated] on re-exports #132038

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions library/core/src/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/collections/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions tests/ui/deprecation/deprecation-sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
8 changes: 7 additions & 1 deletion tests/ui/deprecation/deprecation-sanity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions tests/ui/imports/unused-import-issue-87973.fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-rustfix
#![deny(unused_imports)]
#![allow(useless_deprecated)]

// Check that attributes get removed too. See #87973.
//~^ ERROR unused import
Expand Down
1 change: 1 addition & 0 deletions tests/ui/imports/unused-import-issue-87973.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-rustfix
#![deny(unused_imports)]
#![allow(useless_deprecated)]

// Check that attributes get removed too. See #87973.
#[deprecated]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/imports/unused-import-issue-87973.stderr
Original file line number Diff line number Diff line change
@@ -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;
| ^^^^^^^
Expand Down
Loading