Skip to content

Commit dcb9859

Browse files
committed
Add the same logic to the old solver
1 parent 6ee174b commit dcb9859

File tree

1 file changed

+23
-2
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+23
-2
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
404404
ty::PredicateKind::AliasRelate(..) => {
405405
bug!("AliasRelate is only used by the new solver")
406406
}
407-
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_)) => todo!(), // TODO: not sure what will happen here.
407+
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_)) => {
408+
unreachable!("unexpected higher ranked `UnstableFeature` goal")
409+
}
408410
},
409411
Some(pred) => match pred {
410412
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
@@ -762,7 +764,26 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
762764
}
763765
}
764766
}
765-
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_)) => todo!(),
767+
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
768+
// Iterate through all goals in param_env to find the one that has the same symbol.
769+
for pred in obligation.param_env.caller_bounds().iter() {
770+
match pred.kind().skip_binder() {
771+
ty::ClauseKind::UnstableFeature(sym) => {
772+
if sym == symbol {
773+
return ProcessResult::Changed(Default::default());
774+
}
775+
}
776+
_ => {} // don't care
777+
}
778+
}
779+
// Check if feature is enabled at crate level with #[feature(..)] or if we are currently in codegen.
780+
if self.selcx.tcx().features().enabled(symbol) || (self.selcx.infcx.typing_mode() == TypingMode::PostAnalysis) {
781+
return ProcessResult::Changed(Default::default());
782+
} else {
783+
return ProcessResult::Error(FulfillmentErrorCode::Ambiguity { overflow: None });
784+
}
785+
786+
}
766787
},
767788
}
768789
}

0 commit comments

Comments
 (0)