Skip to content

Commit de4f805

Browse files
Add new typing mode
1 parent e964cca commit de4f805

File tree

21 files changed

+81
-26
lines changed

21 files changed

+81
-26
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ impl<'tcx> InferCtxt<'tcx> {
968968
// and post-borrowck analysis mode. We may need to modify its uses
969969
// to support PostBorrowckAnalysis in the old solver as well.
970970
TypingMode::Coherence
971+
| TypingMode::CheckObjectOverlap
971972
| TypingMode::PostBorrowckAnalysis { .. }
972973
| TypingMode::PostAnalysis => false,
973974
}
@@ -1260,6 +1261,7 @@ impl<'tcx> InferCtxt<'tcx> {
12601261
TypingMode::non_body_analysis()
12611262
}
12621263
mode @ (ty::TypingMode::Coherence
1264+
| TypingMode::CheckObjectOverlap
12631265
| ty::TypingMode::PostBorrowckAnalysis { .. }
12641266
| ty::TypingMode::PostAnalysis) => mode,
12651267
};

compiler/rustc_infer/src/infer/opaque_types/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ impl<'tcx> InferCtxt<'tcx> {
8787
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
8888
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => {
8989
let def_id = def_id.expect_local();
90-
if let ty::TypingMode::Coherence = self.typing_mode() {
90+
if let ty::TypingMode::Coherence | ty::TypingMode::CheckObjectOverlap =
91+
self.typing_mode()
92+
{
9193
// See comment on `insert_hidden_type` for why this is sufficient in coherence
9294
return Some(self.register_hidden_type(
9395
OpaqueTypeKey { def_id, args },
@@ -226,7 +228,7 @@ impl<'tcx> InferCtxt<'tcx> {
226228
// these are the same span, but not in cases like `-> (impl
227229
// Foo, impl Bar)`.
228230
match self.typing_mode() {
229-
ty::TypingMode::Coherence => {
231+
ty::TypingMode::Coherence | ty::TypingMode::CheckObjectOverlap => {
230232
// During intercrate we do not define opaque types but instead always
231233
// force ambiguity unless the hidden type is known to not implement
232234
// our trait.

compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
519519
//
520520
// cc trait-system-refactor-initiative#108
521521
if self.infcx.next_trait_solver()
522-
&& !matches!(self.infcx.typing_mode(), TypingMode::Coherence)
522+
&& !matches!(
523+
self.infcx.typing_mode(),
524+
TypingMode::Coherence | TypingMode::CheckObjectOverlap
525+
)
523526
&& self.in_alias
524527
{
525528
inner.type_variables().equate(vid, new_var_id);
@@ -650,7 +653,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
650653
// See the comment for type inference variables
651654
// for more details.
652655
if self.infcx.next_trait_solver()
653-
&& !matches!(self.infcx.typing_mode(), TypingMode::Coherence)
656+
&& !matches!(
657+
self.infcx.typing_mode(),
658+
TypingMode::Coherence | TypingMode::CheckObjectOverlap
659+
)
654660
&& self.in_alias
655661
{
656662
variable_table.union(vid, new_var_id);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ where
380380

381381
let mut candidates = vec![];
382382

383-
if let TypingMode::Coherence = self.typing_mode() {
383+
if let TypingMode::Coherence | TypingMode::CheckObjectOverlap = self.typing_mode() {
384384
if let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal) {
385385
return vec![candidate];
386386
}
@@ -831,7 +831,7 @@ where
831831
candidates: &mut Vec<Candidate<I>>,
832832
) {
833833
match self.typing_mode() {
834-
TypingMode::Coherence => return,
834+
TypingMode::Coherence | TypingMode::CheckObjectOverlap => return,
835835
TypingMode::Analysis { .. }
836836
| TypingMode::Borrowck { .. }
837837
| TypingMode::PostBorrowckAnalysis { .. }

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ where
339339
fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool {
340340
match self.typing_mode() {
341341
// Opaques are never rigid outside of analysis mode.
342-
TypingMode::Coherence | TypingMode::PostAnalysis => false,
342+
TypingMode::Coherence | TypingMode::CheckObjectOverlap | TypingMode::PostAnalysis => {
343+
false
344+
}
343345
// During analysis, opaques are rigid unless they may be defined by
344346
// the current body.
345347
TypingMode::Analysis { defining_opaque_types_and_generators: non_rigid_opaques }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ where
240240
// would be relevant if any of the nested goals refer to the `term`.
241241
// This is not the case here and we only prefer adding an ambiguous
242242
// nested goal for consistency.
243-
ty::TypingMode::Coherence => {
243+
ty::TypingMode::Coherence | ty::TypingMode::CheckObjectOverlap => {
244244
ecx.add_goal(GoalSource::Misc, goal.with(cx, PredicateKind::Ambiguous));
245245
return ecx
246246
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
@@ -280,7 +280,7 @@ where
280280
// would be relevant if any of the nested goals refer to the `term`.
281281
// This is not the case here and we only prefer adding an ambiguous
282282
// nested goal for consistency.
283-
ty::TypingMode::Coherence => {
283+
ty::TypingMode::Coherence | ty::TypingMode::CheckObjectOverlap => {
284284
ecx.add_goal(GoalSource::Misc, goal.with(cx, PredicateKind::Ambiguous));
285285
return ecx
286286
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);

compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ where
2323
let expected = goal.predicate.term.as_type().expect("no such thing as an opaque const");
2424

2525
match self.typing_mode() {
26-
TypingMode::Coherence => {
26+
TypingMode::Coherence | TypingMode::CheckObjectOverlap => {
2727
// An impossible opaque type bound is the only way this goal will fail
2828
// e.g. assigning `impl Copy := NotCopy`
2929
self.add_item_bounds_for_hidden_type(

compiler/rustc_next_trait_solver/src/solve/search_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ where
5858
// example where this would matter. We likely should change these cycles to `NoSolution`
5959
// even in coherence once this is a bit more settled.
6060
PathKind::Inductive => match input.typing_mode {
61-
TypingMode::Coherence => {
61+
TypingMode::Coherence | TypingMode::CheckObjectOverlap => {
6262
response_no_constraints(cx, input, Certainty::overflow(false))
6363
}
6464
TypingMode::Analysis { .. }

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ where
7070
// In intercrate mode, this is ambiguous. But outside of intercrate,
7171
// it's not a real impl.
7272
(ty::ImplPolarity::Reservation, _) => match ecx.typing_mode() {
73-
TypingMode::Coherence => Certainty::AMBIGUOUS,
73+
TypingMode::Coherence | TypingMode::CheckObjectOverlap => Certainty::AMBIGUOUS,
7474
TypingMode::Analysis { .. }
7575
| TypingMode::Borrowck { .. }
7676
| TypingMode::PostBorrowckAnalysis { .. }
@@ -1257,7 +1257,7 @@ where
12571257
&mut self,
12581258
mut candidates: Vec<Candidate<I>>,
12591259
) -> Result<(CanonicalResponse<I>, Option<TraitGoalProvenVia>), NoSolution> {
1260-
if let TypingMode::Coherence = self.typing_mode() {
1260+
if let TypingMode::Coherence | TypingMode::CheckObjectOverlap = self.typing_mode() {
12611261
let all_candidates: Vec<_> = candidates.into_iter().map(|c| c.result).collect();
12621262
return if let Some(response) = self.try_merge_responses(&all_candidates) {
12631263
Ok((response, Some(TraitGoalProvenVia::Misc)))
@@ -1360,6 +1360,7 @@ where
13601360
}
13611361
}
13621362
TypingMode::Coherence
1363+
| TypingMode::CheckObjectOverlap
13631364
| TypingMode::PostAnalysis
13641365
| TypingMode::Borrowck { defining_opaque_types: _ }
13651366
| TypingMode::PostBorrowckAnalysis { defined_opaque_types: _ } => {}

compiler/rustc_trait_selection/src/solve/delegate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
178178
// get a result which isn't correct for all monomorphizations.
179179
match self.typing_mode() {
180180
TypingMode::Coherence
181+
| TypingMode::CheckObjectOverlap
181182
| TypingMode::Analysis { .. }
182183
| TypingMode::Borrowck { .. }
183184
| TypingMode::PostBorrowckAnalysis { .. } => false,

0 commit comments

Comments
 (0)