Skip to content
Closed
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
34562bb
avoid Terminator:None in mir building by using Either in the builder
panstromek Nov 7, 2026
78fda19
BPF: Define max/min atomic width per CPU version
vadorovsky Oct 30, 2026
7e4758f
Disable no_threads compiler errors for Trusty targets
randomPoison Nov 9, 2026
98c617e
Simplify logic in `warn_on_duplicate_attribute`
JonathanBrouwer Nov 10, 2026
f07a4aa
Add regression test with multiple diagnostics
JonathanBrouwer Nov 10, 2026
75ac596
Use the nicer `UnusedMultiple` diagnostic from `rustc_attr_parsing`
JonathanBrouwer Nov 10, 2026
5baf366
Support underscore as associated const name in inherent impls
makai410 Nov 10, 2026
b6f220a
Properly clear search state when sidebar link is clicked
yotamofek Nov 9, 2026
df9f646
rustdoc: Rename `--show-coverage` CLI flag into `--coverage`
GuillaumeGomez Nov 10, 2026
3e405fc
Use dist profile when benching std
adamgemmell Nov 10, 2026
f2a332d
Extract assert_terminator* functions to remove duplication at block_d…
panstromek Nov 10, 2026
e20623c
Add test for `test_case`
JonathanBrouwer Nov 10, 2026
e011db1
Rollup merge of #158970 - makai410:us-assoc-cnst, r=jackh726,fmease
JonathanBrouwer Nov 10, 2026
166cce8
Rollup merge of #165192 - vadorovsky:vad/bpf-cpu-v4, r=nagisa
JonathanBrouwer Nov 10, 2026
20ad7b1
Rollup merge of #165611 - panstromek:no-terminator-option-4, r=oli-obk
JonathanBrouwer Nov 10, 2026
607fc90
Rollup merge of #165749 - JonathanBrouwer:simplify_code, r=tmiasko
JonathanBrouwer Nov 10, 2026
22a7fac
Rollup merge of #165762 - adamgemmell:dev/adagem01/bench-library, r=K…
JonathanBrouwer Nov 10, 2026
4e43f3c
Rollup merge of #165726 - yotamofek:fix-search-button-sidebar-anchor,…
JonathanBrouwer Nov 10, 2026
9fe13b4
Rollup merge of #165728 - randomPoison:trusty-std-no-threads, r=joboet
JonathanBrouwer Nov 10, 2026
a79befd
Rollup merge of #165754 - GuillaumeGomez:rustdoc-coverage, r=Urgau
JonathanBrouwer Nov 10, 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
14 changes: 11 additions & 3 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,11 +1071,19 @@ impl<'a> AstValidator<'a> {
}
}

