Skip to content

Commit

Permalink
stabilize -Znext-solver=coherence
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Mar 1, 2024
1 parent 6cbf092 commit 8f16e02
Show file tree
Hide file tree
Showing 43 changed files with 240 additions and 155 deletions.
10 changes: 10 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,16 @@ pub struct NextSolverConfig {
pub dump_tree: DumpSolverProofTree,
}

impl Default for NextSolverConfig {
fn default() -> Self {
NextSolverConfig {
coherence: true,
globally: false,
dump_tree: DumpSolverProofTree::default(),
}
}
}

#[derive(Default, Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum DumpSolverProofTree {
Always,
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,10 @@ mod parse {
let mut dump_tree = None;
for c in config.split(',') {
match c {
"no" => {
*slot = None;
return true;
}
"globally" => globally = true,
"coherence" => {
globally = false;
Expand Down Expand Up @@ -1736,7 +1740,7 @@ options! {
"the size at which the `large_assignments` lint starts to be emitted"),
mutable_noalias: bool = (true, parse_bool, [TRACKED],
"emit noalias metadata for mutable references (default: yes)"),
next_solver: Option<NextSolverConfig> = (None, parse_next_solver_config, [TRACKED],
next_solver: Option<NextSolverConfig> = (Some(NextSolverConfig::default()), parse_next_solver_config, [TRACKED],
"enable and configure the next generation trait solver used by rustc"),
nll_facts: bool = (false, parse_bool, [UNTRACKED],
"dump facts from NLL analysis into side files (default: no)"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `Cow<'_, _>`
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `<_ as ToOwned>::Owned`
--> $DIR/associated-types-coherence-failure.rs:21:1
|
LL | impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned {
| ----------------------------------------------------------------------------- first implementation here
...
LL | impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Cow<'_, _>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `<_ as ToOwned>::Owned`

error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `&_`
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `<_ as ToOwned>::Owned`
--> $DIR/associated-types-coherence-failure.rs:28:1
|
LL | impl<'a, B: ?Sized> IntoCow<'a, B> for <B as ToOwned>::Owned where B: ToOwned {
| ----------------------------------------------------------------------------- first implementation here
...
LL | impl<'a, B: ?Sized> IntoCow<'a, B> for &'a B where B: ToOwned {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `<_ as ToOwned>::Owned`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | impl<'a, T: MyPredicate<'a>> MyTrait<'a> for T {}
| ---------------------------------------------- first implementation here
LL | impl<'a, T> MyTrait<'a> for &'a T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
|
= note: downstream crates may implement trait `MyPredicate<'_>` for type `&_`

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | impl<'a, T: MyPredicate<'a>> MyTrait<'a> for T {}
| ---------------------------------------------- first implementation here
LL | impl<'a, T> MyTrait<'a> for &'a T {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
|
= note: downstream crates may implement trait `MyPredicate<'_>` for type `&_`

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | impl<T: DerefMut> Foo for T {}
| --------------------------- first implementation here
LL | impl<U> Foo for &U {}
| ^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
|
= note: downstream crates may implement trait `std::ops::DerefMut` for type `&_`

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LL | impl<T> Bar for T where T: Foo {}
| ------------------------------ first implementation here
LL | impl<T> Bar for Box<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Box<_>`
|
= note: downstream crates may implement trait `Foo` for type `std::boxed::Box<_>`

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ LL | impl<T> Bar for T where T: Foo {}
...
LL | impl<T> Bar for &T {}
| ^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
|
= note: downstream crates may implement trait `Foo` for type `&_`

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LL | impl<T: ?Sized> FnMarker for fn(&T) {}
|
= warning: the behavior may change in a future release
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
= note: downstream crates may implement trait `Marker` for type `&_`
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
note: the lint level is defined here
--> $DIR/negative-coherence-placeholder-region-constraints-on-unification.rs:4:11
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/coherence/normalize-for-errors.current.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0119]: conflicting implementations of trait `MyTrait<_>` for type `(Box<(MyType,)>, _)`
error[E0119]: conflicting implementations of trait `MyTrait<_>` for type `(Box<(MyType,)>, <_ as Iterator>::Item)`
--> $DIR/normalize-for-errors.rs:16:1
|
LL | impl<T: Copy, S: Iterator> MyTrait<S> for (T, S::Item) {}
| ------------------------------------------------------ first implementation here
LL |
LL | impl<S: Iterator> MyTrait<S> for (Box<<(MyType,) as Mirror>::Assoc>, S::Item) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(Box<(MyType,)>, _)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(Box<(MyType,)>, <_ as Iterator>::Item)`
|
= note: upstream crates may add a new impl of trait `std::marker::Copy` for type `std::boxed::Box<(MyType,)>` in future versions

Expand Down
8 changes: 2 additions & 6 deletions tests/ui/coherence/occurs-check/associated-type.old.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, RePlaceholder(!2_BoundRegion { var: 0, kind: BrNamed(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1), 'a) })], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit) }
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), _)>` for type `for<'a> fn(&'a (), _)`
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
--> $DIR/associated-type.rs:31:1
|
LL | impl<T> Overlap<T> for T {
Expand All @@ -16,7 +12,7 @@ LL | / impl<T> Overlap<for<'a> fn(&'a (), Assoc<'a, T>)> for T
LL | |
LL | | where
LL | | for<'a> *const T: ToUnit<'a>,
| |_________________________________^ conflicting implementation for `for<'a> fn(&'a (), _)`
| |_________________________________^ conflicting implementation for `for<'a> fn(&'a (), ())`
|
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details

Expand Down
12 changes: 12 additions & 0 deletions tests/ui/coherence/occurs-check/opaques.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0119]: conflicting implementations of trait `Trait<_>`
--> $DIR/opaques.rs:27:1
|
LL | impl<T> Trait<T> for T {
| ---------------------- first implementation here
...
LL | impl<T> Trait<T> for defining_scope::Alias<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
4 changes: 2 additions & 2 deletions tests/ui/coherence/occurs-check/opaques.next.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0119]: conflicting implementations of trait `Trait<_>`
--> $DIR/opaques.rs:30:1
--> $DIR/opaques.rs:27:1
|
LL | impl<T> Trait<T> for T {
| ---------------------- first implementation here
Expand All @@ -8,7 +8,7 @@ LL | impl<T> Trait<T> for defining_scope::Alias<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error[E0282]: type annotations needed
--> $DIR/opaques.rs:13:20
--> $DIR/opaques.rs:10:20
|
LL | pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
| ^ cannot infer type for struct `Container<T, T>`
Expand Down
7 changes: 2 additions & 5 deletions tests/ui/coherence/occurs-check/opaques.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//@revisions: old next
//@revisions: current next
//@[next] compile-flags: -Znext-solver

// A regression test for #105787

//@[old] known-bug: #105787
//@[old] check-pass
#![feature(type_alias_impl_trait)]
mod defining_scope {
use super::*;
Expand All @@ -28,7 +25,7 @@ impl<T> Trait<T> for T {
type Assoc = Box<u32>;
}
impl<T> Trait<T> for defining_scope::Alias<T> {
//[next]~^ ERROR conflicting implementations of trait
//~^ ERROR conflicting implementations of trait
type Assoc = usize;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/dyn-star/param-env-region-infer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ revisions: current
//@ incremental

// FIXME(-Znext-solver): THis currently results in unstable query results:
// FIXME(-Znext-solver): This currently results in unstable query results:
// `normalizes-to(opaque, opaque)` changes from `Maybe(Ambiguous)` to `Maybe(Overflow)`
// once the hidden type of the opaque is already defined to be itself.

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/e0119/issue-23563.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0119]: conflicting implementations of trait `LolFrom<&[_]>` for type `LocalType<_>`
error[E0119]: conflicting implementations of trait `LolFrom<&[u8]>` for type `LocalType<u8>`
--> $DIR/issue-23563.rs:13:1
|
LL | impl<'a, T> LolFrom<&'a [T]> for LocalType<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ LL | impl<T: std::ops::DerefMut> Foo for T { }
LL |
LL | impl<T> Foo for &T { }
| ^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`
|
= note: downstream crates may implement trait `std::ops::DerefMut` for type `&_`

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/auto-trait-coherence.old.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<_>`
--> $DIR/auto-trait-coherence.rs:24:1
|
LL | impl<T: Send> AnotherTrait for T {}
| -------------------------------- first implementation here
...
LL | impl AnotherTrait for D<OpaqueType> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<_>`

error: aborting due to 1 previous error

Expand Down
6 changes: 1 addition & 5 deletions tests/ui/impl-trait/auto-trait-coherence.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//@ revisions: old next
//@[next] compile-flags: -Znext-solver

// Tests that type alias impls traits do not leak auto-traits for
// the purposes of coherence checking
#![feature(type_alias_impl_trait)]
Expand All @@ -22,8 +19,7 @@ impl<T: Send> AnotherTrait for T {}
// (We treat opaque types as "foreign types" that could grow more impls
// in the future.)
impl AnotherTrait for D<OpaqueType> {
//[old]~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
//[next]~^^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<_>`
//~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<_>`
}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/impl-trait/auto-trait-coherence.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<_>`
--> $DIR/auto-trait-coherence.rs:21:1
|
LL | impl<T: Send> AnotherTrait for T {}
| -------------------------------- first implementation here
...
LL | impl AnotherTrait for D<OpaqueType> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<_>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/coherence-treats-tait-ambig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type T = impl Sized;
struct Foo;

impl Into<T> for Foo {
//~^ ERROR conflicting implementations of trait `Into<T>` for type `Foo`
//~^ ERROR conflicting implementations of trait `Into<_>` for type `Foo`
fn into(self) -> T {
Foo
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/coherence-treats-tait-ambig.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0119]: conflicting implementations of trait `Into<T>` for type `Foo`
error[E0119]: conflicting implementations of trait `Into<_>` for type `Foo`
--> $DIR/coherence-treats-tait-ambig.rs:7:1
|
LL | impl Into<T> for Foo {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/negative-reasoning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<T: std::fmt::Debug> AnotherTrait for T {}

// This is in error, because we cannot assume that `OpaqueType: !Debug`
impl AnotherTrait for D<OpaqueType> {
//~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
//~^ ERROR conflicting implementations of trait `AnotherTrait` for type `D<_>`
}

fn main() {}
6 changes: 2 additions & 4 deletions tests/ui/impl-trait/negative-reasoning.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<_>`
--> $DIR/negative-reasoning.rs:19:1
|
LL | impl<T: std::fmt::Debug> AnotherTrait for T {}
| ------------------------------------------- first implementation here
...
LL | impl AnotherTrait for D<OpaqueType> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
|
= note: upstream crates may add a new impl of trait `std::marker::FnPtr` for type `OpaqueType` in future versions
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<_>`

error: aborting due to 1 previous error

Expand Down
46 changes: 26 additions & 20 deletions tests/ui/impl-unused-tps.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,69 @@
//~ ERROR overflow evaluating the requirement `([isize; 0], _): Sized

trait Foo<A> {
fn get(&self, A: &A) { }
fn get(&self, A: &A) {}
}

trait Bar {
type Out;
}

impl<T> Foo<T> for [isize;0] {
impl<T> Foo<T> for [isize; 0] {
// OK, T is used in `Foo<T>`.
}

impl<T,U> Foo<T> for [isize;1] {
impl<T, U> Foo<T> for [isize; 1] {
//~^ ERROR the type parameter `U` is not constrained
}

impl<T,U> Foo<T> for [isize;2] where T : Bar<Out=U> {
impl<T, U> Foo<T> for [isize; 2]
where
T: Bar<Out = U>,
{
// OK, `U` is now constrained by the output type parameter.
}

impl<T:Bar<Out=U>,U> Foo<T> for [isize;3] {
impl<T: Bar<Out = U>, U> Foo<T> for [isize; 3] {
// OK, same as above but written differently.
}

impl<T,U> Foo<T> for U {
impl<T, U> Foo<T> for U {
//~^ ERROR conflicting implementations of trait `Foo<_>` for type `[isize; 0]`
}

impl<T,U> Bar for T {
impl<T, U> Bar for T {
//~^ ERROR the type parameter `U` is not constrained

type Out = U;

// Using `U` in an associated type within the impl is not good enough!
}

impl<T,U> Bar for T
where T : Bar<Out=U>
impl<T, U> Bar for T
where
T: Bar<Out = U>,
{
//~^^^ ERROR the type parameter `U` is not constrained

//~^^^^ ERROR the type parameter `U` is not constrained by the impl trait, self type, or predicates
//~| ERROR conflicting implementations of trait `Bar`
// This crafty self-referential attempt is still no good.
}

impl<T,U,V> Foo<T> for T
where (T,U): Bar<Out=V>
impl<T, U, V> Foo<T> for T
where
(T, U): Bar<Out = V>,
{
//~^^^ ERROR the type parameter `U` is not constrained
//~| ERROR the type parameter `V` is not constrained
//~^^^^ ERROR the type parameter `U` is not constrained
//~| ERROR the type parameter `V` is not constrained
//~| ERROR conflicting implementations of trait `Foo<[isize; 0]>` for type `[isize; 0]`

// Here, `V` is bound by an output type parameter, but the inputs
// are not themselves constrained.
}

impl<T,U,V> Foo<(T,U)> for T
where (T,U): Bar<Out=V>
impl<T, U, V> Foo<(T, U)> for T
where
(T, U): Bar<Out = V>,
{
//~^^^^ ERROR conflicting implementations of trait `Foo<([isize; 0], _)>` for type `[isize; 0]`
// As above, but both T and U ARE constrained.
}

fn main() { }
fn main() {}

0 comments on commit 8f16e02

Please sign in to comment.