Skip to content

Commit 02e1211

Browse files
committed
Merge remote-tracking branch 'origin' into free-more-space-ubuntu-24
2 parents 6bfbed7 + e6f12c8 commit 02e1211

File tree

149 files changed

+3024
-1531
lines changed

Some content is hidden

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

149 files changed

+3024
-1531
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
13911391
None,
13921392
);
13931393
// Destructure like a unit struct.
1394-
let unit_struct_pat = hir::PatKind::Path(qpath);
1394+
let unit_struct_pat = hir::PatKind::Expr(self.arena.alloc(hir::PatExpr {
1395+
kind: hir::PatExprKind::Path(qpath),
1396+
hir_id: self.next_id(),
1397+
span: self.lower_span(lhs.span),
1398+
}));
13951399
return self.pat_without_dbm(lhs.span, unit_struct_pat);
13961400
}
13971401
}

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6969
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
7070
None,
7171
);
72-
break hir::PatKind::Path(qpath);
72+
let kind = hir::PatExprKind::Path(qpath);
73+
let span = self.lower_span(pattern.span);
74+
let expr = hir::PatExpr { hir_id: pat_hir_id, span, kind };
75+
let expr = self.arena.alloc(expr);
76+
return hir::Pat {
77+
hir_id: self.next_id(),
78+
kind: hir::PatKind::Expr(expr),
79+
span,
80+
default_binding_modes: true,
81+
};
7382
}
7483
PatKind::Struct(qself, path, fields, etc) => {
7584
let qpath = self.lower_qpath(
@@ -304,16 +313,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
304313
)
305314
}
306315
Some(res) => {
307-
let hir_id = self.next_id();
308316
let res = self.lower_res(res);
309-
hir::PatKind::Path(hir::QPath::Resolved(
310-
None,
311-
self.arena.alloc(hir::Path {
312-
span: self.lower_span(ident.span),
313-
res,
314-
segments: arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
315-
}),
316-
))
317+
let span = self.lower_span(ident.span);
318+
hir::PatKind::Expr(self.arena.alloc(hir::PatExpr {
319+
kind: hir::PatExprKind::Path(hir::QPath::Resolved(
320+
None,
321+
self.arena.alloc(hir::Path {
322+
span,
323+
res,
324+
segments: arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), self.next_id(), res)],
325+
}),
326+
)),
327+
hir_id: self.next_id(),
328+
span,
329+
}))
317330
}
318331
}
319332
}

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,10 +1140,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11401140

11411141
let amp_mut_sugg = match *local_decl.local_info() {
11421142
LocalInfo::User(mir::BindingForm::ImplicitSelf(_)) => {
1143-
let suggestion = suggest_ampmut_self(self.infcx.tcx, decl_span);
1144-
let additional =
1145-
local_trait.map(|span| (span, suggest_ampmut_self(self.infcx.tcx, span)));
1146-
Some(AmpMutSugg { has_sugg: true, span: decl_span, suggestion, additional })
1143+
let (span, suggestion) = suggest_ampmut_self(self.infcx.tcx, decl_span);
1144+
let additional = local_trait.map(|span| suggest_ampmut_self(self.infcx.tcx, span));
1145+
Some(AmpMutSugg { has_sugg: true, span, suggestion, additional })
11471146
}
11481147

11491148
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
@@ -1202,10 +1201,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12021201
opt_ty_info: None,
12031202
..
12041203
})) => {
1205-
let sugg = suggest_ampmut_self(self.infcx.tcx, decl_span);
1204+
let (span, sugg) =
1205+
suggest_ampmut_self(self.infcx.tcx, decl_span);
12061206
Some(AmpMutSugg {
12071207
has_sugg: true,
1208-
span: decl_span,
1208+
span,
12091209
suggestion: sugg,
12101210
additional: None,
12111211
})
@@ -1461,17 +1461,12 @@ fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symb
14611461
}
14621462
}
14631463

1464-
fn suggest_ampmut_self<'tcx>(tcx: TyCtxt<'tcx>, span: Span) -> String {
1464+
fn suggest_ampmut_self(tcx: TyCtxt<'_>, span: Span) -> (Span, String) {
14651465
match tcx.sess.source_map().span_to_snippet(span) {
1466-
Ok(snippet) => {
1467-
let lt_pos = snippet.find('\'');
1468-
if let Some(lt_pos) = lt_pos {
1469-
format!("&{}mut self", &snippet[lt_pos..snippet.len() - 4])
1470-
} else {
1471-
"&mut self".to_string()
1472-
}
1466+
Ok(snippet) if snippet.ends_with("self") => {
1467+
(span.with_hi(span.hi() - BytePos(4)).shrink_to_hi(), "mut ".to_string())
14731468
}
1474-
_ => "&mut self".to_string(),
1469+
_ => (span, "&mut self".to_string()),
14751470
}
14761471
}
14771472

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ use super::error::*;
2121
use crate::errors::{LongRunning, LongRunningWarn};
2222
use crate::fluent_generated as fluent;
2323
use crate::interpret::{
24-
self, AllocId, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame, GlobalAlloc, ImmTy,
25-
InterpCx, InterpResult, MPlaceTy, OpTy, RangeSet, Scalar, compile_time_machine, interp_ok,
26-
throw_exhaust, throw_inval, throw_ub, throw_ub_custom, throw_unsup, throw_unsup_format,
24+
self, AllocId, AllocInit, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame,
25+
GlobalAlloc, ImmTy, InterpCx, InterpResult, MPlaceTy, OpTy, RangeSet, Scalar,
26+
compile_time_machine, interp_ok, throw_exhaust, throw_inval, throw_ub, throw_ub_custom,
27+
throw_unsup, throw_unsup_format,
2728
};
2829

2930
/// When hitting this many interpreted terminators we emit a deny by default lint
@@ -420,6 +421,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
420421
Size::from_bytes(size),
421422
align,
422423
interpret::MemoryKind::Machine(MemoryKind::Heap),
424+
AllocInit::Uninit,
423425
)?;
424426
ecx.write_pointer(ptr, dest)?;
425427
}

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2020
use tracing::{debug, instrument, trace};
2121

2222
use super::{
23-
AllocBytes, AllocId, AllocMap, AllocRange, Allocation, CheckAlignMsg, CheckInAllocMsg,
24-
CtfeProvenance, GlobalAlloc, InterpCx, InterpResult, Machine, MayLeak, Misalignment, Pointer,
25-
PointerArithmetic, Provenance, Scalar, alloc_range, err_ub, err_ub_custom, interp_ok, throw_ub,
26-
throw_ub_custom, throw_unsup, throw_unsup_format,
23+
AllocBytes, AllocId, AllocInit, AllocMap, AllocRange, Allocation, CheckAlignMsg,
24+
CheckInAllocMsg, CtfeProvenance, GlobalAlloc, InterpCx, InterpResult, Machine, MayLeak,
25+
Misalignment, Pointer, PointerArithmetic, Provenance, Scalar, alloc_range, err_ub,
26+
err_ub_custom, interp_ok, throw_ub, throw_ub_custom, throw_unsup, throw_unsup_format,
2727
};
2828
use crate::fluent_generated as fluent;
2929

@@ -230,11 +230,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
230230
size: Size,
231231
align: Align,
232232
kind: MemoryKind<M::MemoryKind>,
233+
init: AllocInit,
233234
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
234235
let alloc = if M::PANIC_ON_ALLOC_FAIL {
235-
Allocation::uninit(size, align)
236+
Allocation::new(size, align, init)
236237
} else {
237-
Allocation::try_uninit(size, align)?
238+
Allocation::try_new(size, align, init)?
238239
};
239240
self.insert_allocation(alloc, kind)
240241
}
@@ -270,13 +271,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
270271
M::adjust_alloc_root_pointer(self, Pointer::from(id), Some(kind))
271272
}
272273

274+
/// If this grows the allocation, `init_growth` determines
275+
/// whether the additional space will be initialized.
273276
pub fn reallocate_ptr(
274277
&mut self,
275278
ptr: Pointer<Option<M::Provenance>>,
276279
old_size_and_align: Option<(Size, Align)>,
277280
new_size: Size,
278281
new_align: Align,
279282
kind: MemoryKind<M::MemoryKind>,
283+
init_growth: AllocInit,
280284
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
281285
let (alloc_id, offset, _prov) = self.ptr_get_alloc_id(ptr, 0)?;
282286
if offset.bytes() != 0 {
@@ -289,7 +293,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
289293

290294
// For simplicities' sake, we implement reallocate as "alloc, copy, dealloc".
291295
// This happens so rarely, the perf advantage is outweighed by the maintenance cost.
292-
let new_ptr = self.allocate_ptr(new_size, new_align, kind)?;
296+
// If requested, we zero-init the entire allocation, to ensure that a growing
297+
// allocation has its new bytes properly set. For the part that is copied,
298+
// `mem_copy` below will de-initialize things as necessary.
299+
let new_ptr = self.allocate_ptr(new_size, new_align, kind, init_growth)?;
293300
let old_size = match old_size_and_align {
294301
Some((size, _align)) => size,
295302
None => self.get_alloc_raw(alloc_id)?.size(),
@@ -830,9 +837,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
830837
/// [`InterpCx::get_alloc_info`] if all you need to check is whether the kind is
831838
/// [`AllocKind::Dead`] because it doesn't have to look up the type and layout of statics.
832839
pub fn is_alloc_live(&self, id: AllocId) -> bool {
833-
self.tcx.try_get_global_alloc(id).is_some()
834-
|| self.memory.alloc_map.contains_key_ref(&id)
840+
self.memory.alloc_map.contains_key_ref(&id)
835841
|| self.memory.extra_fn_ptr_map.contains_key(&id)
842+
// We check `tcx` last as that has to acquire a lock in `many-seeds` mode.
843+
// This also matches the order in `get_alloc_info`.
844+
|| self.tcx.try_get_global_alloc(id).is_some()
836845
}
837846

838847
/// Obtain the size and alignment of an allocation, even if that allocation has

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use rustc_middle::{bug, mir, span_bug};
1212
use tracing::{instrument, trace};
1313

1414
use super::{
15-
AllocRef, AllocRefMut, CheckAlignMsg, CtfeProvenance, ImmTy, Immediate, InterpCx, InterpResult,
16-
Machine, MemoryKind, Misalignment, OffsetMode, OpTy, Operand, Pointer, Projectable, Provenance,
17-
Scalar, alloc_range, interp_ok, mir_assign_valid_types,
15+
AllocInit, AllocRef, AllocRefMut, CheckAlignMsg, CtfeProvenance, ImmTy, Immediate, InterpCx,
16+
InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy, Operand, Pointer,
17+
Projectable, Provenance, Scalar, alloc_range, interp_ok, mir_assign_valid_types,
1818
};
1919

2020
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
@@ -983,7 +983,7 @@ where
983983
let Some((size, align)) = self.size_and_align_of(&meta, &layout)? else {
984984
span_bug!(self.cur_span(), "cannot allocate space for `extern` type, size is not known")
985985
};
986-
let ptr = self.allocate_ptr(size, align, kind)?;
986+
let ptr = self.allocate_ptr(size, align, kind, AllocInit::Uninit)?;
987987
interp_ok(self.ptr_with_meta_to_mplace(ptr.into(), meta, layout, /*unaligned*/ false))
988988
}
989989

compiler/rustc_const_eval/src/interpret/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ops::ControlFlow;
22

33
use rustc_hir::def_id::LocalDefId;
44
use rustc_middle::mir;
5-
use rustc_middle::mir::interpret::{Allocation, InterpResult, Pointer};
5+
use rustc_middle::mir::interpret::{AllocInit, Allocation, InterpResult, Pointer};
66
use rustc_middle::ty::layout::TyAndLayout;
77
use rustc_middle::ty::{
88
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
@@ -76,7 +76,7 @@ pub(crate) fn create_static_alloc<'tcx>(
7676
static_def_id: LocalDefId,
7777
layout: TyAndLayout<'tcx>,
7878
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
79-
let alloc = Allocation::try_uninit(layout.size, layout.align.abi)?;
79+
let alloc = Allocation::try_new(layout.size, layout.align.abi, AllocInit::Uninit)?;
8080
let alloc_id = ecx.tcx.reserve_and_set_static_alloc(static_def_id.into());
8181
assert_eq!(ecx.machine.static_root_ids, None);
8282
ecx.machine.static_root_ids = Some((alloc_id, static_def_id));

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub trait Callbacks {
160160
fn after_crate_root_parsing(
161161
&mut self,
162162
_compiler: &interface::Compiler,
163-
_queries: &ast::Crate,
163+
_krate: &mut ast::Crate,
164164
) -> Compilation {
165165
Compilation::Continue
166166
}
@@ -311,7 +311,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
311311

312312
// Parse the crate root source code (doesn't parse submodules yet)
313313
// Everything else is parsed during macro expansion.
314-
let krate = passes::parse(sess);
314+
let mut krate = passes::parse(sess);
315315

316316
// If pretty printing is requested: Figure out the representation, print it and exit
317317
if let Some(pp_mode) = sess.opts.pretty {
@@ -328,7 +328,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
328328
return early_exit();
329329
}
330330

331-
if callbacks.after_crate_root_parsing(compiler, &krate) == Compilation::Stop {
331+
if callbacks.after_crate_root_parsing(compiler, &mut krate) == Compilation::Stop {
332332
return early_exit();
333333
}
334334

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ impl<'hir> Pat<'hir> {
14371437

14381438
use PatKind::*;
14391439
match self.kind {
1440-
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => true,
1440+
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => true,
14411441
Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_short_(it),
14421442
Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)),
14431443
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)),
@@ -1464,7 +1464,7 @@ impl<'hir> Pat<'hir> {
14641464

14651465
use PatKind::*;
14661466
match self.kind {
1467-
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => {}
1467+
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => {}
14681468
Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it),
14691469
Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)),
14701470
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)),
@@ -1618,9 +1618,6 @@ pub enum PatKind<'hir> {
16181618
/// A never pattern `!`.
16191619
Never,
16201620

