Skip to content

Commit bb25654

Browse files
committed
Merge ref '7189d39d9ce9' (nightly-2026-10-23) from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Previous upstream ref: b6eeb93 New upstream ref: 7189d39 Filtered ref: rust-lang/rustc_codegen_cranelift@6efc32f Upstream diff: b6eeb93...7189d39 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents b40a816 + 7189d39 commit bb25654

1,401 files changed

Lines changed: 15954 additions & 3325 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ dependencies = [
684684
"anstream 0.6.21",
685685
"chrono",
686686
"clap",
687-
"indoc",
687+
"indoc 1.0.9",
688688
"itertools",
689689
"memchr",
690690
"opener",
@@ -1996,6 +1996,15 @@ version = "1.0.9"
19961996
source = "registry+https://github.com/rust-lang/crates.io-index"
19971997
checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306"
19981998

1999+
[[package]]
2000+
name = "indoc"
2001+
version = "2.0.8"
2002+
source = "registry+https://github.com/rust-lang/crates.io-index"
2003+
checksum = "a37b2691796cffeb8a8cd305ac66e65841559f147f4e63231d0eafa4db5384d1"
2004+
dependencies = [
2005+
"rustversion",
2006+
]
2007+
19992008
[[package]]
20002009
name = "inout"
20012010
version = "0.2.2"
@@ -5171,6 +5180,7 @@ dependencies = [
51715180
"dirs",
51725181
"getopts",
51735182
"ignore",
5183+
"indoc 2.0.8",
51745184
"insta",
51755185
"itertools",
51765186
"regex",
@@ -5184,6 +5194,7 @@ dependencies = [
51845194
"toml 1.1.0+spec-1.1.0",
51855195
"tracing",
51865196
"tracing-subscriber",
5197+
"tracing-tree",
51875198
"unicode-properties",
51885199
"unicode-segmentation",
51895200
"unicode-width 0.1.14",

‎compiler/rustc_ast_lowering/src/path.rs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use std::sync::Arc;
22

33
use rustc_ast::{self as ast, *};
4+
use rustc_attr_ir::target::Target;
45
use rustc_errors::StashKey;
56
use rustc_hir::def::{DefKind, PerNS, Res};
67
use rustc_hir::def_id::DefId;
7-
use rustc_hir::{self as hir, GenericArg};
8+
use rustc_hir::{self as hir, GenericArg, HirId};
89
use rustc_middle::middle::resolve::PartialRes;
910
use rustc_middle::ty;
1011
use rustc_session::diagnostics::add_feature_diagnostics;
@@ -263,6 +264,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
263264
bound_modifier_allowed_features: Option<Arc<[Symbol]>>,
264265
) -> hir::PathSegment<'hir> {
265266
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment);
267+
268+
let res = self.expect_full_res(segment.id);
269+
let hir_id = self.lower_node_id(segment.id);
270+
266271
let (mut generic_args, infer_args) = if let Some(generic_args) = segment.args.as_deref() {
267272
match generic_args {
268273
GenericArgs::AngleBracketed(data) => {
@@ -315,6 +320,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
315320
data,
316321
itctx,
317322
bound_modifier_allowed_features,
323+
hir_id,
318324
),
319325
GenericArgsMode::Err => {
320326
// Suggest replacing parentheses with angle brackets `Trait(params...)` to `Trait<params...>`
@@ -398,13 +404,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
398404
);
399405
}
400406

401-
let res = self.expect_full_res(segment.id);
402-
let hir_id = self.lower_node_id(segment.id);
403407
debug!(
404408
"lower_path_segment: ident={:?} original-id={:?} new-id={:?}",
405409
segment.ident, segment.id, hir_id,
406410
);
407-
408411
hir::PathSegment {
409412
ident: self.lower_ident(segment.ident),
410413
hir_id,
@@ -508,13 +511,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
508511
data: &ParenthesizedArgs,
509512
itctx: ImplTraitContext,
510513
bound_modifier_allowed_features: Option<Arc<[Symbol]>>,
514+
segment_hir_id: HirId,
511515
) -> (GenericArgsCtor<'hir>, bool) {
512516
// Switch to `PassThrough` mode for anonymous lifetimes; this
513517
// means that we permit things like `&Ref<T>`, where `Ref` has
514518
// a hidden lifetime parameter. This is needed for backwards
515519
// compatibility, even in contexts like an impl header where
516520
// we generally don't permit such things (see #51008).
517521
let ParenthesizedArgs { span, inputs, inputs_span, output } = data;
522+
523+
// FIXME uses the segments HIR id which is not correct, it should
524+
// be the parameters HIR id instead. This is currently not lowered.
525+
for input in inputs {
526+
self.lower_attrs(segment_hir_id, &input.attrs, input.span, Target::Param);
527+
}
528+
518529
let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
519530
self.lower_ty(&param.ty, ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam))
520531
}));

‎compiler/rustc_ast_passes/src/ast_validation.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl<'a> AstValidator<'a> {
399399
self.check_decl_num_args(fn_decl);
400400
let c_variadic_span = self.check_decl_cvariadic_pos(fn_decl);
401401
self.check_decl_splatting(fn_decl, c_variadic_span, splat_semantic);
402-
self.check_decl_attrs(fn_decl);
402+
self.check_decl_attrs(&fn_decl.inputs);
403403
self.check_decl_self_param(&fn_decl.inputs, self_semantic);
404404
self.check_decl_const_param(&fn_decl.inputs);
405405
}
@@ -518,10 +518,9 @@ impl<'a> AstValidator<'a> {
518518
}
519519
}
520520

521-
fn check_decl_attrs(&self, fn_decl: &FnDecl) {
521+
fn check_decl_attrs(&self, fn_inputs: &[Param]) {
522522
use SyntheticAttr::*;
523-
fn_decl
524-
.inputs
523+
fn_inputs
525524
.iter()
526525
.flat_map(|i| i.attrs.as_ref())
527526
.filter(|attr| match &attr.kind {
@@ -2230,6 +2229,7 @@ impl Visitor<'_> for AstValidator<'_> {
22302229
fn visit_path_segment(&mut self, seg: &PathSegment) -> Self::Result {
22312230
if let Some(Parenthesized(args)) = &seg.args {
22322231
self.check_decl_self_param(&args.inputs, SelfSemantic::No);
2232+
self.check_decl_attrs(&args.inputs);
22332233
Self::check_decl_no_pat(&args.inputs, |span, _, _| {
22342234
self.dcx().emit_err(diagnostics::PatternParenthesizedArgList { span });
22352235
});

‎compiler/rustc_attr_ir/src/attr.rs‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use smallvec::SmallVec;
1111
use thin_vec::ThinVec;
1212

1313
use crate::AttributeKind;
14-
/// Arguments passed to an attribute macro.
14+
15+
/// Arguments of a unparsed attribute.
1516
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
1617
pub enum AttrArgs {
1718
/// No arguments: `#[attr]`.
@@ -63,6 +64,9 @@ impl fmt::Display for AttrPath {
6364
}
6465
}
6566

67+
/// A non built-in attribute.
68+
///
69+
/// This is either a tool attribute or a derive helper attribute.
6670
#[derive(Clone, Debug, StableHash, Encodable, Decodable)]
6771
pub struct AttrItem {
6872
// Not lowered to hir::Path because we have no NodeId to resolve to.
@@ -88,20 +92,27 @@ impl StableHash for HashIgnoredAttrId {
8892
/* we don't hash HashIgnoredAttrId, we ignore them */
8993
}
9094
}
91-
92-
/// Many functions on this type have their documentation in the [`AttributeExt`] trait,
93-
/// since they defer their implementation directly to that trait.
95+
/// A high level representation of an attribute.
96+
///
97+
/// Not to be confused with [`ast::Attribute`], which represents the syntax-level form of
98+
/// an attribute.
99+
///
100+
/// [`ast::Attribute`]: rustc_ast::ast::Attribute
94101
#[derive(Clone, Debug, Encodable, Decodable, StableHash)]
95102
pub enum Attribute {
96103
/// A parsed built-in attribute.
97104
///
98-
/// Each attribute has a span connected to it. However, you must be somewhat careful using it.
99-
/// That's because sometimes we merge multiple attributes together, like when an item has
100-
/// multiple `repr` attributes. In this case the span might not be very useful.
105+
/// Parsed attributes don't generally have a span associated with them. This is because
106+
/// multiple syntax-level attributes can be represented into a single semantic attribute. For
107+
/// example, an item can have multiple `repr` attributes on it, which will coalesce into a
108+
/// single [`AttributeKind::Repr`], and the `stable`, `unstable`, and
109+
/// `rustc_allowed_through_unstable_modules` all combine into a single
110+
/// [`AttributeKind::Stability`] attribute. Most `Attribute` variants do have a [`Span`] field,
111+
/// though, mostly for the purpose of generating diagnostics later in the compilation process.
101112
Parsed(AttributeKind),
102-
103-
/// An attribute that could not be parsed, out of a token-like representation.
104-
/// This is the case for custom tool attributes.
113+
/// Represents non built-in attributes, which are not converted into a parsed form.
114+
///
115+
/// This is the case for custom tool attributes and derive helper attributes.
105116
Unparsed(Box<AttrItem>),
106117
}
107118

‎compiler/rustc_attr_ir/src/data_structures.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ pub enum AttributeKind {
859859
Deprecated {
860860
deprecation: Deprecation,
861861
span: Span,
862+
/// `true` if this an inner attribute (ie `#![]`).
863+
is_inner: bool,
862864
},
863865

864866
/// Represents `#[diagnostic::do_not_recommend]`.

‎compiler/rustc_attr_parsing/src/attributes/deprecation.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ impl SingleAttributeParser for DeprecatedParser {
210210
Some(AttributeKind::Deprecated {
211211
deprecation: Deprecation { since, note, suggestion },
212212
span: cx.attr_span,
213+
is_inner: matches!(cx.attr_style, rustc_ast::AttrStyle::Inner),
213214
})
214215
}
215216
}

‎compiler/rustc_attr_parsing/src/lib.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
//! ### 1. Active Attributes
2424
//! These are attribute-like proc-macros that expand into other Rust code.
2525
//! They can be either user-defined or compiler-provided. Examples of compiler-provided active attributes:
26-
//! - `#[derive(...)]`: Expands into trait implementations
27-
//! - `#[cfg()]`: Expands based on configuration
28-
//! - `#[cfg_attr()]`: Conditional attribute application
26+
//! - `#[derive(Debug)]`: Expands into trait implementations
27+
//! - `#[cfg(target_os = "windows")]`: Expands based on configuration
28+
//! - `#[cfg_attr(feature = "foo", test)]`: Conditional attribute application
2929
//!
3030
//! ### 2. Inert Attributes
3131
//! These are pure markers that don't expand into other code. They guide the compilation process.
3232
//! They can be user-defined (in proc-macro helpers) or built-in. Examples of built-in inert attributes:
33-
//! - `#[stable()]`: Marks stable API items
34-
//! - `#[inline()]`: Suggests function inlining
35-
//! - `#[repr()]`: Controls type representation
33+
//! - `#[stable(feature = "scoped_threads", since = "1.63.0")]`: Marks stable API items
34+
//! - `#[inline(never)]`: Suggests function inlining
35+
//! - `#[repr(C)]`: Controls type representation
3636
//!
3737
//! ```text
3838
//! Active Inert
@@ -58,10 +58,10 @@
5858
//! In this crate, syntactical attributes (sequences of tokens that look like
5959
//! `#[something(something else)]`) are parsed into more semantic attributes, markers on items.
6060
//! Multiple syntactic attributes might influence a single semantic attribute. For example,
61-
//! `#[stable(...)]` and `#[unstable()]` cannot occur together, and both semantically define
61+
//! the `stable` and `unstable` attributes cannot occur together, and both semantically define
6262
//! a "stability" of an item. So, the stability attribute has an
63-
//! [`AttributeParser`](attributes::AttributeParser) that recognizes both the `#[stable()]`
64-
//! and `#[unstable()]` syntactic attributes, and at the end produces a single
63+
//! [`AttributeParser`](attributes::AttributeParser) that recognizes both the `stable`
64+
//! and `unstable` syntactic attributes, and at the end produces a single
6565
//! [`AttributeKind::Stability`](rustc_attr_ir::AttributeKind::Stability).
6666
//!
6767
//! When multiple instances of the same attribute are allowed, they're combined into a single

‎compiler/rustc_builtin_macros/src/deriving/debug.rs‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ fn show_fieldless_enum(
232232
def: &EnumDef,
233233
type_ident: Ident,
234234
) -> BlockOrExpr {
235+
if let Some(expr) = show_fieldless_enum_concat_str(cx, span, def, type_ident) {
236+
return BlockOrExpr::new_expr(expr);
237+
}
235238
let fmt = cx.expr_name(span, sym::f);
236239
let arms = def
237240
.variants
@@ -256,3 +259,94 @@ fn show_fieldless_enum(
256259
let fn_path_write_str = cx.std_path(span, &[sym::fmt, sym::Formatter, sym::write_str]);
257260
BlockOrExpr::new_expr(cx.expr_call_global(span, fn_path_write_str, thin_vec![fmt, name]))
258261
}
262+
263+
/// Special case for large enums with no fields. Builds:
264+
/// ```text
265+
/// impl ::core::fmt::Debug for A {
266+
/// fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
267+
/// ::core::fmt::Formatter::debug_c_like_enum_write_str(f,
268+
/// "A B C D E F",
269+
/// match self {
270+
/// A::A => 0usize,
271+
/// A::B => 2usize,
272+
/// A::C => 4usize,
273+
/// A::D => 6usize,
274+
/// A::E => 8usize,
275+
/// A::F => 10usize,
276+
/// })
277+
/// }
278+
/// }
279+
/// ```
280+
fn show_fieldless_enum_concat_str(
281+
cx: &ExtCtxt<'_>,
282+
span: Span,
283+
def: &EnumDef,
284+
type_ident: Ident,
285+
) -> Option<Box<ast::Expr>> {
286+
// Minimum variant count where this optimization starts to pay off.
287+
// Initial value of 10 came from https://github.com/rust-lang/rust/pull/155452.
288+
// Refined with the new impl in https://github.com/rust-lang/rust/pull/162535.
289+
// Tested with thresholds 10,5,2 on rustc-perf
290+
// and by comparing MIR sizes for various enums in GodBolt.
291+
//
292+
// `match` with strings generates:
293+
// - a local for each arm
294+
// - a basic block with 5 statements for each arm,
295+
//
296+
// `match` with integers to index a concatenated string generates
297+
// - a single local for the string
298+
// - a single local for the index
299+
// - a basic block with 2 statements for each arm
300+
//
301+
// This reduces borrowck costs on larger enums.
302+
const THRESHOLD: usize = 5;
303+
let variants_count = def.variants.len();
304+
if variants_count < THRESHOLD {
305+
return None;
306+
}
307+
let fmt = cx.expr_name(span, sym::f);
308+
309+
let mut concatenated_names = String::new();
310+
311+
let arms = def
312+
.variants
313+
.iter()
314+
.enumerate()
315+
.map(|(i, v)| {
316+
let name_offset = concatenated_names.len();
317+
318+
let name = v.ident.name.as_str();
319+
concatenated_names.push_str(name);
320+
321+
let is_last = i == def.variants.len() - 1;
322+
if !is_last {
323+
concatenated_names.push(' ');
324+
}
325+
326+
let variant_path = cx.path(span, &[type_ident, v.ident]);
327+
let pat = match &v.data {
328+
ast::VariantData::Tuple(fields, _) => {
329+
debug_assert!(fields.is_empty());
330+
cx.pat_tuple_struct(span, variant_path, ThinVec::new())
331+
}
332+
ast::VariantData::Struct { fields, .. } => {
333+
debug_assert!(fields.is_empty());
334+
cx.pat_struct(span, variant_path, ThinVec::new())
335+
}
336+
ast::VariantData::Unit(_) => cx.pat_path(span, variant_path),
337+
};
338+
339+
cx.arm(span, pat, cx.expr_usize(span, name_offset))
340+
})
341+
.collect::<ThinVec<_>>();
342+
343+
let names_str_body = cx.expr_str(span, Symbol::intern(&concatenated_names));
344+
345+
let variant_index_expr = cx.expr_match(span, cx.expr_self(span), arms);
346+
347+
let fn_path = cx.std_path(span, &[sym::fmt, sym::Formatter, sym::debug_c_like_enum_write_str]);
348+
let call_expr =
349+
cx.expr_call_global(span, fn_path, thin_vec![fmt, names_str_body, variant_index_expr]);
350+
351+
Some(call_expr)
352+
}

‎compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ rm -r tests/run-make-cargo/panic-immediate-abort-codegen # same
161161
rm -r tests/run-make-cargo/panic-strategies # same
162162
rm -r tests/run-make/missing-unstable-trait-bound # This disables support for unstable features, but running cg_clif needs some unstable features
163163
rm -r tests/run-make/const-trait-stable-toolchain # same
164-
rm -r tests/run-make/print-request-help-stable-unstable # same
165164
rm -r tests/run-make/issue-149402-suggest-unresolve # same
166-
rm -r tests/run-make/const-destruct-stable-toolchain # same
167165
rm -r tests/run-make/unstable-target-feature # same
168166
rm -r tests/run-make/incr-add-rust-src-component
169167
rm tests/ui/errors/remap-path-prefix-sysroot.rs # different sysroot source path

‎compiler/rustc_codegen_cranelift/src/driver/aot.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use rustc_errors::{DiagCtxt, DiagCtxtHandle};
2222
use rustc_middle::dep_graph::WorkProduct;
2323
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
2424
use rustc_middle::mono::{MonoItem, MonoItemData, Visibility};
25-
use rustc_session::Session;
2625
use rustc_session::config::{OptLevel, OutputFilenames, OutputType};
26+
use rustc_session::{BorrowedIncrCompSession, Session};
2727
use rustc_span::Symbol;
2828

2929
use crate::base::CodegenedFunction;
@@ -341,6 +341,7 @@ impl WriteBackendMethods for AotDriver {
341341
fn run_thin_lto(
342342
_cgcx: &CodegenContext,
343343
_prof: &SelfProfilerRef,
344+
_incr_comp_session: Option<&BorrowedIncrCompSession>,
344345
_dcx: rustc_errors::DiagCtxtHandle<'_>,
345346
_exported_symbols_for_lto: &[String],
346347
_each_linked_rlib_for_lto: &[PathBuf],

0 commit comments

Comments
 (0)