Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5621173
Reorder keywords to place restrictions next to visibility
CoCo-Japan-pan Apr 18, 2026
5d8a297
Update `rustfmt`
CoCo-Japan-pan Apr 18, 2026
a0b8e89
Update AST pretty printing
CoCo-Japan-pan Apr 18, 2026
614994f
Update HIR pretty printing
CoCo-Japan-pan Apr 18, 2026
0e6efe5
Update UI tests
CoCo-Japan-pan Apr 18, 2026
ffcbfc1
Use singular wording for single _ placeholders in type suggestions
cijiugechu Apr 20, 2026
470e462
Rule out `const unsafe impl` from `FnHeader` to
CoCo-Japan-pan Apr 21, 2026
cbba81e
Add early returns in `check_trait_front_matter`
CoCo-Japan-pan Apr 21, 2026
9be8fca
Fix ICE when const closure appears inside a non-const trait method
lapla-cogito Apr 7, 2026
abd8c38
Support self ty propagation for functions in free to trait reuse
aerooneqq Apr 22, 2026
0dca307
Account for titlecase in casing lints
Jules-Bertholet Apr 18, 2026
78435a9
Remove #![allow(incomplete_features)] from delegation tests
aerooneqq Apr 23, 2026
4d2b607
Fix E0191 suggestion for empty dyn trait args
qaijuang Apr 23, 2026
359910e
Remove `AttributeLintKind::MalformedDoc` variant
GuillaumeGomez Apr 22, 2026
af3652c
Remove `AttributeLintKind::ExpectedNoArgs` variant
GuillaumeGomez Apr 22, 2026
ad11f2e
Remove `AttributeLintKind::ExpectedNameValue` variant
GuillaumeGomez Apr 22, 2026
9bf2522
Remove `AttributeLintKind::MalFormedDiagnosticAttribute` variant
GuillaumeGomez Apr 22, 2026
eb8be4f
Remove `AttributeLintKind::MalformedDiagnosticFormat` variant
GuillaumeGomez Apr 22, 2026
f9cb684
Remove `AttributeLintKind::DiagnosticWrappedParserError` variant
GuillaumeGomez Apr 22, 2026
b716ebc
Remove `AttributeLintKind::IgnoredDiagnosticOption` variant
GuillaumeGomez Apr 22, 2026
4f4c1d5
Rollup merge of #155469 - Jules-Bertholet:titlecase-idents, r=petroch…
GuillaumeGomez Apr 23, 2026
aebbe6b
Rollup merge of #155644 - aerooneqq:delegation-self-ty-propagation-2,…
GuillaumeGomez Apr 23, 2026
0595fcd
Rollup merge of #154957 - lapla-cogito:issue_153891, r=oli-obk
GuillaumeGomez Apr 23, 2026
abce9f9
Rollup merge of #155442 - CoCo-Japan-pan:impl-restriction-reorder, r=…
GuillaumeGomez Apr 23, 2026
8c3864b
Rollup merge of #155561 - cijiugechu:fix/need-type-info-underscore-wo…
GuillaumeGomez Apr 23, 2026
8a4df77
Rollup merge of #155637 - qaijuang:fix-e0191-empty-dyn-trait-suggesti…
GuillaumeGomez Apr 23, 2026
0a4e73e
Rollup merge of #155661 - GuillaumeGomez:rm-attributelintkind, r=Jona…
GuillaumeGomez Apr 23, 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
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3786,10 +3786,10 @@ pub struct TraitAlias {

#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
pub struct Trait {
pub impl_restriction: ImplRestriction,
pub constness: Const,
pub safety: Safety,
pub is_auto: IsAuto,
pub impl_restriction: ImplRestriction,
pub ident: Ident,
pub generics: Generics,
#[visitable(extra = BoundKind::SuperTraits)]
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {

let (param_count, c_variadic) = self.param_count(sig_id);

let mut generics = self.uplift_delegation_generics(delegation, sig_id, item_id);
let mut generics =
self.uplift_delegation_generics(delegation, sig_id, item_id, is_method);

let body_id = self.lower_delegation_body(
delegation,
Expand Down Expand Up @@ -301,6 +302,8 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
hir::InferDelegationSig::Output(self.arena.alloc(hir::DelegationGenerics {
child_args_segment_id: generics.child.args_segment_id,
parent_args_segment_id: generics.parent.args_segment_id,
self_ty_id: generics.self_ty_id,
propagate_self_ty: generics.propagate_self_ty,
})),
)),
span,
Expand Down Expand Up @@ -554,6 +557,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
}
};

