Skip to content

FulfilmentError ICE with trait-provided method implementations and -Clink-dead-code #90992

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

Closed
nagisa opened this issue Nov 17, 2021 · 1 comment
Labels
A-codegen Area: Code generation I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nagisa
Copy link
Member

nagisa commented Nov 17, 2021

The following code ICEs from 1.24.0 onwards when built with -Clink-dead-code (godbolt):

struct Banana<'a>(&'a ());

pub trait Peach: Sized {
    fn chaenomeles() -> Self;
    fn apple() -> Self {
        Self::chaenomeles()
    }
}

impl <'a> Peach for Banana<'a>
where &'a (): Peach {
     fn chaenomeles() -> Banana<'a> {
        unimplemented!()
    }
}

In this example, the where &'a (): Peach bound is never satisfied and it is indeed reported as such by the compiler when attempting to call Banana::<'static>::apple explicitly:

error[E0599]: the function or associated item `apple` exists for struct `Banana<'static>`, but its trait bounds were not satisfied
  --> <source>:18:24
   |
1  | struct Banana<'a>(&'a ());
   | --------------------------
   | |
   | function or associated item `apple` not found for this
   | doesn't satisfy `Banana<'_>: Peach`
...
18 |     Banana::<'static>::apple();
   |                        ^^^^^ function or associated item cannot be called on `Banana<'static>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `&(): Peach`
           which is required by `Banana<'_>: Peach`
   = help: items from traits can only be used if the trait is implemented and in scope
note: `Peach` defines an item `apple`, perhaps you need to implement it
  --> <source>:3:1
   |
3  | pub trait Peach: Sized {
   | ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

However in absence of calls to Banana::apple there is nothing to “force” typeck to report this error and yet -Clink-dead-code causes codegen to attempt to codegen the method anyway, despite the where clause not being satisfied.

The correct fix here would probably to make sure that the monomorphization collector in -Clink-dead-code mode does not collect items with unsatisfied bounds?

Additionally, I feel like a lint warning along the lines of

warning: this where clause is never satisfied
     where &'a (): Peach
           ^^^^^^^^^^^^^

could be useful

@nagisa nagisa added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-codegen Area: Code generation labels Nov 17, 2021
@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@cjgillot
Copy link
Contributor

Fixed by #109321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

3 participants