Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6e4fd87

Browse files
committed
Auto merge of rust-lang#3053 - RalfJung:rustup, r=RalfJung
Rustup
2 parents f2568c8 + b870676 commit 6e4fd87

File tree

1,057 files changed

+9676
-1327
lines changed

Some content is hidden

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

1,057 files changed

+9676
-1327
lines changed

Cargo.lock

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,18 @@ version = "0.8.4"
722722
source = "registry+https://github.com/rust-lang/crates.io-index"
723723
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
724724

725+
[[package]]
726+
name = "coverage-dump"
727+
version = "0.1.0"
728+
dependencies = [
729+
"anyhow",
730+
"leb128",
731+
"md-5",
732+
"miniz_oxide",
733+
"regex",
734+
"rustc-demangle",
735+
]
736+
725737
[[package]]
726738
name = "coverage_test_macros"
727739
version = "0.0.0"
@@ -2041,6 +2053,12 @@ version = "1.3.0"
20412053
source = "registry+https://github.com/rust-lang/crates.io-index"
20422054
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
20432055

2056+
[[package]]
2057+
name = "leb128"
2058+
version = "0.2.5"
2059+
source = "registry+https://github.com/rust-lang/crates.io-index"
2060+
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
2061+
20442062
[[package]]
20452063
name = "levenshtein"
20462064
version = "1.0.5"
@@ -4228,7 +4246,6 @@ dependencies = [
42284246
"measureme",
42294247
"memoffset",
42304248
"rustc-rayon-core",
4231-
"rustc_ast",
42324249
"rustc_data_structures",
42334250
"rustc_errors",
42344251
"rustc_hir",
@@ -4437,15 +4454,12 @@ dependencies = [
44374454
name = "rustc_traits"
44384455
version = "0.0.0"
44394456
dependencies = [
4440-
"rustc_ast",
44414457
"rustc_data_structures",
44424458
"rustc_hir",
44434459
"rustc_infer",
44444460
"rustc_middle",
44454461
"rustc_span",
4446-
"rustc_target",
44474462
"rustc_trait_selection",
4448-
"smallvec",
44494463
"tracing",
44504464
]
44514465

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ members = [
4343
"src/tools/generate-windows-sys",
4444
"src/tools/rustdoc-gui-test",
4545
"src/tools/opt-dist",
46+
"src/tools/coverage-dump",
4647
]
4748

4849
exclude = [

RELEASES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Language
1010
- [expand: Change how `#![cfg(FALSE)]` behaves on crate root](https://github.com/rust-lang/rust/pull/110141/)
1111
- [Stabilize inline asm for LoongArch64](https://github.com/rust-lang/rust/pull/111235/)
1212
- [Uplift `clippy::undropped_manually_drops` lint](https://github.com/rust-lang/rust/pull/111530/)
13-
- [Uplift `clippy::invalid_utf8_in_unchecked` lint](https://github.com/rust-lang/rust/pull/111543/)
14-
- [Uplift `clippy::cast_ref_to_mut` lint](https://github.com/rust-lang/rust/pull/111567/)
15-
- [Uplift `clippy::cmp_nan` lint](https://github.com/rust-lang/rust/pull/111818/)
13+
- [Uplift `clippy::invalid_utf8_in_unchecked` lint](https://github.com/rust-lang/rust/pull/111543/) as `invalid_from_utf8_unchecked` and `invalid_from_utf8`
14+
- [Uplift `clippy::cast_ref_to_mut` lint](https://github.com/rust-lang/rust/pull/111567/) as `invalid_reference_casting`
15+
- [Uplift `clippy::cmp_nan` lint](https://github.com/rust-lang/rust/pull/111818/) as `invalid_nan_comparisons`
1616
- [resolve: Remove artificial import ambiguity errors](https://github.com/rust-lang/rust/pull/112086/)
1717
- [Don't require associated types with Self: Sized bounds in `dyn Trait` objects](https://github.com/rust-lang/rust/pull/112319/)
1818

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,10 @@ impl AttrTokenStream {
213213
.into_iter()
214214
}
215215
AttrTokenTree::Attributes(data) => {
216-
let mut outer_attrs = Vec::new();
217-
let mut inner_attrs = Vec::new();
218-
for attr in &data.attrs {
219-
match attr.style {
220-
crate::AttrStyle::Outer => outer_attrs.push(attr),
221-
crate::AttrStyle::Inner => inner_attrs.push(attr),
222-
}
223-
}
216+
let idx = data
217+
.attrs
218+
.partition_point(|attr| matches!(attr.style, crate::AttrStyle::Outer));
219+
let (outer_attrs, inner_attrs) = data.attrs.split_at(idx);
224220

225221
let mut target_tokens: Vec<_> = data
226222
.tokens
@@ -265,10 +261,10 @@ impl AttrTokenStream {
265261
"Failed to find trailing delimited group in: {target_tokens:?}"
266262
);
267263
}
268-
let mut flat: SmallVec<[_; 1]> = SmallVec::new();
264+
let mut flat: SmallVec<[_; 1]> =
265+
SmallVec::with_capacity(target_tokens.len() + outer_attrs.len());
269266
for attr in outer_attrs {
270-
// FIXME: Make this more efficient
271-
flat.extend(attr.tokens().0.clone().iter().cloned());
267+
flat.extend(attr.tokens().0.iter().cloned());
272268
}
273269
flat.extend(target_tokens);
274270
flat.into_iter()

compiler/rustc_borrowck/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
603603

604604
fn visit_statement_before_primary_effect(
605605
&mut self,
606-
_results: &R,
606+
_results: &mut R,
607607
flow_state: &Flows<'cx, 'tcx>,
608608
stmt: &'cx Statement<'tcx>,
609609
location: Location,
@@ -673,7 +673,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
673673

674674
fn visit_terminator_before_primary_effect(
675675
&mut self,
676-
_results: &R,
676+
_results: &mut R,
677677
flow_state: &Flows<'cx, 'tcx>,
678678
term: &'cx Terminator<'tcx>,
679679
loc: Location,
@@ -784,7 +784,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
784784

785785
fn visit_terminator_after_primary_effect(
786786
&mut self,
787-
_results: &R,
787+
_results: &mut R,
788788
flow_state: &Flows<'cx, 'tcx>,
789789
term: &'cx Terminator<'tcx>,
790790
loc: Location,

compiler/rustc_codegen_cranelift/src/debuginfo/line_info.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,9 @@ impl DebugContext {
8282
match tcx.sess.source_map().lookup_line(span.lo()) {
8383
Ok(SourceFileAndLine { sf: file, line }) => {
8484
let line_pos = file.lines(|lines| lines[line]);
85+
let col = file.relative_position(span.lo()) - line_pos;
8586

86-
(
87-
file,
88-
u64::try_from(line).unwrap() + 1,
89-
u64::from((span.lo() - line_pos).to_u32()) + 1,
90-
)
87+
(file, u64::try_from(line).unwrap() + 1, u64::from(col.to_u32()) + 1)
9188
}
9289
Err(file) => (file, 0, 0),
9390
}

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn make_mir_scope<'ll, 'tcx>(
6868
let file = cx.sess().source_map().lookup_source_file(mir.span.lo());
6969
debug_context.scopes[scope] = DebugScope {
7070
file_start_pos: file.start_pos,
71-
file_end_pos: file.end_pos,
71+
file_end_pos: file.end_position(),
7272
..debug_context.scopes[scope]
7373
};
7474
instantiated.insert(scope);
@@ -120,7 +120,7 @@ fn make_mir_scope<'ll, 'tcx>(
120120
dbg_scope,
121121
inlined_at: inlined_at.or(parent_scope.inlined_at),
122122
file_start_pos: loc.file.start_pos,
123-
file_end_pos: loc.file.end_pos,
123+
file_end_pos: loc.file.end_position(),
124124
};
125125
instantiated.insert(scope);
126126
}

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl CodegenCx<'_, '_> {
267267

268268
// Use 1-based indexing.
269269
let line = (line + 1) as u32;
270-
let col = (pos - line_pos).to_u32() + 1;
270+
let col = (file.relative_position(pos) - line_pos).to_u32() + 1;
271271

272272
(file, line, col)
273273
}

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
7979
intern_const_alloc_recursive(ecx, intern_kind, &ret)?;
8080
// we leave alignment checks off, since this `ecx` will not be used for further evaluation anyway
8181

82-
debug!("eval_body_using_ecx done: {:?}", *ret);
82+
debug!("eval_body_using_ecx done: {:?}", ret);
8383
Ok(ret)
8484
}
8585

@@ -147,7 +147,7 @@ pub(super) fn op_to_const<'tcx>(
147147
// We know `offset` is relative to the allocation, so we can use `into_parts`.
148148
let to_const_value = |mplace: &MPlaceTy<'_>| {
149149
debug!("to_const_value(mplace: {:?})", mplace);
150-
match mplace.ptr.into_parts() {
150+
match mplace.ptr().into_parts() {
151151
(Some(alloc_id), offset) => {
152152
let alloc = ecx.tcx.global_alloc(alloc_id).unwrap_memory();
153153
ConstValue::ByRef { alloc, offset }
@@ -370,7 +370,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
370370
inner = true;
371371
}
372372
};
373-
let alloc_id = mplace.ptr.provenance.unwrap();
373+
let alloc_id = mplace.ptr().provenance.unwrap();
374374

375375
// Validation failed, report an error. This is always a hard error.
376376
if let Err(error) = validation {

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn const_caller_location(
3030
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &loc_place).is_err() {
3131
bug!("intern_const_alloc_recursive should not error in this case")
3232
}
33-
ConstValue::Scalar(Scalar::from_maybe_pointer(loc_place.ptr, &tcx))
33+
ConstValue::Scalar(Scalar::from_maybe_pointer(loc_place.ptr(), &tcx))
3434
}
3535

3636
// We forbid type-level constants that contain more than `VALTREE_MAX_NODES` nodes.

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::const_eval::CanAccessStatics;
55
use crate::interpret::MPlaceTy;
66
use crate::interpret::{
77
intern_const_alloc_recursive, ConstValue, ImmTy, Immediate, InternKind, MemPlaceMeta,
8-
MemoryKind, Place, Projectable, Scalar,
8+
MemoryKind, PlaceTy, Projectable, Scalar,
99
};
1010
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1111
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
@@ -318,7 +318,7 @@ fn valtree_into_mplace<'tcx>(
318318
let len_scalar = Scalar::from_target_usize(len as u64, &tcx);
319319

320320
Immediate::ScalarPair(
321-
Scalar::from_maybe_pointer((*pointee_place).ptr, &tcx),
321+
Scalar::from_maybe_pointer(pointee_place.ptr(), &tcx),
322322
len_scalar,
323323
)
324324
}
@@ -383,5 +383,5 @@ fn valtree_into_mplace<'tcx>(
383383
}
384384

385385
fn dump_place<'tcx>(ecx: &CompileTimeEvalContext<'tcx, 'tcx>, place: &MPlaceTy<'tcx>) {
386-
trace!("{:?}", ecx.dump_place(Place::Ptr(**place)));
386+
trace!("{:?}", ecx.dump_place(&PlaceTy::from(place.clone())));
387387
}

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use rustc_target::abi::{call::FnAbi, Align, HasDataLayout, Size, TargetDataLayou
2121

2222
use super::{
2323
AllocId, GlobalId, Immediate, InterpErrorInfo, InterpResult, MPlaceTy, Machine, MemPlace,
24-
MemPlaceMeta, Memory, MemoryKind, Operand, Place, PlaceTy, PointerArithmetic, Provenance,
25-
Scalar, StackPopJump,
24+
MemPlaceMeta, Memory, MemoryKind, Operand, Place, PlaceTy, Pointer, PointerArithmetic,
25+
Projectable, Provenance, Scalar, StackPopJump,
2626
};
2727
use crate::errors::{self, ErroneousConstUsed};
2828
use crate::util;
@@ -155,17 +155,26 @@ pub enum StackPopCleanup {
155155
}
156156

157157
/// State of a local variable including a memoized layout
158-
#[derive(Clone, Debug)]
158+
#[derive(Clone)]
159159
pub struct LocalState<'tcx, Prov: Provenance = AllocId> {
160-
pub value: LocalValue<Prov>,
160+
value: LocalValue<Prov>,
161161
/// Don't modify if `Some`, this is only used to prevent computing the layout twice.
162162
/// Avoids computing the layout of locals that are never actually initialized.
163-
pub layout: Cell<Option<TyAndLayout<'tcx>>>,
163+
layout: Cell<Option<TyAndLayout<'tcx>>>,
164+
}
165+
166+
impl<Prov: Provenance> std::fmt::Debug for LocalState<'_, Prov> {
167+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
168+
f.debug_struct("LocalState")
169+
.field("value", &self.value)
170+
.field("ty", &self.layout.get().map(|l| l.ty))
171+
.finish()
172+
}
164173
}
165174

166175
/// Current value of a local variable
167176
#[derive(Copy, Clone, Debug)] // Miri debug-prints these
168-
pub enum LocalValue<Prov: Provenance = AllocId> {
177+
pub(super) enum LocalValue<Prov: Provenance = AllocId> {
169178
/// This local is not currently alive, and cannot be used at all.
170179
Dead,
171180
/// A normal, live local.
@@ -176,10 +185,27 @@ pub enum LocalValue<Prov: Provenance = AllocId> {
176185
Live(Operand<Prov>),
177186
}
178187

179-
impl<'tcx, Prov: Provenance + 'static> LocalState<'tcx, Prov> {
188+
impl<'tcx, Prov: Provenance> LocalState<'tcx, Prov> {
189+
pub fn make_live_uninit(&mut self) {
190+
self.value = LocalValue::Live(Operand::Immediate(Immediate::Uninit));
191+
}
192+
193+
/// This is a hack because Miri needs a way to visit all the provenance in a `LocalState`
194+
/// without having a layout or `TyCtxt` available, and we want to keep the `Operand` type
195+
/// private.
196+
pub fn as_mplace_or_imm(
197+
&self,
198+
) -> Option<Either<(Pointer<Option<Prov>>, MemPlaceMeta<Prov>), Immediate<Prov>>> {
199+
match self.value {
200+
LocalValue::Dead => None,
201+
LocalValue::Live(Operand::Indirect(mplace)) => Some(Left((mplace.ptr, mplace.meta))),
202+
LocalValue::Live(Operand::Immediate(imm)) => Some(Right(imm)),
203+
}
204+
}
205+
180206
/// Read the local's value or error if the local is not yet live or not live anymore.
181207
#[inline(always)]
182-
pub fn access(&self) -> InterpResult<'tcx, &Operand<Prov>> {
208+
pub(super) fn access(&self) -> InterpResult<'tcx, &Operand<Prov>> {
183209
match &self.value {
184210
LocalValue::Dead => throw_ub!(DeadLocal), // could even be "invalid program"?
185211
LocalValue::Live(val) => Ok(val),
@@ -189,10 +215,10 @@ impl<'tcx, Prov: Provenance + 'static> LocalState<'tcx, Prov> {
189215
/// Overwrite the local. If the local can be overwritten in place, return a reference
190216
/// to do so; otherwise return the `MemPlace` to consult instead.
191217
///
192-
/// Note: This may only be invoked from the `Machine::access_local_mut` hook and not from
193-
/// anywhere else. You may be invalidating machine invariants if you do!
218+
/// Note: Before calling this, call the `before_access_local_mut` machine hook! You may be
219+
/// invalidating machine invariants otherwise!
194220
#[inline(always)]
195-
pub fn access_mut(&mut self) -> InterpResult<'tcx, &mut Operand<Prov>> {
221+
pub(super) fn access_mut(&mut self) -> InterpResult<'tcx, &mut Operand<Prov>> {
196222
match &mut self.value {
197223
LocalValue::Dead => throw_ub!(DeadLocal), // could even be "invalid program"?
198224
LocalValue::Live(val) => Ok(val),
@@ -694,7 +720,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
694720
&self,
695721
mplace: &MPlaceTy<'tcx, M::Provenance>,
696722
) -> InterpResult<'tcx, Option<(Size, Align)>> {
697-
self.size_and_align_of(&mplace.meta, &mplace.layout)
723+
self.size_and_align_of(&mplace.meta(), &mplace.layout)
698724
}
699725

700726
#[instrument(skip(self, body, return_place, return_to_block), level = "debug")]
@@ -826,7 +852,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
826852
.expect("return place should always be live");
827853
let dest = self.frame().return_place.clone();
828854
let err = self.copy_op(&op, &dest, /*allow_transmute*/ true);
829-
trace!("return value: {:?}", self.dump_place(*dest));
855+
trace!("return value: {:?}", self.dump_place(&dest));
830856
// We delay actually short-circuiting on this error until *after* the stack frame is
831857
// popped, since we want this error to be attributed to the caller, whose type defines
832858
// this transmute.
@@ -974,7 +1000,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9741000
}
9751001
// Need to allocate some memory, since `Immediate::Uninit` cannot be unsized.
9761002
let dest_place = self.allocate_dyn(layout, MemoryKind::Stack, meta)?;
977-
Operand::Indirect(*dest_place)
1003+
Operand::Indirect(*dest_place.mplace())
9781004
} else {
9791005
assert!(!meta.has_meta()); // we're dropping the metadata
9801006
// Just make this an efficient immediate.
@@ -1068,8 +1094,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10681094
}
10691095

10701096
#[must_use]
1071-
pub fn dump_place(&self, place: Place<M::Provenance>) -> PlacePrinter<'_, 'mir, 'tcx, M> {
1072-
PlacePrinter { ecx: self, place }
1097+
pub fn dump_place(
1098+
&self,
1099+
place: &PlaceTy<'tcx, M::Provenance>,
1100+
) -> PlacePrinter<'_, 'mir, 'tcx, M> {
1101+
PlacePrinter { ecx: self, place: *place.place() }
10731102
}
10741103

10751104
#[must_use]

0 commit comments

Comments
 (0)