We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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`.
The text was updated successfully, but these errors were encountered:
Well, that code is actually syntactically correct, it just doesn't type-check.
For example, this works:
#[derive(Copy, Clone)] struct Foo; fn foo(&foo: &Foo) { // legal syntax } fn main() { println!("Hello, world!"); }
And is equivalent to:
#[derive(Copy, Clone)] struct Foo; fn foo(foo_ref: &Foo) { let foo = *foo_ref; } fn main() { println!("Hello, world!"); }
Sorry, something went wrong.
OK. I was just following @dherman's instructions to file here, so I'll defer to those who know better than me.
@ekr yeah, reporting here was the right thing to do. This is confusing and deserves a "did you mean foo: &Foo?".
foo: &Foo
fn foo(&foo: Foo)
Auto merge of #38605 - estebank:fix-38371, r=nikomatsakis
1ca100d
Suggest solutions for `fn foo(&foo: Foo)` For a given file: ```rust struct Foo {} fn foo(&foo: Foo) {} ``` suggest: ``` error[E0308]: mismatched types --> file.rs:3:8 | 3 | fn foo(&foo: Foo) {} | ^^^^ expected struct `Foo`, found reference | = note: expected type `Foo` = note: found type `&_` = help: did you mean `foo: &Foo`? ``` Fix #38371.
No branches or pull requests
See the following code fragment:
This generates the following confusing error:
The text was updated successfully, but these errors were encountered: