Skip to content

Commit f4f5fc3

Browse files
committed
Auto merge of rust-lang#107965 - BoxyUwU:add_const_arg_has_type_predicate, r=compiler-errors
Add `Clause::ConstArgHasType` Currently the way that we check that a const arg has the correct type for the const param it is an argument for is by setting the expected type of `typeck` on the anon const of the argument to be the const param's type. In the future for a potential `min_generic_const_exprs` we will allow providing const arguments that do not have an associated anon const that can be typeck'd which will require us to actually check that the const argument has the correct type. While it would potentially be possible to just call `eq` when creating substs this would not work if we support generics of the form `const N: T, T` (the const parameters type referencing generics declared after itself). Additionally having `ConstArgHasType` will allow us to potentially make progress on removing the `ty` field of `Const` which may be desirable. Once progress has been made on this, `ConstArgHasType` will also be helpful in ensuring we do not make mistakes in trait/impl checking by declaring functions with the wrong const parameter types as the checks that the param env is compatible would catch it. (We have messed this up in the past, and with generic const parameter types these checks will get more complex) There is a [document](https://hackmd.io/wuCS6CJBQ9-fWbwaW7nQRw?view) about the types of const generics that may provide some general information on this subject --- This PR shouldn't have any impact on whether code compiles or not on stable, it primarily exists to make progress on unstable const generics features that are desirable.
2 parents b5c8c32 + 90c8d6b commit f4f5fc3

File tree

28 files changed

+183
-15
lines changed

28 files changed

+183
-15
lines changed

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13281328
ty::Clause::TypeOutlives(_) => {
13291329
// Do nothing, we deal with regions separately
13301330
}
1331-
ty::Clause::RegionOutlives(_) => bug!(),
1331+
ty::Clause::RegionOutlives(_) | ty::Clause::ConstArgHasType(..) => bug!(),
13321332
},
13331333
ty::PredicateKind::WellFormed(_)
13341334
| ty::PredicateKind::AliasEq(..)

Diff for: compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+52-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_hir::def::DefKind;
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_hir::intravisit::{self, Visitor};
1111
use rustc_middle::ty::subst::InternalSubsts;
12-
use rustc_middle::ty::ToPredicate;
1312
use rustc_middle::ty::{self, Ty, TyCtxt};
13+
use rustc_middle::ty::{GenericPredicates, ToPredicate};
1414
use rustc_span::symbol::{sym, Ident};
1515
use rustc_span::{Span, DUMMY_SP};
1616

@@ -151,7 +151,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
151151
trace!(?generics);
152152

153153
// Collect the predicates that were written inline by the user on each
154-
// type parameter (e.g., `<T: Foo>`).
154+
// type parameter (e.g., `<T: Foo>`). Also add `ConstArgHasType` predicates
155+
// for each const parameter.
155156
for param in ast_generics.params {
156157
match param.kind {
157158
// We already dealt with early bound lifetimes above.
@@ -175,7 +176,19 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
175176
trace!(?predicates);
176177
}
177178
GenericParamKind::Const { .. } => {
178-
// Bounds on const parameters are currently not possible.
179+
let name = param.name.ident().name;
180+
let param_const = ty::ParamConst::new(index, name);
181+
182+
let ct_ty = tcx.type_of(param.def_id.to_def_id()).subst_identity();
183+
184+
let ct = tcx.mk_const(param_const, ct_ty);
185+
186+
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
187+
ty::Clause::ConstArgHasType(ct, ct_ty),
188+
))
189+
.to_predicate(tcx);
190+
predicates.insert((predicate, param.span));
191+
179192
index += 1;
180193
}
181194
}
@@ -439,7 +452,9 @@ pub(super) fn explicit_predicates_of<'tcx>(
439452
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
440453
let parent_def_id = tcx.hir().get_parent_item(hir_id);
441454

