Skip to content

Commit 5e68ba8

Browse files
committed
Auto merge of rust-lang#76538 - fusion-engineering-forks:check-useless-unstable-trait-impl, r=lcnr
Warn for #[unstable] on trait impls when it has no effect. Earlier today I sent a PR with an `#[unstable]` attribute on a trait `impl`, but was informed that this attribute has no effect there. (comment: rust-lang#76525 (comment), issue: rust-lang#55436) This PR adds a warning for this situation. Trait `impl` blocks with `#[unstable]` where both the type and the trait are stable will result in a warning: ``` warning: An `#[unstable]` annotation here has no effect. See issue rust-lang#55436 <rust-lang#55436> for more information. --> library/std/src/panic.rs:235:1 | 235 | #[unstable(feature = "integer_atomics", issue = "32976")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` --- It detects three problems in the existing code: 1. A few `RefUnwindSafe` implementations for the atomic integer types in `library/std/src/panic.rs`. Example: https://github.com/rust-lang/rust/blob/d92155bf6ae0b7d79fc83cbeeb0cc0c765353471/library/std/src/panic.rs#L235-L236 2. An implementation of `Error` for `LayoutErr` in `library/std/srd/error.rs`: https://github.com/rust-lang/rust/blob/d92155bf6ae0b7d79fc83cbeeb0cc0c765353471/library/std/src/error.rs#L392-L397 3. `From` implementations for `Waker` and `RawWaker` in `library/alloc/src/task.rs`. Example: https://github.com/rust-lang/rust/blob/d92155bf6ae0b7d79fc83cbeeb0cc0c765353471/library/alloc/src/task.rs#L36-L37 Case 3 interesting: It has a bound with an `#[unstable]` trait (`W: Wake`), so appears to have much effect on stable code. It does however break similar blanket implementations. It would also have immediate effect if `Wake` was implemented for any stable type. (Which is not the case right now, but there are no warnings in place to prevent it.) Whether this case is a problem or not is not clear to me. If it isn't, adding a simple `c.visit_generics(..);` to this PR will stop the warning for this case.
2 parents f36edc5 + 9e3caba commit 5e68ba8

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

alloc/src/task.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub trait Wake {
3333
}
3434
}
3535

36+
#[allow(rustc::ineffective_unstable_trait_impl)]
3637
#[unstable(feature = "wake_trait", issue = "69912")]
3738
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
3839
fn from(waker: Arc<W>) -> Waker {
@@ -42,6 +43,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
4243
}
4344
}
4445

46+
#[allow(rustc::ineffective_unstable_trait_impl)]
4547
#[unstable(feature = "wake_trait", issue = "69912")]
4648
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
4749
fn from(waker: Arc<W>) -> RawWaker {

std/src/error.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,7 @@ impl Error for ! {}
389389
)]
390390
impl Error for AllocErr {}
391391

392-
#[unstable(
393-
feature = "allocator_api",
394-
reason = "the precise API and guarantees it provides may be tweaked.",
395-
issue = "32838"
396-
)]
392+
#[stable(feature = "alloc_layout", since = "1.28.0")]
397393
impl Error for LayoutErr {}
398394

399395
#[stable(feature = "rust1", since = "1.0.0")]

std/src/panic.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,16 @@ impl<T: ?Sized> RefUnwindSafe for RwLock<T> {}
232232
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
233233
impl RefUnwindSafe for atomic::AtomicIsize {}
234234
#[cfg(target_has_atomic_load_store = "8")]
235-
#[unstable(feature = "integer_atomics", issue = "32976")]
235+
#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
236236
impl RefUnwindSafe for atomic::AtomicI8 {}
237237
#[cfg(target_has_atomic_load_store = "16")]
238-
#[unstable(feature = "integer_atomics", issue = "32976")]
238+
#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
239239
impl RefUnwindSafe for atomic::AtomicI16 {}
240240
#[cfg(target_has_atomic_load_store = "32")]
241-
#[unstable(feature = "integer_atomics", issue = "32976")]
241+
#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
242242
impl RefUnwindSafe for atomic::AtomicI32 {}
243243
#[cfg(target_has_atomic_load_store = "64")]
244-
#[unstable(feature = "integer_atomics", issue = "32976")]
244+
#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
245245
impl RefUnwindSafe for atomic::AtomicI64 {}
246246
#[cfg(target_has_atomic_load_store = "128")]
247247
#[unstable(feature = "integer_atomics", issue = "32976")]
@@ -251,16 +251,16 @@ impl RefUnwindSafe for atomic::AtomicI128 {}
251251
#[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
252252
impl RefUnwindSafe for atomic::AtomicUsize {}
253253
#[cfg(target_has_atomic_load_store = "8")]
254-
#[unstable(feature = "integer_atomics", issue = "32976")]
254+
#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
255255
impl RefUnwindSafe for atomic::AtomicU8 {}
256256
#[cfg(target_has_atomic_load_store = "16")]
257-
#[unstable(feature = "integer_atomics", issue = "32976")]
257+
#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
258258
impl RefUnwindSafe for atomic::AtomicU16 {}
259259
#[cfg(target_has_atomic_load_store = "32")]
260-
#[unstable(feature = "integer_atomics", issue = "32976")]
260+
#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
261261
impl RefUnwindSafe for atomic::AtomicU32 {}
262262
#[cfg(target_has_atomic_load_store = "64")]
263-
#[unstable(feature = "integer_atomics", issue = "32976")]
263+
#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
264264
impl RefUnwindSafe for atomic::AtomicU64 {}
265265
#[cfg(target_has_atomic_load_store = "128")]
266266
#[unstable(feature = "integer_atomics", issue = "32976")]

0 commit comments

Comments
 (0)