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

Trait resolution on associated type breaks with type inference for references #94358

Open
Veetaha opened this issue Feb 25, 2022 · 2 comments
Open
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Feb 25, 2022

I tried this code (playground):

fn foo<C>(_: C)
where
    for <'a> &'a C: IntoIterator,
    for <'a> <&'a C as IntoIterator>::IntoIter: ExactSizeIterator,
{}

fn main() {
    foo::<_>(vec![true, false]);
    // But this compiles fine
    // foo::<Vec<bool>>(vec![true, false]);
}

I expected this to compile just fine.
Instead, the following error is produced:

 Compiling ref-into-inter-infer v0.1.0 (/home/veetaha/junk/rust-sandbox/crates/ref-into-inter-infer)
error[E0277]: the trait bound `for<'a> <&'a _ as IntoIterator>::IntoIter: ExactSizeIterator` is not satisfied
 --> crates/ref-into-inter-infer/src/main.rs:8:5
  |
8 |     foo::<_>(vec![true, false]);
  |     ^^^^^^^^ the trait `for<'a> ExactSizeIterator` is not implemented for `<&'a _ as IntoIterator>::IntoIter`
  |
  = help: the following implementations were found:
            <&mut I as ExactSizeIterator>
note: required by a bound in `foo`
 --> crates/ref-into-inter-infer/src/main.rs:4:49
  |
1 | fn foo<C>(_: C)
  |    --- required by a bound in this
...
4 |     for <'a> <&'a C as IntoIterator>::IntoIter: ExactSizeIterator,
  |                                                 ^^^^^^^^^^^^^^^^^ required by this bound in `foo`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `ref-into-inter-infer` due to previous error

Note that when an explicit type is specified in generic parameters, the code compiles just fine.

Meta

rustc --version --verbose:

rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-unknown-linux-gnu
release: 1.58.1
LLVM version: 13.0.0
@Veetaha Veetaha added the C-bug Category: This is a bug. label Feb 25, 2022
@compiler-errors
Copy link
Member

@jackh726 i wonder if this is fixed by the fulfillment normalization PR. i can test later today.

@jackh726
Copy link
Member

Probably not. I think this is #90950

@compiler-errors compiler-errors added the fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. label Mar 13, 2023
@fmease fmease added A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system A-associated-items Area: Associated items (types, constants & functions) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system C-bug Category: This is a bug. fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. 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