Skip to content

Commit 6ee174b

Browse files
committed
Complete compute_unstable_feature_goal
1 parent d87b6a3 commit 6ee174b

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
821821
fn impl_stability(self) -> bool {
822822
self.impl_stability()
823823
}
824+
825+
fn enabled(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool {
826+
self.enabled(symbol)
827+
}
824828
}
825829

826830
impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ where
598598
}
599599
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
600600
self.compute_unstable_feature_goal(param_env, symbol)
601-
},
601+
}
602602
ty::PredicateKind::Subtype(predicate) => {
603603
self.compute_subtype_goal(Goal { param_env, predicate })
604604
}

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,41 @@ where
147147
None => self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS),
148148
}
149149
}
150-
151-
fn compute_unstable_feature_goal(&mut self, param_env: <I as Interner>::ParamEnv, symbol: <I as Interner>::Symbol) -> QueryResult<I> {
152-
// Iterate through all goals in param_env to find the one that has the same
153-
// symbol as the one in the goal
150+
151+
fn compute_unstable_feature_goal(
152+
&mut self,
153+
param_env: <I as Interner>::ParamEnv,
154+
symbol: <I as Interner>::Symbol,
155+
) -> QueryResult<I> {
156+
// Iterate through all goals in param_env to find the one that has the same symbol.
154157
for pred in param_env.caller_bounds().iter() {
155158
match pred.kind().skip_binder() {
156159
ty::ClauseKind::UnstableFeature(sym) => {
157160
if sym == symbol {
158-
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
161+
return self
162+
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
159163
}
160164
}
161165
_ => {} // don't care
162166
}
163167
}
164168

165169
if self.cx().features().impl_stability() {
166-
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe(MaybeCause::Ambiguity));
170+
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe(
171+
MaybeCause::Ambiguity,
172+
));
167173
} else {
168-
todo!();
174+
// Check if feature is enabled at crate level with #[feature(..)] or if we are currently in codegen.
175+
if self.cx().features().enabled(symbol)
176+
|| (self.typing_mode() == TypingMode::PostAnalysis)
177+
{
178+
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
179+
} else {
180+
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe(
181+
MaybeCause::Ambiguity,
182+
));
183+
}
169184
}
170-
171185
}
172186

173187
#[instrument(level = "trace", skip(self))]

compiler/rustc_type_ir/src/inherent.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ pub trait Features<I: Interner>: Copy {
585585
fn associated_const_equality(self) -> bool;
586586

587587
fn impl_stability(self) -> bool;
588+
589+
fn enabled(self, symbol: I::Symbol) -> bool;
588590
}
589591

590592
pub trait DefId<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {

0 commit comments

Comments
 (0)