Skip to content

Commit 7b2fc7c

Browse files
committed
Auto merge of rust-lang#128440 - oli-obk:defines, r=lcnr
Add `#[define_opaques]` attribute and require it for all type-alias-impl-trait sites that register a hidden type Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed. A previous version of this PR used an actual attribute, but had to keep the resolved `DefId`s in a side table. Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable. Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems `#[defines()]` can be used to overwrite the default of searching for opaques in the signature. One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I would need to add a custom field to closures and statics to track this information. During a T-types discussion we decided to just not do this for now. fixes rust-lang#131298
2 parents 7dfdb32 + 065a29b commit 7b2fc7c

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

core/src/macros/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,21 @@ pub(crate) mod builtin {
17431743
/* compiler built-in */
17441744
}
17451745

1746+
/// Provide a list of type aliases and other opaque-type-containing type definitions.
1747+
/// This list will be used in the body of the item it is applied to to define opaque
1748+
/// types' hidden types.
1749+
/// Can only be applied to things that have bodies.
1750+
#[unstable(
1751+
feature = "type_alias_impl_trait",
1752+
issue = "63063",
1753+
reason = "`type_alias_impl_trait` has open design concerns"
1754+
)]
1755+
#[rustc_builtin_macro]
1756+
#[cfg(not(bootstrap))]
1757+
pub macro define_opaque($($tt:tt)*) {
1758+
/* compiler built-in */
1759+
}
1760+
17461761
/// Unstable placeholder for type ascription.
17471762
#[allow_internal_unstable(builtin_syntax)]
17481763
#[unstable(

core/src/prelude/v1.rs

+8
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,11 @@ pub use crate::macros::builtin::type_ascribe;
111111
reason = "placeholder syntax for deref patterns"
112112
)]
113113
pub use crate::macros::builtin::deref;
114+
115+
#[unstable(
116+
feature = "type_alias_impl_trait",
117+
issue = "63063",
118+
reason = "`type_alias_impl_trait` has open design concerns"
119+
)]
120+
#[cfg(not(bootstrap))]
121+
pub use crate::macros::builtin::define_opaque;

std/src/backtrace.rs

+1
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ mod helper {
432432
use super::*;
433433
pub(super) type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe;
434434

435+
#[cfg_attr(not(bootstrap), define_opaque(LazyResolve))]
435436
pub(super) fn lazy_resolve(mut capture: Capture) -> LazyResolve {
436437
move || {
437438
// Use the global backtrace lock to synchronize this as it's a

std/src/prelude/v1.rs

+9
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ pub use core::prelude::v1::type_ascribe;
103103
)]
104104
pub use core::prelude::v1::deref;
105105

106+
// Do not `doc(no_inline)` either.
107+
#[unstable(
108+
feature = "type_alias_impl_trait",
109+
issue = "63063",
110+
reason = "`type_alias_impl_trait` has open design concerns"
111+
)]
112+
#[cfg(not(bootstrap))]
113+
pub use core::prelude::v1::define_opaque;
114+
106115
// The file so far is equivalent to core/src/prelude/v1.rs. It is duplicated
107116
// rather than glob imported because we want docs to show these re-exports as
108117
// pointing to within `std`.

0 commit comments

Comments
 (0)