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

Cross-crate RPITIT loses bounds #113155

Closed
Ltrlg opened this issue Jun 29, 2023 · 4 comments · Fixed by #113165
Closed

Cross-crate RPITIT loses bounds #113155

Ltrlg opened this issue Jun 29, 2023 · 4 comments · Fixed by #113165
Assignees
Labels
C-bug Category: This is a bug.

Comments

@Ltrlg
Copy link

Ltrlg commented Jun 29, 2023

Cross-crate

I tried this code:

a/src/lib.rs

#![feature(return_position_impl_trait_in_trait)]

pub trait A {
    fn get_iter(&self) -> impl Iterator<Item = ()>;
}

b/src/lib.rs

use a::A;

pub fn b(a: &impl A) -> usize {
    a.get_iter().count()
}

Compiled fine with 1.72.0-nightly (5ea666864 2023-06-27), but gives the following error with 1.72.0-nightly (5bd28f5ea 2023-06-28):

error[E0599]: `impl ?Sized` is not an iterator
 --> src/lib.rs:6:18
  |
4 |     a.get_iter().count()
  |                  ^^^^^ `impl ?Sized` is not an iterator
  |
  = note: the following trait bounds were not satisfied:
          `impl ?Sized: Iterator`
          which is required by `&mut impl ?Sized: Iterator`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `b` (lib) due to previous error

Single crate

My initial attempt at minimizing the case shown that the single-crate equivalent:

c/src/lib.rs

#![feature(return_position_impl_trait_in_trait)]

pub trait A {
    fn get_iter(&self) -> impl Iterator<Item = ()>;
}

pub fn b(a: &impl A) -> usize {
    a.get_iter().count()
}

compiles just fine.

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (5bd28f5ea 2023-06-28)
binary: rustc
commit-hash: 5bd28f5eac1ba3569bfa8d49ec3f5acbdfdff7a0
commit-date: 2023-06-28
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

EDIT: Reduced reproduction code.

@Ltrlg Ltrlg added the C-bug Category: This is a bug. label Jun 29, 2023
@Ltrlg Ltrlg changed the title Cross-crate RPITIT: impl ?Sized is not an iterator Cross-crate RPITIT loses bounds Jun 29, 2023
@lqd
Copy link
Member

lqd commented Jun 29, 2023

(This is a #![feature(return_position_impl_trait_in_trait)] issue that is fixed under -Zlower-impl-trait-in-trait-to-assoc-ty and #112988).

cc @spastorino: a nice test case to add.

@compiler-errors
Copy link
Member

compiler-errors commented Jun 29, 2023

@lqd: Why do you think this is a limitation of the current lowering? This should definitely work with the current lowering and ideally shouldn't be dependent on -Zlower-impl-trait-in-trait-to-assoc-ty. This is just a plain bug 🤣

@rustbot claim

@lqd
Copy link
Member

lqd commented Jun 29, 2023

The reason: incorrect eyeballing + complete ignorance of the subject matter, AKA saying stupid things 😅 .

Even better it it's fixable without requiring the new lowering.

@compiler-errors
Copy link
Member

compiler-errors commented Jun 29, 2023

This regressed in #98867, cc @cjgillot. I will fix this, but I hope that PR doesn't also regress other things, like the last time the encoding for certain items was reduced without sufficient tests :/

compiler-errors added a commit to compiler-errors/rust that referenced this issue Jun 30, 2023
…unds, r=spastorino

Encode item bounds for `DefKind::ImplTraitPlaceholder`

This was lost in a refactoring -- `hir::ItemKind::OpaqueTy` doesn't always map to `DefKind::Opaque`, specifically for RPITITs, so the check was migrated subtly wrong, and unfortunately I never had a test for this 🙃

Fixes rust-lang#113155

r? `@cjgillot`
@bors bors closed this as completed in c8f50ee Jun 30, 2023
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants