mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Do not suggest introducing new binding when other suggestions are present
This commit is contained in:
@@ -138,6 +138,14 @@ pub fn unwrap_tag(self) -> Vec<CodeSuggestion> {
|
||||
Suggestions::Disabled => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
match self {
|
||||
Suggestions::Enabled(suggestions) => suggestions.len(),
|
||||
Suggestions::Sealed(suggestions) => suggestions.len(),
|
||||
Suggestions::Disabled => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Suggestions {
|
||||
|
||||
@@ -1644,7 +1644,9 @@ fn emit_bad_pat_path(
|
||||
return;
|
||||
}
|
||||
};
|
||||
if let [hir::PathSegment { ident, args: None, .. }] = segments {
|
||||
if let [hir::PathSegment { ident, args: None, .. }] = segments
|
||||
&& e.suggestions.len() == 0
|
||||
{
|
||||
e.span_label(span, format!("{} defined here", res.descr()));
|
||||
e.span_label(
|
||||
pat_span,
|
||||
|
||||
@@ -21,7 +21,6 @@ fn b(s: Option<S>) {
|
||||
S => {
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP try wrapping
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -32,7 +31,6 @@ fn c(s: Result<S, S>) {
|
||||
S => {
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP try wrapping
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,10 @@ LL | Foo::Bar(Bar { x }) => {
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/compatible-variants-in-pat.rs:21:9
|
||||
|
|
||||
LL | struct S;
|
||||
| -------- unit struct defined here
|
||||
...
|
||||
LL | match s {
|
||||
| - this expression has type `Option<S>`
|
||||
LL | S => {
|
||||
| ^
|
||||
| |
|
||||
| expected `Option<S>`, found `S`
|
||||
| `S` is interpreted as a unit struct, not a new binding
|
||||
| ^ expected `Option<S>`, found `S`
|
||||
|
|
||||
= note: expected enum `Option<S>`
|
||||
found struct `S`
|
||||
@@ -31,25 +25,14 @@ help: try wrapping the pattern in `Some`
|
||||
|
|
||||
LL | Some(S) => {
|
||||
| +++++ +
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - S => {
|
||||
LL + other_s => {
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/compatible-variants-in-pat.rs:32:9
|
||||
--> $DIR/compatible-variants-in-pat.rs:31:9
|
||||
|
|
||||
LL | struct S;
|
||||
| -------- unit struct defined here
|
||||
...
|
||||
LL | match s {
|
||||
| - this expression has type `Result<S, S>`
|
||||
LL | S => {
|
||||
| ^
|
||||
| |
|
||||
| expected `Result<S, S>`, found `S`
|
||||
| `S` is interpreted as a unit struct, not a new binding
|
||||
| ^ expected `Result<S, S>`, found `S`
|
||||
|
|
||||
= note: expected enum `Result<S, S>`
|
||||
found struct `S`
|
||||
@@ -59,11 +42,6 @@ LL | Ok(S) => {
|
||||
| +++ +
|
||||
LL | Err(S) => {
|
||||
| ++++ +
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - S => {
|
||||
LL + other_s => {
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
||||
@@ -20,14 +20,7 @@ LL | match t {
|
||||
| - this expression has type `Result<_, {integer}>`
|
||||
...
|
||||
LL | None => ()
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Result<_, {integer}>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Result<_, {integer}>`, found `Option<_>`
|
||||
|
|
||||
= note: expected enum `Result<_, {integer}>`
|
||||
found enum `Option<_>`
|
||||
@@ -35,11 +28,6 @@ help: try wrapping the pattern in `Ok`
|
||||
|
|
||||
LL | Ok(None) => ()
|
||||
| +++ +
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => ()
|
||||
LL + other_none => ()
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
None => {}
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
|
||||
match &x {
|
||||
@@ -18,7 +17,6 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
None => {}
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
|
||||
let mut y = Box::new(Some(1));
|
||||
@@ -29,7 +27,6 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
None => {}
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
|
||||
let mut z = Arc::new(Some(1));
|
||||
@@ -40,7 +37,6 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
None => {}
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
|
||||
let z_const: &Arc<Option<i32>> = &z;
|
||||
@@ -51,7 +47,6 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
None => {}
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
|
||||
// Normal reference because Arc doesn't implement DerefMut.
|
||||
@@ -63,7 +58,6 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
None => {}
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
|
||||
// Mutable reference because Box does implement DerefMut.
|
||||
@@ -75,7 +69,6 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
None => {}
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
|
||||
// Difficult expression.
|
||||
@@ -87,6 +80,5 @@ fn main() {
|
||||
//~^ ERROR mismatched types
|
||||
None => {}
|
||||
//~^ ERROR mismatched types
|
||||
//~| HELP introduce a new binding instead
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,7 @@ LL | match x {
|
||||
| - this expression has type `Arc<Option<{integer}>>`
|
||||
...
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Arc<Option<{integer}>>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Arc<Option<{integer}>>`, found `Option<_>`
|
||||
|
|
||||
= note: expected struct `Arc<Option<{integer}>>`
|
||||
found enum `Option<_>`
|
||||
@@ -36,14 +29,9 @@ help: consider dereferencing to access the inner value using the Deref trait
|
||||
|
|
||||
LL | match *x {
|
||||
| +
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => {}
|
||||
LL + other_none => {}
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:17:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:16:9
|
||||
|
|
||||
LL | match &x {
|
||||
| -- this expression has type `&Arc<Option<{integer}>>`
|
||||
@@ -59,20 +47,13 @@ LL | match &*x {
|
||||
| +
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:19:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:18:9
|
||||
|
|
||||
LL | match &x {
|
||||
| -- this expression has type `&Arc<Option<{integer}>>`
|
||||
...
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Arc<Option<{integer}>>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Arc<Option<{integer}>>`, found `Option<_>`
|
||||
|
|
||||
= note: expected struct `Arc<Option<{integer}>>`
|
||||
found enum `Option<_>`
|
||||
@@ -80,14 +61,9 @@ help: consider dereferencing to access the inner value using the Deref trait
|
||||
|
|
||||
LL | match &*x {
|
||||
| +
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => {}
|
||||
LL + other_none => {}
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:28:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:26:9
|
||||
|
|
||||
LL | match y {
|
||||
| - this expression has type `Box<Option<{integer}>>`
|
||||
@@ -103,20 +79,13 @@ LL | match *y {
|
||||
| +
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:30:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:28:9
|
||||
|
|
||||
LL | match y {
|
||||
| - this expression has type `Box<Option<{integer}>>`
|
||||
...
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Box<Option<{integer}>>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Box<Option<{integer}>>`, found `Option<_>`
|
||||
|
|
||||
= note: expected struct `Box<Option<{integer}>>`
|
||||
found enum `Option<_>`
|
||||
@@ -124,14 +93,9 @@ help: consider dereferencing to access the inner value using the Deref trait
|
||||
|
|
||||
LL | match *y {
|
||||
| +
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => {}
|
||||
LL + other_none => {}
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:39:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:36:9
|
||||
|
|
||||
LL | match z as Arc<Option<i32>> {
|
||||
| --------------------- this expression has type `Arc<Option<i32>>`
|
||||
@@ -148,20 +112,13 @@ LL + match *(z as Arc<Option<i32>>) {
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:41:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:38:9
|
||||
|
|
||||
LL | match z as Arc<Option<i32>> {
|
||||
| --------------------- this expression has type `Arc<Option<i32>>`
|
||||
...
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Arc<Option<i32>>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Arc<Option<i32>>`, found `Option<_>`
|
||||
|
|
||||
= note: expected struct `Arc<Option<i32>>`
|
||||
found enum `Option<_>`
|
||||
@@ -170,14 +127,9 @@ help: consider dereferencing to access the inner value using the Deref trait
|
||||
LL - match z as Arc<Option<i32>> {
|
||||
LL + match *(z as Arc<Option<i32>>) {
|
||||
|
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => {}
|
||||
LL + other_none => {}
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:50:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:46:9
|
||||
|
|
||||
LL | match z_const {
|
||||
| ------- this expression has type `&Arc<Option<i32>>`
|
||||
@@ -193,20 +145,13 @@ LL | match &**z_const {
|
||||
| +++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:52:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:48:9
|
||||
|
|
||||
LL | match z_const {
|
||||
| ------- this expression has type `&Arc<Option<i32>>`
|
||||
...
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Arc<Option<i32>>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Arc<Option<i32>>`, found `Option<_>`
|
||||
|
|
||||
= note: expected struct `Arc<Option<i32>>`
|
||||
found enum `Option<_>`
|
||||
@@ -214,14 +159,9 @@ help: consider dereferencing to access the inner value using the Deref trait
|
||||
|
|
||||
LL | match &**z_const {
|
||||
| +++
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => {}
|
||||
LL + other_none => {}
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:62:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:57:9
|
||||
|
|
||||
LL | match z_mut {
|
||||
| ----- this expression has type `&mut Arc<Option<i32>>`
|
||||
@@ -237,20 +177,13 @@ LL | match &**z_mut {
|
||||
| +++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:64:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:59:9
|
||||
|
|
||||
LL | match z_mut {
|
||||
| ----- this expression has type `&mut Arc<Option<i32>>`
|
||||
...
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Arc<Option<i32>>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Arc<Option<i32>>`, found `Option<_>`
|
||||
|
|
||||
= note: expected struct `Arc<Option<i32>>`
|
||||
found enum `Option<_>`
|
||||
@@ -258,14 +191,9 @@ help: consider dereferencing to access the inner value using the Deref trait
|
||||
|
|
||||
LL | match &**z_mut {
|
||||
| +++
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => {}
|
||||
LL + other_none => {}
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:74:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:68:9
|
||||
|
|
||||
LL | match y_mut {
|
||||
| ----- this expression has type `&mut Box<Option<i32>>`
|
||||
@@ -281,20 +209,13 @@ LL | match &**y_mut {
|
||||
| +++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:76:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:70:9
|
||||
|
|
||||
LL | match y_mut {
|
||||
| ----- this expression has type `&mut Box<Option<i32>>`
|
||||
...
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Box<Option<i32>>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Box<Option<i32>>`, found `Option<_>`
|
||||
|
|
||||
= note: expected struct `Box<Option<i32>>`
|
||||
found enum `Option<_>`
|
||||
@@ -302,14 +223,9 @@ help: consider dereferencing to access the inner value using the Deref trait
|
||||
|
|
||||
LL | match &**y_mut {
|
||||
| +++
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => {}
|
||||
LL + other_none => {}
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:86:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:79:9
|
||||
|
|
||||
LL | match (& (&difficult) ) {
|
||||
| ------------------ this expression has type `&&Arc<Option<{integer}>>`
|
||||
@@ -326,20 +242,13 @@ LL + match &*difficult {
|
||||
|
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:88:9
|
||||
--> $DIR/suggest-deref-in-match-issue-132784.rs:81:9
|
||||
|
|
||||
LL | match (& (&difficult) ) {
|
||||
| ------------------ this expression has type `&&Arc<Option<{integer}>>`
|
||||
...
|
||||
LL | None => {}
|
||||
| ^^^^
|
||||
| |
|
||||
| expected `Arc<Option<{integer}>>`, found `Option<_>`
|
||||
| `None` is interpreted as a unit variant, not a new binding
|
||||
|
|
||||
--> $SRC_DIR/core/src/option.rs:LL:COL
|
||||
|
|
||||
= note: unit variant defined here
|
||||
| ^^^^ expected `Arc<Option<{integer}>>`, found `Option<_>`
|
||||
|
|
||||
= note: expected struct `Arc<Option<{integer}>>`
|
||||
found enum `Option<_>`
|
||||
@@ -348,11 +257,6 @@ help: consider dereferencing to access the inner value using the Deref trait
|
||||
LL - match (& (&difficult) ) {
|
||||
LL + match &*difficult {
|
||||
|
|
||||
help: introduce a new binding instead
|
||||
|
|
||||
LL - None => {}
|
||||
LL + other_none => {}
|
||||
|
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user