Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d3a782d
Partially stabilize LoongArch target features
heiher Mar 27, 2026
510f709
rustc_public: implement `Pattern` type
makai410 Apr 19, 2026
dface0a
Fix ICE: Scalar layout for non-primitive non-enum type unsafe binder
cijiugechu Apr 21, 2026
9515f52
Change `ItemKind::Trait` to have named fields.
mejrs Apr 24, 2026
33a1ed1
disallow non_exhaustive structs and enums with non_exhaustive variant…
zedddie Apr 20, 2026
d5a26d8
Support trailing self in import paths
mu001999 Apr 11, 2026
4467940
Support trailing self in normal paths
mu001999 Apr 11, 2026
8b584eb
Remove type_ns_only
mu001999 Apr 11, 2026
ddb2721
Add test for middle self
mu001999 Apr 13, 2026
d93395c
Remove the special case of ::self after edition 2018
mu001999 Apr 13, 2026
7616881
Avoid misleading closure return type note
chenyukang Apr 27, 2026
57008e9
CI: rfl: move job forward to Linux v7.1-rc1
ojeda Apr 26, 2026
e8243d2
Rollup merge of #154510 - heiher:stabilize-loongarch-target-features,…
JonathanBrouwer Apr 27, 2026
56c2ab6
Rollup merge of #155137 - mu001999-contrib:self-at-end, r=petrochenkov
JonathanBrouwer Apr 27, 2026
8a0ee88
Rollup merge of #155513 - makai410:rpub-pat, r=celinval
JonathanBrouwer Apr 27, 2026
e8ad7f2
Rollup merge of #155702 - mejrs:itemkind_trait-fields, r=petrochenkov
JonathanBrouwer Apr 27, 2026
e683a17
Rollup merge of #154896 - cijiugechu:fix-unsafe-binder-layout-ice, r=…
JonathanBrouwer Apr 27, 2026
76a502d
Rollup merge of #155675 - zedddie:disallow-non_exhaustive-adt-const-p…
JonathanBrouwer Apr 27, 2026
3a532d6
Rollup merge of #155874 - chenyukang:yukang-fix-155770-return-note-in…
JonathanBrouwer Apr 27, 2026
5a87e1c
Rollup merge of #155876 - ojeda:rfl, r=lqd
JonathanBrouwer Apr 27, 2026
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
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,16 +569,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
(safety, items, bounds)
},
);
hir::ItemKind::Trait(
hir::ItemKind::Trait {
impl_restriction,
constness,
*is_auto,
is_auto: *is_auto,
safety,
ident,
generics,
bounds,
items,
)
}
}
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
let constness = self.lower_constness(*constness);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0429.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#### Note: this error code is no longer emitted by the compiler.

The `self` keyword cannot appear alone as the last segment in a `use`
declaration.

Erroneous code example:

```compile_fail,E0429
```ignore (error is no longer emitted)
use std::fmt::self; // error: `self` imports are only allowed within a { } list
```

Expand Down
26 changes: 13 additions & 13 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4467,7 +4467,7 @@ impl<'hir> Item<'hir> {
GenericBounds<'hir>,
&'hir [TraitItemId]
),
ItemKind::Trait(impl_restriction, constness, is_auto, safety, ident, generics, bounds, items),
ItemKind::Trait { impl_restriction, constness, is_auto, safety, ident, generics, bounds, items },
(impl_restriction, *constness, *is_auto, *safety, *ident, generics, bounds, items);

expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
Expand Down Expand Up @@ -4659,16 +4659,16 @@ pub enum ItemKind<'hir> {
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
/// A trait definition.
Trait(
&'hir ImplRestriction<'hir>,
Constness,
IsAuto,
Safety,
Ident,
&'hir Generics<'hir>,
GenericBounds<'hir>,
&'hir [TraitItemId],
),
Trait {
impl_restriction: &'hir ImplRestriction<'hir>,
constness: Constness,
is_auto: IsAuto,
safety: Safety,
ident: Ident,
generics: &'hir Generics<'hir>,
bounds: GenericBounds<'hir>,
items: &'hir [TraitItemId],
},
/// A trait alias.
TraitAlias(Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),

Expand Down Expand Up @@ -4714,7 +4714,7 @@ impl ItemKind<'_> {
| ItemKind::Enum(ident, ..)
| ItemKind::Struct(ident, ..)
| ItemKind::Union(ident, ..)
| ItemKind::Trait(_, _, _, _, ident, ..)
| ItemKind::Trait { ident, .. }
| ItemKind::TraitAlias(_, ident, ..) => Some(ident),

ItemKind::Use(_, UseKind::Glob | UseKind::ListStem)
Expand All @@ -4732,7 +4732,7 @@ impl ItemKind<'_> {
| ItemKind::Enum(_, generics, _)
| ItemKind::Struct(_, generics, _)
| ItemKind::Union(_, generics, _)
| ItemKind::Trait(_, _, _, _, _, generics, _, _)
| ItemKind::Trait { generics, .. }
| ItemKind::TraitAlias(_, _, generics, _)
| ItemKind::Impl(Impl { generics, .. }) => generics,
_ => return None,
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,16 +618,16 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
try_visit!(visitor.visit_generics(generics));
try_visit!(visitor.visit_variant_data(struct_definition));
}
ItemKind::Trait(
ref impl_restriction,
_constness,
_is_auto,
_safety,
ItemKind::Trait {
impl_restriction,
constness: _,
is_auto: _,
safety: _,
ident,
ref generics,
generics,
bounds,
trait_item_refs,
) => {
items: trait_item_refs,
} => {
if let RestrictionKind::Restricted(path) = &impl_restriction.kind {
walk_list!(visitor, visit_path_segment, path.segments);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Target {
ItemKind::Enum(..) => Target::Enum,
ItemKind::Struct(..) => Target::Struct,
ItemKind::Union(..) => Target::Union,
ItemKind::Trait(..) => Target::Trait,
ItemKind::Trait { .. } => Target::Trait,
ItemKind::TraitAlias(..) => Target::TraitAlias,
ItemKind::Impl(imp_) => Target::Impl { of_trait: imp_.of_trait.is_some() },
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ pub(super) fn check_item<'tcx>(
hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false),
hir::ItemKind::Union(..) => check_type_defn(tcx, item, true),
hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true),
hir::ItemKind::Trait(..) => check_trait(tcx, item),
hir::ItemKind::Trait { .. } => check_trait(tcx, item),
hir::ItemKind::TraitAlias(..) => check_trait(tcx, item),
_ => Ok(()),
}
Expand Down Expand Up @@ -911,6 +911,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er
// Can never implement `ConstParamTy`, don't suggest anything.
Err(
ConstParamTyImplementationError::NotAnAdtOrBuiltinAllowed
| ConstParamTyImplementationError::NonExhaustive(..)
| ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(..),
) => None,
Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired) => {
Expand Down Expand Up @@ -1188,7 +1189,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
});

// Only check traits, don't check trait aliases
if let hir::ItemKind::Trait(..) = item.kind {
if let hir::ItemKind::Trait { .. } = item.kind {
check_gat_where_clauses(tcx, item.owner_id.def_id);
}
res
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E
let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span;
Err(tcx.dcx().emit_err(errors::ConstParamTyImplOnNonAdt { span }))
}
Err(ConstParamTyImplementationError::NonExhaustive(attr_span)) => {
let defn_span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span;
Err(tcx
.dcx()
.emit_err(errors::ConstParamTyImplOnNonExhaustive { defn_span, attr_span }))
}
Err(ConstParamTyImplementationError::InvalidInnerTyOfBuiltinTy(infringing_tys)) => {
let span = tcx.hir_expect_item(impl_did).expect_impl().self_ty.span;
Err(infringing_fields_error(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
let item = tcx.hir_expect_item(def_id);

let (constness, is_alias, is_auto, safety, impl_restriction) = match item.kind {
hir::ItemKind::Trait(impl_restriction, constness, is_auto, safety, ..) => (
hir::ItemKind::Trait { impl_restriction, constness, is_auto, safety, .. } => (
constness,
false,
is_auto == hir::IsAuto::Yes,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {

// Add in the self type parameter.
let opt_self = if let Node::Item(item) = node
&& let ItemKind::Trait(..) | ItemKind::TraitAlias(..) = item.kind
&& let ItemKind::Trait { .. } | ItemKind::TraitAlias(..) = item.kind
{
// Something of a hack: We reuse the node ID of the trait for the self type parameter.
Some(ty::GenericParamDef {
Expand Down Expand Up @@ -402,7 +402,7 @@ fn param_default_policy(node: Node<'_>) -> Option<ParamDefaultPolicy> {

Some(match node {
Node::Item(item) => match item.kind {
ItemKind::Trait(..)
ItemKind::Trait { .. }
| ItemKind::TraitAlias(..)
| ItemKind::TyAlias(..)
| ItemKind::Enum(..)
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
));
}
}
ItemKind::Trait(_, _, _, _, _, _, self_bounds, ..)
ItemKind::Trait { bounds: self_bounds, .. }
| ItemKind::TraitAlias(_, _, _, self_bounds) => {
is_trait = Some((self_bounds, item.span));
}
Expand Down Expand Up @@ -669,7 +669,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
};

let (generics, superbounds) = match item.kind {
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
hir::ItemKind::Trait { generics, bounds: supertraits, .. } => (generics, supertraits),
hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits),
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
};
Expand Down Expand Up @@ -934,7 +934,7 @@ pub(super) fn type_param_predicates<'tcx>(
};

if let Node::Item(item) = hir_node
&& let hir::ItemKind::Trait(..) = item.kind
&& let hir::ItemKind::Trait { .. } = item.kind
// Implied `Self: Trait` and supertrait bounds.
&& param_id == item_hir_id
{
Expand Down Expand Up @@ -1073,7 +1073,7 @@ pub(super) fn const_conditions<'tcx>(
Node::Item(item) => match item.kind {
hir::ItemKind::Impl(impl_) => (impl_.generics, None, false),
hir::ItemKind::Fn { generics, .. } => (generics, None, false),
hir::ItemKind::Trait(_, _, _, _, _, generics, supertraits, _) => {
hir::ItemKind::Trait { generics, bounds: supertraits, .. } => {
(generics, Some((Some(item.owner_id.def_id), supertraits)), false)
}
hir::ItemKind::TraitAlias(_, _, generics, supertraits) => {
Expand Down Expand Up @@ -1194,7 +1194,7 @@ pub(super) fn explicit_implied_const_bounds<'tcx>(
}
None => match tcx.hir_node_by_def_id(def_id) {
Node::Item(hir::Item {
kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..),
kind: hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..),
..
}) => implied_predicates_with_filter(
tcx,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
| hir::ItemKind::Enum(_, generics, _)
| hir::ItemKind::Struct(_, generics, _)
| hir::ItemKind::Union(_, generics, _)
| hir::ItemKind::Trait(_, _, _, _, _, generics, ..)
| hir::ItemKind::Trait { generics, .. }
| hir::ItemKind::TraitAlias(_, _, generics, ..)
| hir::ItemKind::Impl(hir::Impl { generics, .. }) => {
// These kinds of items have only early-bound lifetime parameters.
Expand Down Expand Up @@ -2258,7 +2258,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
// we already do that in `BoundVarContext::supertrait_hrtb_vars`.
if let Res::SelfTyParam { trait_: _ } = expected_res
&& let hir::Node::Item(item) = node
&& let hir::ItemKind::Trait(..) = item.kind
&& let hir::ItemKind::Trait { .. } = item.kind
{
// Yield the trait's def id. Supertraits will be
// elaborated from that.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
Ty::new_adt(tcx, def, args)
}
ItemKind::GlobalAsm { .. } => tcx.typeck(def_id).node_type(hir_id),
ItemKind::Trait(..)
ItemKind::Trait { .. }
| ItemKind::TraitAlias(..)
| ItemKind::Macro(..)
| ItemKind::Mod(..)
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ pub(crate) struct ConstParamTyImplOnNonAdt {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("the trait `ConstParamTy` may not be implemented for this type")]
pub(crate) struct ConstParamTyImplOnNonExhaustive {
#[primary_span]
#[label("non exhaustive const params are forbidden")]
pub defn_span: Span,
#[label("caused by this attribute")]
pub attr_span: Span,
}

#[derive(Diagnostic)]
#[diag("the trait `ConstParamTy` may not be implemented for this struct")]
pub(crate) struct ConstParamTyFieldVisMismatch {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,16 +757,16 @@ impl<'a> State<'a> {
}
self.bclose(item.span, cb);
}
hir::ItemKind::Trait(
hir::ItemKind::Trait {
impl_restriction,
constness,
is_auto,
safety,
ident,
generics,
bounds,
trait_items,
) => {
items: trait_items,
} => {
let (cb, ib) = self.head("");
self.print_impl_restriction(impl_restriction);
self.print_constness(constness);
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,9 +1998,13 @@ impl<'tcx> CoerceMany<'tcx> {
);
}

let ret_coercion_span = fcx.ret_coercion_span.get();
let is_return_position = fcx
.tcx
.hir_get_fn_id_for_return_block(block_or_return_id)
.is_some_and(|fn_id| fn_id == fcx.tcx.local_def_id_to_hir_id(fcx.body_id));

if let Some(sp) = ret_coercion_span
if is_return_position
&& let Some(sp) = fcx.ret_coercion_span.get()
// If the closure has an explicit return type annotation, or if
// the closure's return type has been inferred from outside
// requirements (such as an Fn* trait bound), then a type error
Expand All @@ -2009,9 +2013,6 @@ impl<'tcx> CoerceMany<'tcx> {
// note in this case, since it would be incorrect.
&& let Some(fn_sig) = fcx.body_fn_sig()
&& fn_sig.output().is_ty_var()
&& fcx.ret_coercion.as_ref().is_some_and(|ret_coercion| {
fcx.resolve_vars_if_possible(ret_coercion.borrow().expected_ty()) == expected
})
{
err.span_note(sp, format!("return type inferred to be `{expected}` here"));
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
entry.1.insert((self_ty.span, String::new()));
}
Some(Node::Item(hir::Item {
kind: hir::ItemKind::Trait(_, _, rustc_ast::ast::IsAuto::Yes, ..),
kind: hir::ItemKind::Trait { is_auto: rustc_ast::ast::IsAuto::Yes, .. },
span: item_span,
..
})) => {
Expand All @@ -1979,7 +1979,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(
Node::Item(hir::Item {
kind:
hir::ItemKind::Trait(_, _, _, _, ident, ..)
hir::ItemKind::Trait { ident, .. }
| hir::ItemKind::TraitAlias(_, ident, ..),
..
})
Expand Down Expand Up @@ -4638,7 +4638,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return;
}
Node::Item(hir::Item {
kind: hir::ItemKind::Trait(_, _, _, _, ident, _, bounds, _),
kind: hir::ItemKind::Trait { ident, bounds, .. },
..
}) => {
let (sp, sep, article) = if bounds.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<'tcx> CleanVisitor<'tcx> {
HirItem::Union(..) => ("ItemUnion", LABELS_ADT),

// Represents a Trait Declaration
HirItem::Trait(..) => ("ItemTrait", LABELS_TRAIT),
HirItem::Trait { .. } => ("ItemTrait", LABELS_TRAIT),

// An implementation, eg `impl<A> Trait for Foo { .. }`
HirItem::Impl { .. } => ("ItemKind::Impl", LABELS_IMPL),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/multiple_supertrait_upcastable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable {
let def_id = item.owner_id.to_def_id();
// NOTE(nbdd0121): use `dyn_compatibility_violations` instead of `is_dyn_compatible` because
// the latter will report `where_clause_object_safety` lint.
if let hir::ItemKind::Trait(_, _, _, _, ident, ..) = item.kind
if let hir::ItemKind::Trait { ident, .. } = item.kind
&& cx.tcx.is_dyn_compatible(def_id)
{
let direct_super_traits_iter = cx
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/types/improper_ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesLint {
// Doesn't define something that can contain a external type to be checked.
hir::ItemKind::Impl(..)
| hir::ItemKind::TraitAlias(..)
| hir::ItemKind::Trait(..)
| hir::ItemKind::Trait { .. }
| hir::ItemKind::GlobalAsm { .. }
| hir::ItemKind::ForeignMod { .. }
| hir::ItemKind::Mod(..)
Expand Down
Loading
Loading