Auto merge of #38605 - estebank:fix-38371, r=nikomatsakis
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.
This commit is contained in:
commit
1ca100d042
6 changed files with 120 additions and 8 deletions
37
src/test/ui/mismatched_types/issue-38371.rs
Normal file
37
src/test/ui/mismatched_types/issue-38371.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
|
||||
struct Foo {
|
||||
}
|
||||
|
||||
fn foo(&foo: Foo) {
|
||||
}
|
||||
|
||||
fn bar(foo: Foo) {
|
||||
}
|
||||
|
||||
fn qux(foo: &Foo) {
|
||||
}
|
||||
|
||||
fn zar(&foo: &Foo) {
|
||||
}
|
||||
|
||||
fn agh(&&bar: &u32) {
|
||||
}
|
||||
|
||||
fn bgh(&&bar: u32) {
|
||||
}
|
||||
|
||||
fn ugh(&[bar]: &u32) {
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
36
src/test/ui/mismatched_types/issue-38371.stderr
Normal file
36
src/test/ui/mismatched_types/issue-38371.stderr
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-38371.rs:16:8
|
||||
|
|
||||
16 | fn foo(&foo: Foo) {
|
||||
| ^^^^ expected struct `Foo`, found reference
|
||||
|
|
||||
= note: expected type `Foo`
|
||||
= note: found type `&_`
|
||||
= help: did you mean `foo: &Foo`?
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-38371.rs:28:9
|
||||
|
|
||||
28 | fn agh(&&bar: &u32) {
|
||||
| ^^^^ expected u32, found reference
|
||||
|
|
||||
= note: expected type `u32`
|
||||
= note: found type `&_`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-38371.rs:31:8
|
||||
|
|
||||
31 | fn bgh(&&bar: u32) {
|
||||
| ^^^^^ expected u32, found reference
|
||||
|
|
||||
= note: expected type `u32`
|
||||
= note: found type `&_`
|
||||
|
||||
error[E0529]: expected an array or slice, found `u32`
|
||||
--> $DIR/issue-38371.rs:34:9
|
||||
|
|
||||
34 | fn ugh(&[bar]: &u32) {
|
||||
| ^^^^^ pattern cannot match with input type `u32`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue