Check unsafe impls on safe EIIs#159783
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
|
r? @oli-obk rustbot has assigned @oli-obk. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Another approach is to emit the Right now, it is a breaking change to declare a unsafe trait but later remove the unsafe requirement. On the other hand, it is not a breaking change to have a unsafe function and then later remove the unsafe requirement. This PR proposes to go the former way, where both adding and removing the unsafe requirement are breaking changes. I'm undecided on what's best (so please don't go off making changes now), but note that this PR is a change to the semantics of the feature, not merely a "fix". |
|
I think it makes sense to follow the example of traits given that EIIs are kinda traits that can have a single global impl. If we decide to make removing unsafe from traits no longer a breaking change, we can adjust EII to follow this. |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| #[derive(Diagnostic)] | ||
| #[diag("`#[{$name}]` is not unsafe to implement")] |
There was a problem hiding this comment.
As of #159755 we don't mention the #[/] parts
| #[diag("`#[{$name}]` is not unsafe to implement")] | |
| #[diag("`{$name}` is not unsafe to implement")] |
| #[primary_span] | ||
| #[label("`unsafe` is not allowed here")] | ||
| pub span: Span, |
There was a problem hiding this comment.
For consistency with regular attributes I'd prefer if this message pointed at the entire attribute, and then the label only to the redundant unsafe
| #[primary_span] | |
| #[label("`unsafe` is not allowed here")] | |
| pub span: Span, | |
| #[primary_span] | |
| pub impl_span: Span, | |
| #[label("`unsafe` is not allowed here")] | |
| pub unsafe_span: Span, |
|
Reminder, once the PR becomes ready for a review, use |
e8c3cb3 to
bae7e21
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Resolved conflicts and updated according to review comments. @rustbot ready |
|
@rustbot label +F-extern_item_impls |
| impl_unsafe_span: match *impl_safety { | ||
| Safety::Unsafe(span) => Some(self.lower_span(span)), | ||
| Safety::Safe(_) | Safety::Default => None, | ||
| }, |
There was a problem hiding this comment.
I'm fine with this change and would prefer to address the concept of how we carry around "safety" in the compiler in a more comprehensive manner (i.e., not here and not today).
@JonathanBrouwer are you okay with this change or would you rather we lower+carry Safety here?
There was a problem hiding this comment.
Using rustc_hir::Safety would be nicer as the type is more descriptive, but it does not contain the span so unless we change that (which is too much for this PR) it's not usable. This is fine for now
…r=mejrs,JonathanBrouwer Check unsafe impls on safe EIIs Tracking issue: rust-lang#125418 Unsafe EIIs require implementations to use `#[unsafe(...)]`, but safe EIIs currently accept this form as well. This should be rejected, just like `unsafe impl` on a safe trait. This also fixes existing EII UI tests using this pattern and adds a new regression test.
…r=mejrs,JonathanBrouwer Check unsafe impls on safe EIIs Tracking issue: rust-lang#125418 Unsafe EIIs require implementations to use `#[unsafe(...)]`, but safe EIIs currently accept this form as well. This should be rejected, just like `unsafe impl` on a safe trait. This also fixes existing EII UI tests using this pattern and adds a new regression test.
…r=mejrs,JonathanBrouwer Check unsafe impls on safe EIIs Tracking issue: rust-lang#125418 Unsafe EIIs require implementations to use `#[unsafe(...)]`, but safe EIIs currently accept this form as well. This should be rejected, just like `unsafe impl` on a safe trait. This also fixes existing EII UI tests using this pattern and adds a new regression test.
…r=mejrs,JonathanBrouwer Check unsafe impls on safe EIIs Tracking issue: rust-lang#125418 Unsafe EIIs require implementations to use `#[unsafe(...)]`, but safe EIIs currently accept this form as well. This should be rejected, just like `unsafe impl` on a safe trait. This also fixes existing EII UI tests using this pattern and adds a new regression test.
…uwer Rollup of 24 pull requests Successful merges: - #159638 (bootstrap: Split the `Step` trait into multiple traits) - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations) - #159837 (line-tables-only test: check that the line number matches the function name) - #159946 (Update Enzyme submodule to imporve llvm-cov) - #159617 (Fix up `#[linkage]` target checking) - #159733 (std: Switch implementations of `thread_local!` for WASI) - #159783 (Check unsafe impls on safe EIIs) - #159810 (Add tuple never coercion collection regression test) - #159821 (Update expect message using the recommended style in binary_heap module) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159846 (Implement `str::copy_from_str`) - #159849 (rustc_parse: Stop returning `Option` from statement parsing) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159875 (More cleanup in `rustc_attr_parsing`) - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide) - #159891 (Split multiline derives into std/rustc macros) - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups) - #159895 (rustc-dev-guide subtree update) - #159902 (Clarify that the expected runtime symbols signature is for the current target only) - #159914 (Fix error in diagnostic on_unmatched_args) - #159917 (spare capacity mut constification) - #159918 (rename abort_unwind → abort_on_unwind) - #159936 (Minor `rustc_ast::ast` doc cleanups) - #159945 (Update expect messages in library/core/src/ptr/non_null.rs)
…uwer Rollup of 24 pull requests Successful merges: - #159638 (bootstrap: Split the `Step` trait into multiple traits) - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations) - #159837 (line-tables-only test: check that the line number matches the function name) - #159946 (Update Enzyme submodule to imporve llvm-cov) - #159617 (Fix up `#[linkage]` target checking) - #159733 (std: Switch implementations of `thread_local!` for WASI) - #159783 (Check unsafe impls on safe EIIs) - #159810 (Add tuple never coercion collection regression test) - #159821 (Update expect message using the recommended style in binary_heap module) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159846 (Implement `str::copy_from_str`) - #159849 (rustc_parse: Stop returning `Option` from statement parsing) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159875 (More cleanup in `rustc_attr_parsing`) - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide) - #159891 (Split multiline derives into std/rustc macros) - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups) - #159895 (rustc-dev-guide subtree update) - #159902 (Clarify that the expected runtime symbols signature is for the current target only) - #159914 (Fix error in diagnostic on_unmatched_args) - #159917 (spare capacity mut constification) - #159918 (rename abort_unwind → abort_on_unwind) - #159936 (Minor `rustc_ast::ast` doc cleanups) - #159945 (Update expect messages in library/core/src/ptr/non_null.rs)
…r=mejrs,JonathanBrouwer Check unsafe impls on safe EIIs Tracking issue: rust-lang#125418 Unsafe EIIs require implementations to use `#[unsafe(...)]`, but safe EIIs currently accept this form as well. This should be rejected, just like `unsafe impl` on a safe trait. This also fixes existing EII UI tests using this pattern and adds a new regression test.
…uwer Rollup of 28 pull requests Successful merges: - #159638 (bootstrap: Split the `Step` trait into multiple traits) - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations) - #159837 (line-tables-only test: check that the line number matches the function name) - #159946 (Update Enzyme submodule to imporve llvm-cov) - #159962 (miri subtree update) - #156570 (tests: extend remap-path-prefix-std to all stdlib rlibs) - #159617 (Fix up `#[linkage]` target checking) - #159633 (Improve workings of attribute suggestions) - #159733 (std: Switch implementations of `thread_local!` for WASI) - #159783 (Check unsafe impls on safe EIIs) - #159810 (Add tuple never coercion collection regression test) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159846 (Implement `str::copy_from_str`) - #159849 (rustc_parse: Stop returning `Option` from statement parsing) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159875 (More cleanup in `rustc_attr_parsing`) - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide) - #159891 (Split multiline derives into std/rustc macros) - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups) - #159895 (rustc-dev-guide subtree update) - #159902 (Clarify that the expected runtime symbols signature is for the current target only) - #159914 (Fix error in diagnostic on_unmatched_args) - #159917 (spare capacity mut constification) - #159918 (rename abort_unwind → abort_on_unwind) - #159927 (Remove sve2 from the ImpliedFeatures of AArch64 v9a.) - #159936 (Minor `rustc_ast::ast` doc cleanups) - #159945 (Update expect messages in library/core/src/ptr/non_null.rs) - #159950 (Add CFI tests for return types and never type)
Tracking issue: #125418
Unsafe EIIs require implementations to use
#[unsafe(...)], but safe EIIs currently accept this form as well. This should be rejected, just likeunsafe implon a safe trait.This also fixes existing EII UI tests using this pattern and adds a new regression test.