Skip to content

Allow #[unsafe(may_dangle)]#159800

Open
mejrs wants to merge 1 commit into
rust-lang:mainfrom
mejrs:unsafe_may_dangle
Open

Allow #[unsafe(may_dangle)]#159800
mejrs wants to merge 1 commit into
rust-lang:mainfrom
mejrs:unsafe_may_dangle

Conversation

@mejrs

@mejrs mejrs commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Tracking issue: #159799

This PR allows declaring the attribute itself unsafe, rather than the impl:

#![feature(dropck_eyepatch)]

struct PerhapsLoosely<T>(T);

impl<#[unsafe(may_dangle)] T> Drop for PerhapsLoosely<T> {
    fn drop(&mut self) {
        todo!()
    }
}

It is still possible to use unsafe impl<#[may_dangle] T> Drop, for now. Using both, however, is an error.

r? @JonathanBrouwer
cc @Zoxc

Happy to make a MCP if necessary.

@rustbot

rustbot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 23, 2026
@rustbot

rustbot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

JonathanBrouwer is currently at their maximum review capacity.
They may take a while to respond.

@mejrs mejrs added the F-dropck_eyepatch `#![feature(dropck_eyepatch)]` label Jul 23, 2026
Comment thread compiler/rustc_hir/src/attrs/data_structures.rs
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 24, 2026
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

I'm leaning towards this not needing an MCP, but not entirely sure

@mejrs

mejrs commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

I'm leaning towards this not needing an MCP, but not entirely sure

Hmm I've been thinking about it

  • adding this should be uncontroversial
  • removing unsafe impl Drop and migrating everything requires discussion and coordination

So I think it's OK to merge this but do a MCP before merging followups.

@JonathanBrouwer JonathanBrouwer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors r+ rollup
Sounds reasonable

View changes since this review

@rust-bors

rust-bors Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a892808 has been approved by JonathanBrouwer

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 1. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious CI failures

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 24, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

I would actually like to block this PR on the MCP, it doesn't make sense to merge this if the MCP is rejected
@bors r-

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 24, 2026
@rust-bors

rust-bors Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@JonathanBrouwer JonathanBrouwer added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-blocked Status: Blocked on something else such as an RFC or other implementation work. needs-mcp This change is large enough that it needs a major change proposal before starting work. labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) F-dropck_eyepatch `#![feature(dropck_eyepatch)]` needs-mcp This change is large enough that it needs a major change proposal before starting work. S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants