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

Fix/tweak some tests in new solver #138838

Merged
merged 4 commits into from
Mar 25, 2025
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
16 changes: 9 additions & 7 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,15 +971,17 @@ where
rhs: T,
) -> Result<(), NoSolution> {
let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
if cfg!(debug_assertions) {
for g in goals.iter() {
match g.predicate.kind().skip_binder() {
ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {}
p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
for &goal in goals.iter() {
let source = match goal.predicate.kind().skip_binder() {
ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {
GoalSource::TypeRelating
}
}
// FIXME(-Znext-solver=coinductive): should these WF goals also be unproductive?
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc,
p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
};
self.add_goal(source, goal);
}
self.add_goals(GoalSource::TypeRelating, goals);
Ok(())
}

Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ fn layout_of_uncached<'tcx>(
}

// Types with no meaningful known layout.
ty::Param(_) => {
ty::Param(_) | ty::Placeholder(..) => {
return Err(error(cx, LayoutError::TooGeneric(ty)));
}

Expand All @@ -628,11 +628,7 @@ fn layout_of_uncached<'tcx>(
return Err(error(cx, err));
}

ty::Placeholder(..)
| ty::Bound(..)
| ty::CoroutineWitness(..)
| ty::Infer(_)
| ty::Error(_) => {
ty::Bound(..) | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Error(_) => {
// `ty::Error` is handled at the top of this function.
bug!("layout_of: unexpected type `{ty}`")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0283]: type annotations needed
--> $DIR/dedup-normalized-2-higher-ranked.rs:23:5
--> $DIR/dedup-normalized-2-higher-ranked.rs:28:5
|
LL | impls(rigid);
| ^^^^^ cannot infer type of the type parameter `U` declared on the function `impls`
|
= note: cannot satisfy `for<'b> <P as Trait>::Rigid: Bound<'b, _>`
note: required by a bound in `impls`
--> $DIR/dedup-normalized-2-higher-ranked.rs:20:13
--> $DIR/dedup-normalized-2-higher-ranked.rs:25:13
|
LL | fn impls<T: for<'b> Bound<'b, U>, U>(_: T) {}
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `impls`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@[next] check-pass

// We try to prove `for<'b> T::Rigid: Bound<'b, ?0>` and have 2 candidates from where-clauses:
//
// - `for<'a> Bound<'a, String>`
Expand All @@ -21,7 +26,7 @@ fn impls<T: for<'b> Bound<'b, U>, U>(_: T) {}

fn test<P: Trait>(rigid: P::Rigid) {
impls(rigid);
//~^ ERROR type annotations needed
//[current]~^ ERROR type annotations needed
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error: constant expression depends on a generic parameter
--> $DIR/too_generic_eval_ice.rs:7:13
--> $DIR/too_generic_eval_ice.rs:11:13
|
LL | [5; Self::HOST_SIZE] == [6; 0]
| ^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
--> $DIR/too_generic_eval_ice.rs:7:9
--> $DIR/too_generic_eval_ice.rs:11:9
|
LL | [5; Self::HOST_SIZE] == [6; 0]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
--> $DIR/too_generic_eval_ice.rs:7:30
--> $DIR/too_generic_eval_ice.rs:11:30
|
LL | [5; Self::HOST_SIZE] == [6; 0]
| ^^
|
= note: this may fail depending on what value the parameter takes

error[E0277]: can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
--> $DIR/too_generic_eval_ice.rs:7:30
--> $DIR/too_generic_eval_ice.rs:11:30
|
LL | [5; Self::HOST_SIZE] == [6; 0]
| ^^ no implementation for `[{integer}; Self::HOST_SIZE] == [{integer}; 0]`
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/consts/too_generic_eval_ice.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0284]: type annotations needed: cannot satisfy `the constant `Self::HOST_SIZE` can be evaluated`
--> $DIR/too_generic_eval_ice.rs:11:13
|
LL | [5; Self::HOST_SIZE] == [6; 0]
| ^^^^^^^^^^^^^^^ cannot satisfy `the constant `Self::HOST_SIZE` can be evaluated`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0284`.
13 changes: 9 additions & 4 deletions tests/ui/consts/too_generic_eval_ice.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

pub struct Foo<A, B>(A, B);

impl<A, B> Foo<A, B> {
const HOST_SIZE: usize = std::mem::size_of::<B>();

pub fn crash() -> bool {
[5; Self::HOST_SIZE] == [6; 0]
//~^ ERROR constant expression depends on a generic parameter
//~| ERROR constant expression depends on a generic parameter
//~| ERROR constant expression depends on a generic parameter
//~| ERROR can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
//[current]~^ ERROR constant expression depends on a generic parameter
//[current]~| ERROR constant expression depends on a generic parameter
//[current]~| ERROR constant expression depends on a generic parameter
//[current]~| ERROR can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
//[next]~^^^^^ ERROR type annotations needed
}
}

Expand Down
1 change: 0 additions & 1 deletion tests/ui/privacy/where-pub-type-impls-priv-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// priv-in-pub lint tests where the private trait bounds a public type

#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

struct PrivTy;
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/privacy/where-pub-type-impls-priv-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
warning: trait `PrivTr` is more private than the item `S`
--> $DIR/where-pub-type-impls-priv-trait.rs:20:1
--> $DIR/where-pub-type-impls-priv-trait.rs:19:1
|
LL | pub struct S
| ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
--> $DIR/where-pub-type-impls-priv-trait.rs:9:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
= note: `#[warn(private_bounds)]` on by default

warning: trait `PrivTr` is more private than the item `E`
--> $DIR/where-pub-type-impls-priv-trait.rs:27:1
--> $DIR/where-pub-type-impls-priv-trait.rs:26:1
|
LL | pub enum E
| ^^^^^^^^^^ enum `E` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
--> $DIR/where-pub-type-impls-priv-trait.rs:9:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^

warning: trait `PrivTr` is more private than the item `f`
--> $DIR/where-pub-type-impls-priv-trait.rs:34:1
--> $DIR/where-pub-type-impls-priv-trait.rs:33:1
|
LL | / pub fn f()
LL | |
Expand All @@ -33,13 +33,13 @@ LL | | PubTy: PrivTr
| |_________________^ function `f` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
--> $DIR/where-pub-type-impls-priv-trait.rs:9:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^

warning: trait `PrivTr` is more private than the item `S`
--> $DIR/where-pub-type-impls-priv-trait.rs:41:1
--> $DIR/where-pub-type-impls-priv-trait.rs:40:1
|
LL | / impl S
LL | |
Expand All @@ -48,13 +48,13 @@ LL | | PubTy: PrivTr
| |_________________^ implementation `S` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
--> $DIR/where-pub-type-impls-priv-trait.rs:9:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^

warning: trait `PrivTr` is more private than the item `S::f`
--> $DIR/where-pub-type-impls-priv-trait.rs:46:5
--> $DIR/where-pub-type-impls-priv-trait.rs:45:5
|
LL | / pub fn f()
LL | |
Expand All @@ -63,7 +63,7 @@ LL | | PubTy: PrivTr
| |_____________________^ associated function `S::f` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
--> $DIR/where-pub-type-impls-priv-trait.rs:9:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/traits/next-solver/well-formed-in-relate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
fn main() {
let x;
//~^ ERROR type annotations needed for `Map<_, _>`
higher_ranked();
x = unconstrained_map();
}

fn higher_ranked() where for<'a> &'a (): Sized {}

struct Map<T, U> where T: Fn() -> U {
t: T,
}

trait Mirror {
type Assoc;
}
impl<T> Mirror for T {
type Assoc = T;
}

fn unconstrained_map<T: Fn() -> U, U>() -> <Map<T, U> as Mirror>::Assoc { todo!() }
27 changes: 27 additions & 0 deletions tests/ui/traits/next-solver/well-formed-in-relate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0283]: type annotations needed for `Map<_, _>`
--> $DIR/well-formed-in-relate.rs:2:9
|
LL | let x;
| ^
...
LL | x = unconstrained_map();
| ------------------- type must be known at this point
|
= note: multiple `impl`s satisfying `_: Fn()` found in the following crates: `alloc`, `core`:
- impl<A, F> Fn<A> for &F
where A: Tuple, F: Fn<A>, F: ?Sized;
- impl<Args, F, A> Fn<Args> for Box<F, A>
where Args: Tuple, F: Fn<Args>, A: Allocator, F: ?Sized;
note: required by a bound in `unconstrained_map`
--> $DIR/well-formed-in-relate.rs:21:25
|
LL | fn unconstrained_map<T: Fn() -> U, U>() -> <Map<T, U> as Mirror>::Assoc { todo!() }
| ^^^^^^^^^ required by this bound in `unconstrained_map`
help: consider giving `x` an explicit type, where the type for type parameter `T` is specified
|
LL | let x: Map<T, U>;
| +++++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0283`.
Loading