Skip to content

Commit 7cc28c1

Browse files
committed
Auto merge of #93468 - matthiaskrgr:rollup-vxullvd, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #93256 (Make `join!` description more accurate) - #93358 (Add note suggesting that predicate may be satisfied, but is not `const`) - #93362 (Do not register infer var for GAT projection in RPIT) - #93391 (rustdoc: remove tooltip from source link) - #93414 (Move unstable is_{arch}_feature_detected! macros to std::arch) - #93441 (rustdoc: load the set of in-scope traits for modules with no docstring) - #93459 (fs: Don't copy d_name from struct dirent) - #93463 (Rename _args -> args in format_args expansion) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a00e130 + 9f6d0cb commit 7cc28c1

File tree

30 files changed

+219
-48
lines changed

30 files changed

+219
-48
lines changed

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ impl<'a, 'b> Context<'a, 'b> {
791791
// Thus in the not nicely ordered case we emit the following instead:
792792
//
793793
// match (&$arg0, &$arg1, …) {
794-
// _args => [ArgumentV1::new(_args.$i, …), ArgumentV1::new(_args.$j, …), …]
794+
// args => [ArgumentV1::new(args.$i, …), ArgumentV1::new(args.$j, …), …]
795795
// }
796796
//
797797
// for the sequence of indices $i, $j, … governed by fmt_arg_index_and_ty.
@@ -804,7 +804,7 @@ impl<'a, 'b> Context<'a, 'b> {
804804
self.ecx.expr_addr_of(expansion_span, P(e.take()))
805805
} else {
806806
let def_site = self.ecx.with_def_site_ctxt(span);
807-
let args_tuple = self.ecx.expr_ident(def_site, Ident::new(sym::_args, def_site));
807+
let args_tuple = self.ecx.expr_ident(def_site, Ident::new(sym::args, def_site));
808808
let member = Ident::new(sym::integer(arg_index), def_site);
809809
self.ecx.expr(def_site, ast::ExprKind::Field(args_tuple, member))
810810
};
@@ -828,7 +828,7 @@ impl<'a, 'b> Context<'a, 'b> {
828828
.map(|e| self.ecx.expr_addr_of(e.span.with_ctxt(self.macsp.ctxt()), e))
829829
.collect();
830830

831-
let pat = self.ecx.pat_ident(self.macsp, Ident::new(sym::_args, self.macsp));
831+
let pat = self.ecx.pat_ident(self.macsp, Ident::new(sym::args, self.macsp));
832832
let arm = self.ecx.arm(self.macsp, pat, args_array);
833833
let head = self.ecx.expr(self.macsp, ast::ExprKind::Tup(heads));
834834
self.ecx.expr_match(self.macsp, head, vec![arm])

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::interpret::{
77
};
88

99
use rustc_errors::ErrorReported;
10-
use rustc_hir as hir;
1110
use rustc_hir::def::DefKind;
1211
use rustc_middle::mir;
1312
use rustc_middle::mir::interpret::ErrorHandled;
@@ -216,7 +215,7 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
216215
tcx: TyCtxt<'tcx>,
217216
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
218217
) -> ::rustc_middle::mir::interpret::EvalToConstValueResult<'tcx> {
219-
assert!(key.param_env.constness() == hir::Constness::Const);
218+
assert!(key.param_env.is_const());
220219
// see comment in eval_to_allocation_raw_provider for what we're doing here
221220
if key.param_env.reveal() == Reveal::All {
222221
let mut key = key;
@@ -251,7 +250,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
251250
tcx: TyCtxt<'tcx>,
252251
key: ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>,
253252
) -> ::rustc_middle::mir::interpret::EvalToAllocationRawResult<'tcx> {
254-
assert!(key.param_env.constness() == hir::Constness::Const);
253+
assert!(key.param_env.is_const());
255254
// Because the constant is computed twice (once per value of `Reveal`), we are at risk of
256255
// reporting the same error twice here. To resolve this, we check whether we can evaluate the
257256
// constant in the more restrictive `Reveal::UserFacing`, which most likely already was

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,13 +569,15 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
569569
let predicate = predicate.fold_with(&mut BottomUpFolder {
570570
tcx,
571571
ty_op: |ty| match ty.kind() {
572-
ty::Projection(projection_ty) => infcx.infer_projection(
573-
self.param_env,
574-
*projection_ty,
575-
traits::ObligationCause::misc(self.value_span, self.body_id),
576-
0,
577-
&mut self.obligations,
578-
),
572+
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => {
573+
infcx.infer_projection(
574+
self.param_env,
575+
*projection_ty,
576+
traits::ObligationCause::misc(self.value_span, self.body_id),
577+
0,
578+
&mut self.obligations,
579+
)
580+
}
579581
_ => ty,
580582
},
581583
lt_op: |lt| lt,

compiler/rustc_lint/src/traits.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,14 @@ declare_lint_pass!(
8686

8787
impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
8888
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
89-
use rustc_middle::ty;
9089
use rustc_middle::ty::PredicateKind::*;
9190

9291
let predicates = cx.tcx.explicit_predicates_of(item.def_id);
9392
for &(predicate, span) in predicates.predicates {
9493
let Trait(trait_predicate) = predicate.kind().skip_binder() else {
9594
continue
9695
};
97-
if trait_predicate.constness == ty::BoundConstness::ConstIfConst {
96+
if trait_predicate.is_const_if_const() {
9897
// `~const Drop` definitely have meanings so avoid linting here.
9998
continue;
10099
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,11 @@ impl<'tcx> TraitPredicate<'tcx> {
784784
pub fn self_ty(self) -> Ty<'tcx> {
785785
self.trait_ref.self_ty()
786786
}
787+
788+
#[inline]
789+
pub fn is_const_if_const(self) -> bool {
790+
self.constness == BoundConstness::ConstIfConst
791+
}
787792
}
788793

789794
impl<'tcx> PolyTraitPredicate<'tcx> {
@@ -803,6 +808,11 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
803808
p
804809
});
805810
}
811+
812+
#[inline]
813+
pub fn is_const_if_const(self) -> bool {
814+
self.skip_binder().is_const_if_const()
815+
}
806816
}
807817

808818
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
@@ -1388,6 +1398,11 @@ impl<'tcx> ParamEnv<'tcx> {
13881398
self.packed.tag().constness
13891399
}
13901400

1401+
#[inline]
1402+
pub fn is_const(self) -> bool {
1403+
self.packed.tag().constness == hir::Constness::Const
1404+
}
1405+
13911406
/// Construct a trait environment with no where-clauses in scope
13921407
/// where the values of all `impl Trait` and other hidden types
13931408
/// are revealed. This is suitable for monomorphized, post-typeck
@@ -1503,6 +1518,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
15031518
polarity: ty::ImplPolarity::Positive,
15041519
})
15051520
}
1521+
15061522
#[inline]
15071523
pub fn without_const(self) -> PolyTraitPredicate<'tcx> {
15081524
self.with_constness(BoundConstness::NotConst)

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ symbols! {
272272
__H,
273273
__S,
274274
__try_var,
275-
_args,
276275
_d,
277276
_e,
278277
_task_context,
@@ -324,6 +323,7 @@ symbols! {
324323
append_const_msg,
325324
arbitrary_enum_discriminant,
326325
arbitrary_self_types,
326+
args,
327327
arith_offset,
328328
arm,
329329
arm_target_feature,

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
439439
} else {
440440
err.span_label(span, explanation);
441441
}
442+
443+
if trait_predicate.is_const_if_const() && obligation.param_env.is_const() {
444+
let non_const_predicate = trait_ref.without_const();
445+
let non_const_obligation = Obligation {
446+
cause: obligation.cause.clone(),
447+
param_env: obligation.param_env.without_const(),
448+
predicate: non_const_predicate.to_predicate(tcx),
449+
recursion_depth: obligation.recursion_depth,
450+
};
451+
if self.predicate_may_hold(&non_const_obligation) {
452+
err.span_note(
453+
span,
454+
&format!(
455+
"the trait `{}` is implemented for `{}`, \
456+
but that implementation is not `const`",
457+
non_const_predicate.print_modifiers_and_trait_path(),
458+
trait_ref.skip_binder().self_ty(),
459+
),
460+
);
461+
}
462+
}
463+
442464
if let Some((msg, span)) = type_def {
443465
err.span_label(span, &msg);
444466
}

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
305305
} else if lang_items.unsize_trait() == Some(def_id) {
306306
self.assemble_candidates_for_unsizing(obligation, &mut candidates);
307307
} else if lang_items.drop_trait() == Some(def_id)
308-
&& obligation.predicate.skip_binder().constness == ty::BoundConstness::ConstIfConst
308+
&& obligation.predicate.is_const_if_const()
309309
{
310310
self.assemble_const_drop_candidates(obligation, &mut candidates);
311311
} else {

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
7272
// CheckPredicate(&A: Super)
7373
// CheckPredicate(A: ~const Super) // <- still const env, failure
7474
// ```
75-
if obligation.param_env.constness() == Constness::Const
76-
&& obligation.predicate.skip_binder().constness == ty::BoundConstness::NotConst
77-
{
75+
if obligation.param_env.is_const() && !obligation.predicate.is_const_if_const() {
7876
new_obligation = TraitObligation {
7977
cause: obligation.cause.clone(),
8078
param_env: obligation.param_env.without_const(),

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,9 +1173,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11731173
ImplCandidate(def_id)
11741174
if tcx.impl_constness(def_id) == hir::Constness::Const => {}
11751175
// const param
1176-
ParamCandidate(trait_pred)
1177-
if trait_pred.skip_binder().constness
1178-
== ty::BoundConstness::ConstIfConst => {}
1176+
ParamCandidate(trait_pred) if trait_pred.is_const_if_const() => {}
11791177
// auto trait impl
11801178
AutoImplCandidate(..) => {}
11811179
// generator, this will raise error in other places

0 commit comments

Comments
 (0)