Skip to content

Commit 9728930

Browse files
committed
deduplication logic in trait selection
1 parent 49799f2 commit 9728930

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
3232
uv: ty::Unevaluated<'tcx, ()>,
3333
param_env: ty::ParamEnv<'tcx>,
3434
span: Span,
35-
) -> Result<(), NotConstEvaluatable> {
35+
) -> Result<(), NotConstEvaluatable<'tcx>> {
3636
debug!("is_const_evaluatable({:?})", uv);
3737
if infcx.tcx.features().generic_const_exprs {
3838
let tcx = infcx.tcx;
@@ -174,6 +174,7 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
174174
Err(NotConstEvaluatable::Error(ErrorReported))
175175
}
176176
Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e)),
177+
Err(ErrorHandled::Silent(id)) => Err(NotConstEvaluatable::Silent(id)),
177178
Ok(_) => Ok(()),
178179
}
179180
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,14 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
528528
}
529529

530530
ty::PredicateKind::ConstEvaluatable(uv) => {
531-
match const_evaluatable::is_const_evaluatable(
531+
let res = const_evaluatable::is_const_evaluatable(
532532
self.selcx.infcx(),
533533
uv,
534-
obligation.param_env,
534+
obligation.param_env.with_reveal_selection(),
535535
obligation.cause.span,
536-
) {
536+
);
537+
538+
match res {
537539
Ok(()) => ProcessResult::Changed(vec![]),
538540
Err(NotConstEvaluatable::MentionsInfer) => {
539541
pending_obligation.stalled_on.clear();
@@ -546,7 +548,8 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
546548
}
547549
Err(
548550
e @ NotConstEvaluatable::MentionsParam
549-
| e @ NotConstEvaluatable::Error(_),
551+
| e @ NotConstEvaluatable::Error(_)
552+
| e @ NotConstEvaluatable::Silent(_),
550553
) => ProcessResult::Error(CodeSelectionError(
551554
SelectionError::NotConstEvaluatable(e),
552555
)),
@@ -625,10 +628,12 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
625628
"ConstEquate: const_eval_resolve returned an unexpected error"
626629
)
627630
}
628-
(Err(ErrorHandled::Silent), _) | (_, Err(ErrorHandled::Silent)) => {
629-
ProcessResult::Error(CodeSelectionError(ConstEvalFailure(
630-
ErrorHandled::Silent,
631-
)))
631+
(Err(ErrorHandled::Silent(id)), _) | (_, Err(ErrorHandled::Silent(id))) => {
632+
ProcessResult::Error(CodeSelectionError(
633+
SelectionError::NotConstEvaluatable(NotConstEvaluatable::Silent(
634+
id,
635+
)),
636+
))
632637
}
633638
(Err(ErrorHandled::TooGeneric), _) | (_, Err(ErrorHandled::TooGeneric)) => {
634639
if c1.has_infer_types_or_consts() || c2.has_infer_types_or_consts() {

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ fn do_normalize_predicates<'tcx>(
273273

274274
// FIXME: this is gonna need to be removed ...
275275
/// Normalizes the parameter environment, reporting errors if they occur.
276+
#[instrument(skip(tcx), level = "debug")]
276277
pub fn normalize_param_env_or_error<'tcx>(
277278
tcx: TyCtxt<'tcx>,
278279
region_context: DefId,

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rustc_hir::def_id::DefId;
2626
use rustc_hir::lang_items::LangItem;
2727
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
2828
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
29+
2930
use rustc_middle::ty::subst::Subst;
3031
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
3132
use rustc_span::symbol::sym;
@@ -296,7 +297,7 @@ where
296297

297298
pub(crate) fn needs_normalization<'tcx, T: TypeFoldable<'tcx>>(value: &T, reveal: Reveal) -> bool {
298299
match reveal {
299-
Reveal::UserFacing => value
300+
Reveal::Selection | Reveal::UserFacing => value
300301
.has_type_flags(ty::TypeFlags::HAS_TY_PROJECTION | ty::TypeFlags::HAS_CT_PROJECTION),
301302
Reveal::All => value.has_type_flags(
302303
ty::TypeFlags::HAS_TY_PROJECTION

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
675675
Err(_) => Ok(EvaluatedToErr),
676676
}
677677
}
678-
(Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Silent), _)
679-
| (_, Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Silent)) => {
680-
Ok(EvaluatedToErr)
681-
}
678+
(
679+
Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Silent(_)),
680+
_,
681+
)
682+
| (
683+
_,
684+
Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Silent(_)),
685+
) => Ok(EvaluatedToErr),
682686
(Err(ErrorHandled::Linted), _) | (_, Err(ErrorHandled::Linted)) => {
683687
span_bug!(
684688
obligation.cause.span(self.tcx()),
@@ -2659,11 +2663,7 @@ impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> {
26592663
}
26602664

26612665
fn depth(&self) -> usize {
2662-
if let Some(head) = self.head {
2663-
head.depth
2664-
} else {
2665-
0
2666-
}
2666+
if let Some(head) = self.head { head.depth } else { 0 }
26672667
}
26682668
}
26692669

0 commit comments

Comments
 (0)