generics.self_ty_id = match new_path {
hir::QPath::Resolved(ty, _) => ty,
hir::QPath::TypeRelative(ty, _) => Some(ty),
}
.map(|ty| ty.hir_id);

let callee_path = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(new_path), span));
self.arena.alloc(self.mk_expr(hir::ExprKind::Call(callee_path, args), span))
};
Expand Down
15 changes: 13 additions & 2 deletions compiler/rustc_ast_lowering/src/delegation/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub(super) struct GenericsGenerationResult<'hir> {
pub(super) struct GenericsGenerationResults<'hir> {
pub(super) parent: GenericsGenerationResult<'hir>,
pub(super) child: GenericsGenerationResult<'hir>,
pub(super) self_ty_id: Option<HirId>,
pub(super) propagate_self_ty: bool,
}

pub(super) struct GenericArgsPropagationDetails {
Expand Down Expand Up @@ -209,6 +211,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
delegation: &Delegation,
sig_id: DefId,
item_id: NodeId,
is_method: bool,
) -> GenericsGenerationResults<'hir> {
let delegation_parent_kind =
self.tcx.def_kind(self.tcx.local_parent(self.local_def_id(item_id)));
Expand All @@ -230,21 +233,27 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
let child = DelegationGenerics::trait_impl(sig_params, child_user_specified);
let child = GenericsGenerationResult::new(child);

return GenericsGenerationResults { parent, child };
return GenericsGenerationResults {
parent,
child,
self_ty_id: None,
propagate_self_ty: false,
};
}

let delegation_in_free_ctx =
!matches!(delegation_parent_kind, DefKind::Trait | DefKind::Impl { .. });

let sig_parent = self.tcx.parent(sig_id);
let sig_in_trait = matches!(self.tcx.def_kind(sig_parent), DefKind::Trait);
let free_to_trait_delegation = delegation_in_free_ctx && sig_in_trait;
let generate_self = free_to_trait_delegation && is_method && delegation.qself.is_none();

let can_add_generics_to_parent = len >= 2
&& self.get_resolution_id(segments[len - 2].id).is_some_and(|def_id| {
matches!(self.tcx.def_kind(def_id), DefKind::Trait | DefKind::TraitAlias)
});

let generate_self = delegation_in_free_ctx && sig_in_trait;
let parent_generics = if can_add_generics_to_parent {
let sig_parent_params = &self.tcx.generics_of(sig_parent).own_params[..];

Expand Down Expand Up @@ -278,6 +287,8 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
GenericsGenerationResults {
parent: GenericsGenerationResult::new(parent_generics),
child: GenericsGenerationResult::new(child_generics),
self_ty_id: None,
propagate_self_ty: free_to_trait_delegation && !generate_self,
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
})
}
ItemKind::Trait(box Trait {
impl_restriction,
constness,
is_auto,
safety,
impl_restriction,
ident,
generics,
bounds,
Expand All @@ -586,10 +586,10 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
},
);
hir::ItemKind::Trait(
impl_restriction,
constness,
*is_auto,
safety,
impl_restriction,
ident,
generics,
bounds,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,21 @@ impl<'a> State<'a> {
self.bclose(item.span, empty, cb);
}
ast::ItemKind::Trait(box ast::Trait {
impl_restriction,
constness,
safety,
is_auto,
impl_restriction,
ident,
generics,
bounds,
items,
}) => {
let (cb, ib) = self.head("");
self.print_visibility(&item.vis);
self.print_impl_restriction(impl_restriction);
self.print_constness(*constness);
self.print_safety(*safety);
self.print_is_auto(*is_auto);
self.print_impl_restriction(impl_restriction);
self.word_nbsp("trait");
self.print_ident(*ident);
self.print_generic_params(&generics.params);
Expand Down
78 changes: 51 additions & 27 deletions compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Range;

use rustc_errors::E0232;
use rustc_errors::{Diagnostic, E0232};
use rustc_hir::AttrPath;
use rustc_hir::attrs::diagnostic::{
Directive, FilterFormatString, Flag, FormatArg, FormatString, LitOrArg, Name, NameValue,
Expand All @@ -18,6 +18,10 @@ use rustc_span::{Ident, InnerSpan, Span, Symbol, kw, sym};
use thin_vec::{ThinVec, thin_vec};

use crate::context::{AcceptContext, Stage};
use crate::errors::{
DisallowedPlaceholder, DisallowedPositionalArgument, IgnoredDiagnosticOption,
InvalidFormatSpecifier, MalFormedDiagnosticAttributeLint, WrappedParserError,
};
use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser};

pub(crate) mod do_not_recommend;
Expand Down Expand Up @@ -112,12 +116,12 @@ fn merge<T, S: Stage>(
match (first, later) {
(Some(_) | None, None) => {}
(Some((first_span, _)), Some((later_span, _))) => {
cx.emit_lint(
let first_span = *first_span;
cx.emit_dyn_lint(
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
AttributeLintKind::IgnoredDiagnosticOption {
first_span: *first_span,
later_span,
option_name,
move |dcx, level| {
IgnoredDiagnosticOption { first_span, later_span, option_name }
.into_diag(dcx, level)
},
later_span,
);
Expand Down Expand Up @@ -157,12 +161,15 @@ fn parse_list<'p, S: Stage>(
);
}
ArgParser::NameValue(_) => {
cx.emit_lint(
cx.emit_dyn_lint(
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
AttributeLintKind::MalFormedDiagnosticAttribute {
attribute: mode.as_str(),
options: mode.allowed_options(),
span,
move |dcx, level| {
MalFormedDiagnosticAttributeLint {
attribute: mode.as_str(),
options: mode.allowed_options(),
span,
}
.into_diag(dcx, level)
},
span,
);
Expand All @@ -188,12 +195,15 @@ fn parse_directive_items<'p, S: Stage>(
let span = item.span();

macro malformed() {{
cx.emit_lint(
cx.emit_dyn_lint(
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
AttributeLintKind::MalFormedDiagnosticAttribute {
attribute: mode.as_str(),
options: mode.allowed_options(),
span,
move |dcx, level| {
MalFormedDiagnosticAttributeLint {
attribute: mode.as_str(),
options: mode.allowed_options(),
span,
}
.into_diag(dcx, level)
},
span,
);
Expand All @@ -210,13 +220,14 @@ fn parse_directive_items<'p, S: Stage>(
}}

macro duplicate($name: ident, $($first_span:tt)*) {{
cx.emit_lint(
let first_span = $($first_span)*;
cx.emit_dyn_lint(
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
AttributeLintKind::IgnoredDiagnosticOption {
first_span: $($first_span)*,
move |dcx, level| IgnoredDiagnosticOption {
first_span,
later_span: span,
option_name: $name,
},
}.into_diag(dcx, level),
span,
);
}}
Expand Down Expand Up @@ -245,22 +256,35 @@ fn parse_directive_items<'p, S: Stage>(
let (FormatWarning::InvalidSpecifier { span, .. }
| FormatWarning::PositionalArgument { span, .. }
| FormatWarning::DisallowedPlaceholder { span }) = warning;
cx.emit_lint(
cx.emit_dyn_lint(
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
AttributeLintKind::MalformedDiagnosticFormat { warning },
move |dcx, level| match warning {
FormatWarning::PositionalArgument { .. } => {
DisallowedPositionalArgument.into_diag(dcx, level)
}
FormatWarning::InvalidSpecifier { .. } => {
InvalidFormatSpecifier.into_diag(dcx, level)
}
FormatWarning::DisallowedPlaceholder { .. } => {
DisallowedPlaceholder.into_diag(dcx, level)
}
},
span,
);
}

f
}
Err(e) => {
cx.emit_lint(
cx.emit_dyn_lint(
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
AttributeLintKind::DiagnosticWrappedParserError {
description: e.description,
label: e.label,
span: slice_span(input.span, e.span, is_snippet),
move |dcx, level| {
WrappedParserError {
description: &e.description,
label: &e.label,
span: slice_span(input.span, e.span.clone(), is_snippet),
}
.into_diag(dcx, level)
},
input.span,
);
Expand Down
28 changes: 14 additions & 14 deletions compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc_hir::Target;
use rustc_hir::attrs::{
AttributeKind, CfgEntry, CfgHideShow, CfgInfo, DocAttribute, DocInline, HideOrShow,
};
use rustc_hir::lints::AttributeLintKind;
use rustc_session::parse::feature_err;
use rustc_span::{Span, Symbol, edition, sym};
use thin_vec::ThinVec;
Expand All @@ -17,7 +16,8 @@ use crate::errors::{
AttrCrateLevelOnly, DocAliasDuplicated, DocAutoCfgExpectsHideOrShow,
DocAutoCfgHideShowExpectsList, DocAutoCfgHideShowUnexpectedItem, DocAutoCfgWrongLiteral,
DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude,
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, IllFormedAttributeInput,
DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, ExpectedNameValue, ExpectedNoArgs,
IllFormedAttributeInput, MalformedDoc,
};
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
use crate::session_diagnostics::{
Expand Down Expand Up @@ -84,18 +84,18 @@ fn expected_name_value<S: Stage>(
span: Span,
_name: Option<Symbol>,
) {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::ExpectedNameValue,
|dcx, level| ExpectedNameValue.into_diag(dcx, level),
span,
);
}

// FIXME: remove this method once merged and use `cx.expected_no_args(span)` instead.
fn expected_no_args<S: Stage>(cx: &mut AcceptContext<'_, '_, S>, span: Span) {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::ExpectedNoArgs,
|dcx, level| ExpectedNoArgs.into_diag(dcx, level),
span,
);
}
Expand All @@ -107,9 +107,9 @@ fn expected_string_literal<S: Stage>(
span: Span,
_actual_literal: Option<&MetaItemLit>,
) {
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::MalformedDoc,
|dcx, level| MalformedDoc.into_diag(dcx, level),
span,
);
}
Expand Down Expand Up @@ -203,9 +203,9 @@ impl DocParser {
// FIXME: remove this method once merged and uncomment the line below instead.
// cx.expected_list(cx.attr_span, args);
let span = cx.attr_span;
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::MalformedDoc,
|dcx, level| MalformedDoc.into_diag(dcx, level),
span,
);
return;
Expand Down Expand Up @@ -399,9 +399,9 @@ impl DocParser {
// FIXME: remove this method once merged and uncomment the line
// below instead.
// cx.expected_identifier(sub_item.path().span());
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::MalformedDoc,
|dcx, level| MalformedDoc.into_diag(dcx, level),
sub_item.path().span(),
);
continue;
Expand Down Expand Up @@ -605,9 +605,9 @@ impl DocParser {
// FIXME: remove this method once merged and uncomment the line
// below instead.
// cx.unexpected_literal(lit.span);
cx.emit_lint(
cx.emit_dyn_lint(
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
AttributeLintKind::MalformedDoc,
|dcx, level| MalformedDoc.into_diag(dcx, level),
lit.span,
);
}
Expand Down
Loading
Loading