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

lazy_type_alias: trait bound no longer satisified #114218

Open
matthiaskrgr opened this issue Jul 29, 2023 · 5 comments
Open

lazy_type_alias: trait bound no longer satisified #114218

matthiaskrgr opened this issue Jul 29, 2023 · 5 comments
Labels
C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

I tried this code:
tests/ui/associated-types/param-env-normalize-cycle.rs

// Minimized case from typenum that didn't compile because:
// - We tried to normalize the ParamEnv of the second impl
// - This requires trying to normalize `GrEq<Self, Square<Square<U>>>`
// - This requires proving `Square<Square<U>>: Sized` so that the first impl
//   applies
// - This requires Providing `Square<Square<U>>` is well-formed, so that we
//   can use the `Sized` bound on `Mul::Output`
// - This requires proving `Square<U>: Mul`
// - But first we tried normalizing the whole obligation, including the
//   ParamEnv, which leads to a cycle error.

// check-pass

trait PrivateSquareRoot {}

pub trait Mul<Rhs = Self> {
    type Output;
}

pub trait IsGreaterOrEqual<Rhs> {
    type Output;
}

pub type Square<A> = <A as Mul>::Output;
pub type GrEq<A, B> = <A as IsGreaterOrEqual<B>>::Output;

impl<A, B> IsGreaterOrEqual<B> for A {
    type Output = ();
}

impl<U> PrivateSquareRoot for U
where
    U: Mul,
    Square<U>: Mul,
    GrEq<Self, Square<Square<U>>>: Sized,
{
}

fn main() {}

without `-Zcrate-attr=feature(lazy_type_alias)´: no warnings

with -Zcrate-attr=feature(lazy_type_alias):

error[E0277]: the trait bound `<U as Mul>::Output: Mul` is not satisfied
  --> tests/ui/associated-types/param-env-normalize-cycle.rs:31:1
   |
31 | impl<U> PrivateSquareRoot for U
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mul` is not implemented for `<U as Mul>::Output`
   |
help: consider further restricting the associated type
   |
35 |     GrEq<Self, Square<Square<U>>>: Sized, <U as Mul>::Output: Mul
   |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0277]: the trait bound `<U as Mul>::Output: Mul` is not satisfied
  --> tests/ui/associated-types/param-env-normalize-cycle.rs:31:1
   |
31 | / impl<U> PrivateSquareRoot for U
32 | | where
33 | |     U: Mul,
34 | |     Square<U>: Mul,
35 | |     GrEq<Self, Square<Square<U>>>: Sized,
36 | | {
37 | | }
   | |_^ the trait `Mul` is not implemented for `<U as Mul>::Output`
   |
help: consider further restricting the associated type
   |
35 |     GrEq<Self, Square<Square<U>>>: Sized, <U as Mul>::Output: Mul
   |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
rustc 1.73.0-nightly (04abc370b 2023-07-28)
binary: rustc
commit-hash: 04abc370b9f3855b28172b65a7f7d5a433f41412
commit-date: 2023-07-28
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5
@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` labels Jul 29, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2023
@compiler-errors
Copy link
Member

I'm gonna mark this and all the other issues you just opened as needs-mcve, since the UI test you provided is not totally minimized

@compiler-errors compiler-errors added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example requires-nightly This issue requires a nightly compiler in some way. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 29, 2023
@compiler-errors
Copy link
Member

Also, for the posterity of other folks who may want to work on these issues or repro them in the future, it would be very helpful if you copied all the -Zcrate-attr= into the code itself.

@compiler-errors compiler-errors added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 29, 2023
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Jul 29, 2023

script for reducing with treereduce

treereduce-rust --passes=10 --min-reduction=10 --interesting-exit-code=101 --source file.rs -- ./reduce.sh @@.rs

#!/bin/bash

if  rustc --crate-type lib --cap-lints allow $1 ; then
	if ! rustc "-Zcrate-attr=feature(lazy_type_alias)" --crate-type lib $1 ; then
		exit 101
	else
		exit 0
	fi
else
	exit 0
fi

@fmease
Copy link
Member

fmease commented Aug 10, 2023

Slightly reduced:

#![feature(lazy_type_alias)]

type H<A: F> = <A as F>::O;

trait F { type O; }
trait G {}

impl<A> G for A {}

fn f<U: F>()
where
    H<U>: F,
    H<H<U>>: G,
{}

fn main() {}

And as usual, repro[ty::Weakty::Projection] has exactly the same errors.

@fmease fmease removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Feb 20, 2024
@fmease
Copy link
Member

fmease commented Apr 22, 2024

Fixed by the next solver.

@fmease fmease added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants