Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3730,6 +3730,7 @@ impl Item {
| ItemKind::Union(_, generics, _) => Some(&generics),
ItemKind::Trait(i) => Some(&i.generics),
ItemKind::Impl(i) => Some(&i.generics),
ItemKind::AutoImplTrait(i) => Some(&i.generics),
}
}
}
Expand Down Expand Up @@ -3885,6 +3886,24 @@ pub struct TraitImplHeader {
pub trait_ref: TraitRef,
}

/// A supertrait auto-implementation declaration.
///
/// E.g., `auto impl Super for trait Sub {}` or
/// `unsafe auto impl Super for trait Sub { type Assoc = u8; }`
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct AutoImplTrait {
/// The safety of this auto impl (`unsafe auto impl ...`)
pub safety: Safety,
/// Generics on the auto impl (reserved for future use)
pub generics: Generics,
/// The supertrait being auto-implemented (e.g., `Super`)
pub trait_ref: TraitRef,
/// The subtrait this auto impl belongs to (e.g., `Sub` in `for trait Sub`)
pub for_trait: Ident,
/// The items inside the auto impl block (associated item defaults)
pub items: ThinVec<Box<AssocItem>>,
}

#[derive(Clone, Encodable, Decodable, Debug, Default, Walkable)]
pub struct FnContract {
/// Declarations of variables accessible both in the `requires` and
Expand Down Expand Up @@ -4113,6 +4132,10 @@ pub enum ItemKind {
///
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
Impl(Impl),
/// A supertrait auto-implementation.
///
/// E.g., `auto impl Super for trait Sub { .. }`.
AutoImplTrait(Box<AutoImplTrait>),
/// A macro invocation.
///
/// E.g., `foo!(..)`.
Expand Down Expand Up @@ -4151,6 +4174,7 @@ impl ItemKind {
| ItemKind::ForeignMod(_)
| ItemKind::GlobalAsm(_)
| ItemKind::Impl(_)
| ItemKind::AutoImplTrait(_)
| ItemKind::MacCall(_)
| ItemKind::DelegationMac(_) => None,
}
Expand All @@ -4163,7 +4187,8 @@ impl ItemKind {
Use(..) | Static(..) | Const(..) | ConstBlock(..) | Fn(..) | Mod(..)
| GlobalAsm(..) | TyAlias(..) | Struct(..) | Union(..) | Trait(..) | TraitAlias(..)
| MacroDef(..) | Delegation(..) | DelegationMac(..) => "a",
ExternCrate(..) | ForeignMod(..) | MacCall(..) | Enum(..) | Impl { .. } => "an",
ExternCrate(..) | ForeignMod(..) | MacCall(..) | Enum(..) | Impl { .. }
| AutoImplTrait(..) => "an",
}
}

Expand All @@ -4187,6 +4212,7 @@ impl ItemKind {
ItemKind::MacCall(..) => "item macro invocation",
ItemKind::MacroDef(..) => "macro definition",
ItemKind::Impl { .. } => "implementation",
ItemKind::AutoImplTrait(..) => "supertrait auto implementation",
ItemKind::Delegation(..) => "delegated function",
ItemKind::DelegationMac(..) => "delegation",
}
Expand All @@ -4202,7 +4228,8 @@ impl ItemKind {
| Self::Union(_, generics, _)
| Self::Trait(Trait { generics, .. })
| Self::TraitAlias(TraitAlias { generics, .. })
| Self::Impl(Impl { generics, .. }) => Some(generics),
| Self::Impl(Impl { generics, .. })
| Self::AutoImplTrait(AutoImplTrait { generics, .. }) => Some(generics),

Self::ExternCrate(..)
| Self::Use(..)
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ macro_rules! common_visitor_and_walkers {
AsmMacro,
AssignOpKind,
AssocItemConstraintKind,
AutoImplTrait,
AttrArgs,
AttrItem,
AttrKind,
Expand Down Expand Up @@ -849,6 +850,8 @@ macro_rules! common_visitor_and_walkers {
visit_visitable!($($mut)? vis, ident, generics, variant_data),
ItemKind::Impl(impl_) =>
visit_visitable!($($mut)? vis, impl_),
ItemKind::AutoImplTrait(auto_impl) =>
visit_visitable!($($mut)? vis, auto_impl),
ItemKind::Trait(trait_) =>
visit_visitable!($($mut)? vis, trait_),
ItemKind::TraitAlias(TraitAlias { constness, ident, generics, bounds}) => {
Expand Down Expand Up @@ -958,6 +961,13 @@ macro_rules! common_visitor_and_walkers {
V::Result::output()
});

impl_walkable!(|&$($mut)? $($lt)? self: AutoImplTrait, vis: &mut V| {
let AutoImplTrait { safety, generics, trait_ref, for_trait, items } = self;
visit_visitable!($($mut)? vis, safety, generics, trait_ref, for_trait);
visit_visitable_with!($($mut)? vis, items, AssocCtxt::Impl { of_trait: true });
V::Result::output()
});

// Special case to call `visit_method_receiver_expr`.
impl_walkable!(|&$($mut)? $($lt)? self: MethodCall, vis: &mut V| {
let MethodCall { seg, receiver, args, span } = self;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(return_type_notation, "return type notation is experimental");
gate_all!(splat, "`fn(#[splat] (a, ...))` is incomplete", "call as func((a, ...)) instead");
gate_all!(super_let, "`super let` is experimental");
gate_all!(supertrait_auto_impl, "`auto impl` syntax is experimental");
gate_all!(try_blocks_heterogeneous, "`try bikeshed` expression is experimental");
gate_all!(unnamed_enum_variants, "unnamed enum variants are experimental");
gate_all!(unsafe_binders, "unsafe binder types are experimental");
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ declare_features! (
(unstable, strict_provenance_lints, "1.61.0", Some(130351)),
/// Allows `super let` statements.
(unstable, super_let, "1.88.0", Some(139076)),
/// Allows `auto impl Supertrait for trait Subtrait { .. }`.
(unstable, supertrait_auto_impl, "CURRENT_RUSTC_VERSION", Some(149556)),
/// Allows subtrait items to shadow supertrait items.
(unstable, supertrait_item_shadowing, "1.86.0", Some(89151)),
/// Allows using `#[thread_local]` on `static` items.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,7 @@ symbols! {
sub_with_overflow,
suggestion,
super_let,
supertrait_auto_impl,
supertrait_item_shadowing,
sve_cast,
sve_tuple_create2,
Expand Down
Loading