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

Implied bound not implied across crates #122859

Closed
benluelo opened this issue Mar 22, 2024 · 2 comments · Fixed by #122891
Closed

Implied bound not implied across crates #122859

benluelo opened this issue Mar 22, 2024 · 2 comments · Fixed by #122891
Assignees
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@benluelo
Copy link
Contributor

benluelo commented Mar 22, 2024

I tried this code:

use crate_b::{Foo, Super, Unsatisfied};

fn foo<T: Foo>() {
   unsatisfied::<<T::FooAssoc as Super>::SuperAssoc>()
}

fn unsatisfied<B: Unsatisfied>() {}

pub mod crate_b {
    pub trait Foo {
        type FooAssoc: Bar;
    }

    pub trait Bar: Super<SuperAssoc: Bound> {}

    pub trait Super {
        type SuperAssoc;
    }

    pub trait Bound: Unsatisfied {}

    pub trait Unsatisfied {}
}

This compiles fine, however if crate_b is a separate crate instead of a local module, it errors with:

error[E0277]: the trait bound `<<T as Foo>::FooAssoc as Super>::SuperAssoc: Unsatisfied` is not satisfied
 --> src/main.rs:4:19
  |
4 |     unsatisfied::<<T::FooAssoc as Super>::SuperAssoc>()
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unsatisfied` is not implemented for `<<T as Foo>::FooAssoc as Super>::SuperAssoc`
  |
note: required by a bound in `unsatisfied`
 --> src/main.rs:7:19
  |
7 | fn unsatisfied<B: Unsatisfied>() {}
  |                   ^^^^^^^^^^^ required by this bound in `unsatisfied`
help: consider further restricting the associated type
  |
3 | fn foo<T: Foo>() where <<T as Foo>::FooAssoc as Super>::SuperAssoc: Unsatisfied {
  |                  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error

This is not fixed by the next solver (-Znext-solver).

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (1388d7a06 2024-03-20)
binary: rustc
commit-hash: 1388d7a069d872bcfe5e5dd97ef61fa0a586fac0
commit-date: 2024-03-20
host: aarch64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2
@benluelo benluelo added the C-bug Category: This is a bug. label Mar 22, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 22, 2024
@benluelo
Copy link
Contributor Author

I was able to narrow this down even further:

use crate_b::Bar;

fn bar<B: Bar>() {}

pub mod crate_b {
    pub trait Bar: Super<SuperAssoc: Bound> {}

    pub trait Super {
        type SuperAssoc;
    }

    pub trait Bound {}
}

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-implied-bounds Area: Implied bounds / inferred outlives-bounds S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 22, 2024
@compiler-errors compiler-errors self-assigned this Mar 22, 2024
@compiler-errors
Copy link
Member

🤦 yep yep makes sense i'll fix it, sorry

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 22, 2024
…cates-always, r=<try>

Encode implied predicates for traits

In rust-lang#112629, we decided to make associated type bounds in the "supertrait" AST position *implied* even though they're not supertraits themselves.

This means that the `super_predicates` and `implied_predicates` queries now differ for regular traits. The assumption that they didn't differ was hard-coded in rust-lang#107614, so in cross-crate positions this means that we forget the implied predicates from associated type bounds.

This isn't unsound, just kind of annoying. This should be backported since associated type bounds are slated to stabilize for 1.78 -- either that, or associated type bounds can be reverted on beta and re-shipped in 1.79 with this patch.

Fixes rust-lang#122859
@bors bors closed this as completed in 6a92312 Mar 24, 2024
RenjiSann pushed a commit to RenjiSann/rust that referenced this issue Mar 25, 2024
…cates-always, r=oli-obk

Encode implied predicates for traits

In rust-lang#112629, we decided to make associated type bounds in the "supertrait" AST position *implied* even though they're not supertraits themselves.

This means that the `super_predicates` and `implied_predicates` queries now differ for regular traits. The assumption that they didn't differ was hard-coded in rust-lang#107614, so in cross-crate positions this means that we forget the implied predicates from associated type bounds.

This isn't unsound, just kind of annoying. This should be backported since associated type bounds are slated to stabilize for 1.78 -- either that, or associated type bounds can be reverted on beta and re-shipped in 1.79 with this patch.

Fixes rust-lang#122859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants