Skip to content

Commit f3626a3

Browse files
committed
Auto merge of rust-lang#132018 - fmease:rollup-0sbaxce, r=fmease
Rollup of 6 pull requests Successful merges: - rust-lang#129935 (make unsupported_calling_conventions a hard error) - rust-lang#130432 (rust_for_linux: -Zregparm=<N> commandline flag for X86 (rust-lang#116972)) - rust-lang#131697 (`rt::Argument`: elide lifetimes) - rust-lang#131954 (shave 150ms off bootstrap) - rust-lang#131982 (Represent `hir::TraitBoundModifiers` as distinct parts in HIR) - rust-lang#132017 (Update triagebot.toml) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 814df6e + ce0d299 commit f3626a3

File tree

57 files changed

+618
-393
lines changed

Some content is hidden

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

57 files changed

+618
-393
lines changed

compiler/rustc_ast/src/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ impl fmt::Debug for ImplPolarity {
26972697
}
26982698

26992699
/// The polarity of a trait bound.
2700-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
2700+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash)]
27012701
#[derive(HashStable_Generic)]
27022702
pub enum BoundPolarity {
27032703
/// `Type: Trait`
@@ -2719,7 +2719,7 @@ impl BoundPolarity {
27192719
}
27202720

27212721
/// The constness of a trait bound.
2722-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
2722+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash)]
27232723
#[derive(HashStable_Generic)]
27242724
pub enum BoundConstness {
27252725
/// `Type: Trait`

compiler/rustc_ast_lowering/src/lib.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19561956

19571957
hir::GenericBound::Trait(hir::PolyTraitRef {
19581958
bound_generic_params: &[],
1959-
modifiers: hir::TraitBoundModifier::None,
1959+
modifiers: hir::TraitBoundModifiers::NONE,
19601960
trait_ref: hir::TraitRef {
19611961
path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
19621962
hir_ref_id: self.next_id(),
@@ -2445,22 +2445,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24452445
fn lower_trait_bound_modifiers(
24462446
&mut self,
24472447
modifiers: TraitBoundModifiers,
2448-
) -> hir::TraitBoundModifier {
2449-
// Invalid modifier combinations will cause an error during AST validation.
2450-
// Arbitrarily pick a placeholder for them to make compilation proceed.
2451-
match (modifiers.constness, modifiers.polarity) {
2452-
(BoundConstness::Never, BoundPolarity::Positive) => hir::TraitBoundModifier::None,
2453-
(_, BoundPolarity::Maybe(_)) => hir::TraitBoundModifier::Maybe,
2454-
(BoundConstness::Never, BoundPolarity::Negative(_)) => {
2455-
if self.tcx.features().negative_bounds {
2456-
hir::TraitBoundModifier::Negative
2457-
} else {
2458-
hir::TraitBoundModifier::None
2459-
}
2460-
}
2461-
(BoundConstness::Always(_), _) => hir::TraitBoundModifier::Const,
2462-
(BoundConstness::Maybe(_), _) => hir::TraitBoundModifier::MaybeConst,
2463-
}
2448+
) -> hir::TraitBoundModifiers {
2449+
hir::TraitBoundModifiers { constness: modifiers.constness, polarity: modifiers.polarity }
24642450
}
24652451

24662452
// Helper methods for building HIR.
@@ -2626,7 +2612,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26262612
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
26272613
let principal = hir::PolyTraitRef {
26282614
bound_generic_params: &[],
2629-
modifiers: hir::TraitBoundModifier::None,
2615+
modifiers: hir::TraitBoundModifiers::NONE,
26302616
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
26312617
span: self.lower_span(span),
26322618
};

compiler/rustc_codegen_gcc/src/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
3030
use rustc_span::Span;
3131
use rustc_span::def_id::DefId;
3232
use rustc_target::abi::call::FnAbi;
33-
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, Target, WasmCAbi};
33+
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, Target, WasmCAbi, X86Abi};
3434

3535
use crate::common::{SignType, TypeReflection, type_is_pointer};
3636
use crate::context::CodegenCx;
@@ -2347,6 +2347,12 @@ impl<'tcx> HasWasmCAbiOpt for Builder<'_, '_, 'tcx> {
23472347
}
23482348
}
23492349

2350+
impl<'tcx> HasX86AbiOpt for Builder<'_, '_, 'tcx> {
2351+
fn x86_abi_opt(&self) -> X86Abi {
2352+
self.cx.x86_abi_opt()
2353+
}
2354+
}
2355+
23502356
pub trait ToGccComp {
23512357
fn to_gcc_comparison(&self) -> ComparisonOp;
23522358
}

compiler/rustc_codegen_gcc/src/context.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use rustc_session::Session;
1919
use rustc_span::source_map::respan;
2020
use rustc_span::{DUMMY_SP, Span};
2121
use rustc_target::abi::{HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
22-
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, Target, TlsModel, WasmCAbi};
22+
use rustc_target::spec::{
23+
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, Target, TlsModel, WasmCAbi, X86Abi,
24+
};
2325

2426
use crate::callee::get_fn;
2527
use crate::common::SignType;
@@ -538,6 +540,12 @@ impl<'gcc, 'tcx> HasWasmCAbiOpt for CodegenCx<'gcc, 'tcx> {
538540
}
539541
}
540542

