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 bounds on Self with generic parameter precludes other uses of that trait on Self #90841

Closed
HactarCE opened this issue Nov 12, 2021 · 1 comment
Labels
C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@HactarCE
Copy link
Contributor

I tried this code:

struct S;

trait T<V> {
    fn t(_: V) {}
}

impl T<()> for S {}

impl S {
    fn f1() {
        S::t(())
    }
    
    fn f2<V>()
    where
        Self: T<V>,
    {
        S::t(())
    }
    
    fn f3<V>()
    where
        Self: T<V> + T<()>,
    {
        S::t(())
    }
}

Try it on the Rust Playground

I expected to see this happen: All functions should compile with no error.

Instead, this happened: The following error was produced by rustc:

error[E0308]: mismatched types
  --> src/lib.rs:18:14
   |
14 |     fn f2<V>()
   |           - this type parameter
...
18 |         S::t(())
   |              ^^ expected type parameter `V`, found `()`
   |
   = note: expected type parameter `V`
                   found unit type `()`

Meta

rustc --version --verbose:

rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-pc-windows-msvc
release: 1.56.0
LLVM version: 13.0.0

This bug also occurs on the nightly and stable versions on the playground.

Coming up with a title for this issue was really tricky; if anyone can come up with a better one, please replace it.

@HactarCE HactarCE added the C-bug Category: This is a bug. label Nov 12, 2021
@fmease fmease added A-trait-system Area: Trait system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-inference Area: Type inference T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage-legacy A-inference Area: Type inference labels Jan 26, 2024
@fmease
Copy link
Member

fmease commented Jan 26, 2024

Closing as duplicate of #24066. If you disagree with my assessment I will of course reopen this issue.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2024
@fmease fmease removed the A-trait-system Area: Trait system label Dec 21, 2024
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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