Skip to content

Commit 012c38d

Browse files
committed
Auto merge of #143211 - GuillaumeGomez:rollup-ug242zk, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #142429 (`tests/ui`: A New Order [13/N]) - #143066 (Use let chains in the new solver) - #143156 (inherit `#[align]` from trait method prototypes) - #143176 (fix typos and improve clarity in documentation) - #143187 (Add my work email to mailmap) - #143194 (fix bitcast of single-element SIMD vectors) - #143199 (Re-disable `tests/run-make/short-ice` on Windows MSVC again) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 35f6036 + e28298e commit 012c38d

File tree

36 files changed

+391
-259
lines changed

36 files changed

+391
-259
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ Xinye Tao <xy.tao@outlook.com>
690690
Xuefeng Wu <benewu@gmail.com> Xuefeng Wu <xfwu@thoughtworks.com>
691691
Xuefeng Wu <benewu@gmail.com> XuefengWu <benewu@gmail.com>
692692
York Xiang <bombless@126.com>
693+
Yotam Ofek <yotam.ofek@gmail.com> <yotamofek@microsoft.com>
693694
Youngsoo Son <ysson83@gmail.com> <ysoo.son@samsung.com>
694695
Youngsuk Kim <joseph942010@gmail.com>
695696
Yuki Okushi <jtitor@2k36.org>

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::str::FromStr;
22

3-
use rustc_abi::ExternAbi;
3+
use rustc_abi::{Align, ExternAbi};
44
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
55
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
66
use rustc_attr_data_structures::{
@@ -402,6 +402,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
402402
codegen_fn_attrs.alignment =
403403
Ord::max(codegen_fn_attrs.alignment, tcx.sess.opts.unstable_opts.min_function_alignment);
404404

405+
// On trait methods, inherit the `#[align]` of the trait's method prototype.
406+
codegen_fn_attrs.alignment = Ord::max(codegen_fn_attrs.alignment, tcx.inherited_align(did));
407+
405408
let inline_span;
406409
(codegen_fn_attrs.inline, inline_span) = if let Some((inline_attr, span)) =
407410
find_attr!(attrs, AttributeKind::Inline(i, span) => (*i, *span))
@@ -556,17 +559,26 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
556559
codegen_fn_attrs
557560
}
558561

562+
/// If the provided DefId is a method in a trait impl, return the DefId of the method prototype.
563+
fn opt_trait_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
564+
let impl_item = tcx.opt_associated_item(def_id)?;
565+
match impl_item.container {
566+
ty::AssocItemContainer::Impl => impl_item.trait_item_def_id,
567+
_ => None,
568+
}
569+
}
570+
559571
/// Checks if the provided DefId is a method in a trait impl for a trait which has track_caller
560572
/// applied to the method prototype.
561573
fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
562-
if let Some(impl_item) = tcx.opt_associated_item(def_id)
563-
&& let ty::AssocItemContainer::Impl = impl_item.container
564-
&& let Some(trait_item) = impl_item.trait_item_def_id
565-
{
566-
return tcx.codegen_fn_attrs(trait_item).flags.intersects(CodegenFnAttrFlags::TRACK_CALLER);
567-
}
574+
let Some(trait_item) = opt_trait_item(tcx, def_id) else { return false };
575+
tcx.codegen_fn_attrs(trait_item).flags.intersects(CodegenFnAttrFlags::TRACK_CALLER)
576+
}
568577

569-
false
578+
/// If the provided DefId is a method in a trait impl, return the value of the `#[align]`
579+
/// attribute on the method prototype (if any).
580+
fn inherited_align<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Align> {
581+
tcx.codegen_fn_attrs(opt_trait_item(tcx, def_id)?).alignment
570582
}
571583

572584
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &hir::Attribute) -> Option<u16> {
@@ -734,5 +746,6 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
734746
}
735747

