Skip to content

Commit 12a833a

Browse files
committed
Add lint rule for #[deprecated] on use
1 parent 916e9ce commit 12a833a

File tree

9 files changed

+38
-8
lines changed

9 files changed

+38
-8
lines changed

compiler/rustc_passes/src/stability.rs

+3
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
366366
kind = AnnotationKind::DeprecationProhibited;
367367
const_stab_inherit = InheritConstStability::Yes;
368368
}
369+
hir::ItemKind::Use(_, _) => {
370+
kind = AnnotationKind::DeprecationProhibited;
371+
}
369372
hir::ItemKind::Struct(ref sd, _) => {
370373
if let Some(ctor_def_id) = sd.ctor_def_id() {
371374
self.annotate(

library/core/src/alloc/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ pub use self::global::GlobalAlloc;
1010
#[stable(feature = "alloc_layout", since = "1.28.0")]
1111
pub use self::layout::Layout;
1212
#[stable(feature = "alloc_layout", since = "1.28.0")]
13-
#[deprecated(
14-
since = "1.52.0",
15-
note = "Name does not follow std convention, use LayoutError",
16-
suggestion = "LayoutError"
17-
)]
1813
#[allow(deprecated, deprecated_in_future)]
1914
pub use self::layout::LayoutErr;
2015
#[stable(feature = "alloc_layout_error", since = "1.50.0")]

library/std/src/collections/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ pub use self::hash_map::HashMap;
433433
#[doc(inline)]
434434
pub use self::hash_set::HashSet;
435435
#[stable(feature = "rust1", since = "1.0.0")]
436-
// FIXME(#82080) The deprecation here is only theoretical, and does not actually produce a warning.
437-
#[deprecated(note = "moved to `std::ops::Bound`", since = "1.26.0")]
436+
// FIXME(#82080) This has moved but #[deprecated] on `use` is unsupported.
438437
#[doc(hidden)]
439438
pub use crate::ops::Bound;
440439

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ run-rustfix
2+
mod a_module {
3+
pub struct ActiveType;
4+
}
5+
6+
//~^ ERROR this `#[deprecated]` annotation has no effect
7+
pub use a_module::ActiveType;
8+
9+
fn main() {
10+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ run-rustfix
2+
mod a_module {
3+
pub struct ActiveType;
4+
}
5+
6+
#[deprecated]
7+
//~^ ERROR this `#[deprecated]` annotation has no effect
8+
pub use a_module::ActiveType;
9+
10+
fn main() {
11+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: this `#[deprecated]` annotation has no effect
2+
--> $DIR/deprecated_use.rs:6:1
3+
|
4+
LL | #[deprecated]
5+
| ^^^^^^^^^^^^^ help: remove the unnecessary deprecation attribute
6+
|
7+
= note: `#[deny(useless_deprecated)]` on by default
8+
9+
error: aborting due to 1 previous error
10+

tests/ui/imports/unused-import-issue-87973.fixed

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ run-rustfix
22
#![deny(unused_imports)]
3+
#![allow(useless_deprecated)]
34

45
// Check that attributes get removed too. See #87973.
56
//~^ ERROR unused import

tests/ui/imports/unused-import-issue-87973.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ run-rustfix
22
#![deny(unused_imports)]
3+
#![allow(useless_deprecated)]
34

45
// Check that attributes get removed too. See #87973.
56
#[deprecated]

tests/ui/imports/unused-import-issue-87973.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unused import: `std::fs`
2-
--> $DIR/unused-import-issue-87973.rs:8:5
2+
--> $DIR/unused-import-issue-87973.rs:9:5
33
|
44
LL | use std::fs;
55
| ^^^^^^^

0 commit comments

Comments
 (0)