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

Commit 614f273

Browse files
committed
Auto merge of rust-lang#71721 - tmandry:rollup-e27pxex, r=tmandry
Rollup of 8 pull requests Successful merges: - rust-lang#71148 (Vec drop and truncate: drop using raw slice *mut [T]) - rust-lang#71465 (Add a convenience method on `TyCtxt` for checking for thread locals) - rust-lang#71567 (Handle build completion message from Cargo) - rust-lang#71590 (MIR dump: print pointers consistently with Miri output) - rust-lang#71682 (Bump pulldown-cmark) - rust-lang#71688 (Allow `Downcast` projections unconditionally in const-checking) - rust-lang#71691 (Allow `Unreachable` terminators unconditionally in const-checking) - rust-lang#71719 (Update backtrace-sys) Failed merges: r? @ghost
2 parents 7ced01a + 59abc2a commit 614f273

40 files changed

+176
-174
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ dependencies = [
135135

136136
[[package]]
137137
name = "backtrace-sys"
138-
version = "0.1.36"
138+
version = "0.1.37"
139139
source = "registry+https://github.com/rust-lang/crates.io-index"
140-
checksum = "78848718ee1255a2485d1309ad9cdecfc2e7d0362dd11c6829364c6b35ae1bc7"
140+
checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399"
141141
dependencies = [
142142
"cc",
143143
"compiler_builtins",
@@ -487,7 +487,7 @@ dependencies = [
487487
"if_chain",
488488
"itertools 0.9.0",
489489
"lazy_static 1.4.0",
490-
"pulldown-cmark 0.7.0",
490+
"pulldown-cmark 0.7.1",
491491
"quine-mc_cluskey",
492492
"regex-syntax",
493493
"semver",
@@ -2657,9 +2657,9 @@ dependencies = [
26572657

26582658
[[package]]
26592659
name = "pulldown-cmark"
2660-
version = "0.7.0"
2660+
version = "0.7.1"
26612661
source = "registry+https://github.com/rust-lang/crates.io-index"
2662-
checksum = "2c2d7fd131800e0d63df52aff46201acaab70b431a4a1ec6f0343fe8e64f35a4"
2662+
checksum = "3e142c3b8f49d2200605ee6ba0b1d757310e9e7a72afe78c36ee2ef67300ee00"
26632663
dependencies = [
26642664
"bitflags",
26652665
"memchr",
@@ -4342,7 +4342,7 @@ version = "0.0.0"
43424342
dependencies = [
43434343
"itertools 0.8.0",
43444344
"minifier",
4345-
"pulldown-cmark 0.7.0",
4345+
"pulldown-cmark 0.7.1",
43464346
"rustc-rayon",
43474347
"serde",
43484348
"serde_json",

src/bootstrap/compile.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,4 +1012,7 @@ pub enum CargoMessage<'a> {
10121012
BuildScriptExecuted {
10131013
package_id: Cow<'a, str>,
10141014
},
1015+
BuildFinished {
1016+
success: bool,
1017+
},
10151018
}

src/liballoc/vec.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl<T> Vec<T> {
741741
return;
742742
}
743743
let remaining_len = self.len - len;
744-
let s = slice::from_raw_parts_mut(self.as_mut_ptr().add(len), remaining_len);
744+
let s = ptr::slice_from_raw_parts_mut(self.as_mut_ptr().add(len), remaining_len);
745745
self.len = len;
746746
ptr::drop_in_place(s);
747747
}
@@ -2379,7 +2379,9 @@ unsafe impl<#[may_dangle] T> Drop for Vec<T> {
23792379
fn drop(&mut self) {
23802380
unsafe {
23812381
// use drop for [T]
2382-
ptr::drop_in_place(&mut self[..]);
2382+
// use a raw slice to refer to the elements of the vector as weakest necessary type;
2383+
// could avoid questions of validity in certain cases
2384+
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(self.as_mut_ptr(), self.len))
23832385
}
23842386
// RawVec handles deallocation
23852387
}
@@ -2596,7 +2598,11 @@ impl<T> IntoIter<T> {
25962598
/// ```
25972599
#[stable(feature = "vec_into_iter_as_slice", since = "1.15.0")]
25982600
pub fn as_mut_slice(&mut self) -> &mut [T] {
2599-
unsafe { slice::from_raw_parts_mut(self.ptr as *mut T, self.len()) }
2601+
unsafe { &mut *self.as_raw_mut_slice() }
2602+
}
2603+
2604+
fn as_raw_mut_slice(&mut self) -> *mut [T] {
2605+
ptr::slice_from_raw_parts_mut(self.ptr as *mut T, self.len())
26002606
}
26012607
}
26022608

@@ -2708,7 +2714,7 @@ unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
27082714
let guard = DropGuard(self);
27092715
// destroy the remaining elements
27102716
unsafe {
2711-
ptr::drop_in_place(guard.0.as_mut_slice());
2717+
ptr::drop_in_place(guard.0.as_raw_mut_slice());
27122718
}
27132719
// now `guard` will be dropped and do the rest
27142720
}

src/librustc_codegen_llvm/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl CodegenCx<'ll, 'tcx> {
212212
let g = if let Some(def_id) = def_id.as_local() {
213213
let id = self.tcx.hir().as_local_hir_id(def_id);
214214
let llty = self.layout_of(ty).llvm_type(self);
215+
// FIXME: refactor this to work without accessing the HIR
215216
let (g, attrs) = match self.tcx.hir().get(id) {
216217
Node::Item(&hir::Item { attrs, span, kind: hir::ItemKind::Static(..), .. }) => {
217218
let sym_str = sym.as_str();

src/librustc_middle/mir/interpret/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,7 @@ impl fmt::Debug for UndefinedBehaviorInfo {
438438
/// Error information for when the program did something that might (or might not) be correct
439439
/// to do according to the Rust spec, but due to limitations in the interpreter, the
440440
/// operation could not be carried out. These limitations can differ between CTFE and the
441-
/// Miri engine, e.g., CTFE does not support casting pointers to "real" integers.
442-
///
443-
/// Currently, we also use this as fall-back error kind for errors that have not been
444-
/// categorized yet.
441+
/// Miri engine, e.g., CTFE does not support dereferencing pointers at integral addresses.
445442
pub enum UnsupportedOpInfo {
446443
/// Free-form case. Only for errors that are never caught!
447444
Unsupported(String),
@@ -451,6 +448,9 @@ pub enum UnsupportedOpInfo {
451448
NoMirFor(DefId),
452449
/// Encountered a pointer where we needed raw bytes.
453450
ReadPointerAsBytes,
451+
//
452+
// The variants below are only reachable from CTFE/const prop, miri will never emit them.
453+
//
454454
/// Encountered raw bytes where we needed a pointer.
455455
ReadBytesAsPointer,
456456
}

src/librustc_middle/mir/interpret/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,17 @@ pub enum LitToConstError {
168168
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
169169
pub struct AllocId(pub u64);
170170

171+
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
172+
// all the Miri types.
171173
impl fmt::Debug for AllocId {
172-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
173-
fmt::Display::fmt(self, fmt)
174+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
175+
if f.alternate() { write!(f, "a{}", self.0) } else { write!(f, "alloc{}", self.0) }
174176
}
175177
}
176178

177179
impl fmt::Display for AllocId {
178180
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
179-
write!(f, "alloc{}", self.0)
181+
fmt::Debug::fmt(self, f)
180182
}
181183
}
182184

src/librustc_middle/mir/interpret/pointer.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,33 @@ pub struct Pointer<Tag = (), Id = AllocId> {
119119

120120
static_assert_size!(Pointer, 16);
121121

122+
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
123+
// all the Miri types.
124+
// We have to use `Debug` output for the tag, because `()` does not implement
125+
// `Display` so we cannot specialize that.
122126
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Pointer<Tag, Id> {
123127
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124-
write!(f, "{:?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
128+
if f.alternate() {
129+
write!(f, "{:#?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
130+
} else {
131+
write!(f, "{:?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
132+
}
125133
}
126134
}
127135
// Specialization for no tag
128136
impl<Id: fmt::Debug> fmt::Debug for Pointer<(), Id> {
129137
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
130-
write!(f, "{:?}+0x{:x}", self.alloc_id, self.offset.bytes())
138+
if f.alternate() {
139+
write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes())
140+
} else {
141+
write!(f, "{:?}+0x{:x}", self.alloc_id, self.offset.bytes())
142+
}
143+
}
144+
}
145+
146+
impl<Tag: fmt::Debug> fmt::Display for Pointer<Tag> {
147+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
148+
fmt::Debug::fmt(self, f)
131149
}
132150
}
133151

src/librustc_middle/mir/interpret/value.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ pub enum Scalar<Tag = (), Id = AllocId> {
107107
#[cfg(target_arch = "x86_64")]
108108
static_assert_size!(Scalar, 24);
109109

110+
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
111+
// all the Miri types.
110112
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Scalar<Tag, Id> {
111113
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112114
match self {
@@ -125,11 +127,11 @@ impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Scalar<Tag, Id> {
125127
}
126128
}
127129

128-
impl<Tag> fmt::Display for Scalar<Tag> {
130+
impl<Tag: fmt::Debug> fmt::Display for Scalar<Tag> {
129131
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
130132
match self {
131-
Scalar::Ptr(_) => write!(f, "a pointer"),
132-
Scalar::Raw { data, .. } => write!(f, "{}", data),
133+
Scalar::Ptr(ptr) => write!(f, "pointer to {}", ptr),
134+
Scalar::Raw { .. } => fmt::Debug::fmt(self, f),
133135
}
134136
}
135137
}
@@ -559,16 +561,18 @@ impl<Tag> From<Pointer<Tag>> for ScalarMaybeUndef<Tag> {
559561
}
560562
}
561563

564+
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
565+
// all the Miri types.
562566
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for ScalarMaybeUndef<Tag, Id> {
563567
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
564568
match self {
565-
ScalarMaybeUndef::Undef => write!(f, "Undef"),
569+
ScalarMaybeUndef::Undef => write!(f, "<uninitialized>"),
566570
ScalarMaybeUndef::Scalar(s) => write!(f, "{:?}", s),
567571
}
568572
}
569573
}
570574

571-
impl<Tag> fmt::Display for ScalarMaybeUndef<Tag> {
575+
impl<Tag: fmt::Debug> fmt::Display for ScalarMaybeUndef<Tag> {
572576
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
573577
match self {
574578
ScalarMaybeUndef::Undef => write!(f, "uninitialized bytes"),

src/librustc_middle/ty/util.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
22
33
use crate::ich::NodeIdHashingMode;
4+
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
45
use crate::mir::interpret::{sign_extend, truncate};
56
use crate::ty::layout::IntegerExt;
67
use crate::ty::query::TyCtxtAt;
@@ -528,6 +529,11 @@ impl<'tcx> TyCtxt<'tcx> {
528529
self.static_mutability(def_id).is_some()
529530
}
530531

532+
/// Returns `true` if this is a `static` item with the `#[thread_local]` attribute.
533+
pub fn is_thread_local_static(&self, def_id: DefId) -> bool {
534+
self.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
535+
}
536+
531537
/// Returns `true` if the node pointed to by `def_id` is a mutable `static` item.
532538
pub fn is_mutable_static(&self, def_id: DefId) -> bool {
533539
self.static_mutability(def_id) == Some(hir::Mutability::Mut)

src/librustc_mir/interpret/machine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
8484
/// Tag tracked alongside every pointer. This is used to implement "Stacked Borrows"
8585
/// <https://www.ralfj.de/blog/2018/08/07/stacked-borrows.html>.
8686
/// The `default()` is used for pointers to consts, statics, vtables and functions.
87+
/// The `Debug` formatting is used for displaying pointers; we cannot use `Display`
88+
/// as `()` does not implement that, but it should be "nice" output.
8789
type PointerTag: ::std::fmt::Debug + Copy + Eq + Hash + 'static;
8890

8991
/// Machines can define extra (non-instance) things that represent values of function pointers.

0 commit comments

Comments
 (0)