Skip to content

Commit 6cf068d

Browse files
committed
Auto merge of rust-lang#129721 - workingjubilee:rollup-y2o1mnp, r=workingjubilee
Rollup of 14 pull requests Successful merges: - rust-lang#128192 (rustc_target: Add various aarch64 features) - rust-lang#129170 (Add an ability to convert between `Span` and `visit::Location`) - rust-lang#129343 (Emit specific message for time<=0.3.35) - rust-lang#129378 (Clean up cfg-gating of ProcessPrng extern) - rust-lang#129401 (Partially stabilize `feature(new_uninit)`) - rust-lang#129467 (derive(SmartPointer): assume pointee from the single generic and better error messages) - rust-lang#129494 (format code in tests/ui/threads-sendsync) - rust-lang#129617 (Update books) - rust-lang#129673 (Add fmt::Debug to sync::Weak<T, A>) - rust-lang#129683 (copysign with sign being a NaN can have non-portable results) - rust-lang#129689 (Move `'tcx` lifetime off of impl and onto methods for `CrateMetadataRef`) - rust-lang#129695 (Fix path to run clippy on rustdoc) - rust-lang#129712 (Correct trusty targets to be tier 3) - rust-lang#129715 (Update `compiler_builtins` to `0.1.123`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents acb4e8b + bd66fad commit 6cf068d

File tree

113 files changed

+805
-474
lines changed

Some content is hidden

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

113 files changed

+805
-474
lines changed

compiler/rustc_arena/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#![feature(decl_macro)]
2222
#![feature(dropck_eyepatch)]
2323
#![feature(maybe_uninit_slice)]
24-
#![feature(new_uninit)]
2524
#![feature(rustc_attrs)]
2625
#![feature(rustdoc_internals)]
2726
#![feature(strict_provenance)]

compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs

+47-28
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1111
use rustc_expand::base::{Annotatable, ExtCtxt};
1212
use rustc_span::symbol::{sym, Ident};
1313
use rustc_span::{Span, Symbol};
14-
use smallvec::{smallvec, SmallVec};
1514
use thin_vec::{thin_vec, ThinVec};
1615

1716
macro_rules! path {
@@ -68,43 +67,63 @@ pub(crate) fn expand_deriving_smart_ptr(
6867
};
6968

7069
// Convert generic parameters (from the struct) into generic args.
71-
let mut pointee_param = None;
72-
let mut multiple_pointee_diag: SmallVec<[_; 2]> = smallvec![];
73-
let self_params = generics
70+
let self_params: Vec<_> = generics
7471
.params
7572
.iter()
76-
.enumerate()
77-
.map(|(idx, p)| match p.kind {
73+
.map(|p| match p.kind {
7874
GenericParamKind::Lifetime => GenericArg::Lifetime(cx.lifetime(p.span(), p.ident)),
79-
GenericParamKind::Type { .. } => {
80-
if p.attrs().iter().any(|attr| attr.has_name(sym::pointee)) {
81-
if pointee_param.is_some() {
82-
multiple_pointee_diag.push(cx.dcx().struct_span_err(
83-
p.span(),
84-
"`SmartPointer` can only admit one type as pointee",
85-
));
86-
} else {
87-
pointee_param = Some(idx);
88-
}
89-
}
90-
GenericArg::Type(cx.ty_ident(p.span(), p.ident))
91-
}
75+
GenericParamKind::Type { .. } => GenericArg::Type(cx.ty_ident(p.span(), p.ident)),
9276
GenericParamKind::Const { .. } => GenericArg::Const(cx.const_ident(p.span(), p.ident)),
9377
})
94-
.collect::<Vec<_>>();
95-
let Some(pointee_param_idx) = pointee_param else {
78+
.collect();
79+
let type_params: Vec<_> = generics
80+
.params
81+
.iter()
82+
.enumerate()
83+
.filter_map(|(idx, p)| {
84+
if let GenericParamKind::Type { .. } = p.kind {
85+
Some((idx, p.span(), p.attrs().iter().any(|attr| attr.has_name(sym::pointee))))
86+
} else {
87+
None
88+
}
89+
})
90+
.collect();
91+
92+
let pointee_param_idx = if type_params.is_empty() {
93+
// `#[derive(SmartPointer)]` requires at least one generic type on the target `struct`
9694
cx.dcx().struct_span_err(
9795
span,
98-
"At least one generic type should be designated as `#[pointee]` in order to derive `SmartPointer` traits",
96+
"`SmartPointer` can only be derived on `struct`s that are generic over at least one type",
9997
).emit();
10098
return;
101-
};
102-
if !multiple_pointee_diag.is_empty() {
103-
for diag in multiple_pointee_diag {
104-
diag.emit();
99+
} else if type_params.len() == 1 {
100+
// Regardless of the only type param being designed as `#[pointee]` or not, we can just use it as such
101+
type_params[0].0
102+
} else {
103+
let mut pointees = type_params
104+
.iter()
105+
.filter_map(|&(idx, span, is_pointee)| is_pointee.then_some((idx, span)))
106+
.fuse();
107+
match (pointees.next(), pointees.next()) {
108+
(Some((idx, _span)), None) => idx,
109+
(None, _) => {
110+
cx.dcx().struct_span_err(
111+
span,
112+
"exactly one generic type parameter must be marked as #[pointee] to derive SmartPointer traits",
113+
).emit();
114+
return;
115+
}
116+
(Some((_, one)), Some((_, another))) => {
117+
cx.dcx()
118+
.struct_span_err(
119+
vec![one, another],
120+
"only one type parameter can be marked as `#[pointee]` when deriving SmartPointer traits",
121+
)
122+
.emit();
123+
return;
124+
}
105125
}
106-
return;
107-
}
126+
};
108127

109128
// Create the type of `self`.
110129
let path = cx.path_all(span, false, vec![name_ident], self_params.clone());

compiler/rustc_codegen_llvm/src/attributes.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,20 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
521521

522522
let function_features = function_features
523523
.iter()
524-
.flat_map(|feat| {
525-
llvm_util::to_llvm_features(cx.tcx.sess, feat).into_iter().map(|f| format!("+{f}"))
526-
})
524+
// Convert to LLVMFeatures and filter out unavailable ones
525+
.flat_map(|feat| llvm_util::to_llvm_features(cx.tcx.sess, feat))
526+
// Convert LLVMFeatures & dependencies to +<feats>s
527+
.flat_map(|feat| feat.into_iter().map(|f| format!("+{f}")))
527528
.chain(codegen_fn_attrs.instruction_set.iter().map(|x| match x {
528529
InstructionSetAttr::ArmA32 => "-thumb-mode".to_string(),
529530
InstructionSetAttr::ArmT32 => "+thumb-mode".to_string(),
530531
}))
532+
// HACK: LLVM versions 19+ do not have the FPMR feature and treat it as always enabled
533+
// It only exists as a feature in LLVM 18, cannot be passed down for any other version
534+
.chain(match &*cx.tcx.sess.target.arch {
535+
"aarch64" if llvm_util::get_version().0 == 18 => vec!["+fpmr".to_string()],
536+
_ => vec![],
537+
})
531538
.collect::<Vec<String>>();
532539

533540
if cx.tcx.sess.target.is_like_wasm {

compiler/rustc_codegen_llvm/src/llvm_util.rs

+59-33
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'a> IntoIterator for LLVMFeature<'a> {
209209
// Though note that Rust can also be build with an external precompiled version of LLVM
210210
// which might lead to failures if the oldest tested / supported LLVM version
211211
// doesn't yet support the relevant intrinsics
212-
pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> LLVMFeature<'a> {
212+
pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFeature<'a>> {
213213
let arch = if sess.target.arch == "x86_64" {
214214
"x86"
215215
} else if sess.target.arch == "arm64ec" {
@@ -218,40 +218,59 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> LLVMFeature<'a
218218
&*sess.target.arch
219219
};
220220
match (arch, s) {
221-
("x86", "sse4.2") => {
222-
LLVMFeature::with_dependency("sse4.2", TargetFeatureFoldStrength::EnableOnly("crc32"))
223-
}
224-
("x86", "pclmulqdq") => LLVMFeature::new("pclmul"),
225-
("x86", "rdrand") => LLVMFeature::new("rdrnd"),
226-
("x86", "bmi1") => LLVMFeature::new("bmi"),
227-
("x86", "cmpxchg16b") => LLVMFeature::new("cx16"),
228-
("x86", "lahfsahf") => LLVMFeature::new("sahf"),
229-
("aarch64", "rcpc2") => LLVMFeature::new("rcpc-immo"),
230-
("aarch64", "dpb") => LLVMFeature::new("ccpp"),
231-
("aarch64", "dpb2") => LLVMFeature::new("ccdp"),
232-
("aarch64", "frintts") => LLVMFeature::new("fptoint"),
233-
("aarch64", "fcma") => LLVMFeature::new("complxnum"),
234-
("aarch64", "pmuv3") => LLVMFeature::new("perfmon"),
235-
("aarch64", "paca") => LLVMFeature::new("pauth"),
236-
("aarch64", "pacg") => LLVMFeature::new("pauth"),
221+
("x86", "sse4.2") => Some(LLVMFeature::with_dependency(
222+
"sse4.2",
223+
TargetFeatureFoldStrength::EnableOnly("crc32"),
224+
)),
225+
("x86", "pclmulqdq") => Some(LLVMFeature::new("pclmul")),
226+
("x86", "rdrand") => Some(LLVMFeature::new("rdrnd")),
227+
("x86", "bmi1") => Some(LLVMFeature::new("bmi")),
228+
("x86", "cmpxchg16b") => Some(LLVMFeature::new("cx16")),
229+
("x86", "lahfsahf") => Some(LLVMFeature::new("sahf")),
230+
("aarch64", "rcpc2") => Some(LLVMFeature::new("rcpc-immo")),
231+
("aarch64", "dpb") => Some(LLVMFeature::new("ccpp")),
232+
("aarch64", "dpb2") => Some(LLVMFeature::new("ccdp")),
233+
("aarch64", "frintts") => Some(LLVMFeature::new("fptoint")),
234+
("aarch64", "fcma") => Some(LLVMFeature::new("complxnum")),
235+
("aarch64", "pmuv3") => Some(LLVMFeature::new("perfmon")),
236+
("aarch64", "paca") => Some(LLVMFeature::new("pauth")),
237+
("aarch64", "pacg") => Some(LLVMFeature::new("pauth")),
238+
("aarch64", "sve-b16b16") => Some(LLVMFeature::new("b16b16")),
239+
("aarch64", "flagm2") => Some(LLVMFeature::new("altnzcv")),
237240
// Rust ties fp and neon together.
238241
("aarch64", "neon") => {
239-
LLVMFeature::with_dependency("neon", TargetFeatureFoldStrength::Both("fp-armv8"))
242+
Some(LLVMFeature::with_dependency("neon", TargetFeatureFoldStrength::Both("fp-armv8")))
240243
}
241244
// In LLVM neon implicitly enables fp, but we manually enable
242245
// neon when a feature only implicitly enables fp
243-
("aarch64", "fhm") => LLVMFeature::new("fp16fml"),
244-
("aarch64", "fp16") => LLVMFeature::new("fullfp16"),
246+
("aarch64", "fhm") => Some(LLVMFeature::new("fp16fml")),
247+
("aarch64", "fp16") => Some(LLVMFeature::new("fullfp16")),
248+
// Filter out features that are not supported by the current LLVM version
249+
("aarch64", "faminmax") if get_version().0 < 18 => None,
250+
("aarch64", "fp8") if get_version().0 < 18 => None,
251+
("aarch64", "fp8dot2") if get_version().0 < 18 => None,
252+
("aarch64", "fp8dot4") if get_version().0 < 18 => None,
253+
("aarch64", "fp8fma") if get_version().0 < 18 => None,
254+
("aarch64", "fpmr") if get_version().0 != 18 => None,
255+
("aarch64", "lut") if get_version().0 < 18 => None,
256+
("aarch64", "sme-f8f16") if get_version().0 < 18 => None,
257+
("aarch64", "sme-f8f32") if get_version().0 < 18 => None,
258+
("aarch64", "sme-fa64") if get_version().0 < 18 => None,
259+
("aarch64", "sme-lutv2") if get_version().0 < 18 => None,
260+
("aarch64", "ssve-fp8dot2") if get_version().0 < 18 => None,
261+
("aarch64", "ssve-fp8dot4") if get_version().0 < 18 => None,
262+
("aarch64", "ssve-fp8fma") if get_version().0 < 18 => None,
263+
("aarch64", "v9.5a") if get_version().0 < 18 => None,
245264
// In LLVM 18, `unaligned-scalar-mem` was merged with `unaligned-vector-mem` into a single feature called
246265
// `fast-unaligned-access`. In LLVM 19, it was split back out.
247266
("riscv32" | "riscv64", "unaligned-scalar-mem") if get_version().0 == 18 => {
248-
LLVMFeature::new("fast-unaligned-access")
267+
Some(LLVMFeature::new("fast-unaligned-access"))
249268
}
250269
// For LLVM 18, enable the evex512 target feature if a avx512 target feature is enabled.
251270
("x86", s) if get_version().0 >= 18 && s.starts_with("avx512") => {
252-
LLVMFeature::with_dependency(s, TargetFeatureFoldStrength::EnableOnly("evex512"))
271+
Some(LLVMFeature::with_dependency(s, TargetFeatureFoldStrength::EnableOnly("evex512")))
253272
}
254-
(_, s) => LLVMFeature::new(s),
273+
(_, s) => Some(LLVMFeature::new(s)),
255274
}
256275
}
257276

@@ -291,13 +310,17 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
291310
return true;
292311
}
293312
// check that all features in a given smallvec are enabled
294-
for llvm_feature in to_llvm_features(sess, feature) {
295-
let cstr = SmallCStr::new(llvm_feature);
296-
if !unsafe { llvm::LLVMRustHasFeature(&target_machine, cstr.as_ptr()) } {
297-
return false;
313+
if let Some(feat) = to_llvm_features(sess, feature) {
314+
for llvm_feature in feat {
315+
let cstr = SmallCStr::new(llvm_feature);
316+
if !unsafe { llvm::LLVMRustHasFeature(&target_machine, cstr.as_ptr()) } {
317+
return false;
318+
}
298319
}
320+
true
321+
} else {
322+
false
299323
}
300-
true
301324
})
302325
.map(|(feature, _, _)| Symbol::intern(feature)),
303326
);
@@ -386,9 +409,9 @@ fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMach
386409
.target
387410
.supported_target_features()
388411
.iter()
389-
.map(|(feature, _gate, _implied)| {
412+
.filter_map(|(feature, _gate, _implied)| {
390413
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these strings.
391-
let llvm_feature = to_llvm_features(sess, *feature).llvm_feature_name;
414+
let llvm_feature = to_llvm_features(sess, *feature)?.llvm_feature_name;
392415
let desc =
393416
match llvm_target_features.binary_search_by_key(&llvm_feature, |(f, _d)| f).ok() {
394417
Some(index) => {
@@ -398,7 +421,7 @@ fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMach
398421
None => "",
399422
};
400423

401-
(*feature, desc)
424+
Some((*feature, desc))
402425
})
403426
.collect::<Vec<_>>();
404427

@@ -595,7 +618,7 @@ pub(crate) fn global_llvm_features(
595618
if feature_state.is_none() {
596619
let rust_feature =
597620
supported_features.iter().find_map(|&(rust_feature, _, _)| {
598-
let llvm_features = to_llvm_features(sess, rust_feature);
621+
let llvm_features = to_llvm_features(sess, rust_feature)?;
599622
if llvm_features.contains(feature)
600623
&& !llvm_features.contains(rust_feature)
601624
{
@@ -641,7 +664,7 @@ pub(crate) fn global_llvm_features(
641664
// passing requests down to LLVM. This means that all in-language
642665
// features also work on the command line instead of having two
643666
// different names when the LLVM name and the Rust name differ.
644-
let llvm_feature = to_llvm_features(sess, feature);
667+
let llvm_feature = to_llvm_features(sess, feature)?;
645668

646669
Some(
647670
std::iter::once(format!(
@@ -691,6 +714,9 @@ fn backend_feature_name<'a>(sess: &Session, s: &'a str) -> Option<&'a str> {
691714
let feature = s
692715
.strip_prefix(&['+', '-'][..])
693716
.unwrap_or_else(|| sess.dcx().emit_fatal(InvalidTargetFeaturePrefix { feature: s }));
717+
if s.is_empty() {
718+
return None;
719+
}
694720
// Rustc-specific feature requests like `+crt-static` or `-crt-static`
695721
// are not passed down to LLVM.
696722
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {

compiler/rustc_feature/src/unstable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ declare_features! (
302302
// FIXME: Document these and merge with the list below.
303303

304304
// Unstable `#[target_feature]` directives.
305+
(unstable, aarch64_unstable_target_feature, "CURRENT_RUSTC_VERSION", Some(44839)),
305306
(unstable, aarch64_ver_target_feature, "1.27.0", Some(44839)),
306307
(unstable, arm_target_feature, "1.27.0", Some(44839)),
307308
(unstable, avx512_target_feature, "1.27.0", Some(44839)),

compiler/rustc_index/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// tidy-alphabetical-start
22
#![cfg_attr(all(feature = "nightly", test), feature(stmt_expr_attributes))]
33
#![cfg_attr(feature = "nightly", allow(internal_features))]
4-
#![cfg_attr(feature = "nightly", feature(extend_one, new_uninit, step_trait, test))]
4+
#![cfg_attr(feature = "nightly", feature(extend_one, step_trait, test))]
55
#![cfg_attr(feature = "nightly", feature(new_zeroed_alloc))]
66
#![warn(unreachable_pub)]
77
// tidy-alphabetical-end

0 commit comments

Comments
 (0)