1621-
/// A path pattern for a unit struct/variant or a (maybe-associated) constant.
1622-
Path(QPath<'hir>),
1623-
16241621
/// A tuple pattern (e.g., `(a, b)`).
16251622
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
16261623
/// `0 <= position <= subpats.len()`

compiler/rustc_hir/src/intravisit.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,9 +709,6 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V:
709709
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
710710
walk_list!(visitor, visit_pat, children);
711711
}
712-
PatKind::Path(ref qpath) => {
713-
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
714-
}
715712
PatKind::Struct(ref qpath, fields, _) => {
716713
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
717714
walk_list!(visitor, visit_pat_field, fields);

compiler/rustc_hir/src/pat_util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ impl hir::Pat<'_> {
105105
let mut variants = vec![];
106106
self.walk(|p| match &p.kind {
107107
PatKind::Or(_) => false,
108-
PatKind::Path(hir::QPath::Resolved(_, path))
108+
PatKind::Expr(hir::PatExpr {
109+
kind: hir::PatExprKind::Path(hir::QPath::Resolved(_, path)),
110+
..
111+
})
109112
| PatKind::TupleStruct(hir::QPath::Resolved(_, path), ..)
110113
| PatKind::Struct(hir::QPath::Resolved(_, path), ..) => {
111114
if let Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), id) =

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ fn resolve_local<'tcx>(
703703
| PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), ..)
704704
| PatKind::Wild
705705
| PatKind::Never
706-
| PatKind::Path(_)
707706
| PatKind::Expr(_)
708707
| PatKind::Range(_, _, _)
709708
| PatKind::Err(_) => false,

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
4141
kind: hir::ExprKind::Path(hir::QPath::TypeRelative(qself, _)),
4242
..
4343
})
44-
| hir::Node::Pat(hir::Pat {
45-
kind: hir::PatKind::Path(hir::QPath::TypeRelative(qself, _)),
44+
| hir::Node::PatExpr(hir::PatExpr {
45+
kind: hir::PatExprKind::Path(hir::QPath::TypeRelative(qself, _)),
4646
..
4747
}) if qself.hir_id == self_ty.hir_id => true,
4848
_ => false,

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,9 +1906,6 @@ impl<'a> State<'a> {
19061906
}
19071907
self.pclose();
19081908
}
1909-
PatKind::Path(ref qpath) => {
1910-
self.print_qpath(qpath, true);
1911-
}
19121909
PatKind::Struct(ref qpath, fields, etc) => {
19131910
self.print_qpath(qpath, true);
19141911
self.nbsp();

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
480480
hir::PatKind::Binding(_, _, _, _)
481481
| hir::PatKind::Struct(_, _, _)
482482
| hir::PatKind::TupleStruct(_, _, _)
483-
| hir::PatKind::Path(_)
484483
| hir::PatKind::Tuple(_, _)
485484
| hir::PatKind::Box(_)
486485
| hir::PatKind::Ref(_, _)

0 commit comments

Comments
 (0)