-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #97964 - WaffleLapkin:fix_borrow_par_suggestions, r=c…
…ompiler-errors Fix suggestions for `&a: T` parameters I've accidentally discovered that we have broken suggestions for `&a: T` parameters: ```rust fn f(&mut bar: u32) {} fn main() { let _ = |&mut a| (); } ``` ```text error[E0308]: mismatched types --> ./t.rs:1:6 | 1 | fn f(&mut bar: u32) {} | ^^^^^^^^----- | | | | | expected due to this | expected `u32`, found `&mut _` | help: did you mean `bar`: `&u32` | = note: expected type `u32` found mutable reference `&mut _` error[E0308]: mismatched types --> ./t.rs:4:23 | 4 | let _: fn(u32) = |&mut a| (); | ^^^^^-- | | | | | expected due to this | expected `u32`, found `&mut _` | help: did you mean `a`: `&u32` | = note: expected type `u32` found mutable reference `&mut _` ``` It's hard to see, but 1. The help span is overlapping with "expected" spans 2. It suggests `fn f( &u32) {}` (no `mut` and lost parameter name) and `|&u32 ()` (no closing `|` and lost parameter name) I've tried to fix this. r? ``@compiler-errors``
- Loading branch information
Showing
12 changed files
with
480 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fn ugh(&[bar]: &u32) {} //~ ERROR expected an array or slice | ||
|
||
fn bgh(&&bar: u32) {} //~ ERROR mismatched types | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0529]: expected an array or slice, found `u32` | ||
--> $DIR/issue-38371-unfixable.rs:1:9 | ||
| | ||
LL | fn ugh(&[bar]: &u32) {} | ||
| ^^^^^ pattern cannot match with input type `u32` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-38371-unfixable.rs:3:8 | ||
| | ||
LL | fn bgh(&&bar: u32) {} | ||
| ^^^^^ --- expected due to this | ||
| | | ||
| expected `u32`, found reference | ||
| | ||
= note: expected type `u32` | ||
found reference `&_` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0529. | ||
For more information about an error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// run-rustfix | ||
// see also issue-38371-unfixable.rs | ||
#![allow(dead_code)] | ||
|
||
#[derive(Copy, Clone)] | ||
struct Foo {} | ||
|
||
fn foo(_a: &Foo) {} //~ ERROR mismatched types | ||
|
||
fn bar(_a: Foo) {} | ||
|
||
fn qux(_a: &Foo) {} | ||
|
||
fn zar(&_a: &Foo) {} | ||
|
||
fn agh(&_a: &u32) {} //~ ERROR mismatched types | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,18 @@ | ||
struct Foo { | ||
} | ||
// run-rustfix | ||
// see also issue-38371-unfixable.rs | ||
#![allow(dead_code)] | ||
|
||
fn foo(&foo: Foo) { //~ ERROR mismatched types | ||
} | ||
#[derive(Copy, Clone)] | ||
struct Foo {} | ||
|
||
fn bar(foo: Foo) { | ||
} | ||
fn foo(&_a: Foo) {} //~ ERROR mismatched types | ||
|
||
fn qux(foo: &Foo) { | ||
} | ||
fn bar(_a: Foo) {} | ||
|
||
fn zar(&foo: &Foo) { | ||
} | ||
fn qux(_a: &Foo) {} | ||
|
||
// The somewhat unexpected help message in this case is courtesy of | ||
// match_default_bindings. | ||
fn agh(&&bar: &u32) { //~ ERROR mismatched types | ||
} | ||
fn zar(&_a: &Foo) {} | ||
|
||
fn bgh(&&bar: u32) { //~ ERROR mismatched types | ||
} | ||
|
||
fn ugh(&[bar]: &u32) { //~ ERROR expected an array or slice | ||
} | ||
fn agh(&&_a: &u32) {} //~ ERROR mismatched types | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,35 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-38371.rs:4:8 | ||
--> $DIR/issue-38371.rs:8:8 | ||
| | ||
LL | fn foo(&foo: Foo) { | ||
| ^^^^----- | ||
| | | | ||
| | expected due to this | ||
LL | fn foo(&_a: Foo) {} | ||
| ^^^ --- expected due to this | ||
| | | ||
| expected struct `Foo`, found reference | ||
| help: did you mean `foo`: `&Foo` | ||
| | ||
= note: expected struct `Foo` | ||
found reference `&_` | ||
help: to take parameter `_a` by reference, move `&` to the type | ||
| | ||
LL - fn foo(&_a: Foo) {} | ||
LL + fn foo(_a: &Foo) {} | ||
| | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-38371.rs:18:9 | ||
--> $DIR/issue-38371.rs:16:9 | ||
| | ||
LL | fn agh(&&bar: &u32) { | ||
| ^^^^ ---- expected due to this | ||
LL | fn agh(&&_a: &u32) {} | ||
| ^^^ ---- expected due to this | ||
| | | ||
| expected `u32`, found reference | ||
| help: you can probably remove the explicit borrow: `bar` | ||
| | ||
= note: expected type `u32` | ||
found reference `&_` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-38371.rs:21:8 | ||
| | ||
LL | fn bgh(&&bar: u32) { | ||
| ^^^^^ --- expected due to this | ||
| | | ||
| expected `u32`, found reference | ||
| | ||
= note: expected type `u32` | ||
found reference `&_` | ||
|
||
error[E0529]: expected an array or slice, found `u32` | ||
--> $DIR/issue-38371.rs:24:9 | ||
help: consider removing `&` from the pattern | ||
| | ||
LL | fn ugh(&[bar]: &u32) { | ||
| ^^^^^ pattern cannot match with input type `u32` | ||
LL - fn agh(&&_a: &u32) {} | ||
LL + fn agh(&_a: &u32) {} | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0529. | ||
For more information about an error, try `rustc --explain E0308`. | ||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// run-rustfix | ||
|
||
fn _f0(_a: &u32) {} //~ ERROR mismatched types | ||
fn _f1(_a: &mut u32) {} //~ ERROR mismatched types | ||
fn _f2(&_a: &u32) {} //~ ERROR mismatched types | ||
fn _f3(&mut _a: &mut u32) {} //~ ERROR mismatched types | ||
fn _f4(&_a: &u32) {} //~ ERROR mismatched types | ||
fn _f5(&mut _a: &mut u32) {} //~ ERROR mismatched types | ||
|
||
fn main() { | ||
let _: fn(u32) = |_a| (); //~ ERROR mismatched types | ||
let _: fn(u32) = |_a| (); //~ ERROR mismatched types | ||
let _: fn(&u32) = |&_a| (); //~ ERROR mismatched types | ||
let _: fn(&mut u32) = |&mut _a| (); //~ ERROR mismatched types | ||
let _: fn(&u32) = |&_a| (); //~ ERROR mismatched types | ||
let _: fn(&mut u32) = |&mut _a| (); //~ ERROR mismatched types | ||
|
||
let _ = |_a: &u32| (); //~ ERROR mismatched types | ||
let _ = |_a: &mut u32| (); //~ ERROR mismatched types | ||
let _ = |&_a: &u32| (); //~ ERROR mismatched types | ||
let _ = |&mut _a: &mut u32| (); //~ ERROR mismatched types | ||
let _ = |&_a: &u32| (); //~ ERROR mismatched types | ||
let _ = |&mut _a: &mut u32| (); //~ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// run-rustfix | ||
|
||
fn _f0(&_a: u32) {} //~ ERROR mismatched types | ||
fn _f1(&mut _a: u32) {} //~ ERROR mismatched types | ||
fn _f2(&&_a: &u32) {} //~ ERROR mismatched types | ||
fn _f3(&mut &_a: &mut u32) {} //~ ERROR mismatched types | ||
fn _f4(&&mut _a: &u32) {} //~ ERROR mismatched types | ||
fn _f5(&mut &mut _a: &mut u32) {} //~ ERROR mismatched types | ||
|
||
fn main() { | ||
let _: fn(u32) = |&_a| (); //~ ERROR mismatched types | ||
let _: fn(u32) = |&mut _a| (); //~ ERROR mismatched types | ||
let _: fn(&u32) = |&&_a| (); //~ ERROR mismatched types | ||
let _: fn(&mut u32) = |&mut &_a| (); //~ ERROR mismatched types | ||
let _: fn(&u32) = |&&mut _a| (); //~ ERROR mismatched types | ||
let _: fn(&mut u32) = |&mut &mut _a| (); //~ ERROR mismatched types | ||
|
||
let _ = |&_a: u32| (); //~ ERROR mismatched types | ||
let _ = |&mut _a: u32| (); //~ ERROR mismatched types | ||
let _ = |&&_a: &u32| (); //~ ERROR mismatched types | ||
let _ = |&mut &_a: &mut u32| (); //~ ERROR mismatched types | ||
let _ = |&&mut _a: &u32| (); //~ ERROR mismatched types | ||
let _ = |&mut &mut _a: &mut u32| (); //~ ERROR mismatched types | ||
} |
Oops, something went wrong.