Skip to content

Commit 2931a9d

Browse files
committed
make check less conservative and add explanation
1 parent 54d4fc2 commit 2931a9d

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,12 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
649649
if obligation.predicate.is_global() {
650650
// no type variables present, can use evaluation for better caching.
651651
// FIXME: consider caching errors too.
652-
if infcx.predicate_must_hold_considering_regions(obligation) {
652+
//
653+
// If the predicate is considered const, then we cannot use this because
654+
// it will cause false negatives in the ui tests.
655+
if !self.selcx.is_predicate_const(obligation.predicate)
656+
&& infcx.predicate_must_hold_considering_regions(obligation)
657+
{
653658
debug!(
654659
"selecting trait at depth {} evaluated to holds",
655660
obligation.recursion_depth
@@ -703,7 +708,12 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
703708
if obligation.predicate.is_global() {
704709
// no type variables present, can use evaluation for better caching.
705710
// FIXME: consider caching errors too.
706-
if self.selcx.infcx().predicate_must_hold_considering_regions(obligation) {
711+
//
712+
// If the predicate is considered const, then we cannot use this because
713+
// it will cause false negatives in the ui tests.
714+
if !self.selcx.is_predicate_const(obligation.predicate)
715+
&& self.selcx.infcx().predicate_must_hold_considering_regions(obligation)
716+
{
707717
return ProcessResult::Changed(vec![]);
708718
} else {
709719
tracing::debug!("Does NOT hold: {:?}", obligation);

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use rustc_hir as hir;
2-
use rustc_middle::ty::PredicateKind;
3-
41
use crate::infer::canonical::OriginalQueryValues;
52
use crate::infer::InferCtxt;
63
use crate::traits::{
@@ -49,12 +46,6 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
4946
&self,
5047
obligation: &PredicateObligation<'tcx>,
5148
) -> bool {
52-
if let PredicateKind::Trait(pred) = obligation.predicate.kind().skip_binder() {
53-
if let hir::Constness::Const = pred.constness {
54-
// do not evaluate to holds when we have a const predicate.
55-
return false;
56-
}
57-
}
5849
self.evaluate_obligation_no_overflow(obligation).must_apply_considering_regions()
5950
}
6051

compiler/rustc_trait_selection/src/traits/select/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
316316
self.infcx.tcx
317317
}
318318

319+
/// returns `true` if the predicate is considered `const` to
320+
/// this selection context.
321+
pub fn is_predicate_const(&self, pred: ty::Predicate<'_>) -> bool {
322+
match pred.kind().skip_binder() {
323+
ty::PredicateKind::Trait(ty::TraitPredicate {
324+
constness: hir::Constness::Const,
325+
..
326+
}) if self.const_impls_required => true,
327+
_ => false,
328+
}
329+
}
330+
319331
///////////////////////////////////////////////////////////////////////////
320332
// Selection
321333
//

0 commit comments

Comments
 (0)