Skip to content

Error for mismatched types involving generics seems to be missing something #78206

Closed

Description

pub fn f<T>(a: &T) -> *const T {
    &1 as *const i32
}

(Playground)

The error includes a label that says "this type parameter", but it doesn't complete the sentence:

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
1 | pub fn f<T>(a: &T) -> *const T {
  |          -            -------- expected `*const T` because of return type
  |          |
  |          this type parameter
2 |     &1 as *const i32
  |     ^^^^^^^^^^^^^^^^ expected type parameter `T`, found `i32`
  |
  = note: expected raw pointer `*const T`
             found raw pointer `*const i32`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-typesystemArea: The type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions