Skip to content

Commit 8597bf1

Browse files
Make things work by using the new solver
1 parent 7f3c2c7 commit 8597bf1

File tree

9 files changed

+22
-18
lines changed

9 files changed

+22
-18
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub(super) trait GoalKind<'tcx>:
3737

3838
fn trait_ref(self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx>;
3939

40+
fn polarity(self) -> ty::ImplPolarity;
41+
4042
fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self;
4143

4244
fn trait_def_id(self, tcx: TyCtxt<'tcx>) -> DefId;

compiler/rustc_trait_selection/src/solve/project_goals/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
101101
self.projection_ty.trait_ref(tcx)
102102
}
103103

104+
fn polarity(self) -> ty::ImplPolarity {
105+
ty::ImplPolarity::Positive
106+
}
107+
104108
fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
105109
self.with_self_ty(tcx, self_ty)
106110
}

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
2222
self.trait_ref
2323
}
2424

25+
fn polarity(self) -> ty::ImplPolarity {
26+
self.polarity
27+
}
28+
2529
fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
2630
self.with_self_ty(tcx, self_ty)
2731
}

compiler/rustc_trait_selection/src/traits/coherence.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ fn impl_intersection_has_negative_obligation(
398398
) -> bool {
399399
debug!("negative_impl(impl1_def_id={:?}, impl2_def_id={:?})", impl1_def_id, impl2_def_id);
400400

401-
let ref infcx = tcx.infer_ctxt().intercrate(true).build();
402-
let universe = infcx.create_next_universe();
401+
let ref infcx = tcx.infer_ctxt().intercrate(true).with_next_trait_solver(true).build();
402+
let universe = infcx.universe();
403403

404404
let impl1_header = fresh_impl_header(infcx, impl1_def_id);
405405
let param_env =

compiler/rustc_trait_selection/src/traits/engine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> {
3737
(TraitSolver::Classic, false) | (TraitSolver::NextCoherence, false) => {
3838
Box::new(FulfillmentContext::new(infcx))
3939
}
40-
(TraitSolver::Next | TraitSolver::NextCoherence, true) => {
40+
(TraitSolver::Classic | TraitSolver::Next | TraitSolver::NextCoherence, true) => {
4141
Box::new(NextFulfillmentCtxt::new(infcx))
4242
}
4343
_ => bug!(

tests/ui/coherence/coherence-overlap-trait-alias.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ impl B for u32 {}
1313
trait C {}
1414
impl<T: AB> C for T {}
1515
impl C for u32 {}
16-
//~^ ERROR
17-
// FIXME it's giving an ungreat error but unsure if we care given that it's using an internal rustc
18-
// attribute and an artificial code path for testing purposes
16+
//~^ ERROR conflicting implementations of trait `C` for type `u32`
1917

2018
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
error[E0283]: type annotations needed: cannot satisfy `u32: C`
2-
--> $DIR/coherence-overlap-trait-alias.rs:15:12
3-
|
4-
LL | impl C for u32 {}
5-
| ^^^
6-
|
7-
note: multiple `impl`s satisfying `u32: C` found
8-
--> $DIR/coherence-overlap-trait-alias.rs:14:1
1+
error[E0119]: conflicting implementations of trait `C` for type `u32`
2+
--> $DIR/coherence-overlap-trait-alias.rs:15:1
93
|
104
LL | impl<T: AB> C for T {}
11-
| ^^^^^^^^^^^^^^^^^^^
5+
| ------------------- first implementation here
126
LL | impl C for u32 {}
13-
| ^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^ conflicting implementation for `u32`
148

159
error: aborting due to previous error
1610

17-
For more information about this error, try `rustc --explain E0283`.
11+
For more information about this error, try `rustc --explain E0119`.

tests/ui/impl-trait/negative-reasoning.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | impl<T: std::fmt::Debug> AnotherTrait for T {}
77
LL | impl AnotherTrait for D<OpaqueType> {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
99
|
10-
= note: upstream crates may add a new impl of trait `std::fmt::Debug` for type `OpaqueType` in future versions
10+
= note: upstream crates may add a new impl of trait `std::marker::FnPtr` for type `OpaqueType` in future versions
1111

1212
error: aborting due to previous error
1313

tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ LL | impl Bop for Bar<()> {}
1515
...
1616
LL | impl Bop for Barr {}
1717
| ^^^^^^^^^^^^^^^^^ conflicting implementation for `Bar<()>`
18+
|
19+
= note: upstream crates may add a new impl of trait `std::marker::FnPtr` for type `Barr` in future versions
1820

1921
error[E0119]: conflicting implementations of trait `Bop` for type `Bar<()>`
2022
--> $DIR/impl_trait_for_same_tait.rs:30:1

0 commit comments

Comments
 (0)