Skip to content

Commit 151dce8

Browse files
committed
Auto merge of #143853 - jhpratt:rollup-q9wv8di, r=jhpratt
Rollup of 15 pull requests Successful merges: - #143554 (slice: Mark `rotate_left`, `rotate_right` unstably const) - #143634 (interpret/allocation: expose init + write_wildcards on a range) - #143710 (Updates to random number generation APIs) - #143774 (constify `From` and `Into`) - #143776 (std: move NuttX to use arc4random for random number generation) - #143778 (Some const_trait_impl test cleanups) - #143782 (Disambiguate between rustc vs std having debug assertions in `run-make-support` and `run-make` tests) - #143791 (Update sysinfo version to `0.36.0`) - #143796 (Fix ICE for parsed attributes with longer path not handled by CheckAttribute) - #143798 (Remove format short command trait) - #143803 (New tracking issues for const_ops and const_cmp) - #143814 (htmldocck: better error messages for some negative directives) - #143817 (Access `wasi_sdk_path` instead of reading environment variable in bootstrap) - #143822 (./x test miri: fix cleaning the miri_ui directory) - #143823 ([COMPILETEST-UNTANGLE 5/N] Test mode adjustments and other assorted cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bfc046a + f223ade commit 151dce8

File tree

67 files changed

+527
-404
lines changed

Some content is hidden

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

67 files changed

+527
-404
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,6 +4349,7 @@ dependencies = [
43494349
"rustc_ast_lowering",
43504350
"rustc_ast_pretty",
43514351
"rustc_attr_data_structures",
4352+
"rustc_attr_parsing",
43524353
"rustc_data_structures",
43534354
"rustc_errors",
43544355
"rustc_expand",
@@ -5230,9 +5231,9 @@ dependencies = [
52305231

52315232
[[package]]
52325233
name = "sysinfo"
5233-
version = "0.35.2"
5234+
version = "0.36.0"
52345235
source = "registry+https://github.com/rust-lang/crates.io-index"
5235-
checksum = "3c3ffa3e4ff2b324a57f7aeb3c349656c7b127c3c189520251a648102a92496e"
5236+
checksum = "aab138f5c1bb35231de19049060a87977ad23e04f2303e953bc5c2947ac7dec4"
52365237
dependencies = [
52375238
"libc",
52385239
"objc2-core-foundation",

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,11 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
735735
attributes
736736
}
737737

738+
/// Returns whether there is a parser for an attribute with this name
739+
pub fn is_parsed_attribute(path: &[Symbol]) -> bool {
740+
Late::parsers().0.contains_key(path)
741+
}
742+
738743
fn lower_attr_args(&self, args: &ast::AttrArgs, lower_span: impl Fn(Span) -> Span) -> AttrArgs {
739744
match args {
740745
ast::AttrArgs::Empty => AttrArgs::Empty,

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
14981498
dest_alloc
14991499
.write_uninit(&tcx, dest_range)
15001500
.map_err(|e| e.to_interp_error(dest_alloc_id))?;
1501-
// We can forget about the provenance, this is all not initialized anyway.
1501+
// `write_uninit` also resets the provenance, so we are done.
15021502
return interp_ok(());
15031503
}
15041504

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub struct Allocation<Prov: Provenance = CtfeProvenance, Extra = (), Bytes = Box
101101
/// at the given offset.
102102
provenance: ProvenanceMap<Prov>,
103103
/// Denotes which part of this allocation is initialized.
104+
///
105+
/// Invariant: the uninitialized parts have no provenance.
104106
init_mask: InitMask,
105107
/// The alignment of the allocation to detect unaligned reads.
106108
/// (`Align` guarantees that this is a power of two.)
@@ -796,24 +798,19 @@ impl<Prov: Provenance, Extra, Bytes: AllocBytes> Allocation<Prov, Extra, Bytes>
796798
Ok(())
797799
}
798800

799-
/// Initialize all previously uninitialized bytes in the entire allocation, and set
800-
/// provenance of everything to `Wildcard`. Before calling this, make sure all
801-
/// provenance in this allocation is exposed!
802-
pub fn prepare_for_native_access(&mut self) {
803-
let full_range = AllocRange { start: Size::ZERO, size: Size::from_bytes(self.len()) };
804-
// Overwrite uninitialized bytes with 0, to ensure we don't leak whatever their value happens to be.
805-
for chunk in self.init_mask.range_as_init_chunks(full_range) {
806-
if !chunk.is_init() {
807-
let uninit_bytes = &mut self.bytes
808-
[chunk.range().start.bytes_usize()..chunk.range().end.bytes_usize()];
809-
uninit_bytes.fill(0);
810-
}
811-
}
812-
// Mark everything as initialized now.
813-
self.mark_init(full_range, true);
814-
815-
// Set provenance of all bytes to wildcard.
816-
self.provenance.write_wildcards(self.len());
801+
/// Mark all bytes in the given range as initialised and reset the provenance
802+
/// to wildcards. This entirely breaks the normal mechanisms for tracking
803+
/// initialisation and is only provided for Miri operating in native-lib
804+
/// mode. UB will be missed if the underlying bytes were not actually written to.
805+
///
806+
/// If `range` is `None`, defaults to performing this on the whole allocation.
807+
pub fn process_native_write(&mut self, cx: &impl HasDataLayout, range: Option<AllocRange>) {
808+
let range = range.unwrap_or_else(|| AllocRange {
809+
start: Size::ZERO,
810+
size: Size::from_bytes(self.len()),
811+
});
812+
self.mark_init(range, true);
813+
self.provenance.write_wildcards(cx, range);
817814
}
818815

819816
/// Remove all provenance in the given memory range.

compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,37 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
212212
Ok(())
213213
}
214214

215-
/// Overwrites all provenance in the allocation with wildcard provenance.
215+
/// Overwrites all provenance in the given range with wildcard provenance.
216+
/// Pointers partially overwritten will have their provenances preserved
217+
/// bytewise on their remaining bytes.
216218
///
217219
/// Provided for usage in Miri and panics otherwise.
218-
pub fn write_wildcards(&mut self, alloc_size: usize) {
220+
pub fn write_wildcards(&mut self, cx: &impl HasDataLayout, range: AllocRange) {
219221
assert!(
220222
Prov::OFFSET_IS_ADDR,
221223
"writing wildcard provenance is not supported when `OFFSET_IS_ADDR` is false"
222224
);
223225
let wildcard = Prov::WILDCARD.unwrap();
224226

225-
// Remove all pointer provenances, then write wildcards into the whole byte range.
226-
self.ptrs.clear();
227-
let last = Size::from_bytes(alloc_size);
228227
let bytes = self.bytes.get_or_insert_with(Box::default);
229-
for offset in Size::ZERO..last {
228+
229+
// Remove pointer provenances that overlap with the range, then readd the edge ones bytewise.
230+
let ptr_range = Self::adjusted_range_ptrs(range, cx);
231+
let ptrs = self.ptrs.range(ptr_range.clone());
232+
if let Some((offset, prov)) = ptrs.first() {
233+
for byte_ofs in *offset..range.start {
234+
bytes.insert(byte_ofs, *prov);
235+
}
236+
}
237+
if let Some((offset, prov)) = ptrs.last() {
238+
for byte_ofs in range.end()..*offset + cx.data_layout().pointer_size() {
239+
bytes.insert(byte_ofs, *prov);
240+
}
241+
}
242+
self.ptrs.remove_range(ptr_range);
243+
244+
// Overwrite bytewise provenance.
245+
for offset in range.start..range.end() {
230246
bytes.insert(offset, wildcard);
231247
}
232248
}

compiler/rustc_passes/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rustc_ast = { path = "../rustc_ast" }
1010
rustc_ast_lowering = { path = "../rustc_ast_lowering" }
1111
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1212
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
13+
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
1314
rustc_data_structures = { path = "../rustc_data_structures" }
1415
rustc_errors = { path = "../rustc_errors" }
1516
rustc_expand = { path = "../rustc_expand" }

compiler/rustc_passes/src/check_attr.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
88
use std::cell::Cell;
99
use std::collections::hash_map::Entry;
10+
use std::slice;
1011

1112
use rustc_abi::{Align, ExternAbi, Size};
1213
use rustc_ast::{AttrStyle, LitKind, MetaItemInner, MetaItemKind, ast};
1314
use rustc_attr_data_structures::{AttributeKind, InlineAttr, ReprAttr, find_attr};
15+
use rustc_attr_parsing::{AttributeParser, Late};
1416
use rustc_data_structures::fx::FxHashMap;
1517
use rustc_errors::{Applicability, DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey};
1618
use rustc_feature::{AttributeDuplicates, AttributeType, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute};
@@ -384,11 +386,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
384386
| sym::custom_mir,
385387
..
386388
] => {}
387-
[name, ..] => {
389+
[name, rest@..] => {
388390
match BUILTIN_ATTRIBUTE_MAP.get(name) {
389391
// checked below
390392
Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) => {}
391393
Some(_) => {
394+
if rest.len() > 0 && AttributeParser::<Late>::is_parsed_attribute(slice::from_ref(name)) {
395+
// Check if we tried to use a builtin attribute as an attribute namespace, like `#[must_use::skip]`.
396+
// This check is here to solve https://github.com/rust-lang/rust/issues/137590
397+
// An error is already produced for this case elsewhere
398+
continue
399+
}
400+
392401
// FIXME: differentiate between unstable and internal attributes just
393402
// like we do with features instead of just accepting `rustc_`
394403
// attributes by name. That should allow trimming the above list, too.

library/core/src/cmp.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ use crate::ops::ControlFlow;
248248
)]
249249
#[rustc_diagnostic_item = "PartialEq"]
250250
#[const_trait]
251-
#[rustc_const_unstable(feature = "const_trait_impl", issue = "67792")]
251+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
252252
pub trait PartialEq<Rhs: PointeeSized = Self>: PointeeSized {
253253
/// Tests for `self` and `other` values to be equal, and is used by `==`.
254254
#[must_use]
@@ -1809,7 +1809,7 @@ mod impls {
18091809
macro_rules! partial_eq_impl {
18101810
($($t:ty)*) => ($(
18111811
#[stable(feature = "rust1", since = "1.0.0")]
1812-
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
1812+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
18131813
impl const PartialEq for $t {
18141814
#[inline]
18151815
fn eq(&self, other: &Self) -> bool { *self == *other }
@@ -2017,7 +2017,7 @@ mod impls {
20172017
// & pointers
20182018

20192019
#[stable(feature = "rust1", since = "1.0.0")]
2020-
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
2020+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
20212021
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&B> for &A
20222022
where
20232023
A: ~const PartialEq<B>,
@@ -2089,7 +2089,7 @@ mod impls {
20892089
// &mut pointers
20902090

20912091
#[stable(feature = "rust1", since = "1.0.0")]
2092-
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
2092+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
20932093
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&mut B> for &mut A
20942094
where
20952095
A: ~const PartialEq<B>,
@@ -2159,7 +2159,7 @@ mod impls {
21592159
impl<A: PointeeSized> Eq for &mut A where A: Eq {}
21602160

21612161
#[stable(feature = "rust1", since = "1.0.0")]
2162-
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
2162+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
21632163
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&mut B> for &A
21642164
where
21652165
A: ~const PartialEq<B>,
@@ -2175,7 +2175,7 @@ mod impls {
21752175
}
21762176

21772177
#[stable(feature = "rust1", since = "1.0.0")]
2178-
#[rustc_const_unstable(feature = "const_cmp", issue = "92391")]
2178+
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
21792179
impl<A: PointeeSized, B: PointeeSized> const PartialEq<&B> for &mut A
21802180
where
21812181
A: ~const PartialEq<B>,

library/core/src/convert/mod.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ pub trait AsMut<T: PointeeSized>: PointeeSized {
445445
#[rustc_diagnostic_item = "Into"]
446446
#[stable(feature = "rust1", since = "1.0.0")]
447447
#[doc(search_unbox)]
448+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
449+
#[const_trait]
448450
pub trait Into<T>: Sized {
449451
/// Converts this type into the (usually inferred) input type.
450452
#[must_use]
@@ -580,6 +582,8 @@ pub trait Into<T>: Sized {
580582
note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
581583
))]
582584
#[doc(search_unbox)]
585+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
586+
#[const_trait]
583587
pub trait From<T>: Sized {
584588
/// Converts to this type from the input type.
585589
#[rustc_diagnostic_item = "from_fn"]
@@ -607,6 +611,8 @@ pub trait From<T>: Sized {
607611
/// [`Into`], see there for details.
608612
#[rustc_diagnostic_item = "TryInto"]
609613
#[stable(feature = "try_from", since = "1.34.0")]
614+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
615+
#[const_trait]
610616
pub trait TryInto<T>: Sized {
611617
/// The type returned in the event of a conversion error.
612618
#[stable(feature = "try_from", since = "1.34.0")]
@@ -685,6 +691,8 @@ pub trait TryInto<T>: Sized {
685691
/// [`try_from`]: TryFrom::try_from
686692
#[rustc_diagnostic_item = "TryFrom"]
687693
#[stable(feature = "try_from", since = "1.34.0")]
694+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
695+
#[const_trait]
688696
pub trait TryFrom<T>: Sized {
689697
/// The type returned in the event of a conversion error.
690698
#[stable(feature = "try_from", since = "1.34.0")]
@@ -754,9 +762,10 @@ where
754762

755763
// From implies Into
756764
#[stable(feature = "rust1", since = "1.0.0")]
757-
impl<T, U> Into<U> for T
765+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
766+
impl<T, U> const Into<U> for T
758767
where
759-
U: From<T>,
768+
U: ~const From<T>,
760769
{
761770
/// Calls `U::from(self)`.
762771
///
@@ -771,7 +780,8 @@ where
771780

772781
// From (and thus Into) is reflexive
773782
#[stable(feature = "rust1", since = "1.0.0")]
774-
impl<T> From<T> for T {
783+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
784+
impl<T> const From<T> for T {
775785
/// Returns the argument unchanged.
776786
#[inline(always)]
777787
fn from(t: T) -> T {
@@ -787,17 +797,19 @@ impl<T> From<T> for T {
787797
#[stable(feature = "convert_infallible", since = "1.34.0")]
788798
#[rustc_reservation_impl = "permitting this impl would forbid us from adding \
789799
`impl<T> From<!> for T` later; see rust-lang/rust#64715 for details"]
790-
impl<T> From<!> for T {
800+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
801+
impl<T> const From<!> for T {
791802
fn from(t: !) -> T {
792803
t
793804
}
794805
}
795806

796807
// TryFrom implies TryInto
797808
#[stable(feature = "try_from", since = "1.34.0")]
798-
impl<T, U> TryInto<U> for T
809+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
810+
impl<T, U> const TryInto<U> for T
799811
where
800-
U: TryFrom<T>,
812+
U: ~const TryFrom<T>,
801813
{
802814
type Error = U::Error;
803815

@@ -810,9 +822,10 @@ where
810822
// Infallible conversions are semantically equivalent to fallible conversions
811823
// with an uninhabited error type.
812824
#[stable(feature = "try_from", since = "1.34.0")]
813-
impl<T, U> TryFrom<U> for T
825+
#[rustc_const_unstable(feature = "const_from", issue = "143773")]
826+
impl<T, U> const TryFrom<U> for T
814827
where
815-
U: Into<T>,
828+
U: ~const Into<T>,
816829
{
817830
type Error = Infallible;
818831

0 commit comments

Comments
 (0)