Skip to content

Commit 9d46c7a

Browse files
committed
Auto merge of rust-lang#104555 - matthiaskrgr:rollup-tncyca8, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#103852 (Don't remap early-bound regions for return-position `impl Trait` in trait originating from `impl`) - rust-lang#104366 (Simplify settings theme choice) - rust-lang#104433 (Fix `emit_unused_delims_expr` ICE) - rust-lang#104444 (Fix ICE in in_operand for ty error) - rust-lang#104483 (Convert predicates into Predicate in the Obligation constructor) - rust-lang#104496 (Don't attempt to normalize compiler backtraces) - rust-lang#104503 (rustdoc: remove redundant font-color CSS on `.where`) - rust-lang#104508 (Check `dyn*` return type correctly) - rust-lang#104515 (ICE fixing, remove is_tainted_by_errors since we have ty_error for delay bug) - rust-lang#104532 (Migrate tooltip style to CSS variables) - rust-lang#104545 (Readd the matches_macro diag item) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 30117a1 + 239f84b commit 9d46c7a

Some content is hidden

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

73 files changed

+640
-372
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use rustc_infer::infer::{DefiningAnchor, InferCtxt};
77
use rustc_infer::traits::{Obligation, ObligationCause};
88
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
99
use rustc_middle::ty::visit::TypeVisitable;
10-
use rustc_middle::ty::{
11-
self, OpaqueHiddenType, OpaqueTypeKey, ToPredicate, Ty, TyCtxt, TypeFoldable,
12-
};
10+
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
1311
use rustc_span::Span;
1412
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
1513
use rustc_trait_selection::traits::ObligationCtxt;
@@ -256,8 +254,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
256254
// Require the hidden type to be well-formed with only the generics of the opaque type.
257255
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
258256
// hidden type is well formed even without those bounds.
259-
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()))
260-
.to_predicate(infcx.tcx);
257+
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()));
261258

262259
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
263260

@@ -282,6 +279,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
282279
}
283280

284281
ocx.register_obligation(Obligation::misc(
282+
infcx.tcx,
285283
instantiated_ty.span,
286284
body_id,
287285
param_env,

compiler/rustc_borrowck/src/type_check/canonical.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9292
trait_ref,
9393
constness: ty::BoundConstness::NotConst,
9494
polarity: ty::ImplPolarity::Positive,
95-
}))
96-
.to_predicate(self.tcx()),
95+
})),
9796
locations,
9897
category,
9998
);
@@ -122,26 +121,26 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
122121

123122
pub(super) fn prove_predicates(
124123
&mut self,
125-
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
124+
predicates: impl IntoIterator<
125+
Item = impl ToPredicate<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
126+
>,
126127
locations: Locations,
127128
category: ConstraintCategory<'tcx>,
128129
) {
129130
for predicate in predicates {
130-
let predicate = predicate.to_predicate(self.tcx());
131-
debug!("prove_predicates(predicate={:?}, locations={:?})", predicate, locations,);
132-
133131
self.prove_predicate(predicate, locations, category);
134132
}
135133
}
136134

137135
#[instrument(skip(self), level = "debug")]
138136
pub(super) fn prove_predicate(
139137
&mut self,
140-
predicate: ty::Predicate<'tcx>,
138+
predicate: impl ToPredicate<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
141139
locations: Locations,
142140
category: ConstraintCategory<'tcx>,
143141
) {
144142
let param_env = self.param_env;
143+
let predicate = predicate.to_predicate(self.tcx());
145144
self.fully_perform_op(
146145
locations,
147146
category,

compiler/rustc_borrowck/src/type_check/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ use rustc_middle::ty::subst::{SubstsRef, UserSubsts};
3333
use rustc_middle::ty::visit::TypeVisitable;
3434
use rustc_middle::ty::{
3535
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic,
36-
OpaqueHiddenType, OpaqueTypeKey, RegionVid, ToPredicate, Ty, TyCtxt, UserType,
37-
UserTypeAnnotationIndex,
36+
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
3837
};
3938
use rustc_span::def_id::CRATE_DEF_ID;
4039
use rustc_span::{Span, DUMMY_SP};
@@ -1069,8 +1068,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10691068
}
10701069

10711070
self.prove_predicate(
1072-
ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into()))
1073-
.to_predicate(self.tcx()),
1071+
ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into())),
10741072
Locations::All(span),
10751073
ConstraintCategory::TypeAnnotation,
10761074
);

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
732732
polarity: ty::ImplPolarity::Positive,
733733
});
734734
let obligation =
735-
Obligation::new(ObligationCause::dummy(), param_env, poly_trait_pred);
735+
Obligation::new(tcx, ObligationCause::dummy(), param_env, poly_trait_pred);
736736

737737
let implsrc = {
738738
let infcx = tcx.infer_ctxt().build();
@@ -816,6 +816,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
816816

817817
if !nonconst_call_permission {
818818
let obligation = Obligation::new(
819+
tcx,
819820
ObligationCause::dummy_with_span(*fn_span),
820821
param_env,
821822
tcx.mk_predicate(

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
147147
}
148148
Adt(..) => {
149149
let obligation = Obligation::new(
150+
tcx,
150151
ObligationCause::dummy(),
151152
param_env,
152153
Binder::dummy(TraitPredicate {

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl Qualif for NeedsNonConstDrop {
156156
let destruct = cx.tcx.require_lang_item(LangItem::Destruct, None);
157157

158158
let obligation = Obligation::new(
159+
cx.tcx,
159160
ObligationCause::dummy(),
160161
cx.param_env,
161162
ty::Binder::dummy(ty::TraitPredicate {
@@ -351,7 +352,11 @@ where
351352
// FIXME(valtrees): check whether const qualifs should behave the same
352353
// way for type and mir constants.
353354
let uneval = match constant.literal {
354-
ConstantKind::Ty(ct) if matches!(ct.kind(), ty::ConstKind::Param(_)) => None,
355+
ConstantKind::Ty(ct)
356+
if matches!(ct.kind(), ty::ConstKind::Param(_) | ty::ConstKind::Error(_)) =>
357+
{
358+
None
359+
}
355360
ConstantKind::Ty(c) => bug!("expected ConstKind::Param here, found {:?}", c),
356361
ConstantKind::Unevaluated(uv, _) => Some(uv),
357362
ConstantKind::Val(..) => None,

compiler/rustc_hir_analysis/src/check/check.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use rustc_middle::middle::stability::EvalResult;
1919
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
2020
use rustc_middle::ty::subst::GenericArgKind;
2121
use rustc_middle::ty::util::{Discr, IntTypeExt};
22-
use rustc_middle::ty::{
23-
self, ParamEnv, ToPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
24-
};
22+
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
2523
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
2624
use rustc_span::symbol::sym;
2725
use rustc_span::{self, Span};
@@ -464,9 +462,8 @@ fn check_opaque_meets_bounds<'tcx>(
464462
// Additionally require the hidden type to be well-formed with only the generics of the opaque type.
465463
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
466464
// hidden type is well formed even without those bounds.
467-
let predicate =
468-
ty::Binder::dummy(ty::PredicateKind::WellFormed(hidden_ty.into())).to_predicate(tcx);
469-
ocx.register_obligation(Obligation::new(misc_cause, param_env, predicate));
465+
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(hidden_ty.into()));
466+
ocx.register_obligation(Obligation::new(tcx, misc_cause, param_env, predicate));
470467

471468
// Check that all obligations are satisfied by the implementation's
472469
// version.

compiler/rustc_hir_analysis/src/check/compare_method.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn compare_predicate_entailment<'tcx>(
238238
kind: impl_m.kind,
239239
},
240240
);
241-
ocx.register_obligation(traits::Obligation::new(cause, param_env, predicate));
241+
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
242242
}
243243

244244
// We now need to check that the signature of the impl method is
@@ -521,7 +521,13 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
521521
let num_trait_substs = trait_to_impl_substs.len();
522522
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
523523
let ty = tcx.fold_regions(ty, |region, _| {
524-
let (ty::ReFree(_) | ty::ReEarlyBound(_)) = region.kind() else { return region; };
524+
match region.kind() {
525+
// Remap all free regions, which correspond to late-bound regions in the function.
526+
ty::ReFree(_) => {}
527+
// Remap early-bound regions as long as they don't come from the `impl` itself.
528+
ty::ReEarlyBound(ebr) if tcx.parent(ebr.def_id) != impl_m.container_id(tcx) => {}
529+
_ => return region,
530+
}
525531
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
526532
else {
527533
tcx
@@ -605,6 +611,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
605611
);
606612

607613
self.ocx.register_obligation(traits::Obligation::new(
614+
self.tcx(),
608615
ObligationCause::new(
609616
self.span,
610617
self.body_id,
@@ -1579,7 +1586,7 @@ fn compare_type_predicate_entailment<'tcx>(
15791586
},
15801587
);
15811588
ocx.register_obligations(obligations);
1582-
ocx.register_obligation(traits::Obligation::new(cause, param_env, predicate));
1589+
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
15831590
}
15841591

15851592
// Check that all obligations are satisfied by the implementation's
@@ -1784,7 +1791,7 @@ pub fn check_type_bounds<'tcx>(
17841791
.subst_iter_copied(tcx, rebased_substs)
17851792
.map(|(concrete_ty_bound, span)| {
17861793
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
1787-
traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound)
1794+
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
17881795
})
17891796
.collect();
17901797
debug!("check_type_bounds: item_bounds={:?}", obligations);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use rustc_middle::mir::ConstraintCategory;
1414
use rustc_middle::ty::query::Providers;
1515
use rustc_middle::ty::trait_def::TraitSpecializationKind;
1616
use rustc_middle::ty::{
17-
self, AdtKind, DefIdTree, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable,
18-
TypeSuperVisitable, TypeVisitable, TypeVisitor,
17+
self, AdtKind, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
18+
TypeVisitable, TypeVisitor,
1919
};
2020
use rustc_middle::ty::{GenericArgKind, InternalSubsts};
2121
use rustc_session::parse::feature_err;
@@ -75,9 +75,10 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
7575
// for a type to be WF, we do not need to check if const trait predicates satisfy.
7676
let param_env = self.param_env.without_const();
7777
self.ocx.register_obligation(traits::Obligation::new(
78+
self.tcx(),
7879
cause,
7980
param_env,
80-
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(self.tcx()),
81+
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)),
8182
));
8283
}
8384
}
@@ -1111,12 +1112,12 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
11111112
traits::MiscObligation,
11121113
);
11131114
wfcx.register_obligation(traits::Obligation::new(
1115+
tcx,
11141116
cause,
11151117
wfcx.param_env,
11161118
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(
11171119
ty::Const::from_anon_const(tcx, discr_def_id.expect_local()),
1118-
))
1119-
.to_predicate(tcx),
1120+
)),
11201121
));
11211122
}
11221123
}
@@ -1453,7 +1454,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14531454
wfcx.body_id,
14541455
traits::ItemObligation(def_id.to_def_id()),
14551456
);
1456-
traits::Obligation::new(cause, wfcx.param_env, pred)
1457+
traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
14571458
});
14581459

14591460
let predicates = predicates.0.instantiate_identity(tcx);
@@ -1783,8 +1784,7 @@ fn receiver_is_implemented<'tcx>(
17831784
substs: tcx.mk_substs_trait(receiver_ty, &[]),
17841785
});
17851786

1786-
let obligation =
1787-
traits::Obligation::new(cause, wfcx.param_env, trait_ref.without_const().to_predicate(tcx));
1787+
let obligation = traits::Obligation::new(tcx, cause, wfcx.param_env, trait_ref.without_const());
17881788

17891789
if wfcx.infcx.predicate_must_hold_modulo_regions(&obligation) {
17901790
true
@@ -1931,6 +1931,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
19311931
}
19321932

19331933
let obligation = traits::Obligation::new(
1934+
tcx,
19341935
traits::ObligationCause::new(span, self.body_id, traits::TrivialBound),
19351936
empty_env,
19361937
pred,

compiler/rustc_hir_analysis/src/hir_wf_check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::{ForeignItem, ForeignItemKind, HirId};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_infer::traits::{ObligationCause, WellFormedLoc};
77
use rustc_middle::ty::query::Providers;
8-
use rustc_middle::ty::{self, Region, ToPredicate, TyCtxt, TypeFoldable, TypeFolder};
8+
use rustc_middle::ty::{self, Region, TyCtxt, TypeFoldable, TypeFolder};
99
use rustc_trait_selection::traits;
1010

1111
pub fn provide(providers: &mut Providers) {
@@ -74,10 +74,10 @@ fn diagnostic_hir_wf_check<'tcx>(
7474
let errors = traits::fully_solve_obligation(
7575
&infcx,
7676
traits::Obligation::new(
77+
self.tcx,
7778
cause,
7879
self.param_env,
79-
ty::Binder::dummy(ty::PredicateKind::WellFormed(tcx_ty.into()))
80-
.to_predicate(self.tcx),
80+
ty::Binder::dummy(ty::PredicateKind::WellFormed(tcx_ty.into())),
8181
),
8282
);
8383
if !errors.is_empty() {

compiler/rustc_hir_typeck/src/_match.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::{Applicability, Diagnostic, MultiSpan};
44
use rustc_hir::{self as hir, ExprKind};
55
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
66
use rustc_infer::traits::Obligation;
7-
use rustc_middle::ty::{self, ToPredicate, Ty};
7+
use rustc_middle::ty::{self, Ty};
88
use rustc_span::Span;
99
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
1010
use rustc_trait_selection::traits::{
@@ -538,23 +538,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
538538
.bound_explicit_item_bounds(rpit_def_id)
539539
.subst_iter_copied(self.tcx, substs)
540540
{
541-
let pred = match pred.kind().skip_binder() {
541+
let pred = pred.kind().rebind(match pred.kind().skip_binder() {
542542
ty::PredicateKind::Trait(mut trait_pred) => {
543543
assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty);
544544
trait_pred.trait_ref.substs =
545545
self.tcx.mk_substs_trait(ty, &trait_pred.trait_ref.substs[1..]);
546-
pred.kind().rebind(trait_pred).to_predicate(self.tcx)
546+
ty::PredicateKind::Trait(trait_pred)
547547
}
548548
ty::PredicateKind::Projection(mut proj_pred) => {
549549
assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty);
550550
proj_pred.projection_ty.substs = self
551551
.tcx
552552
.mk_substs_trait(ty, &proj_pred.projection_ty.substs[1..]);
553-
pred.kind().rebind(proj_pred).to_predicate(self.tcx)
553+
ty::PredicateKind::Projection(proj_pred)
554554
}
555555
_ => continue,
556-
};
556+
});
557557
if !self.predicate_must_hold_modulo_regions(&Obligation::new(
558+
self.tcx,
558559
ObligationCause::misc(span, self.body_id),
559560
self.param_env,
560561
pred,

compiler/rustc_hir_typeck/src/callee.rs

+1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
380380
predicates.predicates.iter().zip(&predicates.spans)
381381
{
382382
let obligation = Obligation::new(
383+
self.tcx,
383384
ObligationCause::dummy_with_span(callee_expr.span),
384385
self.param_env,
385386
*predicate,

compiler/rustc_hir_typeck/src/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub(super) fn check_fn<'a, 'tcx>(
102102

103103
inherited.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
104104

105-
if let ty::Dynamic(..) = declared_ret_ty.kind() {
105+
if let ty::Dynamic(_, _, ty::Dyn) = declared_ret_ty.kind() {
106106
// FIXME: We need to verify that the return type is `Sized` after the return expression has
107107
// been evaluated so that we have types available for all the nodes being returned, but that
108108
// requires the coerced evaluated type to be stored. Moving `check_return_expr` before this

compiler/rustc_hir_typeck/src/coercion.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use rustc_middle::ty::error::TypeError;
5555
use rustc_middle::ty::relate::RelateResult;
5656
use rustc_middle::ty::subst::SubstsRef;
5757
use rustc_middle::ty::visit::TypeVisitable;
58-
use rustc_middle::ty::{self, ToPredicate, Ty, TypeAndMut};
58+
use rustc_middle::ty::{self, Ty, TypeAndMut};
5959
use rustc_session::parse::feature_err;
6060
use rustc_span::symbol::sym;
6161
use rustc_span::{self, BytePos, DesugaringKind, Span};
@@ -278,13 +278,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
278278
for &source_ty in &[a, b] {
279279
if source_ty != target_ty {
280280
obligations.push(Obligation::new(
281+
self.tcx(),
281282
self.cause.clone(),
282283
self.param_env,
283284
ty::Binder::dummy(ty::PredicateKind::Coerce(ty::CoercePredicate {
284285
a: source_ty,
285286
b: target_ty,
286-
}))
287-
.to_predicate(self.tcx()),
287+
})),
288288
));
289289
}
290290
}
@@ -669,7 +669,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
669669
continue;
670670
}
671671
};
672-
match selcx.select(&obligation.with(trait_pred)) {
672+
match selcx.select(&obligation.with(selcx.tcx(), trait_pred)) {
673673
// Uncertain or unimplemented.
674674
Ok(None) => {
675675
if trait_pred.def_id() == unsize_did {
@@ -783,10 +783,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
783783
// and then require that the resulting predicate (e.g., `usize: Clone`)
784784
// holds (it does).
785785
let predicate = predicate.with_self_ty(self.tcx, a);
786-
Obligation::new(self.cause.clone(), self.param_env, predicate)
786+
Obligation::new(self.tcx, self.cause.clone(), self.param_env, predicate)
787787
})
788788
// Enforce the region bound (e.g., `usize: 'static`, in our example).
789789
.chain([Obligation::new(
790+
self.tcx,
790791
self.cause.clone(),
791792
self.param_env,
792793
self.tcx.mk_predicate(ty::Binder::dummy(ty::PredicateKind::TypeOutlives(

0 commit comments

Comments
 (0)