File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -221,6 +221,9 @@ impl DeepRejectCtxt {
221
221
( GenericArgKind :: Const ( obl) , GenericArgKind :: Const ( imp) ) => {
222
222
self . consts_may_unify ( obl, imp)
223
223
}
224
+ ( GenericArgKind :: Constness ( obl) , GenericArgKind :: Constness ( imp) ) => {
225
+ self . constness_may_unify ( obl, imp)
226
+ }
224
227
_ => bug ! ( "kind mismatch: {obligation_arg} {impl_arg}" ) ,
225
228
}
226
229
}
@@ -402,4 +405,19 @@ impl DeepRejectCtxt {
402
405
}
403
406
}
404
407
}
408
+
409
+ pub fn constness_may_unify (
410
+ self ,
411
+ obligation_ct : ty:: ConstnessArg ,
412
+ impl_ct : ty:: ConstnessArg ,
413
+ ) -> bool {
414
+ match ( obligation_ct, impl_ct) {
415
+ ( _, ty:: ConstnessArg :: Param ) => true ,
416
+ ( ty:: ConstnessArg :: Param , _) => match self . treat_obligation_params {
417
+ TreatParams :: AsPlaceholder => false ,
418
+ TreatParams :: AsInfer => true ,
419
+ } ,
420
+ _ => obligation_ct == impl_ct,
421
+ }
422
+ }
405
423
}
Original file line number Diff line number Diff line change @@ -238,6 +238,11 @@ impl<'tcx> Generics {
238
238
}
239
239
}
240
240
241
+ /// Returns the `ConstnessArg`
242
+ pub fn has_constness_param ( & ' tcx self ) -> bool {
243
+ self . params . iter ( ) . any ( |param| matches ! ( param. kind, ty:: GenericParamDefKind :: Constness ) )
244
+ }
245
+
241
246
/// Returns `true` if `params` has `impl Trait`.
242
247
pub fn has_impl_trait ( & ' tcx self ) -> bool {
243
248
self . params . iter ( ) . any ( |param| {
Original file line number Diff line number Diff line change @@ -573,9 +573,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
573
573
// TODO: fall back to `Not`?
574
574
None => ty:: ConstnessArg :: Param ,
575
575
Some ( context) => {
576
- if tcx. hir ( ) . body_const_context ( context. expect_local ( ) ) . is_some ( ) {
577
- ty:: ConstnessArg :: Required
576
+ if tcx. generics_of ( context) . has_constness_param ( ) {
577
+ ty:: ConstnessArg :: Param
578
578
} else {
579
+ // TODO: should use `Required` if we're in a const context
580
+ // like `const`/`static` item initializers.
579
581
ty:: ConstnessArg :: Not
580
582
}
581
583
}
You can’t perform that action at this time.
0 commit comments