-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #45947 - estebank:match_default_bindings-arg-hint, r=ar…
…ielb1 Be more obvious when suggesting dereference Include `&` span when suggesting dereference on a span that is already a reference: ``` error: non-reference pattern used to match a reference (see issue #42640) --> dont-suggest-dereference-on-arg.rs:16:19 | 16 | .filter(|&(ref a, _)| foo(a)) | ^^^^^^^^^^^ help: consider using: `&&(ref k, _)` | = help: add #![feature(match_default_bindings)] to the crate attributes to enable ``` Fix #45925.
- Loading branch information
Showing
4 changed files
with
53 additions
and
4 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
21 changes: 21 additions & 0 deletions
21
src/test/ui/suggestions/dont-suggest-dereference-on-arg.rs
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 @@ | ||
// 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. | ||
|
||
fn foo(s: &str) -> bool { true } | ||
|
||
fn main() { | ||
let x = vec![(String::new(), String::new())]; | ||
x.iter() | ||
.filter(|&(ref a, _)| foo(a)) | ||
//~^ ERROR non-reference pattern used to match a reference | ||
//~| HELP consider using a reference | ||
//~| HELP add | ||
.collect(); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/suggestions/dont-suggest-dereference-on-arg.stderr
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,10 @@ | ||
error: non-reference pattern used to match a reference (see issue #42640) | ||
--> $DIR/dont-suggest-dereference-on-arg.rs:16:18 | ||
| | ||
16 | .filter(|&(ref a, _)| foo(a)) | ||
| ^^^^^^^^^^^ help: consider using a reference: `&&(ref a, _)` | ||
| | ||
= help: add #![feature(match_default_bindings)] to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|