543+
impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> {
544+
fn x86_abi_opt(&self) -> X86Abi {
545+
X86Abi { regparm: self.tcx.sess.opts.unstable_opts.regparm }
546+
}
547+
}
548+
541549
impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
542550
#[inline]
543551
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {

compiler/rustc_hir/src/hir.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rustc_ast::{
66
LitKind, TraitObjectSyntax, UintTy,
77
};
88
pub use rustc_ast::{
9-
BinOp, BinOpKind, BindingMode, BorrowKind, ByRef, CaptureBy, ImplPolarity, IsAuto, Movability,
10-
Mutability, UnOp,
9+
BinOp, BinOpKind, BindingMode, BorrowKind, BoundConstness, BoundPolarity, ByRef, CaptureBy,
10+
ImplPolarity, IsAuto, Movability, Mutability, UnOp,
1111
};
1212
use rustc_data_structures::fingerprint::Fingerprint;
1313
use rustc_data_structures::sorted_map::SortedMap;
@@ -502,19 +502,16 @@ pub enum GenericArgsParentheses {
502502
ParenSugar,
503503
}
504504

505-
/// A modifier on a trait bound.
505+
/// The modifiers on a trait bound.
506506
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
507-
pub enum TraitBoundModifier {
508-
/// `Type: Trait`
509-
None,
510-
/// `Type: !Trait`
511-
Negative,
512-
/// `Type: ?Trait`
513-
Maybe,
514-
/// `Type: const Trait`
515-
Const,
516-
/// `Type: ~const Trait`
517-
MaybeConst,
507+
pub struct TraitBoundModifiers {
508+
pub constness: BoundConstness,
509+
pub polarity: BoundPolarity,
510+
}
511+
512+
impl TraitBoundModifiers {
513+
pub const NONE: Self =
514+
TraitBoundModifiers { constness: BoundConstness::Never, polarity: BoundPolarity::Positive };
518515
}
519516

520517
#[derive(Clone, Copy, Debug, HashStable_Generic)]
@@ -3180,7 +3177,7 @@ pub struct PolyTraitRef<'hir> {
31803177
/// The constness and polarity of the trait ref.
31813178
///
31823179
/// The `async` modifier is lowered directly into a different trait for now.
3183-
pub modifiers: TraitBoundModifier,
3180+
pub modifiers: TraitBoundModifiers,
31843181

31853182
/// The `Foo<&'a T>` in `for<'a> Foo<&'a T>`.
31863183
pub trait_ref: TraitRef<'hir>,
@@ -4085,7 +4082,7 @@ mod size_asserts {
40854082
static_assert_size!(ForeignItem<'_>, 88);
40864083
static_assert_size!(ForeignItemKind<'_>, 56);
40874084
static_assert_size!(GenericArg<'_>, 16);
4088-
static_assert_size!(GenericBound<'_>, 48);
4085+
static_assert_size!(GenericBound<'_>, 64);
40894086
static_assert_size!(Generics<'_>, 56);
40904087
static_assert_size!(Impl<'_>, 80);
40914088
static_assert_size!(ImplItem<'_>, 88);

compiler/rustc_hir_analysis/src/check/check.rs

+17-28
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::{
2222
AdtDef, GenericArgKind, ParamEnv, RegionKind, TypeSuperVisitable, TypeVisitable,
2323
TypeVisitableExt,
2424
};
25-
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
25+
use rustc_session::lint::builtin::UNINHABITED_STATIC;
2626
use rustc_target::abi::FieldIdx;
2727
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2828
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
@@ -36,36 +36,25 @@ use super::compare_impl_item::{check_type_bounds, compare_impl_method, compare_i
3636
use super::*;
3737
use crate::check::intrinsicck::InlineAsmCtxt;
3838

39-
pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
40-
match tcx.sess.target.is_abi_supported(abi) {
41-
Some(true) => (),
42-
Some(false) => {
43-
struct_span_code_err!(
44-
tcx.dcx(),
45-
span,
46-
E0570,
47-
"`{abi}` is not a supported ABI for the current target",
48-
)
49-
.emit();
50-
}
51-
None => {
52-
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
53-
lint.primary_message("use of calling convention not supported on this target");
54-
});
55-
}
39+
pub fn check_abi(tcx: TyCtxt<'_>, span: Span, abi: Abi) {
40+
if !tcx.sess.target.is_abi_supported(abi) {
41+
struct_span_code_err!(
42+
tcx.dcx(),
43+
span,
44+
E0570,
45+
"`{abi}` is not a supported ABI for the current target",
46+
)
47+
.emit();
5648
}
5749
}
5850

5951
pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
60-
match tcx.sess.target.is_abi_supported(abi) {
61-
Some(true) => (),
62-
Some(false) | None => {
63-
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
64-
lint.primary_message(format!(
65-
"the calling convention {abi} is not supported on this target"
66-
));
67-
});
68-
}
52+
if !tcx.sess.target.is_abi_supported(abi) {
53+
tcx.node_span_lint(UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS, hir_id, span, |lint| {
54+
lint.primary_message(format!(
55+
"the calling convention {abi} is not supported on this target"
56+
));
57+
});
6958
}
7059
}
7160

@@ -705,7 +694,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
705694
let hir::ItemKind::ForeignMod { abi, items } = it.kind else {
706695
return;
707696
};
708-
check_abi(tcx, it.hir_id(), it.span, abi);
697+
check_abi(tcx, it.span, abi);
709698

710699
match abi {
711700
Abi::RustIntrinsic => {

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
4545
let hir::GenericBound::Trait(ptr) = hir_bound else {
4646
continue;
4747
};
48-
match ptr.modifiers {
49-
hir::TraitBoundModifier::Maybe => unbounds.push(ptr),
50-
hir::TraitBoundModifier::Negative => {
48+
match ptr.modifiers.polarity {
49+
hir::BoundPolarity::Maybe(_) => unbounds.push(ptr),
50+
hir::BoundPolarity::Negative(_) => {
5151
if let Some(sized_def_id) = sized_def_id
5252
&& ptr.trait_ref.path.res == Res::Def(DefKind::Trait, sized_def_id)
5353
{
5454
seen_negative_sized_bound = true;
5555
}
5656
}
57-
hir::TraitBoundModifier::None => {
57+
hir::BoundPolarity::Positive => {
5858
if let Some(sized_def_id) = sized_def_id
5959
&& ptr.trait_ref.path.res == Res::Def(DefKind::Trait, sized_def_id)
6060
{
6161
seen_positive_sized_bound = true;
6262
}
6363
}
64-
_ => {}
6564
}
6665
}
6766
};
@@ -169,20 +168,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
169168

170169
match hir_bound {
171170
hir::GenericBound::Trait(poly_trait_ref) => {
172-
let (constness, polarity) = match poly_trait_ref.modifiers {
173-
hir::TraitBoundModifier::Const => {
174-
(Some(ty::BoundConstness::Const), ty::PredicatePolarity::Positive)
175-
}
176-
hir::TraitBoundModifier::MaybeConst => (
177-
Some(ty::BoundConstness::ConstIfConst),
178-
ty::PredicatePolarity::Positive,
179-
),
180-
hir::TraitBoundModifier::None => (None, ty::PredicatePolarity::Positive),
181-
hir::TraitBoundModifier::Negative => {
182-
(None, ty::PredicatePolarity::Negative)
183-
}
184-
hir::TraitBoundModifier::Maybe => continue,
171+
let hir::TraitBoundModifiers { constness, polarity } = poly_trait_ref.modifiers;
172+
// FIXME: We could pass these directly into `lower_poly_trait_ref`
173+
// so that we could use these spans in diagnostics within that function...
174+
let constness = match constness {
175+
hir::BoundConstness::Never => None,
176+
hir::BoundConstness::Always(_) => Some(ty::BoundConstness::Const),
177+
hir::BoundConstness::Maybe(_) => Some(ty::BoundConstness::ConstIfConst),
185178
};
179+
let polarity = match polarity {
180+
rustc_ast::BoundPolarity::Positive => ty::PredicatePolarity::Positive,
181+
rustc_ast::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative,
182+
rustc_ast::BoundPolarity::Maybe(_) => continue,
183+
};
184+
186185
let _ = self.lower_poly_trait_ref(
187186
&poly_trait_ref.trait_ref,
188187
poly_trait_ref.span,

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
4040
let mut potential_assoc_types = Vec::new();
4141
let dummy_self = self.tcx().types.trait_object_dummy_self;
4242
for trait_bound in hir_trait_bounds.iter().rev() {
43-
// FIXME: This doesn't handle `? const`.
44-
if trait_bound.modifiers == hir::TraitBoundModifier::Maybe {
43+
if let hir::BoundPolarity::Maybe(_) = trait_bound.modifiers.polarity {
4544
continue;
4645
}
4746
if let GenericArgCountResult {

compiler/rustc_hir_pretty/src/lib.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_ast_pretty::pprust::{Comments, PrintState};
1616
use rustc_hir::{
1717
BindingMode, ByRef, ConstArgKind, GenericArg, GenericBound, GenericParam, GenericParamKind,
1818
HirId, LifetimeParamKind, Node, PatKind, PreciseCapturingArg, RangeEnd, Term,
19-
TraitBoundModifier,
2019
};
2120
use rustc_span::FileName;
2221
use rustc_span::source_map::SourceMap;
@@ -676,9 +675,16 @@ impl<'a> State<'a> {
676675
}
677676

678677
fn print_poly_trait_ref(&mut self, t: &hir::PolyTraitRef<'_>) {
679-
// FIXME: This isn't correct!
680-
if t.modifiers == TraitBoundModifier::Maybe {
681-
self.word("?");
678+
let hir::TraitBoundModifiers { constness, polarity } = t.modifiers;
679+
match constness {
680+
hir::BoundConstness::Never => {}
681+
hir::BoundConstness::Always(_) => self.word("const"),
682+
hir::BoundConstness::Maybe(_) => self.word("~const"),
683+
}
684+
match polarity {
685+
hir::BoundPolarity::Positive => {}
686+
hir::BoundPolarity::Negative(_) => self.word("!"),
687+
hir::BoundPolarity::Maybe(_) => self.word("?"),
682688
}
683689
self.print_formal_generic_params(t.bound_generic_params);
684690
self.print_trait_ref(&t.trait_ref);

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn typeck_with_fallback<'tcx>(
155155
tcx.fn_sig(def_id).instantiate_identity()
156156
};
157157

158-
check_abi(tcx, id, span, fn_sig.abi());
158+
check_abi(tcx, span, fn_sig.abi());
159159

160160
// Compute the function signature from point of view of inside the fn.
161161
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ fn test_unstable_options_tracking_hash() {
836836
tracked!(profile_emit, Some(PathBuf::from("abc")));
837837
tracked!(profile_sample_use, Some(PathBuf::from("abc")));
838838
tracked!(profiler_runtime, "abc".to_string());
839+
tracked!(regparm, Some(3));
839840
tracked!(relax_elf_relocations, Some(true));
840841
tracked!(remap_cwd_prefix, Some(PathBuf::from("abc")));
841842
tracked!(sanitizer, SanitizerSet::ADDRESS);

compiler/rustc_lint/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ fn register_builtins(store: &mut LintStore) {
598598
"converted into hard error, see PR #125380 \
599599
<https://github.com/rust-lang/rust/pull/125380> for more information",
600600
);
601+
store.register_removed("unsupported_calling_conventions", "converted into hard error");
601602
}
602603

603604
fn register_internals(store: &mut LintStore) {

compiler/rustc_lint/src/traits.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
114114
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
115115
for bound in &bounds[..] {
116116
let def_id = bound.trait_ref.trait_def_id();
117-
if def_id.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::Drop))
118-
// FIXME: ?Drop is not a thing.
119-
&& bound.modifiers != hir::TraitBoundModifier::Maybe
120-
{
117+
if def_id.is_some_and(|def_id| cx.tcx.is_lang_item(def_id, LangItem::Drop)) {
121118
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
122119
cx.emit_span_lint(DYN_DROP, bound.span, DropGlue { tcx: cx.tcx, def_id });
123120
}

0 commit comments

Comments
 (0)