Skip to content

Commit 4530eac

Browse files
committed
Auto merge of rust-lang#157228 - jhpratt:rollup-V1fPjTM, r=jhpratt
Rollup of 6 pull requests Successful merges: - rust-lang#156832 (library: use strict provenance lints consistently) - rust-lang#157223 (rustdoc: Fix ICE on delegated async functions) - rust-lang#156528 (Explicitly request copying `rustc-dev` artifacts for rustfmt/clippy and add rustc libs path for rustc-private tools under `download-rustc`) - rust-lang#157059 (update TargetFeature::Forbidden docs) - rust-lang#157159 (Fix CI free-disk-space-linux script) - rust-lang#157221 (Help people looking for random bytes find `DefaultRandomSource.fill_bytes`)
2 parents bef8e62 + e5b9884 commit 4530eac

34 files changed

Lines changed: 215 additions & 97 deletions

File tree

compiler/rustc_target/src/target_features.rs

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
//! Declares Rust's target feature names for each target.
22
//! Note that these are similar to but not always identical to LLVM's feature names,
33
//! and Rust adds some features that do not correspond to LLVM features at all.
4+
//!
5+
//! The target features listed here can be used in `#[target_feature]` and `#[cfg(target_feature)]`.
6+
//! They also do not trigger any warnings when used with `-Ctarget-feature`.
7+
//!
8+
//! Note that even unstable (and even entirely unlisted) features can be used with `-Ctarget-feature`
9+
//! on stable. Using a feature not on the list of Rust target features only emits a warning.
10+
//! Only `cfg(target_feature)` and `#[target_feature]` actually do any stability gating.
11+
//! `cfg(target_feature)` for unstable features just works on nightly without any feature gate.
12+
//! `#[target_feature]` requires a feature gate.
13+
//!
14+
//! When adding features to the below lists
15+
//! check whether they're named already elsewhere in rust
16+
//! e.g. in stdarch and whether the given name matches LLVM's
17+
//! if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted.
18+
//! Additionally, if the feature is not available in older version of LLVM supported by the current
19+
//! rust, the same function must be updated to filter out these features to avoid triggering
20+
//! warnings.
21+
//!
22+
//! Also note that all target features listed here must be purely additive: for target_feature 1.1 to
23+
//! be sound, we can never allow features like `+soft-float` (on x86) to be controlled on a
24+
//! per-function level, since we would then allow safe calls from functions with `+soft-float` to
25+
//! functions without that feature!
26+
//!
27+
//! It is important for soundness to consider the interaction of target features and the function
28+
//! call ABI. For example, disabling the `x87` feature on x86 changes how scalar floats are passed as
29+
//! arguments, so letting people toggle that feature would be unsound. To this end, the
30+
//! [`Target::abi_required_features`] function computes which target features must and must not be
31+
//! enabled for any given target, and individual features can also be marked as [`Forbidden`]. See
32+
//! <https://github.com/rust-lang/rust/issues/116344> for some more context.
33+
//!
34+
//! The one exception to features that change the ABI is features that enable larger vector
35+
//! registers. Those are permitted to be listed here. The `*_FOR_CORRECT_VECTOR_ABI` arrays store
36+
//! information about which target feature is ABI-required for which vector size; this is used to
37+
//! ensure that vectors can only be passed via `extern "C"` when the right feature is enabled. (For
38+
//! the "Rust" ABI we generally pass vectors by-ref exactly to avoid these issues.)
39+
//! Also see <https://github.com/rust-lang/rust/issues/116558>.
40+
//!
41+
//! Stabilizing a target feature requires t-lang approval.
442
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
543
use rustc_macros::StableHash;
644
use rustc_span::{Symbol, sym};
@@ -32,9 +70,12 @@ pub enum Stability {
3270
Symbol,
3371
),
3472
/// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be
35-
/// set in the target spec. It is never set in `cfg(target_feature)`. Used in
36-
/// particular for features are actually ABI configuration flags (not all targets are as nice as
37-
/// RISC-V and have an explicit way to set the ABI separate from target features).
73+
/// set in the target spec. It is never set in `cfg(target_feature)`. Used in particular for
74+
/// features are actually ABI configuration flags (such as "soft-float" on many targets).
75+
/// However, "forbidden" target features can still sometimes be enabled via `-Ctarget-cpu` or
76+
/// target feature implications (on the Rust/LLVM level). To prevent that, ABI-relevant target
77+
/// features are ideally pinned down (required or forbidden) in
78+
/// [`Target::abi_required_features`].
3879
Forbidden {
3980
reason: &'static str,
4081
/// True if this is always an error, false if this can be reported as a warning when set via
@@ -102,50 +143,11 @@ impl Stability {
102143
}
103144
}
104145

105-
// Here we list target features that rustc "understands": they can be used in `#[target_feature]`
106-
// and `#[cfg(target_feature)]`. They also do not trigger any warnings when used with
107-
// `-Ctarget-feature`.
108-
//
109-
// Note that even unstable (and even entirely unlisted) features can be used with `-Ctarget-feature`
110-
// on stable. Using a feature not on the list of Rust target features only emits a warning.
111-
// Only `cfg(target_feature)` and `#[target_feature]` actually do any stability gating.
112-
// `cfg(target_feature)` for unstable features just works on nightly without any feature gate.
113-
// `#[target_feature]` requires a feature gate.
114-
//
115-
// When adding features to the below lists
116-
// check whether they're named already elsewhere in rust
117-
// e.g. in stdarch and whether the given name matches LLVM's
118-
// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted.
119-
// Additionally, if the feature is not available in older version of LLVM supported by the current
120-
// rust, the same function must be updated to filter out these features to avoid triggering
121-
// warnings.
122-
//
123-
// Also note that all target features listed here must be purely additive: for target_feature 1.1 to
124-
// be sound, we can never allow features like `+soft-float` (on x86) to be controlled on a
125-
// per-function level, since we would then allow safe calls from functions with `+soft-float` to
126-
// functions without that feature!
127-
//
128-
// It is important for soundness to consider the interaction of targets features and the function
129-
// call ABI. For example, disabling the `x87` feature on x86 changes how scalar floats are passed as
130-
// arguments, so letting people toggle that feature would be unsound. To this end, the
131-
// `abi_required_features` function computes which target features must and must not be enabled for
132-
// any given target, and individual features can also be marked as `Forbidden`.
133-
// See https://github.com/rust-lang/rust/issues/116344 for some more context.
134-
//
135-
// The one exception to features that change the ABI is features that enable larger vector
136-
// registers. Those are permitted to be listed here. The `*_FOR_CORRECT_VECTOR_ABI` arrays store
137-
// information about which target feature is ABI-required for which vector size; this is used to
138-
// ensure that vectors can only be passed via `extern "C"` when the right feature is enabled. (For
139-
// the "Rust" ABI we generally pass vectors by-ref exactly to avoid these issues.)
140-
// Also see https://github.com/rust-lang/rust/issues/116558.
141-
//
142-
// Stabilizing a target feature requires t-lang approval.
143-
144-
// If feature A "implies" feature B, then:
145-
// - when A gets enabled (via `-Ctarget-feature` or `#[target_feature]`), we also enable B
146-
// - when B gets disabled (via `-Ctarget-feature`), we also disable A
147-
//
148-
// Both of these are also applied transitively.
146+
/// If feature A "implies" feature B, then:
147+
/// - when A gets enabled (via `-Ctarget-feature` or `#[target_feature]`), we also enable B
148+
/// - when B gets disabled (via `-Ctarget-feature`), we also disable A
149+
///
150+
/// Both of these are also applied transitively.
149151
type ImpliedFeatures = &'static [&'static str];
150152

151153
static ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
// Lints:
7474
#![deny(unsafe_op_in_unsafe_fn)]
7575
#![deny(fuzzy_provenance_casts)]
76+
#![deny(lossy_provenance_casts)]
7677
#![warn(deprecated_in_future)]
7778
#![warn(missing_debug_implementations)]
7879
#![warn(missing_docs)]

library/alloctests/benches/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(strict_provenance_lints)]
88
#![feature(test)]
99
#![deny(fuzzy_provenance_casts)]
10+
#![deny(lossy_provenance_casts)]
1011

1112
extern crate test;
1213

library/alloctests/tests/boxed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ fn box_clone_from_ptr_stability() {
4747
for size in (0..8).map(|i| 2usize.pow(i)) {
4848
let control = vec![Dummy { _data: 42 }; size].into_boxed_slice();
4949
let mut copy = vec![Dummy { _data: 84 }; size].into_boxed_slice();
50-
let copy_raw = copy.as_ptr() as usize;
50+
let copy_raw = copy.as_ptr();
5151
copy.clone_from(&control);
52-
assert_eq!(copy.as_ptr() as usize, copy_raw);
52+
assert_eq!(copy.as_ptr(), copy_raw);
5353
}
5454
}
5555

library/alloctests/tests/heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn check_overalign_requests<T: Allocator>(allocator: T) {
2525
.collect();
2626
for &ptr in &pointers {
2727
assert_eq!(
28-
(ptr.as_non_null_ptr().as_ptr() as usize) % align,
28+
ptr.as_non_null_ptr().as_ptr().addr() % align,
2929
0,
3030
"Got a pointer less aligned than requested"
3131
)

library/alloctests/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#![feature(ptr_cast_slice)]
4545
#![allow(internal_features)]
4646
#![deny(fuzzy_provenance_casts)]
47+
#![deny(lossy_provenance_casts)]
4748
#![deny(unsafe_op_in_unsafe_fn)]
4849

4950
extern crate alloc;

library/alloctests/tests/sort/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ fn self_cmp<T: Ord + Clone + Debug, S: Sort>(
746746
pattern_fn(len).into_iter().map(|val| type_into_fn(val)).collect::<Vec<_>>();
747747

748748
let comparison_fn = |a: &T, b: &T| {
749-
assert_ne!(a as *const T as usize, b as *const T as usize);
749+
assert_ne!(a as *const T, b as *const T);
750750
a.cmp(b)
751751
};
752752

library/alloctests/tests/vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ fn test_into_iter_zst() {
11101110
struct AlignedZstWithDrop([u64; 0]);
11111111
impl Drop for AlignedZstWithDrop {
11121112
fn drop(&mut self) {
1113-
let addr = self as *mut _ as usize;
1113+
let addr = (self as *mut Self).addr();
11141114
assert!(hint::black_box(addr) % align_of::<u64>() == 0);
11151115
}
11161116
}
@@ -1356,10 +1356,10 @@ fn overaligned_allocations() {
13561356
for i in 0..0x1000 {
13571357
v.reserve_exact(i);
13581358
assert!(v[0].0 == 273);
1359-
assert!(v.as_ptr() as usize & 0xff == 0);
1359+
assert!(v.as_ptr().addr() & 0xff == 0);
13601360
v.shrink_to_fit();
13611361
assert!(v[0].0 == 273);
1362-
assert!(v.as_ptr() as usize & 0xff == 0);
1362+
assert!(v.as_ptr().addr() & 0xff == 0);
13631363
}
13641364
}
13651365

@@ -2574,7 +2574,7 @@ fn test_box_zero_allocator() {
25742574

25752575
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
25762576
if layout.size() == 0 {
2577-
let addr = ptr.as_ptr() as usize;
2577+
let addr = ptr.as_ptr().addr();
25782578
let mut state = self.state.borrow_mut();
25792579
std::println!("freeing {addr}");
25802580
assert!(state.0.remove(&addr), "ZST free that wasn't allocated");

library/core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#![deny(rust_2021_incompatible_or_patterns)]
8181
#![deny(unsafe_op_in_unsafe_fn)]
8282
#![deny(fuzzy_provenance_casts)]
83+
#![deny(lossy_provenance_casts)]
8384
#![warn(deprecated_in_future)]
8485
#![warn(missing_debug_implementations)]
8586
#![warn(missing_docs)]

library/core/src/ptr/const_ptr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl<T: PointeeSized> *const T {
183183
/// [`with_exposed_provenance`]: with_exposed_provenance
184184
#[inline(always)]
185185
#[stable(feature = "exposed_provenance", since = "1.84.0")]
186+
#[expect(lossy_provenance_casts, reason = "this *is* the replacement")]
186187
pub fn expose_provenance(self) -> usize {
187188
self.cast::<()>() as usize
188189
}

0 commit comments

Comments
 (0)