Skip to content

Commit 486d3d3

Browse files
committed
Complete compute_unstable_feature_goal
1 parent ab02e3e commit 486d3d3

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
@@ -818,6 +818,10 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
818818
fn impl_stability(self) -> bool {
819819
self.impl_stability()
820820
}
821+
822+
fn enabled(self, symbol: <TyCtxt<'tcx> as Interner>::Symbol) -> bool {
823+
self.enabled(symbol)
824+
}
821825
}
822826

823827
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
@@ -530,7 +530,7 @@ where
530530
}
531531
ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(symbol)) => {
532532
self.compute_unstable_feature_goal(param_env, symbol)
533-
},
533+
}
534534
ty::PredicateKind::Subtype(predicate) => {
535535
self.compute_subtype_goal(Goal { param_env, predicate })
536536
}

compiler/rustc_next_trait_solver/src/solve/mod.rs

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

164168
if self.cx().features().impl_stability() {
165-
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe(MaybeCause::Ambiguity));
169+
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe(
170+
MaybeCause::Ambiguity,
171+
));
166172
} else {
167-
todo!();
173+
// Check if feature is enabled at crate level with #[feature(..)] or if we are currently in codegen.
174+
if self.cx().features().enabled(symbol)
175+
|| (self.typing_mode() == TypingMode::PostAnalysis)
176+
{
177+
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
178+
} else {
179+
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe(
180+
MaybeCause::Ambiguity,
181+
));
182+
}
168183
}
169-
170184
}
171185

172186
#[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
@@ -572,6 +572,8 @@ pub trait Features<I: Interner>: Copy {
572572
fn associated_const_equality(self) -> bool;
573573

574574
fn impl_stability(self) -> bool;
575+
576+
fn enabled(self, symbol: I::Symbol) -> bool;
575577
}
576578

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

0 commit comments

Comments
 (0)