Skip to content

Bad compile error with fun bar(&foo: Foo) syntax #38371

Closed
@ekr

Description

@ekr

See the following code fragment:

struct Foo {
}

fn foo(&foo: Foo) {  // illegal syntax
}

fn main() {
    println!("Hello, world!");
}

This generates the following confusing error:

15:29:19|~/tmp/rust_compile_error (master)$ cargo build
   Compiling rust_compile_error v0.1.0 (file:///Users/ekr/tmp/rust_compile_error)
error[E0308]: mismatched types
 --> src/main.rs:4:8
  |
4 | fn foo(&foo: Foo) {
  |        ^^^^ expected struct `Foo`, found reference
  |
  = note: expected type `Foo`
  = note:    found type `&_`

error: aborting due to previous error

error: Could not compile `rust_compile_error`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions