Skip to content

Commit bd0826a

Browse files
committed
Auto merge of #133006 - matthiaskrgr:rollup-dz6oiq5, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #126046 (Implement `mixed_integer_ops_unsigned_sub`) - #132302 (rustdoc: Treat declarative macros more like other item kinds) - #132842 (ABI checks: add support for tier2 arches) - #132995 (compiletest: Add ``exact-llvm-major-version`` directive) - #132996 (Trim extra space when suggesting removing bad `let`) - #132998 (Unvacation myself) - #133000 ([rustdoc] Fix duplicated footnote IDs) - #133001 (actually test next solver) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8adb4b3 + 2e13bf6 commit bd0826a

34 files changed

Lines changed: 414 additions & 184 deletions

‎compiler/rustc_monomorphize/messages.ftl‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
monomorphize_abi_error_disabled_vector_type_call =
2-
ABI error: this function call uses a vector type that requires the `{$required_feature}` target feature, which is not enabled in the caller
2+
this function call uses a SIMD vector type that (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled in the caller
33
.label = function called here
44
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
55
monomorphize_abi_error_disabled_vector_type_def =
6-
ABI error: this function definition uses a vector type that requires the `{$required_feature}` target feature, which is not enabled
6+
this function definition uses a SIMD vector type that (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled
77
.label = function defined here
88
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
99
10+
monomorphize_abi_error_unsupported_vector_type_call =
11+
this function call uses a SIMD vector type that is not currently supported with the chosen ABI
12+
.label = function called here
13+
monomorphize_abi_error_unsupported_vector_type_def =
14+
this function definition uses a SIMD vector type that is not currently supported with the chosen ABI
15+
.label = function defined here
16+
1017
monomorphize_couldnt_dump_mono_stats =
1118
unexpected error occurred while dumping monomorphization stats: {$error}
1219

‎compiler/rustc_monomorphize/src/errors.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,17 @@ pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
110110
pubspan:Span,
111111
pubrequired_feature:&'astr,
112112
}
113+
114+
#[derive(LintDiagnostic)]
115+
#[diag(monomorphize_abi_error_unsupported_vector_type_def)]
116+
pub(crate)structAbiErrorUnsupportedVectorTypeDef{
117+
#[label]
118+
pubspan:Span,
119+
}
120+
121+
#[derive(LintDiagnostic)]
122+
#[diag(monomorphize_abi_error_unsupported_vector_type_call)]
123+
pub(crate)structAbiErrorUnsupportedVectorTypeCall{
124+
#[label]
125+
pubspan:Span,
126+
}

‎compiler/rustc_monomorphize/src/mono_checks/abi_check.rs‎

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use rustc_span::{DUMMY_SP, Span, Symbol};
1010
use rustc_target::abi::call::{FnAbi,PassMode};
1111
use rustc_target::abi::{BackendRepr,RegKind};
1212

13-
usecrate::errors::{AbiErrorDisabledVectorTypeCall,AbiErrorDisabledVectorTypeDef};
13+
usecrate::errors::{
14+
AbiErrorDisabledVectorTypeCall,AbiErrorDisabledVectorTypeDef,
15+
AbiErrorUnsupportedVectorTypeCall,AbiErrorUnsupportedVectorTypeDef,
16+
};
1417

1518
fnuses_vector_registers(mode:&PassMode,repr:&BackendRepr) -> bool{
1619
match mode {
@@ -23,11 +26,15 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
2326
}
2427
}
2528

29+
/// Checks whether a certain function ABI is compatible with the target features currently enabled
30+
/// for a certain function.
31+
/// If not, `emit_err` is called, with `Some(feature)` if a certain feature should be enabled and
32+
/// with `None` if no feature is known that would make the ABI compatible.
2633
fndo_check_abi<'tcx>(
2734
tcx:TyCtxt<'tcx>,
2835
abi:&FnAbi<'tcx,Ty<'tcx>>,
2936
target_feature_def:DefId,
30-
mutemit_err:implFnMut(&'staticstr),
37+
mutemit_err:implFnMut(Option<&'staticstr>),
3138
){
3239
letSome(feature_def) = tcx.sess.target.features_for_correct_vector_abi()else{
3340
return;
@@ -40,15 +47,15 @@ fn do_check_abi<'tcx>(
4047
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits){
4148
Some((_, feature)) => feature,
4249
None => {
43-
emit_err("<no available feature for this size>");
50+
emit_err(None);
4451
continue;
4552
}
4653
};
4754
let feature_sym = Symbol::intern(feature);
4855
if !tcx.sess.unstable_target_features.contains(&feature_sym)
4956
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym)
5057
{
51-
emit_err(feature);
58+
emit_err(Some(&feature));
5259
}
5360
}
5461
}
@@ -65,12 +72,21 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
6572
};
6673
do_check_abi(tcx, abi, instance.def_id(), |required_feature| {
6774
let span = tcx.def_span(instance.def_id());
68-
tcx.emit_node_span_lint(
69-
ABI_UNSUPPORTED_VECTOR_TYPES,
70-
CRATE_HIR_ID,
71-
span,
72-
AbiErrorDisabledVectorTypeDef{ span, required_feature },
73-
);
75+
ifletSome(required_feature) = required_feature {
76+
tcx.emit_node_span_lint(
77+
ABI_UNSUPPORTED_VECTOR_TYPES,
78+
CRATE_HIR_ID,
79+
span,
80+
AbiErrorDisabledVectorTypeDef{ span, required_feature },
81+
);
82+
}else{
83+
tcx.emit_node_span_lint(
84+
ABI_UNSUPPORTED_VECTOR_TYPES,
85+
CRATE_HIR_ID,
86+
span,
87+
AbiErrorUnsupportedVectorTypeDef{ span },
88+
);
89+
}
7490
})
7591
}
7692

@@ -109,12 +125,21 @@ fn check_call_site_abi<'tcx>(
109125
return;
110126
};
111127
do_check_abi(tcx, callee_abi, caller.def_id(), |required_feature| {
112-
tcx.emit_node_span_lint(
113-
ABI_UNSUPPORTED_VECTOR_TYPES,
114-
CRATE_HIR_ID,
115-
span,
116-
AbiErrorDisabledVectorTypeCall{ span, required_feature },
117-
);
128+
ifletSome(required_feature) = required_feature {
129+
tcx.emit_node_span_lint(
130+
ABI_UNSUPPORTED_VECTOR_TYPES,
131+
CRATE_HIR_ID,
132+
span,
133+
AbiErrorDisabledVectorTypeCall{ span, required_feature },
134+
);
135+
}else{
136+
tcx.emit_node_span_lint(
137+
ABI_UNSUPPORTED_VECTOR_TYPES,
138+
CRATE_HIR_ID,
139+
span,
140+
AbiErrorUnsupportedVectorTypeCall{ span },
141+
);
142+
}
118143
});
119144
}
120145

‎compiler/rustc_parse/src/parser/pat.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,9 @@ impl<'a> Parser<'a> {
683683
})
684684
{
685685
self.bump();
686-
self.dcx().emit_err(RemoveLet{span: lo });
686+
// Trim extra space after the `let`
687+
let span = lo.with_hi(self.token.span.lo());
688+
self.dcx().emit_err(RemoveLet{ span });
687689
lo = self.token.span;
688690
}
689691

‎compiler/rustc_target/src/target_features.rs‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,20 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
586586
// certain size to have their "proper" ABI on each architecture.
587587
// Note that they must be kept sorted by vector size.
588588
constX86_FEATURES_FOR_CORRECT_VECTOR_ABI:&'static[(u64,&'staticstr)] =
589-
&[(128,"sse"),(256,"avx"),(512,"avx512f")];
589+
&[(128,"sse"),(256,"avx"),(512,"avx512f")];// FIXME: might need changes for AVX10.
590590
constAARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI:&'static[(u64,&'staticstr)] = &[(128,"neon")];
591591

592+
// We might want to add "helium" too.
593+
constARM_FEATURES_FOR_CORRECT_VECTOR_ABI:&'static[(u64,&'staticstr)] = &[(128,"neon")];
594+
595+
constPOWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI:&'static[(u64,&'staticstr)] = &[(128,"altivec")];
596+
constWASM_FEATURES_FOR_CORRECT_VECTOR_ABI:&'static[(u64,&'staticstr)] = &[(128,"simd128")];
597+
constS390X_FEATURES_FOR_CORRECT_VECTOR_ABI:&'static[(u64,&'staticstr)] = &[(128,"vector")];
598+
constRISCV_FEATURES_FOR_CORRECT_VECTOR_ABI:&'static[(u64,&'staticstr)] =
599+
&[/*(64, "zvl64b"), */(128,"v")];
600+
// Always warn on SPARC, as the necessary target features cannot be enabled in Rust at the moment.
601+
constSPARC_FEATURES_FOR_CORRECT_VECTOR_ABI:&'static[(u64,&'staticstr)] = &[/*(128, "vis")*/];
602+
592603
implsuper::spec::Target{
593604
pubfnrust_target_features(&self) -> &'static[(&'staticstr,Stability,ImpliedFeatures)]{
594605
match&*self.arch{
@@ -613,8 +624,15 @@ impl super::spec::Target {
613624
pubfnfeatures_for_correct_vector_abi(&self) -> Option<&'static[(u64,&'staticstr)]>{
614625
match&*self.arch{
615626
"x86" | "x86_64" => Some(X86_FEATURES_FOR_CORRECT_VECTOR_ABI),
616-
"aarch64" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
617-
// FIXME: add support for non-tier1 architectures
627+
"aarch64" | "arm64ec" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
628+
"arm" => Some(ARM_FEATURES_FOR_CORRECT_VECTOR_ABI),
629+
"powerpc" | "powerpc64" => Some(POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI),
630+
"loongarch64" => Some(&[]),// on-stack ABI, so we complain about all by-val vectors
631+
"riscv32" | "riscv64" => Some(RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI),
632+
"wasm32" | "wasm64" => Some(WASM_FEATURES_FOR_CORRECT_VECTOR_ABI),
633+
"s390x" => Some(S390X_FEATURES_FOR_CORRECT_VECTOR_ABI),
634+
"sparc" | "sparc64" => Some(SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI),
635+
// FIXME: add support for non-tier2 architectures
618636
_ => None,
619637
}
620638
}

‎library/core/src/num/uint_macros.rs‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,33 @@ macro_rules! uint_impl {
763763
}
764764
}
765765

766+
/// Checked subtraction with a signed integer. Computes `self - rhs`,
767+
/// returning `None` if overflow occurred.
768+
///
769+
/// # Examples
770+
///
771+
/// Basic usage:
772+
///
773+
/// ```
774+
/// #![feature(mixed_integer_ops_unsigned_sub)]
775+
#[doc = concat!("assert_eq!(1", stringify!($SelfT),".checked_sub_signed(2), None);")]
776+
#[doc = concat!("assert_eq!(1", stringify!($SelfT),".checked_sub_signed(-2), Some(3));")]
777+
#[doc = concat!("assert_eq!((", stringify!($SelfT),"::MAX - 2).checked_sub_signed(-4), None);")]
778+
/// ```
779+
#[unstable(feature = "mixed_integer_ops_unsigned_sub", issue = "126043")]
780+
#[must_use = "this returns the result of the operation, \
781+
without modifying the original"]
782+
#[inline]
783+
pubconstfn checked_sub_signed(self, rhs: $SignedT) -> Option<Self> {
784+
let(res, overflow) = self.overflowing_sub_signed(rhs);
785+
786+
if !overflow {
787+
Some(res)
788+
} else {
789+
None
790+
}
791+
}
792+
766793
#[doc = concat!(
767794
"Checked integer subtraction. Computes `self - rhs` and checks if the result fits into an [`",
768795
stringify!($SignedT),"`], returning `None` if overflow occurred."
@@ -1793,6 +1820,35 @@ macro_rules! uint_impl {
17931820
intrinsics::saturating_sub(self, rhs)
17941821
}
17951822

1823+
/// Saturating integer subtraction. Computes `self` - `rhs`, saturating at
1824+
/// the numeric bounds instead of overflowing.
1825+
///
1826+
/// # Examples
1827+
///
1828+
/// Basic usage:
1829+
///
1830+
/// ```
1831+
/// #![feature(mixed_integer_ops_unsigned_sub)]
1832+
#[doc = concat!("assert_eq!(1", stringify!($SelfT),".saturating_sub_signed(2), 0);")]
1833+
#[doc = concat!("assert_eq!(1", stringify!($SelfT),".saturating_sub_signed(-2), 3);")]
1834+
#[doc = concat!("assert_eq!((", stringify!($SelfT),"::MAX - 2).saturating_sub_signed(-4), ", stringify!($SelfT),"::MAX);")]
1835+
/// ```
1836+
#[unstable(feature = "mixed_integer_ops_unsigned_sub", issue = "126043")]
1837+
#[must_use = "this returns the result of the operation, \
1838+
without modifying the original"]
1839+
#[inline]
1840+
pubconstfn saturating_sub_signed(self, rhs: $SignedT) -> Self{
1841+
let(res, overflow) = self.overflowing_sub_signed(rhs);
1842+
1843+
if !overflow {
1844+
res
1845+
} else if rhs < 0{
1846+
Self::MAX
1847+
} else {
1848+
0
1849+
}
1850+
}
1851+
17961852
/// Saturating integer multiplication. Computes `self * rhs`,
17971853
/// saturating at the numeric bounds instead of overflowing.
17981854
///
@@ -1926,6 +1982,27 @@ macro_rules! uint_impl {
19261982
intrinsics::wrapping_sub(self, rhs)
19271983
}
19281984

1985+
/// Wrapping (modular) subtraction with a signed integer. Computes
1986+
/// `self - rhs`, wrapping around at the boundary of the type.
1987+
///
1988+
/// # Examples
1989+
///
1990+
/// Basic usage:
1991+
///
1992+
/// ```
1993+
/// #![feature(mixed_integer_ops_unsigned_sub)]
1994+
#[doc = concat!("assert_eq!(1", stringify!($SelfT),".wrapping_sub_signed(2), ", stringify!($SelfT),"::MAX);")]
1995+
#[doc = concat!("assert_eq!(1", stringify!($SelfT),".wrapping_sub_signed(-2), 3);")]
1996+
#[doc = concat!("assert_eq!((", stringify!($SelfT),"::MAX - 2).wrapping_sub_signed(-4), 1);")]
1997+
/// ```
1998+
#[unstable(feature = "mixed_integer_ops_unsigned_sub", issue = "126043")]
1999+
#[must_use = "this returns the result of the operation, \
2000+
without modifying the original"]
2001+
#[inline]
2002+
pubconstfn wrapping_sub_signed(self, rhs: $SignedT) -> Self{
2003+
self.wrapping_sub(rhs asSelf)
2004+
}
2005+
19292006
/// Wrapping (modular) multiplication. Computes `self *
19302007
/// rhs`, wrapping around at the boundary of the type.
19312008
///
@@ -2378,6 +2455,32 @@ macro_rules! uint_impl {
23782455
(c, b || d)
23792456
}
23802457

2458+
/// Calculates `self` - `rhs` with a signed `rhs`
2459+
///
2460+
/// Returns a tuple of the subtraction along with a boolean indicating
2461+
/// whether an arithmetic overflow would occur. If an overflow would
2462+
/// have occurred then the wrapped value is returned.
2463+
///
2464+
/// # Examples
2465+
///
2466+
/// Basic usage:
2467+
///
2468+
/// ```
2469+
/// #![feature(mixed_integer_ops_unsigned_sub)]
2470+
#[doc = concat!("assert_eq!(1", stringify!($SelfT),".overflowing_sub_signed(2), (", stringify!($SelfT),"::MAX, true));")]
2471+
#[doc = concat!("assert_eq!(1", stringify!($SelfT),".overflowing_sub_signed(-2), (3, false));")]
2472+
#[doc = concat!("assert_eq!((", stringify!($SelfT),"::MAX - 2).overflowing_sub_signed(-4), (1, true));")]
2473+
/// ```
2474+
#[unstable(feature = "mixed_integer_ops_unsigned_sub", issue = "126043")]
2475+
#[must_use = "this returns the result of the operation, \
2476+
without modifying the original"]
2477+
#[inline]
2478+
pubconstfn overflowing_sub_signed(self, rhs: $SignedT) -> (Self,bool){
2479+
let(res, overflow) = self.overflowing_sub(rhs asSelf);
2480+
2481+
(res, overflow ^ (rhs < 0))
2482+
}
2483+
23812484
/// Computes the absolute difference between `self` and `other`.
23822485
///
23832486
/// # Examples

‎src/librustdoc/clean/inline.rs‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,7 @@ pub(crate) fn try_inline(
134134
})
135135
}
136136
Res::Def(DefKind::Macro(kind), did) => {
137-
let is_doc_hidden = cx.tcx.is_doc_hidden(did)
138-
|| attrs_without_docs
139-
.map(|(attrs, _)| attrs)
140-
.is_some_and(|attrs| utils::attrs_have_doc_flag(attrs.iter(), sym::hidden));
141-
let mac = build_macro(cx, did, name, import_def_id, kind, is_doc_hidden);
137+
let mac = build_macro(cx, did, name, kind);
142138

143139
let type_kind = match kind {
144140
MacroKind::Bang => ItemType::Macro,
@@ -740,18 +736,14 @@ fn build_macro(
740736
cx:&mutDocContext<'_>,
741737
def_id:DefId,
742738
name:Symbol,
743-
import_def_id:Option<LocalDefId>,
744739
macro_kind:MacroKind,
745-
is_doc_hidden:bool,
746740
) -> clean::ItemKind{
747741
matchCStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.tcx){
748742
LoadedMacro::MacroDef{ def, .. } => match macro_kind {
749-
MacroKind::Bang => {
750-
let vis = cx.tcx.visibility(import_def_id.map(|d| d.to_def_id()).unwrap_or(def_id));
751-
clean::MacroItem(clean::Macro{
752-
source: utils::display_macro_source(cx, name,&def, def_id, vis, is_doc_hidden),
753-
})
754-
}
743+
MacroKind::Bang => clean::MacroItem(clean::Macro{
744+
source: utils::display_macro_source(cx, name,&def),
745+
macro_rules: def.macro_rules,
746+
}),
755747
MacroKind::Derive | MacroKind::Attr => {
756748
clean::ProcMacroItem(clean::ProcMacro{kind: macro_kind,helpers:Vec::new()})
757749
}

‎src/librustdoc/clean/mod.rs‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,13 +2787,10 @@ fn clean_maybe_renamed_item<'tcx>(
27872787
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
27882788
}),
27892789
ItemKind::Impl(impl_) => returnclean_impl(impl_, item.owner_id.def_id, cx),
2790-
ItemKind::Macro(macro_def,MacroKind::Bang) => {
2791-
let ty_vis = cx.tcx.visibility(def_id);
2792-
MacroItem(Macro{
2793-
// FIXME this shouldn't be false
2794-
source:display_macro_source(cx, name, macro_def, def_id, ty_vis,false),
2795-
})
2796-
}
2790+
ItemKind::Macro(macro_def,MacroKind::Bang) => MacroItem(Macro{
2791+
source:display_macro_source(cx, name, macro_def),
2792+
macro_rules: macro_def.macro_rules,
2793+
}),
27972794
ItemKind::Macro(_, macro_kind) => clean_proc_macro(item,&mut name, macro_kind, cx),
27982795
// proc macros can have a name set by attributes
27992796
ItemKind::Fn(ref sig, generics, body_id) => {

‎src/librustdoc/clean/types.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,8 @@ pub(crate) struct ImportSource {
25432543
#[derive(Clone,Debug)]
25442544
pub(crate)structMacro{
25452545
pub(crate)source:String,
2546+
/// Whether the macro was defined via `macro_rules!` as opposed to `macro`.
2547+
pub(crate)macro_rules:bool,
25462548
}
25472549

25482550
#[derive(Clone,Debug)]

0 commit comments

Comments
 (0)