about summary refs log tree commit diff
path: root/library/std
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-12 18:01:33 +0000
committerbors <bors@rust-lang.org>2020-09-12 18:01:33 +0000
commit989190874fe2a0e9877ce4f02a6c60641e3d42a3 (patch)
treecdc1dd5f294a9c7b29e5ea413f03aaf6e2caa833 /library/std
parent7adeb2c795239e2e5ffbe4cd4672157c8e1b9277 (diff)
parent14cc17759de0863e85eea46c0f5bfcc362d1bfe8 (diff)
downloadrust-989190874fe2a0e9877ce4f02a6c60641e3d42a3.tar.gz
rust-989190874fe2a0e9877ce4f02a6c60641e3d42a3.zip
Auto merge of #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: https://github.com/rust-lang/rust/pull/76525#issuecomment-689678895, issue: https://github.com/rust-lang/rust/issues/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 #55436 <https://github.com/rust-lang/rust/issues/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.
Diffstat (limited to 'library/std')
-rw-r--r--library/std/src/error.rs6
-rw-r--r--library/std/src/panic.rs16
2 files changed, 9 insertions, 13 deletions
diff --git a/library/std/src/error.rs b/library/std/src/error.rs
index 8da03343976..ee25311d3b7 100644
--- a/library/std/src/error.rs
+++ b/library/std/src/error.rs
@@ -389,11 +389,7 @@ impl Error for ! {}
 )]
 impl Error for AllocErr {}
 
-#[unstable(
-    feature = "allocator_api",
-    reason = "the precise API and guarantees it provides may be tweaked.",
-    issue = "32838"
-)]
+#[stable(feature = "alloc_layout", since = "1.28.0")]
 impl Error for LayoutErr {}
 
 #[stable(feature = "rust1", since = "1.0.0")]
diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs
index 87493945db6..18d9c2f11b5 100644
--- a/library/std/src/panic.rs
+++ b/library/std/src/panic.rs
@@ -232,16 +232,16 @@ impl<T: ?Sized> RefUnwindSafe for RwLock<T> {}
 #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
 impl RefUnwindSafe for atomic::AtomicIsize {}
 #[cfg(target_has_atomic_load_store = "8")]
-#[unstable(feature = "integer_atomics", issue = "32976")]
+#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
 impl RefUnwindSafe for atomic::AtomicI8 {}
 #[cfg(target_has_atomic_load_store = "16")]
-#[unstable(feature = "integer_atomics", issue = "32976")]
+#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
 impl RefUnwindSafe for atomic::AtomicI16 {}
 #[cfg(target_has_atomic_load_store = "32")]
-#[unstable(feature = "integer_atomics", issue = "32976")]
+#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
 impl RefUnwindSafe for atomic::AtomicI32 {}
 #[cfg(target_has_atomic_load_store = "64")]
-#[unstable(feature = "integer_atomics", issue = "32976")]
+#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
 impl RefUnwindSafe for atomic::AtomicI64 {}
 #[cfg(target_has_atomic_load_store = "128")]
 #[unstable(feature = "integer_atomics", issue = "32976")]
@@ -251,16 +251,16 @@ impl RefUnwindSafe for atomic::AtomicI128 {}
 #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")]
 impl RefUnwindSafe for atomic::AtomicUsize {}
 #[cfg(target_has_atomic_load_store = "8")]
-#[unstable(feature = "integer_atomics", issue = "32976")]
+#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
 impl RefUnwindSafe for atomic::AtomicU8 {}
 #[cfg(target_has_atomic_load_store = "16")]
-#[unstable(feature = "integer_atomics", issue = "32976")]
+#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
 impl RefUnwindSafe for atomic::AtomicU16 {}
 #[cfg(target_has_atomic_load_store = "32")]
-#[unstable(feature = "integer_atomics", issue = "32976")]
+#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
 impl RefUnwindSafe for atomic::AtomicU32 {}
 #[cfg(target_has_atomic_load_store = "64")]
-#[unstable(feature = "integer_atomics", issue = "32976")]
+#[stable(feature = "integer_atomics_stable", since = "1.34.0")]
 impl RefUnwindSafe for atomic::AtomicU64 {}
 #[cfg(target_has_atomic_load_store = "128")]
 #[unstable(feature = "integer_atomics", issue = "32976")]