Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Stabilize -Znext-solver=coherence" #130249

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(mir_opt_level, Some(4));
tracked!(move_size_limit, Some(4096));
tracked!(mutable_noalias, false);
tracked!(next_solver, NextSolverConfig { coherence: true, globally: true });
tracked!(next_solver, Some(NextSolverConfig { coherence: true, globally: false }));
tracked!(no_generate_arange_section, true);
tracked!(no_jump_tables, true);
tracked!(no_link, true);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3132,11 +3132,11 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn next_trait_solver_globally(self) -> bool {
self.sess.opts.unstable_opts.next_solver.globally
self.sess.opts.unstable_opts.next_solver.map_or(false, |c| c.globally)
}

pub fn next_trait_solver_in_coherence(self) -> bool {
self.sess.opts.unstable_opts.next_solver.coherence
self.sess.opts.unstable_opts.next_solver.map_or(false, |c| c.coherence)
}

pub fn is_impl_trait_in_trait(self, def_id: DefId) -> bool {
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,11 +842,6 @@ pub struct NextSolverConfig {
/// This is only `true` if `coherence` is also enabled.
pub globally: bool,
}
impl Default for NextSolverConfig {
fn default() -> Self {
NextSolverConfig { coherence: true, globally: false }
}
}

#[derive(Clone)]
pub enum Input {
Expand Down
31 changes: 21 additions & 10 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ mod desc {
pub(crate) const parse_unpretty: &str = "`string` or `string=string`";
pub(crate) const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
pub(crate) const parse_next_solver_config: &str =
"either `globally` (when used without an argument), `coherence` (default) or `no`";
"a comma separated list of solver configurations: `globally` (default), and `coherence`";
pub(crate) const parse_lto: &str =
"either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
pub(crate) const parse_linker_plugin_lto: &str =
Expand Down Expand Up @@ -1105,16 +1105,27 @@ mod parse {
}
}

pub(crate) fn parse_next_solver_config(slot: &mut NextSolverConfig, v: Option<&str>) -> bool {
pub(crate) fn parse_next_solver_config(
slot: &mut Option<NextSolverConfig>,
v: Option<&str>,
) -> bool {
if let Some(config) = v {
*slot = match config {
"no" => NextSolverConfig { coherence: false, globally: false },
"coherence" => NextSolverConfig { coherence: true, globally: false },
"globally" => NextSolverConfig { coherence: true, globally: true },
_ => return false,
};
let mut coherence = false;
let mut globally = true;
for c in config.split(',') {
match c {
"globally" => globally = true,
"coherence" => {
globally = false;
coherence = true;
}
_ => return false,
}
}

*slot = Some(NextSolverConfig { coherence: coherence || globally, globally });
} else {
*slot = NextSolverConfig { coherence: true, globally: true };
*slot = Some(NextSolverConfig { coherence: true, globally: true });
}

true
Expand Down Expand Up @@ -1867,7 +1878,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: NextSolverConfig = (NextSolverConfig::default(), parse_next_solver_config, [TRACKED],
next_solver: Option<NextSolverConfig> = (None, 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
4 changes: 3 additions & 1 deletion compiler/rustc_trait_selection/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ where
if infcx.next_trait_solver() {
Box::new(NextFulfillmentCtxt::new(infcx))
} else {
let new_solver_globally =
infcx.tcx.sess.opts.unstable_opts.next_solver.map_or(false, |c| c.globally);
assert!(
!infcx.tcx.next_trait_solver_globally(),
!new_solver_globally,
"using old solver even though new solver is enabled globally"
);
Box::new(FulfillmentContext::new(infcx))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// regression test for #118987
//@ known-bug: #118987
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete

trait Assoc {
Expand All @@ -15,5 +15,3 @@ trait Foo {}

impl Foo for <u8 as Assoc>::Output {}
impl Foo for <u16 as Assoc>::Output {}
//~^ ERROR the trait bound `u16: Assoc` is not satisfied
fn main() {}
17 changes: 17 additions & 0 deletions tests/crashes/118987.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ known-bug: #118987
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete

trait Assoc {
type Output;
}

default impl<T: Clone> Assoc for T {
type Output = bool;
}

impl Assoc for u8 {}

trait Foo {}

impl Foo for <u8 as Assoc>::Output {}
impl Foo for <u16 as Assoc>::Output {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//@ known-bug: #124207
#![feature(transmutability)]
#![feature(type_alias_impl_trait)]
trait OpaqueTrait {}
type OpaqueType = impl OpaqueTrait;
//~^ ERROR unconstrained opaque type
trait AnotherTrait {}
impl<T: std::mem::TransmuteFrom<(), ()>> AnotherTrait for T {}
//~^ ERROR type provided when a constant was expected
impl AnotherTrait for OpaqueType {}
//~^ ERROR conflicting implementations of trait `AnotherTrait`
pub fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// regression test for #73299.
#![feature(specialization)] //~ WARN the feature `specialization` is incomplete
//@ known-bug: #74299
#![feature(specialization)]

trait X {
type U;
Expand All @@ -18,7 +18,6 @@ trait Y {

impl Y for <() as X>::U {}
impl Y for <i32 as X>::U {}
//~^ ERROR conflicting implementations of trait `Y` for type `<() as X>::U`

fn main() {
().f().g();
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 `<_ as ToOwned>::Owned`
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `Cow<'_, _>`
--> $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 `<_ as ToOwned>::Owned`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Cow<'_, _>`

error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `<_ as ToOwned>::Owned`
error[E0119]: conflicting implementations of trait `IntoCow<'_, _>` for type `&_`
--> $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 `<_ as ToOwned>::Owned`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `&_`

error: aborting due to 2 previous errors

Expand Down
30 changes: 30 additions & 0 deletions tests/ui/auto-traits/opaque_type_candidate_selection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! used to ICE: #119272

//@ check-pass

#![feature(type_alias_impl_trait)]
mod defining_scope {
use super::*;
pub type Alias<T> = impl Sized;

pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> {
x
}
}

struct Container<T: Trait<U>, U> {
x: <T as Trait<U>>::Assoc,
}

trait Trait<T> {
type Assoc;
}

impl<T> Trait<T> for T {
type Assoc = Box<u32>;
}
impl<T> Trait<T> for defining_scope::Alias<T> {
type Assoc = usize;
}

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ 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,8 +5,6 @@ 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
@@ -1,5 +1,5 @@
error[E0592]: duplicate definitions with name `dummy`
--> $DIR/coherence-overlap-downstream-inherent.rs:7:26
--> $DIR/coherence-overlap-downstream-inherent.rs:10:26
|
LL | impl<T:Sugar> Sweet<T> { fn dummy(&self) { } }
| ^^^^^^^^^^^^^^^ duplicate definitions for `dummy`
Expand All @@ -8,7 +8,7 @@ LL | impl<T:Fruit> Sweet<T> { fn dummy(&self) { } }
| --------------- other definition for `dummy`

error[E0592]: duplicate definitions with name `f`
--> $DIR/coherence-overlap-downstream-inherent.rs:13:38
--> $DIR/coherence-overlap-downstream-inherent.rs:16:38
|
LL | impl<X, T> A<T, X> where T: Bar<X> { fn f(&self) {} }
| ^^^^^^^^^^^ duplicate definitions for `f`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0592]: duplicate definitions with name `dummy`
--> $DIR/coherence-overlap-downstream-inherent.rs:10:26
|
LL | impl<T:Sugar> Sweet<T> { fn dummy(&self) { } }
| ^^^^^^^^^^^^^^^ duplicate definitions for `dummy`
LL |
LL | impl<T:Fruit> Sweet<T> { fn dummy(&self) { } }
| --------------- other definition for `dummy`

error[E0592]: duplicate definitions with name `f`
--> $DIR/coherence-overlap-downstream-inherent.rs:16:38
|
LL | impl<X, T> A<T, X> where T: Bar<X> { fn f(&self) {} }
| ^^^^^^^^^^^ duplicate definitions for `f`
LL |
LL | impl<X> A<i32, X> { fn f(&self) {} }
| ----------- other definition for `f`
|
= note: downstream crates may implement trait `Bar<_>` for type `i32`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0592`.
3 changes: 3 additions & 0 deletions tests/ui/coherence/coherence-overlap-downstream-inherent.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//@ revisions: old next
//@[next] compile-flags: -Znext-solver

// Tests that we consider `T: Sugar + Fruit` to be ambiguous, even
// though no impls are found.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0119]: conflicting implementations of trait `Sweet`
--> $DIR/coherence-overlap-downstream.rs:8:1
--> $DIR/coherence-overlap-downstream.rs:11:1
|
LL | impl<T:Sugar> Sweet for T { }
| ------------------------- first implementation here
LL | impl<T:Fruit> Sweet for T { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error[E0119]: conflicting implementations of trait `Foo<_>` for type `i32`
--> $DIR/coherence-overlap-downstream.rs:14:1
--> $DIR/coherence-overlap-downstream.rs:17:1
|
LL | impl<X, T> Foo<X> for T where T: Bar<X> {}
| --------------------------------------- first implementation here
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/coherence/coherence-overlap-downstream.old.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0119]: conflicting implementations of trait `Sweet`
--> $DIR/coherence-overlap-downstream.rs:11:1
|
LL | impl<T:Sugar> Sweet for T { }
| ------------------------- first implementation here
LL | impl<T:Fruit> Sweet for T { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error[E0119]: conflicting implementations of trait `Foo<_>` for type `i32`
--> $DIR/coherence-overlap-downstream.rs:17:1
|
LL | impl<X, T> Foo<X> for T where T: Bar<X> {}
| --------------------------------------- first implementation here
LL | impl<X> Foo<X> for i32 {}
| ^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i32`
|
= note: downstream crates may implement trait `Bar<_>` for type `i32`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0119`.
3 changes: 3 additions & 0 deletions tests/ui/coherence/coherence-overlap-downstream.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//@ revisions: old next
//@[next] compile-flags: -Znext-solver

// Tests that we consider `T: Sugar + Fruit` to be ambiguous, even
// though no impls are found.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0592]: duplicate definitions with name `dummy`
--> $DIR/coherence-overlap-issue-23516-inherent.rs:9:25
--> $DIR/coherence-overlap-issue-23516-inherent.rs:12:25
|
LL | impl<T:Sugar> Cake<T> { fn dummy(&self) { } }
| ^^^^^^^^^^^^^^^ duplicate definitions for `dummy`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0592]: duplicate definitions with name `dummy`
--> $DIR/coherence-overlap-issue-23516-inherent.rs:12:25
|
LL | impl<T:Sugar> Cake<T> { fn dummy(&self) { } }
| ^^^^^^^^^^^^^^^ duplicate definitions for `dummy`
LL |
LL | impl<U:Sugar> Cake<Box<U>> { fn dummy(&self) { } }
| --------------- other definition for `dummy`
|
= note: downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0592`.
3 changes: 3 additions & 0 deletions tests/ui/coherence/coherence-overlap-issue-23516-inherent.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//@ revisions: old next
//@[next] compile-flags: -Znext-solver

// Tests that we consider `Box<U>: !Sugar` to be ambiguous, even
// though we see no impl of `Sugar` for `Box`. Therefore, an overlap
// error is reported for the following pair of impls (#23516).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0119]: conflicting implementations of trait `Sweet` for type `Box<_>`
--> $DIR/coherence-overlap-issue-23516.rs:8:1
--> $DIR/coherence-overlap-issue-23516.rs:11:1
|
LL | impl<T:Sugar> Sweet for T { }
| ------------------------- first implementation here
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/coherence/coherence-overlap-issue-23516.old.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0119]: conflicting implementations of trait `Sweet` for type `Box<_>`
--> $DIR/coherence-overlap-issue-23516.rs:11:1
|
LL | impl<T:Sugar> Sweet for T { }
| ------------------------- first implementation here
LL | impl<U:Sugar> Sweet for Box<U> { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Box<_>`
|
= note: downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
3 changes: 3 additions & 0 deletions tests/ui/coherence/coherence-overlap-issue-23516.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//@ revisions: old next
//@[next] compile-flags: -Znext-solver

// Tests that we consider `Box<U>: !Sugar` to be ambiguous, even
// though we see no impl of `Sugar` for `Box`. Therefore, an overlap
// error is reported for the following pair of impls (#23516).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ 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
Loading
Loading