Skip to content

Commit 5468a49

Browse files
committed
Auto merge of #157142 - JonathanBrouwer:rollup-epQjoOE, r=<try>
Rollup of 9 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1 try-job: i686-msvc-2
2 parents 6368fd5 + a4a4146 commit 5468a49

39 files changed

Lines changed: 866 additions & 607 deletions

File tree

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15491549
fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination {
15501550
let target_id = match destination {
15511551
Some((id, _)) => {
1552-
if let Some(loop_id) = self.resolver.get_label_res(id) {
1552+
if let Some(loop_id) = self.owner.get_label_res(id) {
15531553
let local_id = self.ident_and_label_to_local_id[&loop_id];
15541554
let loop_hir_id = HirId { owner: self.current_hir_id_owner, local_id };
15551555
Ok(loop_hir_id)

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
293293
self.import_res_map.get(&id).copied().unwrap_or_default()
294294
}
295295

296-
/// Obtains resolution for a label with the given `NodeId`.
297-
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
298-
self.label_res_map.get(&id).copied()
299-
}
300-
301-
/// Obtains resolution for a lifetime with the given `NodeId`.
302-
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
303-
self.lifetimes_res_map.get(&id).copied()
304-
}
305-
306296
/// Obtain the list of lifetimes parameters to add to an item.
307297
///
308298
/// Extra lifetime parameters should only be added in places that can appear
@@ -321,10 +311,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
321311
fn owner_def_id(&self, id: NodeId) -> LocalDefId {
322312
self.owners[&id].def_id
323313
}
324-
325-
fn lifetime_elision_allowed(&self, id: NodeId) -> bool {
326-
self.lifetime_elision_allowed.contains(&id)
327-
}
328314
}
329315

330316
/// How relaxed bounds `?Trait` should be treated.
@@ -1625,7 +1611,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16251611

16261612
None => {
16271613
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1628-
self.resolver.get_lifetime_res(t.id)
1614+
self.owner.get_lifetime_res(t.id)
16291615
{
16301616
assert_eq!(start.plus(1), end);
16311617
start
@@ -1866,7 +1852,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
18661852
_ => hir::ImplicitSelfKind::None,
18671853
}
18681854
}))
1869-
.set_lifetime_elision_allowed(self.resolver.lifetime_elision_allowed(fn_node_id))
1855+
.set_lifetime_elision_allowed(
1856+
self.owner.id == fn_node_id && self.owner.lifetime_elision_allowed,
1857+
)
18701858
.set_c_variadic(c_variadic);
18711859

18721860
self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })
@@ -2032,7 +2020,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20322020
source: LifetimeSource,
20332021
syntax: LifetimeSyntax,
20342022
) -> &'hir hir::Lifetime {
2035-
let res = if let Some(res) = self.resolver.get_lifetime_res(id) {
2023+
let res = if let Some(res) = self.owner.get_lifetime_res(id) {
20362024
match res {
20372025
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
20382026
LifetimeRes::Fresh { param, .. } => {
@@ -2118,13 +2106,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
21182106
// AST resolution emitted an error on those parameters, so we lower them using
21192107
// `ParamName::Error`.
21202108
let ident = self.lower_ident(param.ident);
2121-
let param_name = if let Some(LifetimeRes::Error(..)) =
2122-
self.resolver.get_lifetime_res(param.id)
2123-
{
2124-
ParamName::Error(ident)
2125-
} else {
2126-
ParamName::Plain(ident)
2127-
};
2109+
let param_name =
2110+
if let Some(LifetimeRes::Error(..)) = self.owner.get_lifetime_res(param.id) {
2111+
ParamName::Error(ident)
2112+
} else {
2113+
ParamName::Plain(ident)
2114+
};
21282115
let kind =
21292116
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
21302117

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::errors::{
1717
};
1818
use super::{
1919
AllowReturnTypeNotation, GenericArgsCtor, GenericArgsMode, ImplTraitContext, ImplTraitPosition,
20-
LifetimeRes, LoweringContext, ParamMode, ResolverAstLoweringExt,
20+
LifetimeRes, LoweringContext, ParamMode,
2121
};
2222

2323
impl<'hir> LoweringContext<'_, 'hir> {
@@ -422,7 +422,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
422422
segment_ident_span: Span,
423423
generic_args: &mut GenericArgsCtor<'hir>,
424424
) {
425-
let (start, end) = match self.resolver.get_lifetime_res(segment_id) {
425+
let (start, end) = match self.owner.get_lifetime_res(segment_id) {
426426
Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end),
427427
None => return,
428428
Some(res) => {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,63 +4023,60 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
40234023
&& decl.can_be_made_mutable()
40244024
{
40254025
let mut is_for_loop = false;
4026-
let mut is_ref_pattern = false;
4026+
let mut is_immut_ref_pattern = false;
40274027
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
40284028
opt_match_place: Some((_, match_span)),
40294029
..
40304030
})) = *decl.local_info()
40314031
{
40324032
if matches!(match_span.desugaring_kind(), Some(DesugaringKind::ForLoop)) {
40334033
is_for_loop = true;
4034+
}
40344035

4035-
if let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
4036-
struct RefPatternFinder<'tcx> {
4037-
tcx: TyCtxt<'tcx>,
4038-
binding_span: Span,
4039-
is_ref_pattern: bool,
4040-
}
4036+
if let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
4037+
struct RefPatternFinder<'tcx> {
4038+
tcx: TyCtxt<'tcx>,
4039+
binding_span: Span,
4040+
is_immut_ref_pattern: bool,
4041+
}
40414042

4042-
impl<'tcx> Visitor<'tcx> for RefPatternFinder<'tcx> {
4043-
type NestedFilter = OnlyBodies;
4043+
impl<'tcx> Visitor<'tcx> for RefPatternFinder<'tcx> {
4044+
type NestedFilter = OnlyBodies;
40444045

4045-
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
4046-
self.tcx
4047-
}
4046+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
4047+
self.tcx
4048+
}
40484049

4049-
fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) {
4050-
if !self.is_ref_pattern
4051-
&& let hir::PatKind::Binding(_, _, ident, _) = pat.kind
4052-
&& ident.span == self.binding_span
4053-
{
4054-
self.is_ref_pattern =
4055-
self.tcx.hir_parent_iter(pat.hir_id).any(|(_, node)| {
4056-
matches!(
4057-
node,
4058-
hir::Node::Pat(hir::Pat {
4059-
kind: hir::PatKind::Ref(..),
4060-
..
4061-
})
4062-
)
4063-
});
4064-
}
4065-
hir::intravisit::walk_pat(self, pat);
4050+
fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) {
4051+
if !self.is_immut_ref_pattern
4052+
&& let hir::PatKind::Binding(_, _, ident, _) = pat.kind
4053+
&& ident.span == self.binding_span
4054+
&& matches!(
4055+
self.tcx.parent_hir_node(pat.hir_id),
4056+
hir::Node::Pat(hir::Pat {
4057+
kind: hir::PatKind::Ref(_, _, hir::Mutability::Not),
4058+
..
4059+
})
4060+
)
4061+
{
4062+
self.is_immut_ref_pattern = true;
40664063
}
4064+
hir::intravisit::walk_pat(self, pat);
40674065
}
4066+
}
40684067

4069-
let mut finder = RefPatternFinder {
4070-
tcx: self.infcx.tcx,
4071-
binding_span: decl.source_info.span,
4072-
is_ref_pattern: false,
4073-
};
4068+
let mut finder = RefPatternFinder {
4069+
tcx: self.infcx.tcx,
4070+
binding_span: decl.source_info.span,
4071+
is_immut_ref_pattern: false,
4072+
};
40744073

4075-
finder.visit_body(body);
4076-
is_ref_pattern = finder.is_ref_pattern;
4077-
}
4074+
finder.visit_body(body);
4075+
is_immut_ref_pattern = finder.is_immut_ref_pattern;
40784076
}
40794077
}
40804078

4081-
let (span, message) = if is_for_loop
4082-
&& is_ref_pattern
4079+
let (span, message) = if is_immut_ref_pattern
40834080
&& let Ok(binding_name) =
40844081
self.infcx.tcx.sess.source_map().span_to_snippet(decl.source_info.span)
40854082
{

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ fn disable_incr_cache() -> bool {
3535
}
3636

3737
struct ModuleCodegenResult {
38-
module_regular: CompiledModule,
39-
module_global_asm: Option<CompiledModule>,
38+
module: CompiledModule,
4039
existing_work_product: Option<(WorkProductId, WorkProduct)>,
4140
}
4241

@@ -80,29 +79,25 @@ impl OngoingCodegen {
8079
Ok(module_codegen_result) => module_codegen_result,
8180
Err(err) => sess.dcx().fatal(err),
8281
};
83-
let ModuleCodegenResult { module_regular, module_global_asm, existing_work_product } =
84-
module_codegen_result;
82+
let ModuleCodegenResult { module, existing_work_product } = module_codegen_result;
8583

8684
if let Some((work_product_id, work_product)) = existing_work_product {
8785
work_products.insert(work_product_id, work_product);
8886
} else {
8987
let work_product = if disable_incr_cache {
9088
None
91-
} else if let Some(module_global_asm) = &module_global_asm {
89+
} else if let Some(global_asm_object) = &module.global_asm_object {
9290
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
9391
sess,
94-
&module_regular.name,
95-
&[
96-
("o", module_regular.object.as_ref().unwrap()),
97-
("asm.o", module_global_asm.object.as_ref().unwrap()),
98-
],
92+
&module.name,
93+
&[("o", module.object.as_ref().unwrap()), ("asm.o", global_asm_object)],
9994
&[],
10095
)
10196
} else {
10297
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
10398
sess,
104-
&module_regular.name,
105-
&[("o", module_regular.object.as_ref().unwrap())],
99+
&module.name,
100+
&[("o", module.object.as_ref().unwrap())],
106101
&[],
107102
)
108103
};
@@ -111,10 +106,7 @@ impl OngoingCodegen {
111106
}
112107
}
113108

114-
modules.push(module_regular);
115-
if let Some(module_global_asm) = module_global_asm {
116-
modules.push(module_global_asm);
117-
}
109+
modules.push(module);
118110
}
119111

120112
self.concurrency_limiter.finished();
@@ -163,29 +155,17 @@ fn emit_cgu(
163155
debug.emit(&mut product);
164156
}
165157

166-
let module_regular = emit_module(
158+
let module = emit_module(
167159
output_filenames,
168160
prof,
169161
product.object,
170162
ModuleKind::Regular,
171163
name.clone(),
164+
global_asm_object_file,
172165
producer,
173166
)?;
174167

175-
Ok(ModuleCodegenResult {
176-
module_regular,
177-
module_global_asm: global_asm_object_file.map(|global_asm_object_file| CompiledModule {
178-
name: format!("{name}.asm"),
179-
kind: ModuleKind::Regular,
180-
object: Some(global_asm_object_file),
181-
dwarf_object: None,
182-
bytecode: None,
183-
assembly: None,
184-
llvm_ir: None,
185-
links_from_incr_cache: Vec::new(),
186-
}),
187-
existing_work_product: None,
188-
})
168+
Ok(ModuleCodegenResult { module, existing_work_product: None })
189169
}
190170

191171
fn emit_module(
@@ -194,6 +174,7 @@ fn emit_module(
194174
mut object: cranelift_object::object::write::Object<'_>,
195175
kind: ModuleKind,
196176
name: String,
177+
global_asm_object: Option<PathBuf>,
197178
producer_str: &str,
198179
) -> Result<CompiledModule, String> {
199180
if object.format() == cranelift_object::object::BinaryFormat::Elf {
@@ -235,6 +216,7 @@ fn emit_module(
235216
name,
236217
kind,
237218
object: Some(tmp_file),
219+
global_asm_object,
238220
dwarf_object: None,
239221
bytecode: None,
240222
assembly: None,
@@ -265,7 +247,7 @@ fn reuse_workproduct_for_cgu(
265247
}
266248

267249
let obj_out_global_asm =
268-
crate::global_asm::add_file_stem_postfix(obj_out_regular.clone(), ".asm");
250+
tcx.output_filenames(()).temp_path_ext_for_cgu("asm.o", cgu.name().as_str());
269251
let source_file_global_asm = if let Some(asm_o) = work_product.saved_files.get("asm.o") {
270252
let source_file_global_asm = rustc_incremental::in_incr_comp_dir_sess(tcx.sess, asm_o);
271253
if let Err(err) = rustc_fs_util::link_or_copy(&source_file_global_asm, &obj_out_global_asm)
@@ -283,26 +265,21 @@ fn reuse_workproduct_for_cgu(
283265
};
284266

285267
Ok(ModuleCodegenResult {
286-
module_regular: CompiledModule {
268+
module: CompiledModule {
287269
name: cgu.name().to_string(),
288270
kind: ModuleKind::Regular,
289271
object: Some(obj_out_regular),
272+
global_asm_object: source_file_global_asm.as_ref().map(|_| obj_out_global_asm),
290273
dwarf_object: None,
291274
bytecode: None,
292275
assembly: None,
293276
llvm_ir: None,
294-
links_from_incr_cache: vec![source_file_regular],
277+
links_from_incr_cache: if let Some(source_file_global_asm) = source_file_global_asm {
278+
vec![source_file_regular, source_file_global_asm]
279+
} else {
280+
vec![source_file_regular]
281+
},
295282
},
296-
module_global_asm: source_file_global_asm.map(|source_file| CompiledModule {
297-
name: cgu.name().to_string(),
298-
kind: ModuleKind::Regular,
299-
object: Some(obj_out_global_asm),
300-
dwarf_object: None,
301-
bytecode: None,
302-
assembly: None,
303-
llvm_ir: None,
304-
links_from_incr_cache: vec![source_file],
305-
}),
306283
existing_work_product: Some((cgu.work_product_id(), work_product)),
307284
})
308285
}
@@ -447,6 +424,7 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option<CompiledModule> {
447424
product.object,
448425
ModuleKind::Allocator,
449426
"allocator_shim".to_owned(),
427+
None,
450428
&crate::debuginfo::producer(tcx.sess),
451429
) {
452430
Ok(allocator_module) => Some(allocator_module),

compiler/rustc_codegen_cranelift/src/global_asm.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::ty::TyCtxt;
1212
use rustc_middle::ty::layout::{
1313
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
1414
};
15-
use rustc_session::config::{OutputFilenames, OutputType};
15+
use rustc_session::config::OutputFilenames;
1616
use rustc_target::asm::InlineAsmArch;
1717

1818
use crate::prelude::*;
@@ -198,10 +198,7 @@ pub(crate) fn compile_global_asm(
198198
.join("\n");
199199
global_asm.push('\n');
200200

201-
let global_asm_object_file = add_file_stem_postfix(
202-
config.output_filenames.temp_path_for_cgu(OutputType::Object, cgu_name),
203-
".asm",
204-
);
201+
let global_asm_object_file = config.output_filenames.temp_path_ext_for_cgu("asm.o", cgu_name);
205202

206203
// Assemble `global_asm`
207204
if option_env!("CG_CLIF_FORCE_GNU_AS").is_some() {
@@ -271,14 +268,3 @@ pub(crate) fn compile_global_asm(
271268

272269
Ok(Some(global_asm_object_file))
273270
}
274-
275-
pub(crate) fn add_file_stem_postfix(mut path: PathBuf, postfix: &str) -> PathBuf {
276-
let mut new_filename = path.file_stem().unwrap().to_owned();
277-
new_filename.push(postfix);
278-
if let Some(extension) = path.extension() {
279-
new_filename.push(".");
280-
new_filename.push(extension);
281-
}
282-
path.set_file_name(new_filename);
283-
path
284-
}

0 commit comments

Comments
 (0)