-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix suggestions for &a: T
parameters
#97964
New issue
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
Merged
bors
merged 5 commits into
rust-lang:master
from
WaffleLapkin:fix_borrow_par_suggestions
Jun 16, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e9d49b2
Fix suggestions for `&a: T` parameters
WaffleLapkin 2411692
Make preconditions of `check_pat_ref` & `borrow_pat_suggestion` clearer
WaffleLapkin 451e030
Improve suggestion wording
WaffleLapkin dc2977e
check for inferred params in a clearer way
WaffleLapkin 33ccd76
Remove trailing whitespace
WaffleLapkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.