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

rustc fails to resolve trait implementation #84548

Closed
BusyJay opened this issue Apr 25, 2021 · 1 comment
Closed

rustc fails to resolve trait implementation #84548

BusyJay opened this issue Apr 25, 2021 · 1 comment
Labels
A-inference Area: Type inference A-traits Area: Trait system C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@BusyJay
Copy link

BusyJay commented Apr 25, 2021

I tried this code:

trait A<T> {
    fn a() -> T;
}

pub struct GlobalA;

impl A<usize> for GlobalA {
    fn a() -> usize {
        0
    }
}

pub struct GlobalB;

impl<T> A<Vec<T>> for GlobalB
where GlobalA: A<T>
{
    fn a() -> Vec<T> {
        let s: usize = GlobalA::a();
        let mut v = Vec::with_capacity(s);
        for _ in 0..s {
            v.push(GlobalA::a());
        }
        v
    }
}

I expected to see this happen:
Compile successfully.

Instead, this happened:

error[E0308]: mismatched types
  --> src/lib.rs:19:24
   |
15 | impl<T> A<Vec<T>> for GlobalB
   |      - this type parameter
...
19 |         let s: usize = GlobalA::a();
   |                -----   ^^^^^^^^^^^^ expected `usize`, found type parameter `T`
   |                |
   |                expected due to this
   |
   = note:        expected type `usize`
           found type parameter `T`

error: aborting due to previous error

Wrote <GlobalA as A<usize>>::a() as a workaround.

Meta

rustc --version --verbose:

rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: aarch64-apple-darwin
release: 1.51.0
LLVM version: 11.0.1
Backtrace

<backtrace>

@BusyJay BusyJay added the C-bug Category: This is a bug. label Apr 25, 2021
@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@fmease fmease added A-traits Area: Trait system T-types Relevant to the types team, which will review and decide on the PR/issue. A-inference Area: Type inference and removed needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. labels Jan 23, 2024
@fmease
Copy link
Member

fmease commented Jan 23, 2024

Closing as duplicate of #24066.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference A-traits Area: Trait system C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants