Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
75d8687
add span to struct pattern rest (..)
Erk- Aug 23, 2025
fc7de99
Ensure we emit an allocator shim when only some crate types need one
bjorn3 Aug 28, 2025
1d30900
Fix typo in comment
bjorn3 Aug 28, 2025
f4888c2
Correctly handle different crate types disagreeing if the allocator s…
bjorn3 Aug 28, 2025
8930d3a
resolve: Avoid a regression from splitting prelude into two scopes
petrochenkov Aug 28, 2025
0711bba
Ignore test when dylibs are not supported
bjorn3 Aug 31, 2025
2784327
alloc: make Cow From impls const
npmccallum Sep 1, 2025
ac89fcb
rustdoc-search: skip loading unneeded fnData
notriddle Sep 1, 2025
f6e7c81
Add compiler error when trying to use concat metavar expr in repetitions
jullanggit Aug 31, 2025
8dfd6b8
fix a constness ordering bug in rustfmt
npmccallum Sep 1, 2025
d8df631
Make `Parser::parse_for_head` public for rustfmt usage
mohe2015 Sep 1, 2025
6fc0cf4
Remove dead code stemming from an old effects desugaring
fmease Sep 1, 2025
ed295ff
Rollup merge of #145783 - Erk-:et-cetera-span, r=compiler-errors
jhpratt Sep 2, 2025
5168be1
Rollup merge of #145961 - petrochenkov:extprelregr, r=nnethercote
jhpratt Sep 2, 2025
c3301a9
Rollup merge of #145962 - bjorn3:linkage_fixes, r=WaffleLapkin
jhpratt Sep 2, 2025
c9e5f3d
Rollup merge of #146064 - jullanggit:patch-1, r=fmease
jhpratt Sep 2, 2025
a972fbc
Rollup merge of #146067 - npmccallum:cow, r=oli-obk
jhpratt Sep 2, 2025
efdb9bb
Rollup merge of #146070 - notriddle:skip-loading-function-data, r=Gui…
jhpratt Sep 2, 2025
50e38b5
Rollup merge of #146089 - npmccallum:rustfmt, r=fmease
jhpratt Sep 2, 2025
f4c5c34
Rollup merge of #146094 - mohe2015:patch-2, r=lcnr
jhpratt Sep 2, 2025
ef60f50
Rollup merge of #146102 - fmease:rm-dead-eff-code-iii, r=fee1-dead
jhpratt Sep 2, 2025
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/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ pub enum PatKind {
#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Walkable)]
pub enum PatFieldsRest {
/// `module::StructName { field, ..}`
Rest,
Rest(Span),
/// `module::StructName { field, syntax error }`
Recovered(ErrorGuaranteed),
/// `module::StructName { field }`
Expand Down Expand Up @@ -4051,8 +4051,8 @@ mod size_asserts {
static_assert_size!(Local, 96);
static_assert_size!(MetaItemLit, 40);
static_assert_size!(Param, 40);
static_assert_size!(Pat, 72);
static_assert_size!(PatKind, 48);
static_assert_size!(Pat, 80);
static_assert_size!(PatKind, 56);
static_assert_size!(Path, 24);
static_assert_size!(PathSegment, 24);
static_assert_size!(Stmt, 32);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,10 +1434,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.dcx().emit_err(FunctionalRecordUpdateDestructuringAssignment {
span: e.span,
});
true
Some(self.lower_span(e.span))
}
StructRest::Rest(_) => true,
StructRest::None => false,
StructRest::Rest(span) => Some(self.lower_span(*span)),
StructRest::None => None,
};
let struct_pat = hir::PatKind::Struct(qpath, field_pats, fields_omitted);
return self.pat_without_dbm(lhs.span, struct_pat);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

(
hir::ParamName::Plain(self.lower_ident(param.ident)),
hir::GenericParamKind::Const { ty, default, synthetic: false },
hir::GenericParamKind::Const { ty, default },
)
}
}
Expand Down Expand Up @@ -2508,7 +2508,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fields: &'hir [hir::PatField<'hir>],
) -> &'hir hir::Pat<'hir> {
let qpath = hir::QPath::LangItem(lang_item, self.lower_span(span));
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
self.pat(span, hir::PatKind::Struct(qpath, fields, None))
}

fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
break hir::PatKind::Struct(
qpath,
fs,
matches!(
etc,
ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_)
),
match etc {
ast::PatFieldsRest::Rest(sp) => Some(self.lower_span(*sp)),
ast::PatFieldsRest::Recovered(_) => Some(Span::default()),
_ => None,
},
);
}
PatKind::Tuple(pats) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ impl<'a> State<'a> {
},
|f| f.pat.span,
);
if let ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_) = etc {
if let ast::PatFieldsRest::Rest(_) | ast::PatFieldsRest::Recovered(_) = etc {
if !fields.is_empty() {
self.word_space(",");
}
Expand Down
17 changes: 13 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use super::linker::{self, Linker};
use super::metadata::{MetadataPosition, create_wrapper_file};
use super::rpath::{self, RPathConfig};
use super::{apple, versioned_llvm_target};
use crate::base::needs_allocator_shim_for_linking;
use crate::{
CodegenResults, CompiledModule, CrateInfo, NativeLib, errors, looks_like_rust_object_file,
};
Expand Down Expand Up @@ -2080,9 +2081,17 @@ fn add_local_crate_regular_objects(cmd: &mut dyn Linker, codegen_results: &Codeg
}

/// Add object files for allocator code linked once for the whole crate tree.
fn add_local_crate_allocator_objects(cmd: &mut dyn Linker, codegen_results: &CodegenResults) {
if let Some(obj) = codegen_results.allocator_module.as_ref().and_then(|m| m.object.as_ref()) {
cmd.add_object(obj);
fn add_local_crate_allocator_objects(
cmd: &mut dyn Linker,
codegen_results: &CodegenResults,
crate_type: CrateType,
) {
if needs_allocator_shim_for_linking(&codegen_results.crate_info.dependency_formats, crate_type)
{
if let Some(obj) = codegen_results.allocator_module.as_ref().and_then(|m| m.object.as_ref())
{
cmd.add_object(obj);
}
}
}

Expand Down Expand Up @@ -2281,7 +2290,7 @@ fn linker_with_args(
codegen_results,
metadata,
);
add_local_crate_allocator_objects(cmd, codegen_results);
add_local_crate_allocator_objects(cmd, codegen_results, crate_type);

// Avoid linking to dynamic libraries unless they satisfy some undefined symbols
// at the point at which they are specified on the command line.
Expand Down
17 changes: 14 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use rustc_metadata::{
};
use rustc_middle::bug;
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::middle::exported_symbols;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind};
use rustc_middle::middle::exported_symbols::{
self, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
Expand All @@ -22,6 +23,8 @@ use tracing::{debug, warn};

use super::command::Command;
use super::symbol_export;
use crate::back::symbol_export::allocator_shim_symbols;
use crate::base::needs_allocator_shim_for_linking;
use crate::errors;

#[cfg(test)]
Expand Down Expand Up @@ -1827,7 +1830,7 @@ fn exported_symbols_for_non_proc_macro(
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
// Do not export mangled symbols from cdylibs and don't attempt to export compiler-builtins
// from any cdylib. The latter doesn't work anyway as we use hidden visibility for
// from any dylib. The latter doesn't work anyway as we use hidden visibility for
// compiler-builtins. Most linkers silently ignore it, but ld64 gives a warning.
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum) {
symbols.push((
Expand All @@ -1838,6 +1841,14 @@ fn exported_symbols_for_non_proc_macro(
}
});

// Mark allocator shim symbols as exported only if they were generated.
if export_threshold == SymbolExportLevel::Rust
&& needs_allocator_shim_for_linking(tcx.dependency_formats(()), crate_type)
&& tcx.allocator_kind(()).is_some()
{
symbols.extend(allocator_shim_symbols(tcx));
}

symbols
}

Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use rustc_middle::ty::TyCtxt;
use rustc_session::config::{CrateType, Lto};
use tracing::info;

use crate::back::symbol_export::{self, symbol_name_for_instance_in_crate};
use crate::back::symbol_export::{self, allocator_shim_symbols, symbol_name_for_instance_in_crate};
use crate::back::write::CodegenContext;
use crate::base::allocator_kind_for_codegen;
use crate::errors::{DynamicLinkingWithLTO, LtoDisallowed, LtoDylib, LtoProcMacro};
use crate::traits::*;

Expand Down Expand Up @@ -115,6 +116,11 @@ pub(super) fn exported_symbols_for_lto(
}
}

// Mark allocator shim symbols as exported only if they were generated.
if export_threshold == SymbolExportLevel::Rust && allocator_kind_for_codegen(tcx).is_some() {
symbols_below_threshold.extend(allocator_shim_symbols(tcx).map(|(name, _kind)| name));
}

symbols_below_threshold
}

Expand Down
52 changes: 26 additions & 26 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_symbol_mangling::mangle_internal_symbol;
use rustc_target::spec::TlsModel;
use tracing::debug;

use crate::base::allocator_kind_for_codegen;
use crate::back::symbol_export;

fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
crates_export_threshold(tcx.crate_types())
Expand Down Expand Up @@ -217,31 +217,6 @@ fn exported_non_generic_symbols_provider_local<'tcx>(
));
}

// Mark allocator shim symbols as exported only if they were generated.
if allocator_kind_for_codegen(tcx).is_some() {
for symbol_name in ALLOCATOR_METHODS
.iter()
.map(|method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
.chain([
mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
])
{
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));

symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
rustc_std_internal_symbol: true,
},
));
}
}

// Sort so we get a stable incr. comp. hash.
symbols.sort_by_cached_key(|s| s.0.symbol_name_for_local_instance(tcx));

Expand Down Expand Up @@ -516,6 +491,31 @@ pub(crate) fn provide(providers: &mut Providers) {
upstream_monomorphizations_for_provider;
}

pub(crate) fn allocator_shim_symbols(
tcx: TyCtxt<'_>,
) -> impl Iterator<Item = (String, SymbolExportKind)> {
ALLOCATOR_METHODS
.iter()
.map(move |method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
.chain([
mangle_internal_symbol(tcx, "__rust_alloc_error_handler"),
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
])
.map(move |symbol_name| {
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));

(
symbol_export::exporting_symbol_name_for_instance_in_crate(
tcx,
exported_symbol,
LOCAL_CRATE,
),
SymbolExportKind::Text,
)
})
}

fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel {
// We export anything that's not mangled at the "C" layer as it probably has
// to do with ABI concerns. We do not, however, apply such treatment to
Expand Down
27 changes: 22 additions & 5 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{ItemId, Target};
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::middle::debugger_visualizer::{DebuggerVisualizerFile, DebuggerVisualizerType};
use rustc_middle::middle::dependency_format::Dependencies;
use rustc_middle::middle::exported_symbols::{self, SymbolExportKind};
use rustc_middle::middle::lang_items;
use rustc_middle::mir::BinOp;
Expand Down Expand Up @@ -630,14 +631,30 @@ pub fn allocator_kind_for_codegen(tcx: TyCtxt<'_>) -> Option<AllocatorKind> {
// If the crate doesn't have an `allocator_kind` set then there's definitely
// no shim to generate. Otherwise we also check our dependency graph for all
// our output crate types. If anything there looks like its a `Dynamic`
// linkage, then it's already got an allocator shim and we'll be using that
// one instead. If nothing exists then it's our job to generate the
// allocator!
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
// linkage for all crate types we may link as, then it's already got an
// allocator shim and we'll be using that one instead. If nothing exists
// then it's our job to generate the allocator! If crate types disagree
// about whether an allocator shim is necessary or not, we generate one
// and let needs_allocator_shim_for_linking decide at link time whether or
// not to use it for any particular linker invocation.
let all_crate_types_any_dynamic_crate = tcx.dependency_formats(()).iter().all(|(_, list)| {
use rustc_middle::middle::dependency_format::Linkage;
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
});
if any_dynamic_crate { None } else { tcx.allocator_kind(()) }
if all_crate_types_any_dynamic_crate { None } else { tcx.allocator_kind(()) }
}

/// Decide if this particular crate type needs an allocator shim linked in.
/// This may return true even when allocator_kind_for_codegen returns false. In
/// this case no allocator shim shall be linked.
pub(crate) fn needs_allocator_shim_for_linking(
dependency_formats: &Dependencies,
crate_type: CrateType,
) -> bool {
use rustc_middle::middle::dependency_format::Linkage;
let any_dynamic_crate =
dependency_formats[&crate_type].iter().any(|&linkage| linkage == Linkage::Dynamic);
!any_dynamic_crate
}

pub fn codegen_crate<B: ExtraBackendMethods>(
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,12 @@ fn metavar_expr_concat<'tx>(
};
match &named_matches[*curr_idx] {
// FIXME(c410-f3r) Nested repetitions are unimplemented
MatchedSeq(_) => unimplemented!(),
MatchedSeq(_) => {
return Err(dcx.struct_span_err(
ident.span,
"nested repetitions with `${concat(...)}` metavariable expressions are not yet supported",
));
}
MatchedSingle(pnr) => extract_symbol_from_pnr(dcx, pnr, ident.span)?,
}
}
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,6 @@ pub enum GenericParamKind<'hir> {
ty: &'hir Ty<'hir>,
/// Optional default value for the const generic param
default: Option<&'hir ConstArg<'hir>>,
synthetic: bool,
},
}

Expand Down Expand Up @@ -1884,8 +1883,8 @@ pub enum PatKind<'hir> {
Binding(BindingMode, HirId, Ident, Option<&'hir Pat<'hir>>),

/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
/// The `bool` is `true` in the presence of a `..`.
Struct(QPath<'hir>, &'hir [PatField<'hir>], bool),
/// The `Option` contains the span of a possible `..`.
Struct(QPath<'hir>, &'hir [PatField<'hir>], Option<Span>),

/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
/// If the `..` pattern fragment is present, then `DotDotPos` denotes its position.
Expand Down Expand Up @@ -4979,8 +4978,8 @@ mod size_asserts {
static_assert_size!(ItemKind<'_>, 64);
static_assert_size!(LetStmt<'_>, 72);
static_assert_size!(Param<'_>, 32);
static_assert_size!(Pat<'_>, 72);
static_assert_size!(PatKind<'_>, 48);
static_assert_size!(Pat<'_>, 80);
static_assert_size!(PatKind<'_>, 56);
static_assert_size!(Path<'_>, 40);
static_assert_size!(PathSegment<'_>, 48);
static_assert_size!(QPath<'_>, 24);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(
GenericParamKind::Type { ref default, .. } => {
visit_opt!(visitor, visit_ty_unambig, default)
}
GenericParamKind::Const { ref ty, ref default, synthetic: _ } => {
GenericParamKind::Const { ref ty, ref default } => {
try_visit!(visitor.visit_ty_unambig(ty));
if let Some(default) = default {
try_visit!(visitor.visit_const_param_default(*hir_id, default));
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {

ty::GenericParamDefKind::Type { has_default: default.is_some(), synthetic }
}
GenericParamKind::Const { ty: _, default, synthetic } => {
GenericParamKind::Const { ty: _, default } => {
if default.is_some() {
match param_default_policy.expect("no policy for generic param default") {
ParamDefaultPolicy::Allowed => {}
Expand All @@ -316,7 +316,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
}
}

ty::GenericParamDefKind::Const { has_default: default.is_some(), synthetic }
ty::GenericParamDefKind::Const { has_default: default.is_some() }
}
};
Some(ty::GenericParamDef {
Expand Down Expand Up @@ -523,7 +523,7 @@ impl<'v> Visitor<'v> for AnonConstInParamTyDetector {
type Result = ControlFlow<()>;

fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) -> Self::Result {
if let GenericParamKind::Const { ty, default: _, synthetic: _ } = p.kind {
if let GenericParamKind::Const { ty, default: _ } = p.kind {
let prev = self.in_param_ty;
self.in_param_ty = true;
let res = self.visit_ty_unambig(ty);
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,7 @@ pub(crate) fn check_generic_arg_count(
.filter(|param| matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. }))
.count();
let named_type_param_count = param_counts.types - has_self as usize - synth_type_param_count;
let synth_const_param_count = gen_params
.own_params
.iter()
.filter(|param| {
matches!(param.kind, ty::GenericParamDefKind::Const { synthetic: true, .. })
})
.count();
let named_const_param_count = param_counts.consts - synth_const_param_count;
let named_const_param_count = param_counts.consts;
let infer_lifetimes =
(gen_pos != GenericArgPosition::Type || seg.infer_args) && !gen_args.has_lifetime_params();

Expand Down
Loading
Loading