Skip to content

Commit 4a58caa

Browse files
committed
Fix typeck probing code to use constness from FnCtxt
1 parent d0db6fe commit 4a58caa

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub struct FnCtxt<'a, 'tcx> {
118118

119119
/// True if the return type has an Opaque type
120120
pub(super) return_type_has_opaque: bool,
121+
constness: ty::ConstnessArg,
121122
}
122123

123124
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -145,6 +146,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
145146
inh,
146147
return_type_pre_known: true,
147148
return_type_has_opaque: false,
149+
constness: {
150+
if body_id.is_owner() {
151+
let did = body_id.expect_owner();
152+
if inh.tcx.is_const_fn_raw(did.to_def_id()) || inh.tcx.is_const_default_method(did.to_def_id()) || inh.tcx.def_kind(did.to_def_id()) == hir::def::DefKind::Const {
153+
ty::ConstnessArg::Param
154+
} else {
155+
ty::ConstnessArg::Not
156+
}
157+
} else {
158+
// TODO: check correctness
159+
ty::ConstnessArg::Not
160+
}
161+
},
148162
}
149163
}
150164

@@ -163,6 +177,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
163177
pub fn errors_reported_since_creation(&self) -> bool {
164178
self.tcx.sess.err_count() > self.err_count_on_creation
165179
}
180+
181+
pub fn constness(&self) -> ty::ConstnessArg {
182+
self.constness
183+
}
166184
}
167185

168186
impl<'a, 'tcx> Deref for FnCtxt<'a, 'tcx> {

compiler/rustc_typeck/src/check/method/probe.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15491549
let predicate = ty::Binder::dummy(trait_ref).to_predicate(self.tcx);
15501550
parent_pred = Some(predicate);
15511551
let obligation = traits::Obligation::new(cause, self.param_env, predicate);
1552+
trace!(?obligation);
15521553
if !self.predicate_may_hold(&obligation) {
1554+
trace!("predicate does not hold");
15531555
result = ProbeResult::NoMatch;
15541556
if self.probe(|_| {
15551557
match self.select_trait_candidate(trait_ref) {
@@ -1839,7 +1841,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18391841
};
18401842
self.next_const_var(self.tcx.type_of(param.def_id), origin).into()
18411843
}
1842-
GenericParamDefKind::Constness => ty::ConstnessArg::Param.into(),
1844+
GenericParamDefKind::Constness => self.fcx.constness().into(),
18431845
})
18441846
}
18451847

0 commit comments

Comments
 (0)