fn check_item_named(&self, ident: Ident, kind: &str) {
fn check_item_named(&self, ident: Ident, kind: &str, ctxt: AssocCtxt) {
if ident.name != kw::Underscore {
return;
}
self.dcx().emit_err(diagnostics::ItemUnderscore { span: ident.span, kind });

if !self.features.associated_const_underscore()
&& matches!(ctxt, AssocCtxt::Impl { of_trait: false })
{
let msg = format!("naming associated constants with `_` is unstable");
feature_err(&self.sess, sym::associated_const_underscore, ident.span, msg).emit();
} else if !matches!(ctxt, AssocCtxt::Impl { of_trait: false }) {
self.dcx().emit_err(diagnostics::ItemUnderscore { span: ident.span, kind });
}
}

fn check_nomangle_item_asciionly(&self, ident: Ident, item_span: Span) {
Expand Down Expand Up @@ -2162,7 +2170,7 @@ impl Visitor<'_> for AstValidator<'_> {
}

if let AssocItemKind::Const(ci) = &item.kind {
self.check_item_named(ci.ident, "const");
self.check_item_named(ci.ident, "const", ctxt);
}

let parent_is_const =
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,10 +1335,9 @@ pub(crate) struct UnknownVersionLiteral {
pub span: Span,
}

// FIXME(jdonszelmann) duplicated from `rustc_passes`, remove once `check_attr` is integrated.
#[derive(Diagnostic)]
#[diag("multiple `{$name}` attributes")]
pub(crate) struct UnusedMultiple {
pub struct UnusedMultiple {
#[primary_span]
#[suggestion("remove this attribute", code = "", applicability = "unspecified")]
pub this: Span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub use attributes::cfg::{
pub use attributes::cfg_select::*;
pub use attributes::util::{is_builtin_attr, parse_version};
pub use context::ShouldEmit;
pub use diagnostics::ParsedDescription;
pub use diagnostics::{ParsedDescription, UnusedMultiple};
pub use interface::{AttributeParser, EmitAttribute};
pub use rustc_parse::parser::Recovery;
pub use template::AttributeTemplate;
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute};

pub(crate) fn expand(
ecx: &mut ExtCtxt<'_>,
_span: Span,
span: Span,
meta_item: &ast::MetaItem,
annotatable: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(ecx, meta_item, sym::cfg_eval);
warn_on_duplicate_attribute(ecx, &annotatable, sym::cfg_eval);
warn_on_duplicate_attribute(ecx, &annotatable, span, sym::cfg_eval);
vec![cfg_eval(ecx.sess, ecx.ecfg.features, annotatable, ecx.current_expansion.lint_node_id)]
}

Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_builtin_macros/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ pub(crate) struct IncompleteInclude;
#[diag("cannot test inner items")]
pub(crate) struct UnnameableTestItems;

#[derive(Diagnostic)]
#[diag("duplicated attribute")]
pub(crate) struct DuplicateMacroAttribute;

#[derive(Diagnostic)]
#[diag("macro requires a cfg-pattern as an argument")]
pub(crate) struct RequiresCfgPattern {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn expand_test_case(
anno_item: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(ecx, meta_item, sym::test_case);
warn_on_duplicate_attribute(ecx, &anno_item, sym::test_case);
warn_on_duplicate_attribute(ecx, &anno_item, attr_sp, sym::test_case);

let sp = ecx.with_def_site_ctxt(attr_sp);
let (mut item, is_stmt) = match anno_item {
Expand Down Expand Up @@ -88,7 +88,7 @@ pub(crate) fn expand_test(
item: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(cx, meta_item, sym::test);
warn_on_duplicate_attribute(cx, &item, sym::test);
warn_on_duplicate_attribute(cx, &item, attr_sp, sym::test);
expand_test_or_bench(cx, attr_sp, item, false)
}

Expand All @@ -99,7 +99,7 @@ pub(crate) fn expand_bench(
item: Annotatable,
) -> Vec<Annotatable> {
check_builtin_macro_attribute(cx, meta_item, sym::bench);
warn_on_duplicate_attribute(cx, &item, sym::bench);
warn_on_duplicate_attribute(cx, &item, attr_path_sp, sym::bench);
expand_test_or_bench(cx, attr_path_sp, item, true)
}

Expand Down
51 changes: 27 additions & 24 deletions compiler/rustc_builtin_macros/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{self as ast, AttrStyle, Attribute, MetaItem, attr, token};
use rustc_attr_parsing::{AttributeTemplate, validate_attr};
use rustc_attr_parsing::{AttributeTemplate, UnusedMultiple, validate_attr};
use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt};
use rustc_expand::expand::AstFragment;
Expand All @@ -26,30 +26,33 @@ pub(crate) fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaI

/// Emit a warning if the item is annotated with the given attribute. This is used to diagnose when
/// an attribute may have been mistakenly duplicated.
pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name: Symbol) {
let attrs: Option<&[Attribute]> = match item {
Annotatable::Item(item) => Some(&item.attrs),
Annotatable::AssocItem(item, _) => Some(&item.attrs),
Annotatable::ForeignItem(item) => Some(&item.attrs),
Annotatable::Expr(expr) => Some(&expr.attrs),
Annotatable::Arm(arm) => Some(&arm.attrs),
Annotatable::ExprField(field) => Some(&field.attrs),
Annotatable::PatField(field) => Some(&field.attrs),
Annotatable::GenericParam(param) => Some(&param.attrs),
Annotatable::Param(param) => Some(&param.attrs),
Annotatable::FieldDef(def) => Some(&def.attrs),
Annotatable::Variant(variant) => Some(&variant.attrs),
_ => None,
pub(crate) fn warn_on_duplicate_attribute(
ecx: &ExtCtxt<'_>,
item: &Annotatable,
span: Span,
name: Symbol,
) {
let attrs: &[Attribute] = match item {
Annotatable::Item(item) => &item.attrs,
Annotatable::AssocItem(item, _) => &item.attrs,
Annotatable::ForeignItem(item) => &item.attrs,
Annotatable::Expr(expr) => &expr.attrs,
Annotatable::Arm(arm) => &arm.attrs,
Annotatable::ExprField(field) => &field.attrs,
Annotatable::PatField(field) => &field.attrs,
Annotatable::GenericParam(param) => &param.attrs,
Annotatable::Param(param) => &param.attrs,
Annotatable::FieldDef(def) => &def.attrs,
Annotatable::Variant(variant) => &variant.attrs,
_ => return,
};
if let Some(attrs) = attrs {
if let Some(attr) = attr::find_by_name(attrs, name) {
ecx.psess().buffer_lint(
DUPLICATE_MACRO_ATTRIBUTES,
attr.span,
ecx.current_expansion.lint_node_id,
diagnostics::DuplicateMacroAttribute,
);
}
if let Some(attr) = attr::find_by_name(attrs, name) {
ecx.psess().buffer_lint(
DUPLICATE_MACRO_ATTRIBUTES,
attr.span,
ecx.current_expansion.lint_node_id,
UnusedMultiple { this: attr.span, other: span, name },
);
}
}

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 @@ -390,6 +390,8 @@ declare_features! (
(unstable, asm_goto_with_outputs, "1.85.0", Some(119364)),
/// Allows the `may_unwind` option in inline assembly.
(unstable, asm_unwind, "1.58.0", Some(93334)),
/// Allows `_` for the name of associated constants.
(unstable, associated_const_underscore, "CURRENT_RUSTC_VERSION", Some(158944)),
/// Allows associated type defaults.
(unstable, associated_type_defaults, "1.2.0", Some(29661)),
/// Allows implementing `AsyncDrop`.
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3144,6 +3144,13 @@ impl<'hir> ImplItem<'hir> {
ImplItemId { owner_id: self.owner_id }
}

/// Returns whether this is an anonymous associated constant in an inherent impl.
pub fn is_anon_const(&self) -> bool {
matches!(self.impl_kind, ImplItemImplKind::Inherent { .. })
&& matches!(self.kind, ImplItemKind::Const(..))
&& self.ident.name == kw::Underscore
}

pub fn vis_span(&self) -> Option<Span> {
match self.impl_kind {
ImplItemImplKind::Trait { .. } => None,
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,10 @@ fn suggestion_signature<'tcx>(
);
format!("type {}{generics} = /* Type */{where_clauses};", assoc.name())
}
ty::AssocKind::Const { name, .. } => {
ty::AssocKind::Const { data: ty::AssocConstData::Anonymous } => {
panic!("anonymous associated consts shouldn't end up here")
}
ty::AssocKind::Const { data: ty::AssocConstData::Named(name) } => {
let ty = tcx.type_of(assoc.def_id).instantiate_identity().skip_norm_wip();
let val = tcx
.infer_ctxt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
std::mem::swap(&mut impl_items1, &mut impl_items2);
}

for &item1 in impl_items1.in_definition_order() {
for &item1 in impl_items1.named_items_in_definition_order() {
let collision = impl_items2
.filter_by_name_unhygienic(item1.name())
.any(|&item2| self.compare_hygienically(item1, item2));
Expand All @@ -74,7 +74,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {

let mut seen_items = FxIndexMap::default();
let mut res = Ok(());
for impl_item in impl_items.in_definition_order() {
for &impl_item in impl_items.named_items_in_definition_order() {
let span = self.tcx.def_span(impl_item.def_id);
let ident = impl_item.ident(self.tcx);

Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
let impl_items2 = self.tcx.associated_items(impl2);

let mut res = Ok(());
for &item1 in impl_items1.in_definition_order() {
for &item1 in impl_items1.named_items_in_definition_order() {
let collision = impl_items2
.filter_by_name_unhygienic(item1.name())
.find(|&&item2| self.compare_hygienically(item1, item2));
Expand Down Expand Up @@ -228,7 +228,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
// First obtain a list of existing connected region ids
let mut idents_to_add = SmallVec::<[Symbol; 8]>::new();
let mut ids = impl_items
.in_definition_order()
.named_items_in_definition_order()
.filter_map(|item| {
let entry = connected_region_ids.entry(item.name());
if let IndexEntry::Occupied(e) = &entry {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

let wider_candidate_names: Vec<_> = visible_traits
.iter()
.flat_map(|trait_def_id| tcx.associated_items(*trait_def_id).in_definition_order())
.filter_map(|item| {
(!item.is_impl_trait_in_trait() && item.tag() == assoc_tag).then(|| item.name())
.flat_map(|trait_def_id| {
tcx.associated_items(*trait_def_id).named_items_in_definition_order()
})
.filter_map(|item| (item.tag() == assoc_tag).then(|| item.name()))
.collect();

if let Some(suggested_name) =
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let Some(iterator_item_id) = tcx
.associated_items(iterator_trait_id)
.in_definition_order()
.named_items_in_definition_order()
.find(|item| item.name() == sym::Item)
.map(|item| item.def_id)
else {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,10 @@ impl<'tcx> Pick<'tcx> {
tcx.def_path_str(this.item.def_id),
));
}
(ty::AssocKind::Const { name, .. }, ty::AssocContainer::Trait) => {
(
ty::AssocKind::Const { data: ty::AssocConstData::Named(name) },
ty::AssocContainer::Trait,
) => {
let def_id = this.item.container_id(tcx);
lint.span_suggestion(
span,
Expand Down Expand Up @@ -2662,7 +2665,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
{
return true;
}

false
}

Expand All @@ -2676,7 +2678,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let max_dist = max(name.as_str().len(), 3) / 3;
self.tcx
.associated_items(def_id)
.in_definition_order()
.named_items_in_definition_order()
.filter(|x| {
if !self.is_relevant_kind_for_mode(x.kind) {
return false;
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,14 @@ impl CrateMetadata {

fn get_associated_item(&self, tcx: TyCtxt<'_>, id: DefIndex) -> ty::AssocItem {
let kind = match self.def_kind(id) {
DefKind::AssocConst => ty::AssocKind::Const { name: self.item_name(id) },
DefKind::AssocConst => {
let data = if let Some(item_name) = self.root.tables.opt_item_name.get(self, id) {
ty::AssocConstData::Named(item_name.decode((self, tcx)))
} else {
ty::AssocConstData::Anonymous
};
ty::AssocKind::Const { data }
}
DefKind::AssocFn => ty::AssocKind::Fn {
name: self.item_name(id),
has_self: self.get_fn_has_self_parameter(tcx, id),
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

self.table_writer().assoc_container(def_id, item.container);

if let Some(item_name) = item.opt_name() {
self.table_writer().opt_item_name(def_id, Some(item_name));
}

if let AssocContainer::Trait = item.container
&& item.is_type()
{
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ define_tables! {
explicit_implied_clauses_of: Table<LazyArray<(ty::Clause<'static>, Span)>>,
explicit_implied_const_bounds: Table<LazyArray<(ty::PolyTraitRef<'static>, Span)>>,
inherent_impls: Table<LazyArray<LocalDefId>>,
opt_item_name: Table<Option<LazyValue<Symbol>>>,
// Reexported names are not associated with individual `DefId`s,
// e.g. a glob import can introduce a lot of names, all with the same `DefId`.
// That's why the encoded list needs to contain `ModChild` structures describing all the names
Expand Down
Loading
Loading