442-
if tcx.hir().opt_const_param_default_param_def_id(hir_id).is_some() {
455+
if let Some(defaulted_param_def_id) =
456+
tcx.hir().opt_const_param_default_param_def_id(hir_id)
457+
{
443458
// In `generics_of` we set the generics' parent to be our parent's parent which means that
444459
// we lose out on the predicates of our actual parent if we dont return those predicates here.
445460
// (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
@@ -452,7 +467,39 @@ pub(super) fn explicit_predicates_of<'tcx>(
452467
//
453468
// In the above code we want the anon const to have predicates in its param env for `T: Trait`
454469
// and we would be calling `explicit_predicates_of(Foo)` here
455-
return tcx.explicit_predicates_of(parent_def_id);
470+
let parent_preds = tcx.explicit_predicates_of(parent_def_id);
471+
472+
// If we dont filter out `ConstArgHasType` predicates then every single defaulted const parameter
473+
// will ICE because of #106994. FIXME(generic_const_exprs): remove this when a more general solution
474+
// to #106994 is implemented.
475+
let filtered_predicates = parent_preds
476+
.predicates
477+
.into_iter()
478+
.filter(|(pred, _)| {
479+
if let ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, _)) =
480+
pred.kind().skip_binder()
481+
{
482+
match ct.kind() {
483+
ty::ConstKind::Param(param_const) => {
484+
let defaulted_param_idx = tcx
485+
.generics_of(parent_def_id)
486+
.param_def_id_to_index[&defaulted_param_def_id.to_def_id()];
487+
param_const.index < defaulted_param_idx
488+
}
489+
_ => bug!(
490+
"`ConstArgHasType` in `predicates_of`\
491+
that isn't a `Param` const"
492+
),
493+
}
494+
} else {
495+
true
496+
}
497+
})
498+
.cloned();
499+
return GenericPredicates {
500+
parent: parent_preds.parent,
501+
predicates: { tcx.arena.alloc_from_iter(filtered_predicates) },
502+
};
456503
}
457504

458505
let parent_def_kind = tcx.def_kind(parent_def_id);

Diff for: compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+11
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,16 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
496496
)
497497
.emit();
498498
}
499+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
500+
// FIXME(min_specialization), FIXME(const_generics):
501+
// It probably isn't right to allow _every_ `ConstArgHasType` but I am somewhat unsure
502+
// about the actual rules that would be sound. Can't just always error here because otherwise
503+
// std/core doesn't even compile as they have `const N: usize` in some specializing impls.
504+
//
505+
// While we do not support constructs like `<T, const N: T>` there is probably no risk of
506+
// soundness bugs, but when we support generic const parameter types this will need to be
507+
// revisited.
508+
}
499509
_ => {
500510
tcx.sess
501511
.struct_span_err(span, &format!("cannot specialize on predicate `{}`", predicate))
@@ -517,6 +527,7 @@ fn trait_predicate_kind<'tcx>(
517527
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
518528
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
519529
| ty::PredicateKind::Clause(ty::Clause::Projection(_))
530+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
520531
| ty::PredicateKind::AliasEq(..)
521532
| ty::PredicateKind::WellFormed(_)
522533
| ty::PredicateKind::Subtype(_)

Diff for: compiler/rustc_hir_analysis/src/outlives/explicit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
5454

5555
ty::PredicateKind::Clause(ty::Clause::Trait(..))
5656
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
57+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
5758
| ty::PredicateKind::WellFormed(..)
5859
| ty::PredicateKind::AliasEq(..)
5960
| ty::PredicateKind::ObjectSafe(..)

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
663663

664664
ty::PredicateKind::Clause(ty::Clause::Trait(..))
665665
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
666+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
666667
| ty::PredicateKind::Subtype(..)
667668
| ty::PredicateKind::Coerce(..)
668669
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))

Diff for: compiler/rustc_hir_typeck/src/method/probe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
826826
}
827827
}
828828
ty::PredicateKind::Subtype(..)
829+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
829830
| ty::PredicateKind::Coerce(..)
830831
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
831832
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))

Diff for: compiler/rustc_infer/src/infer/outlives/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn explicit_outlives_bounds<'tcx>(
2121
.filter_map(move |kind| match kind {
2222
ty::PredicateKind::Clause(ty::Clause::Projection(..))
2323
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
24+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
2425
| ty::PredicateKind::AliasEq(..)
2526
| ty::PredicateKind::Coerce(..)
2627
| ty::PredicateKind::Subtype(..)

Diff for: compiler/rustc_infer/src/traits/util.rs

+3
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ impl<'tcx> Elaborator<'tcx> {
297297
ty::PredicateKind::AliasEq(..) => {
298298
// No
299299
}
300+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
301+
// Nothing to elaborate
302+
}
300303
}
301304
}
302305
}

Diff for: compiler/rustc_lint/src/builtin.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,8 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
15951595
Clause(Clause::TypeOutlives(..)) |
15961596
Clause(Clause::RegionOutlives(..)) => "lifetime",
15971597

1598+
// `ConstArgHasType` is never global as `ct` is always a param
1599+
Clause(Clause::ConstArgHasType(..)) |
15981600
// Ignore projections, as they can only be global
15991601
// if the trait bound is global
16001602
Clause(Clause::Projection(..)) |

Diff for: compiler/rustc_middle/src/ty/flags.rs

+4
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ impl FlagComputation {
251251
self.add_ty(ty);
252252
self.add_region(region);
253253
}
254+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
255+
self.add_const(ct);
256+
self.add_ty(ty);
257+
}
254258
ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
255259
self.add_ty(a);
256260
self.add_ty(b);

Diff for: compiler/rustc_middle/src/ty/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ impl<'tcx> Predicate<'tcx> {
552552
| PredicateKind::Clause(Clause::RegionOutlives(_))
553553
| PredicateKind::Clause(Clause::TypeOutlives(_))
554554
| PredicateKind::Clause(Clause::Projection(_))
555+
| PredicateKind::Clause(Clause::ConstArgHasType(..))
555556
| PredicateKind::AliasEq(..)
556557
| PredicateKind::ObjectSafe(_)
557558
| PredicateKind::ClosureKind(_, _, _)
@@ -590,6 +591,10 @@ pub enum Clause<'tcx> {
590591
/// `where <T as TraitRef>::Name == X`, approximately.
591592
/// See the `ProjectionPredicate` struct for details.
592593
Projection(ProjectionPredicate<'tcx>),
594+
595+
/// Ensures that a const generic argument to a parameter `const N: u8`
596+
/// is of type `u8`.
597+
ConstArgHasType(Const<'tcx>, Ty<'tcx>),
593598
}
594599

595600
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
@@ -1193,6 +1198,7 @@ impl<'tcx> Predicate<'tcx> {
11931198
match predicate.skip_binder() {
11941199
PredicateKind::Clause(Clause::Trait(t)) => Some(predicate.rebind(t)),
11951200
PredicateKind::Clause(Clause::Projection(..))
1201+
| PredicateKind::Clause(Clause::ConstArgHasType(..))
11961202
| PredicateKind::AliasEq(..)
11971203
| PredicateKind::Subtype(..)
11981204
| PredicateKind::Coerce(..)
@@ -1213,6 +1219,7 @@ impl<'tcx> Predicate<'tcx> {
12131219
match predicate.skip_binder() {
12141220
PredicateKind::Clause(Clause::Projection(t)) => Some(predicate.rebind(t)),
12151221
PredicateKind::Clause(Clause::Trait(..))
1222+
| PredicateKind::Clause(Clause::ConstArgHasType(..))
12161223
| PredicateKind::AliasEq(..)
12171224
| PredicateKind::Subtype(..)
12181225
| PredicateKind::Coerce(..)
@@ -1233,6 +1240,7 @@ impl<'tcx> Predicate<'tcx> {
12331240
match predicate.skip_binder() {
12341241
PredicateKind::Clause(Clause::TypeOutlives(data)) => Some(predicate.rebind(data)),
12351242
PredicateKind::Clause(Clause::Trait(..))
1243+
| PredicateKind::Clause(Clause::ConstArgHasType(..))
12361244
| PredicateKind::Clause(Clause::Projection(..))
12371245
| PredicateKind::AliasEq(..)
12381246
| PredicateKind::Subtype(..)

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2822,15 +2822,18 @@ define_print_and_forward_display! {
28222822
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => p!(print(predicate)),
28232823
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => p!(print(predicate)),
28242824
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => p!(print(predicate)),
2825+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
2826+
p!("the constant `", print(ct), "` has type `", print(ty), "`")
2827+
},
28252828
ty::PredicateKind::WellFormed(arg) => p!(print(arg), " well-formed"),
28262829
ty::PredicateKind::ObjectSafe(trait_def_id) => {
28272830
p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe")
28282831
}
2829-
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
2830-
p!("the closure `",
2832+
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => p!(
2833+
"the closure `",
28312834
print_value_path(closure_def_id, &[]),
2832-
write("` implements the trait `{}`", kind))
2833-
}
2835+
write("` implements the trait `{}`", kind)
2836+
),
28342837
ty::PredicateKind::ConstEvaluatable(ct) => {
28352838
p!("the constant `", print(ct), "` can be evaluated")
28362839
}

Diff for: compiler/rustc_middle/src/ty/structural_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl<'tcx> fmt::Debug for ty::Predicate<'tcx> {
147147
impl<'tcx> fmt::Debug for ty::Clause<'tcx> {
148148
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149149
match *self {
150+
ty::Clause::ConstArgHasType(ct, ty) => write!(f, "ConstArgHasType({ct:?}, {ty:?})"),
150151
ty::Clause::Trait(ref a) => a.fmt(f),
151152
ty::Clause::RegionOutlives(ref pair) => pair.fmt(f),
152153
ty::Clause::TypeOutlives(ref pair) => pair.fmt(f),

Diff for: compiler/rustc_privacy/src/lib.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,21 @@ where
159159
_region,
160160
))) => ty.visit_with(self),
161161
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) => ControlFlow::Continue(()),
162+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
163+
ct.visit_with(self)?;
164+
ty.visit_with(self)
165+
}
162166
ty::PredicateKind::ConstEvaluatable(ct) => ct.visit_with(self),
163167
ty::PredicateKind::WellFormed(arg) => arg.visit_with(self),
164-
_ => bug!("unexpected predicate: {:?}", predicate),
168+
169+
ty::PredicateKind::ObjectSafe(_)
170+
| ty::PredicateKind::ClosureKind(_, _, _)
171+
| ty::PredicateKind::Subtype(_)
172+
| ty::PredicateKind::Coerce(_)
173+
| ty::PredicateKind::ConstEquate(_, _)
174+
| ty::PredicateKind::TypeWellFormedFromEnv(_)
175+
| ty::PredicateKind::Ambiguous
176+
| ty::PredicateKind::AliasEq(_, _) => bug!("unexpected predicate: {:?}", predicate),
165177
}
166178
}
167179

Diff for: compiler/rustc_trait_selection/src/solve/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_infer::traits::query::NoSolution;
2525
use rustc_infer::traits::Obligation;
2626
use rustc_middle::infer::canonical::Certainty as OldCertainty;
2727
use rustc_middle::traits::solve::{ExternalConstraints, ExternalConstraintsData};
28-
use rustc_middle::ty::{self, TyCtxt};
28+
use rustc_middle::ty::{self, Ty, TyCtxt};
2929
use rustc_middle::ty::{
3030
CoercePredicate, RegionOutlivesPredicate, SubtypePredicate, ToPredicate, TypeOutlivesPredicate,
3131
};
@@ -290,6 +290,9 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
290290
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
291291
self.compute_region_outlives_goal(Goal { param_env, predicate })
292292
}
293+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
294+
self.compute_const_arg_has_type_goal(Goal { param_env, predicate: (ct, ty) })
295+
}
293296
ty::PredicateKind::Subtype(predicate) => {
294297
self.compute_subtype_goal(Goal { param_env, predicate })
295298
}
@@ -471,6 +474,16 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
471474
}
472475
}
473476
}
477+
478+
#[instrument(level = "debug", skip(self), ret)]
479+
fn compute_const_arg_has_type_goal(
480+
&mut self,
481+
goal: Goal<'tcx, (ty::Const<'tcx>, Ty<'tcx>)>,
482+
) -> QueryResult<'tcx> {
483+
let (ct, ty) = goal.predicate;
484+
let nested_goals = self.infcx.eq(goal.param_env, ct.ty(), ty)?;
485+
self.evaluate_all_and_make_canonical_response(nested_goals)
486+
}
474487
}
475488

476489
impl<'tcx> EvalCtxt<'_, 'tcx> {

Diff for: compiler/rustc_trait_selection/src/traits/auto_trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
830830
// and these don't correspond to adding any new bounds to
831831
// the `ParamEnv`.
832832
ty::PredicateKind::WellFormed(..)
833+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
833834
| ty::PredicateKind::AliasEq(..)
834835
| ty::PredicateKind::ObjectSafe(..)
835836
| ty::PredicateKind::ClosureKind(..)

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
12821282
span,
12831283
"AliasEq predicate should never be the predicate cause of a SelectionError"
12841284
),
1285+
1286+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
1287+
self.tcx.sess.struct_span_err(
1288+
span,
1289+
&format!("the constant `{}` is not of type `{}`", ct, ty),
1290+
)
1291+
}
12851292
}
12861293
}
12871294

Diff for: compiler/rustc_trait_selection/src/traits/fulfill.rs

+14
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
313313
}
314314
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
315315
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
316+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
316317
| ty::PredicateKind::WellFormed(_)
317318
| ty::PredicateKind::ObjectSafe(_)
318319
| ty::PredicateKind::ClosureKind(..)
@@ -600,6 +601,19 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
600601
ty::PredicateKind::AliasEq(..) => {
601602
bug!("AliasEq is only used for new solver")
602603
}
604+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
605+
match self
606+
.selcx
607+
.infcx
608+
.at(&obligation.cause, obligation.param_env)
609+
.eq(ct.ty(), ty)
610+
{
611+
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
612+
Err(_) => ProcessResult::Error(FulfillmentErrorCode::CodeSelectionError(
613+
SelectionError::Unimplemented,
614+
)),
615+
}
616+
}
603617
},
604618
}
605619
}

Diff for: compiler/rustc_trait_selection/src/traits/object_safety.rs

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ fn predicate_references_self<'tcx>(
327327
// possible alternatives.
328328
data.projection_ty.substs[1..].iter().any(has_self_ty).then_some(sp)
329329
}
330+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(_ct, ty)) => {
331+
has_self_ty(&ty.into()).then_some(sp)
332+
}
333+
330334
ty::PredicateKind::AliasEq(..) => bug!("`AliasEq` not allowed as assumption"),
331335

332336
ty::PredicateKind::WellFormed(..)
@@ -362,6 +366,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
362366
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
363367
}
364368
ty::PredicateKind::Clause(ty::Clause::Projection(..))
369+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
365370
| ty::PredicateKind::Subtype(..)
366371
| ty::PredicateKind::Coerce(..)
367372
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))

0 commit comments

Comments
 (0)