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

cannot infer type of the type parameter 'a declared on the trait Baz #109905

Closed
justinlovinger opened this issue Apr 3, 2023 · 1 comment · Fixed by #109957
Closed

cannot infer type of the type parameter 'a declared on the trait Baz #109905

justinlovinger opened this issue Apr 3, 2023 · 1 comment · Fixed by #109957
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@justinlovinger
Copy link

justinlovinger commented Apr 3, 2023

Code

use std::{borrow::Borrow, marker::PhantomData};

pub struct Foo<Borrowed, B> {
    borrowed: PhantomData<Borrowed>,
    y: B,
}

pub struct Bar<A, Borrowed, B, C> {
    x: PhantomData<A>,
    borrowed: PhantomData<Borrowed>,
    y: PhantomData<B>,
    z: C,
}

pub trait Baz<'a, D, B> {
    fn baz(&'a self) -> &'a B;
}

impl<'a, A, Borrowed, B, C> Baz<'a, Bar<A, Borrowed, B, C>, Borrowed> for C
where
    B: Borrow<Borrowed> + 'a,
    C: Borrow<Foo<Borrowed, B>>,
{
    fn baz(&'a self) -> &'a Borrowed {
        self.borrow().y.borrow()
    }
}

// fn foobar<Borrowed, B>(foo: &Foo<Borrowed, B>)
// where
//     B: Borrow<Borrowed>,
// {
//     foo.baz();
// }

fn foobar<'a, Borrowed, B>(foo: &'a Foo<Borrowed, B>)
where
    B: Borrow<Borrowed>,
{
    <Foo<Borrowed, B> as Baz<'a, _, _>>::baz(foo);
}

Meta

rustc --version --verbose:

rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
release: 1.66.1
LLVM version: 15.0.2

This was also tried on with 1.70.0-nightly (2023-04-02 3a8a131e9509c478ece1) on Rust Playground, with the same error.

Error output

error[E0282]: type annotations needed
  --> src/lib.rs:40:5
   |
40 |     <Foo<Borrowed, B> as Baz<'a, _, _>>::baz(foo);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `'a` declared on the trait `Baz`
Backtrace

error[E0282]: type annotations needed
  --> src/lib.rs:40:5
   |
40 |     <Foo<Borrowed, B> as Baz<'a, _, _>>::baz(foo);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `'a` declared on the trait `Baz`

Note

Without the fully qualified path, see commented code, the error is error[E0282]: type annotations needed.

@justinlovinger justinlovinger added C-bug Category: This is a bug. 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. labels Apr 3, 2023
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Apr 3, 2023
@fmease
Copy link
Member

fmease commented Apr 3, 2023

Minimized:

trait Trait<'a, T> {
    fn m();
}

impl<'a, A> Trait<'a, A> for () {
    fn m() {}
}

fn main() {
    <() as Trait<'static, _>>::m();
}
error[E0282]: type annotations needed
  --> input.rs:10:5
   |
10 |     <() as Trait<'static, _>>::m();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `'a` declared on the trait `Trait`

error: aborting due to previous error

Looking into this.
@rustbot claim
@rustbot label D-incorrect

@rustbot rustbot added the D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. label Apr 3, 2023
@Noratrieb Noratrieb changed the title ICE: cannot infer type of the type parameter 'a declared on the trait Baz cannot infer type of the type parameter 'a declared on the trait Baz Apr 5, 2023
@bors bors closed this as completed in e63586f Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. 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