Repository navigation
#[may_dangle], a refined dropck escape hatch (tracking issue for RFC 1327) #34761
Copy link
Copy link
Open
Labels
A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-dropck_eyepatch`#![feature(dropck_eyepatch)]``#![feature(dropck_eyepatch)]`S-tracking-perma-unstableStatus: The feature will stay unstable indefinitely.Status: The feature will stay unstable indefinitely.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
Tracking issue for rust-lang/rfcs#1327
- Allow attributes on lifetime/type formal parameters (
generic_param_attrsfeature): Attributes on generic formals #34764 - Add
#[may_dangle]attribute for lifetime/type formal parameters onunsafe impl<...> Drop(dropck_eyepatchfeature) - Replace uses of
#[unsafe_destructor_blind_to_params]attribute in libstd with#[may_dangle]Replace uses of#[unsafe_destructor_blind_to_params]with#[may_dangle]#38664 - Update nomicon to use
#[may_dangle]instead of#[unsafe_destructor_blind_to_params]Update nomicon to describe#[may_dangle]#39196 - Remove support for
#[unsafe_destructor_blind_to_params]attribute (with warning cycle before removal).- Deprecated in Deprecate
#[unsafe_destructor_blind_to_params]#38970 - need to replace remaining references (e.g. in test suite) to
#[unsafe_destructor_blind_to_params]with[may_dangle]before we can actually remove the former.
- Deprecated in Deprecate
For docs explaining the feature, also see the forge.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.Blocker: Approved by a merged RFC but not yet implemented.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-dropck_eyepatch`#![feature(dropck_eyepatch)]``#![feature(dropck_eyepatch)]`S-tracking-perma-unstableStatus: The feature will stay unstable indefinitely.Status: The feature will stay unstable indefinitely.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Activity
Rollup merge of rust-lang#34764 - pnkfelix:attrs-on-generic-formals, r=
Rollup merge of rust-lang#34764 - pnkfelix:attrs-on-generic-formals, …
pnkfelix commentedon Oct 10, 2016
see also #28498
pnkfelix commentedon Oct 26, 2016
Some people (myself included) have noted that
may_dangleis not an ideal name. (Some have gone so far as to call it "terrible".)Perhaps we could return to calling it an
eyepatch:Replace uses of `#[unsafe_destructor_blind_to_params]` with `#[may_da…
Rollup merge of rust-lang#38664 - apasel422:may-dangle, r=pnkfelix
Rollup merge of rust-lang#38664 - apasel422:may-dangle, r=pnkfelix
Rollup merge of rust-lang#38664 - apasel422:may-dangle, r=pnkfelix
42 remaining items
camsteffen commentedon Aug 8, 2022
Trivial blocker. There doesn't seem to be any restriction on where
#[may_dangle]is allowed. It is currently allowed on const params, types, statements, etc. and shouldn't be AFAICT. (playground)Manishearth commentedon Sep 23, 2022
I feel like for an unsafe escape hatch it's probably not a great idea to have a strong effect system situation? If you're using this you're already doing some unsafe tricky thing; the user is already in a situation where they can't prove safety to the compiler; asking them to prove safety seems suboptimal
I also do agree that this should be stable; being able to implement a stable
Vec<T>seems like something that rust should let you do, and there's no easy workaround to this at the moment.Manishearth commentedon Sep 23, 2022
A workaround hack that can sometimes work is taking types of the form:
and turning them into this:
and implementing
Dropon the inner type. It's more of a problem if the lifetime is really needed in your internal stuff, though.Rollup merge of rust-lang#129235 - GoldsteinE:check-may-dangle, r=com…
Rollup merge of rust-lang#129235 - GoldsteinE:check-may-dangle, r=com…
Rollup merge of rust-lang#129235 - GoldsteinE:check-may-dangle, r=com…
Unrolled build for rust-lang#129235
GoldsteinE commentedon Aug 20, 2024
Nearly five years have passed since this comment. As far as I’m aware, there’ve been no proposed solution and no goal to make one. I think it’s safe to say by this point that unless some actions are deliberately taken, the status quo will remain indefinitely.
I think this state of affairs is less than satisfactory. As of now, it’s impossible to properly implement collections outside of the standard library. This interacts poorly with std’s (completely reasonable) desire to remain lean and leave more complex features to the ecosystem. For example, #56167 was recently closed because one can just use hashbrown, but hashbrown can’t provide a proper dropck interaction on stable. You need to choose between accurate dropck and advanced collection features.
I don’t think blocking this on figuring out effect system, a massive feature that’s not really planned, is reasonable. A different syntax (e.g.
whereclause instead of an attribute) doesn’t need to block stabilization of this one — a lot of features changed syntax over time, e.g.try!()or recentlyaddr_of!(), and it’s usually not a big deal.I think it’s time to at least reevaluate the decision to leave this perma-unstable (even if it results in “yes, we’re leaving this perma-unstable because {reasons}” from T-lang). For what it’s worth, I fixed the technical blocker highlighted by @camsteffen.
GoldsteinE commentedon Sep 1, 2024
I chatted in Zulip for a bit, so here’s the status of this as I understood it.
The current version of
#[may_dangle]will not be stabilized as it’s too error-prone. There’re some proposals for a different semantics, most notably rust-lang/rfcs#3417, but they’re kinda stalled. lcnr, who is the author of that one, said:I’m not totally sure, but as far as I understand it means it’s blocked on t-lang.
Here’re the Zulip threads:
RalfJung commentedon Sep 1, 2024
It's not fully blocked on t-lang -- it needs someone who's taking over that PR to suggest and explain the idea to t-lang.
However, before doing that it'd probably be good to ask for a t-lang liaison to ensure the team has the bandwidth to consider the proposal.
Zoxc commentedon May 7, 2026
I would like
unsafe(may_dangle)so it could be used withcfg_attr!to avoid duplicating drop impls for crates with a nightly feature.