Skip to content

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

+6-6
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

+3
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

+10-4
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

+1
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

+4-4
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

+5-3
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

+20-2
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

+9-5
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

+6
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

+2
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.

src/librustc_mir/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
674674
/// control for this.
675675
pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
676676
// Cannot be a closure because it is generic in `Tag`, `Extra`.
677-
fn write_allocation_track_relocs<'tcx, Tag, Extra>(
677+
fn write_allocation_track_relocs<'tcx, Tag: Copy + fmt::Debug, Extra>(
678678
tcx: TyCtxtAt<'tcx>,
679679
allocs_to_print: &mut VecDeque<AllocId>,
680680
alloc: &Allocation<Tag, Extra>,

src/librustc_mir/interpret/operand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
122122
p(cx, s, ty)?;
123123
return Ok(());
124124
}
125-
write!(f, "{:?}: {}", s.erase_tag(), self.layout.ty)
125+
write!(f, "{}: {}", s.erase_tag(), self.layout.ty)
126126
}
127127
Immediate::ScalarPair(a, b) => {
128128
// FIXME(oli-obk): at least print tuples and slices nicely
129-
write!(f, "({:?}, {:?}): {}", a.erase_tag(), b.erase_tag(), self.layout.ty,)
129+
write!(f, "({}, {}): {}", a.erase_tag(), b.erase_tag(), self.layout.ty,)
130130
}
131131
}
132132
})

src/librustc_mir/transform/check_consts/ops.rs

-9
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ pub trait NonConstOp: std::fmt::Debug {
5353
}
5454
}
5555

56-
/// A `Downcast` projection.
57-
#[derive(Debug)]
58-
pub struct Downcast;
59-
impl NonConstOp for Downcast {
60-
fn feature_gate() -> Option<Symbol> {
61-
Some(sym::const_if_match)
62-
}
63-
}
64-
6556
/// A function call where the callee is a pointer.
6657
#[derive(Debug)]
6758
pub struct FnCallIndirect;

src/librustc_mir/transform/check_consts/validation.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceC
88
use rustc_middle::mir::*;
99
use rustc_middle::ty::cast::CastTy;
1010
use rustc_middle::ty::{self, Instance, InstanceDef, TyCtxt};
11-
use rustc_span::symbol::sym;
1211
use rustc_span::Span;
1312
use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
1413
use rustc_trait_selection::traits::{self, TraitEngine};
@@ -224,7 +223,7 @@ impl Validator<'mir, 'tcx> {
224223

225224
// Ensure that the end result is `Sync` in a non-thread local `static`.
226225
let should_check_for_sync =
227-
const_kind == Some(ConstKind::Static) && !tcx.has_attr(def_id, sym::thread_local);
226+
const_kind == Some(ConstKind::Static) && !tcx.is_thread_local_static(def_id);
228227

229228
if should_check_for_sync {
230229
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
@@ -267,8 +266,7 @@ impl Validator<'mir, 'tcx> {
267266
}
268267

269268
fn check_static(&mut self, def_id: DefId, span: Span) {
270-
let is_thread_local = self.tcx.has_attr(def_id, sym::thread_local);
271-
if is_thread_local {
269+
if self.tcx.is_thread_local_static(def_id) {
272270
self.check_op_spanned(ops::ThreadLocalAccess, span)
273271
} else {
274272
self.check_op_spanned(ops::StaticAccess, span)
@@ -474,6 +472,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
474472
}
475473

476474
ProjectionElem::ConstantIndex { .. }
475+
| ProjectionElem::Downcast(..)
477476
| ProjectionElem::Subslice { .. }
478477
| ProjectionElem::Field(..)
479478
| ProjectionElem::Index(_) => {
@@ -486,10 +485,6 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
486485
_ => {}
487486
}
488487
}
489-
490-
ProjectionElem::Downcast(..) => {
491-
self.check_op(ops::Downcast);
492-
}
493488
}
494489
}
495490

src/librustc_mir/transform/promote_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl<'tcx> Validator<'_, 'tcx> {
522522
return Err(Unpromotable);
523523
}
524524

525-
let is_thread_local = self.tcx.has_attr(def_id, sym::thread_local);
525+
let is_thread_local = self.tcx.is_thread_local_static(def_id);
526526
if is_thread_local {
527527
return Err(Unpromotable);
528528
}

src/librustc_mir/transform/qualify_min_const_fn.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ fn check_place(
286286
while let &[ref proj_base @ .., elem] = cursor {
287287
cursor = proj_base;
288288
match elem {
289-
ProjectionElem::Downcast(..) if !feature_allowed(tcx, def_id, sym::const_if_match) => {
290-
return Err((span, "`match` or `if let` in `const fn` is unstable".into()));
291-
}
292-
ProjectionElem::Downcast(_symbol, _variant_index) => {}
293-
294289
ProjectionElem::Field(..) => {
295290
let base_ty = Place::ty_from(place.local, &proj_base, body, tcx).ty;
296291
if let Some(def) = base_ty.ty_adt_def() {
@@ -303,6 +298,7 @@ fn check_place(
303298
}
304299
}
305300
ProjectionElem::ConstantIndex { .. }
301+
| ProjectionElem::Downcast(..)
306302
| ProjectionElem::Subslice { .. }
307303
| ProjectionElem::Deref
308304
| ProjectionElem::Index(_) => {}
@@ -344,7 +340,8 @@ fn check_terminator(
344340
| TerminatorKind::FalseUnwind { .. }
345341
| TerminatorKind::Goto { .. }
346342
| TerminatorKind::Return
347-
| TerminatorKind::Resume => Ok(()),
343+
| TerminatorKind::Resume
344+
| TerminatorKind::Unreachable => Ok(()),
348345

349346
TerminatorKind::Drop { location, .. } => check_place(tcx, *location, span, def_id, body),
350347
TerminatorKind::DropAndReplace { location, value, .. } => {
@@ -360,12 +357,7 @@ fn check_terminator(
360357
check_operand(tcx, discr, span, def_id, body)
361358
}
362359

363-
// FIXME(ecstaticmorse): We probably want to allow `Unreachable` unconditionally.
364-
TerminatorKind::Unreachable if feature_allowed(tcx, def_id, sym::const_if_match) => Ok(()),
365-
366-
TerminatorKind::Abort | TerminatorKind::Unreachable => {
367-
Err((span, "const fn with unreachable code is not stable".into()))
368-
}
360+
TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())),
369361
TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => {
370362
Err((span, "const fn generators are unstable".into()))
371363
}

0 commit comments

Comments
 (0)