-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Warn for #[unstable] on trait impls when it has no effect. #76538
Warn for #[unstable] on trait impls when it has no effect. #76538
Conversation
r? @lcnr (rust_highfive has picked a reviewer for you, use r? to override) |
I this PR exists, then stability checking has been broken at some point. ...unless Anyway, stability attributes on impls are actually required if not inherited, and very much make sense at least for documentation, and there were always plans to implement stability checking for impls some day, but it's hard and not top priority. |
I don't think complicating stability checking is the right trade off here, it already accumulated quite a bit of technical debt over the years. |
It's easy to make the mistake of adding a |
I have already both made this mistake myself and saw a few other PRs which did the same, so 👍 on adding a warning here. @m-ou-se Considering that you mentioned that this detected 3 mistakes, how does this pass CI without having to fix any of them? Am I missing something here? |
They're just warnings right now. So they do appear in the output, but don't fail the CI: They should be errors instead, like the other messages about stability attributes. I'm not sure how to solve case 3 though. |
We can maybe change this to an unstable lint and explicitly allow it in case 3 🤔 |
I turned them into errors. The first case is fixed using #[stable(feature = "alloc_layout", since = "1.28.0")] The second case is fixed using #[stable(feature = "integer_atomics_stable", since = "1.34.0")] Might be good if someone can verify these. I copied the stability attribute from the types, and checked that the (stable) traits and these ('unstable') trait impls already existed at the time the types were stabilized. The third case still needs a solution. A lint with |
Any idea where would be the best place to call At first |
hmm, maybe adding it to I think that's fine even if we don't really need this outside of std |
Added it to the builtin lints as a Also added a test, as the 'test cases' in std are now fixed. |
Does this mean that the following test compiles rn? #![allow(rustc::ineffective_unstable_trait_impl)]…
fn main() {} I think it would be good to add It should hopefully work by just adding a line similar to
|
Yes. Every All other internal lints also compile just fine like that: #![allow(rustc::usage_of_qualified_ty)]
fn main() {} Tool lints (with |
hmm, ok 👍 Then r=me with the merge commit removed. @petrochenkov do you still have some concerns or questions about this? |
These impls were effectively stable. #[unstable] had no effect here, since both RefUnwindSafe and these types were already stable. These effectively became stable as soon as the types became stable, which was in 1.34.0.
This impl was effectively stable. #[unstable] had no effect here, since both Error and LayoutErr were already stable. This effectively became stable as soon as LayoutErr became stable, which was in 1.28.0.
4fef1bc
to
1c1bfba
Compare
Ok, the previous time I didn't look at the code and misinterpreted what this PR does. We have some conventions regarding lint names (https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#lints), and regarding diagnostic messages ("An r? @lcnr |
@bors r+ |
📌 Commit 14cc177 has been approved by |
…ess-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.
⌛ Testing commit 14cc177 with merge 3697de21c220ab1024b31a801b3a2b88a531111d... |
💔 Test failed - checks-actions |
Uh, that failure seems unrelated. |
yeah, let's hope this one was spurious @bors retry |
☀️ Test successful - checks-actions, checks-azure |
Earlier today I sent a PR with an
#[unstable]
attribute on a traitimpl
, but was informed that this attribute has no effect there. (comment: #76525 (comment), issue: #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:It detects three problems in the existing code:
RefUnwindSafe
implementations for the atomic integer types inlibrary/std/src/panic.rs
. Example:rust/library/std/src/panic.rs
Lines 235 to 236 in d92155b
Error
forLayoutErr
inlibrary/std/srd/error.rs
:rust/library/std/src/error.rs
Lines 392 to 397 in d92155b
From
implementations forWaker
andRawWaker
inlibrary/alloc/src/task.rs
. Example:rust/library/alloc/src/task.rs
Lines 36 to 37 in d92155b
Case 3 interesting: It has a bound with an
#[unstable]
trait (W: Wake
), so appears to have not much effect on stable code. It does however break similar blanket implementations. It would also have immediate effect ifWake
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 simplec.visit_generics(..);
to this PR will stop the warning for this case.