736748
pub(crate) fn provide(providers: &mut Providers) {
737-
*providers = Providers { codegen_fn_attrs, should_inherit_track_caller, ..*providers };
749+
*providers =
750+
Providers { codegen_fn_attrs, should_inherit_track_caller, inherited_align, ..*providers };
738751
}

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ pub(super) fn transmute_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
11231123
// While optimizations will remove no-op transmutes, they might still be
11241124
// there in debug or things that aren't no-op in MIR because they change
11251125
// the Rust type but not the underlying layout/niche.
1126-
if from_scalar == to_scalar {
1126+
if from_scalar == to_scalar && from_backend_ty == to_backend_ty {
11271127
return imm;
11281128
}
11291129

@@ -1142,13 +1142,7 @@ pub(super) fn transmute_immediate<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
11421142
assume_scalar_range(bx, imm, from_scalar, from_backend_ty);
11431143

11441144
imm = match (from_scalar.primitive(), to_scalar.primitive()) {
1145-
(Int(..) | Float(_), Int(..) | Float(_)) => {
1146-
if from_backend_ty == to_backend_ty {
1147-
imm
1148-
} else {
1149-
bx.bitcast(imm, to_backend_ty)
1150-
}
1151-
}
1145+
(Int(..) | Float(_), Int(..) | Float(_)) => bx.bitcast(imm, to_backend_ty),
11521146
(Pointer(..), Pointer(..)) => bx.pointercast(imm, to_backend_ty),
11531147
(Int(..), Pointer(..)) => bx.ptradd(bx.const_null(bx.type_ptr()), imm),
11541148
(Pointer(..), Int(..)) => {

compiler/rustc_middle/src/query/erase.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ trivial! {
266266
Option<rustc_target::spec::PanicStrategy>,
267267
Option<usize>,
268268
Option<rustc_middle::ty::IntrinsicDef>,
269+
Option<rustc_abi::Align>,
269270
Result<(), rustc_errors::ErrorGuaranteed>,
270271
Result<(), rustc_middle::traits::query::NoSolution>,
271272
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ use std::mem;
6767
use std::path::PathBuf;
6868
use std::sync::Arc;
6969

70+
use rustc_abi::Align;
7071
use rustc_arena::TypedArena;
7172
use rustc_ast::expand::StrippedCfgItem;
7273
use rustc_ast::expand::allocator::AllocatorKind;
@@ -1481,6 +1482,10 @@ rustc_queries! {
14811482
desc { |tcx| "computing should_inherit_track_caller of `{}`", tcx.def_path_str(def_id) }
14821483
}
14831484

1485+
query inherited_align(def_id: DefId) -> Option<Align> {
1486+
desc { |tcx| "computing inherited_align of `{}`", tcx.def_path_str(def_id) }
1487+
}
1488+
14841489
query lookup_deprecation_entry(def_id: DefId) -> Option<DeprecationEntry> {
14851490
desc { |tcx| "checking whether `{}` is deprecated", tcx.def_path_str(def_id) }
14861491
cache_on_disk_if { def_id.is_local() }

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,10 @@ where
383383

384384
let mut candidates = vec![];
385385

386-
if let TypingMode::Coherence = self.typing_mode() {
387-
if let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal) {
388-
return vec![candidate];
389-
}
386+
if let TypingMode::Coherence = self.typing_mode()
387+
&& let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal)
388+
{
389+
return vec![candidate];
390390
}
391391

392392
self.assemble_alias_bound_candidates(goal, &mut candidates);

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,12 @@ where
997997
}
998998

999999
fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Ambiguous> {
1000-
if let ty::Alias(ty::Projection, alias_ty) = ty.kind() {
1001-
if let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? {
1002-
return Ok(term.expect_ty());
1003-
}
1000+
if let ty::Alias(ty::Projection, alias_ty) = ty.kind()
1001+
&& let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())?
1002+
{
1003+
Ok(term.expect_ty())
1004+
} else {
1005+
ty.try_super_fold_with(self)
10041006
}
1005-
1006-
ty.try_super_fold_with(self)
10071007
}
10081008
}

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,18 @@ where
4242
goal: Goal<I, Self>,
4343
assumption: I::Clause,
4444
) -> Result<(), NoSolution> {
45-
if let Some(host_clause) = assumption.as_host_effect_clause() {
46-
if host_clause.def_id() == goal.predicate.def_id()
47-
&& host_clause.constness().satisfies(goal.predicate.constness)
48-
{
49-
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
50-
goal.predicate.trait_ref.args,
51-
host_clause.skip_binder().trait_ref.args,
52-
) {
53-
return Ok(());
54-
}
55-
}
45+
if let Some(host_clause) = assumption.as_host_effect_clause()
46+
&& host_clause.def_id() == goal.predicate.def_id()
47+
&& host_clause.constness().satisfies(goal.predicate.constness)
48+
&& DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
49+
goal.predicate.trait_ref.args,
50+
host_clause.skip_binder().trait_ref.args,
51+
)
52+
{
53+
Ok(())
54+
} else {
55+
Err(NoSolution)
5656
}
57-
58-
Err(NoSolution)
5957
}
6058

6159
fn match_assumption(

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -429,22 +429,21 @@ where
429429
// If we have run this goal before, and it was stalled, check that any of the goal's
430430
// args have changed. Otherwise, we don't need to re-run the goal because it'll remain
431431
// stalled, since it'll canonicalize the same way and evaluation is pure.
432-
if let Some(stalled_on) = stalled_on {
433-
if !stalled_on.stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
434-
&& !self
435-
.delegate
436-
.opaque_types_storage_num_entries()
437-
.needs_reevaluation(stalled_on.num_opaques)
438-
{
439-
return Ok((
440-
NestedNormalizationGoals::empty(),
441-
GoalEvaluation {
442-
certainty: Certainty::Maybe(stalled_on.stalled_cause),
443-
has_changed: HasChanged::No,
444-
stalled_on: Some(stalled_on),
445-
},
446-
));
447-
}
432+
if let Some(stalled_on) = stalled_on
433+
&& !stalled_on.stalled_vars.iter().any(|value| self.delegate.is_changed_arg(*value))
434+
&& !self
435+
.delegate
436+
.opaque_types_storage_num_entries()
437+
.needs_reevaluation(stalled_on.num_opaques)
438+
{
439+
return Ok((
440+
NestedNormalizationGoals::empty(),
441+
GoalEvaluation {
442+
certainty: Certainty::Maybe(stalled_on.stalled_cause),
443+
has_changed: HasChanged::No,
444+
stalled_on: Some(stalled_on),
445+
},
446+
));
448447
}
449448

450449
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
@@ -833,14 +832,11 @@ where
833832

834833
match t.kind() {
835834
ty::Infer(ty::TyVar(vid)) => {
836-
if let ty::TermKind::Ty(term) = self.term.kind() {
837-
if let ty::Infer(ty::TyVar(term_vid)) = term.kind() {
838-
if self.delegate.root_ty_var(vid)
839-
== self.delegate.root_ty_var(term_vid)
840-
{
841-
return ControlFlow::Break(());
842-
}
843-
}
835+
if let ty::TermKind::Ty(term) = self.term.kind()
836+
&& let ty::Infer(ty::TyVar(term_vid)) = term.kind()
837+
&& self.delegate.root_ty_var(vid) == self.delegate.root_ty_var(term_vid)
838+
{
839+
return ControlFlow::Break(());
844840
}
845841

846842
self.check_nameable(self.delegate.universe_of_ty(vid).unwrap())?;
@@ -860,15 +856,12 @@ where
860856
fn visit_const(&mut self, c: I::Const) -> Self::Result {
861857
match c.kind() {
862858
ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
863-
if let ty::TermKind::Const(term) = self.term.kind() {
864-
if let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
865-
{
866-
if self.delegate.root_const_var(vid)
867-
== self.delegate.root_const_var(term_vid)
868-
{
869-
return ControlFlow::Break(());
870-
}
871-
}
859+
if let ty::TermKind::Const(term) = self.term.kind()
860+
&& let ty::ConstKind::Infer(ty::InferConst::Var(term_vid)) = term.kind()
861+
&& self.delegate.root_const_var(vid)
862+
== self.delegate.root_const_var(term_vid)
863+
{
864+
return ControlFlow::Break(());
872865
}
873866

874867
self.check_nameable(self.delegate.universe_of_ct(vid).unwrap())

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,17 @@ where
112112
goal: Goal<I, Self>,
113113
assumption: I::Clause,
114114
) -> Result<(), NoSolution> {
115-
if let Some(projection_pred) = assumption.as_projection_clause() {
116-
if projection_pred.item_def_id() == goal.predicate.def_id() {
117-
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
118-
goal.predicate.alias.args,
119-
projection_pred.skip_binder().projection_term.args,
120-
) {
121-
return Ok(());
122-
}
123-
}
115+
if let Some(projection_pred) = assumption.as_projection_clause()
116+
&& projection_pred.item_def_id() == goal.predicate.def_id()
117+
&& DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
118+
goal.predicate.alias.args,
119+
projection_pred.skip_binder().projection_term.args,
120+
)
121+
{
122+
Ok(())
123+
} else {
124+
Err(NoSolution)
124125
}
125-
126-
Err(NoSolution)
127126
}
128127

129128
fn match_assumption(

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,33 +127,32 @@ where
127127
goal: Goal<I, Self>,
128128
assumption: I::Clause,
129129
) -> Result<(), NoSolution> {
130-
if let Some(trait_clause) = assumption.as_trait_clause() {
131-
if trait_clause.polarity() != goal.predicate.polarity {
132-
return Err(NoSolution);
133-
}
134-
135-
if trait_clause.def_id() == goal.predicate.def_id() {
136-
if DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
137-
goal.predicate.trait_ref.args,
138-
trait_clause.skip_binder().trait_ref.args,
139-
) {
140-
return Ok(());
141-
}
142-
}
143-
130+
fn trait_def_id_matches<I: Interner>(
131+
cx: I,
132+
clause_def_id: I::DefId,
133+
goal_def_id: I::DefId,
134+
) -> bool {
135+
clause_def_id == goal_def_id
144136
// PERF(sized-hierarchy): Sizedness supertraits aren't elaborated to improve perf, so
145-
// check for a `Sized` subtrait when looking for `MetaSized`. `PointeeSized` bounds
146-
// are syntactic sugar for a lack of bounds so don't need this.
147-
if ecx.cx().is_lang_item(goal.predicate.def_id(), TraitSolverLangItem::MetaSized)
148-
&& ecx.cx().is_lang_item(trait_clause.def_id(), TraitSolverLangItem::Sized)
149-
{
150-
let meta_sized_clause =
151-
trait_predicate_with_def_id(ecx.cx(), trait_clause, goal.predicate.def_id());
152-
return Self::fast_reject_assumption(ecx, goal, meta_sized_clause);
153-
}
137+
// check for a `MetaSized` supertrait being matched against a `Sized` assumption.
138+
//
139+
// `PointeeSized` bounds are syntactic sugar for a lack of bounds so don't need this.
140+
|| (cx.is_lang_item(clause_def_id, TraitSolverLangItem::Sized)
141+
&& cx.is_lang_item(goal_def_id, TraitSolverLangItem::MetaSized))
154142
}
155143

156-
Err(NoSolution)
144+
if let Some(trait_clause) = assumption.as_trait_clause()
145+
&& trait_clause.polarity() == goal.predicate.polarity
146+
&& trait_def_id_matches(ecx.cx(), trait_clause.def_id(), goal.predicate.def_id())
147+
&& DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
148+
goal.predicate.trait_ref.args,
149+
trait_clause.skip_binder().trait_ref.args,
150+
)
151+
{
152+
return Ok(());
153+
} else {
154+
Err(NoSolution)
155+
}
157156
}
158157

159158
fn match_assumption(

compiler/rustc_type_ir/src/elaborate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ pub fn supertrait_def_ids<I: Interner>(
320320
let trait_def_id = stack.pop()?;
321321

322322
for (predicate, _) in cx.explicit_super_predicates_of(trait_def_id).iter_identity() {
323-
if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder() {
324-
if set.insert(data.def_id()) {
325-
stack.push(data.def_id());
326-
}
323+
if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder()
324+
&& set.insert(data.def_id())
325+
{
326+
stack.push(data.def_id());
327327
}
328328
}
329329

compiler/rustc_type_ir/src/relate/solver_relating.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ where
284284
}
285285

286286
// If they have no bound vars, relate normally.
287-
if let Some(a_inner) = a.no_bound_vars() {
288-
if let Some(b_inner) = b.no_bound_vars() {
289-
self.relate(a_inner, b_inner)?;
290-
return Ok(a);
291-
}
292-
};
287+
if let Some(a_inner) = a.no_bound_vars()
288+
&& let Some(b_inner) = b.no_bound_vars()
289+
{
290+
self.relate(a_inner, b_inner)?;
291+
return Ok(a);
292+
}
293293

294294
match self.ambient_variance {
295295
// Checks whether `for<..> sub <: for<..> sup` holds.

0 commit comments

Comments
 (0)