Skip to content

Commit 3ef7997

Browse files
committed
Try to fix problem
1 parent fe2519b commit 3ef7997

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,11 +1085,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10851085
span_mirbug!(
10861086
self,
10871087
user_annotation,
1088-
"bad user type AscribeUserType({:?}, {:?} {:?}): {:?}",
1088+
"bad user type AscribeUserType({:?}, {:?} {:?}, type_of={:?}): {:?}",
10891089
inferred_ty,
10901090
def_id,
10911091
user_substs,
1092-
terr
1092+
self.tcx().type_of(def_id),
1093+
terr,
10931094
);
10941095
}
10951096
}

compiler/rustc_traits/src/type_op.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
66
use rustc_infer::traits::TraitEngineExt as _;
77
use rustc_middle::ty::query::Providers;
88
use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts};
9-
use rustc_middle::ty::{self, FnSig, Lift, PolyFnSig, Ty, TyCtxt, TypeFoldable, Variance};
9+
use rustc_middle::ty::{
10+
self, FnSig, Lift, PolyFnSig, PredicateKind, Ty, TyCtxt, TypeFoldable, Variance,
11+
};
1012
use rustc_middle::ty::{ParamEnv, ParamEnvAnd, Predicate, ToPredicate};
1113
use rustc_span::DUMMY_SP;
1214
use rustc_trait_selection::infer::InferCtxtBuilderExt;
@@ -85,7 +87,16 @@ impl AscribeUserTypeCx<'me, 'tcx> {
8587
Ok(())
8688
}
8789

88-
fn prove_predicate(&mut self, predicate: Predicate<'tcx>) {
90+
fn prove_predicate(&mut self, mut predicate: Predicate<'tcx>) {
91+
if let PredicateKind::Trait(mut tr) = predicate.kind().skip_binder() {
92+
if let hir::Constness::Const = tr.constness {
93+
// FIXME check if we actually want to prove const predicates inside AscribeUserType
94+
tr.constness = hir::Constness::NotConst;
95+
predicate =
96+
predicate.kind().rebind(PredicateKind::Trait(tr)).to_predicate(self.tcx());
97+
}
98+
}
99+
89100
self.fulfill_cx.register_predicate_obligation(
90101
self.infcx,
91102
Obligation::new(ObligationCause::dummy(), self.param_env, predicate),
@@ -126,6 +137,7 @@ impl AscribeUserTypeCx<'me, 'tcx> {
126137
// outlives" error messages.
127138
let instantiated_predicates =
128139
self.tcx().predicates_of(def_id).instantiate(self.tcx(), substs);
140+
debug!(?instantiated_predicates.predicates);
129141
for instantiated_predicate in instantiated_predicates.predicates {
130142
let instantiated_predicate = self.normalize(instantiated_predicate);
131143
self.prove_predicate(instantiated_predicate);

0 commit comments

Comments
 (0)