Fix #78549
Before #78430, string literals worked because `specialize_constructor` didn't actually care too much which constructor was passed to it unless needed. Since then, string literals are special cased and a bit hacky. I did not anticipate patterns for the `&str` type other than string literals, hence this bug. This makes string literals less hacky.
This commit is contained in:
parent
a53fb30e3b
commit
4cd30197eb
4 changed files with 75 additions and 22 deletions
|
|
@ -1,9 +1,9 @@
|
|||
fn main() {
|
||||
match "world" { //~ ERROR non-exhaustive patterns: `_`
|
||||
match "world" { //~ ERROR non-exhaustive patterns: `&_`
|
||||
"hello" => {}
|
||||
}
|
||||
|
||||
match "world" { //~ ERROR non-exhaustive patterns: `_`
|
||||
match "world" { //~ ERROR non-exhaustive patterns: `&_`
|
||||
ref _x if false => {}
|
||||
"hello" => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
error[E0004]: non-exhaustive patterns: `_` not covered
|
||||
error[E0004]: non-exhaustive patterns: `&_` not covered
|
||||
--> $DIR/issue-30240.rs:2:11
|
||||
|
|
||||
LL | match "world" {
|
||||
| ^^^^^^^ pattern `_` not covered
|
||||
| ^^^^^^^ pattern `&_` not covered
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
= note: the matched value is of type `&str`
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `_` not covered
|
||||
error[E0004]: non-exhaustive patterns: `&_` not covered
|
||||
--> $DIR/issue-30240.rs:6:11
|
||||
|
|
||||
LL | match "world" {
|
||||
| ^^^^^^^ pattern `_` not covered
|
||||
| ^^^^^^^ pattern `&_` not covered
|
||||
|
|
||||
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
|
||||
= note: the matched value is of type `&str`
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
// check-pass
|
||||
// From https://github.com/rust-lang/rust/issues/78549
|
||||
|
||||
fn main() {
|
||||
match "foo" {
|
||||
"foo" => {},
|
||||
&_ => {},
|
||||
}
|
||||
|
||||
match "foo" {
|
||||
&_ => {},
|
||||
"foo" => {},
|
||||
}
|
||||
|
||||
match ("foo", 0, "bar") {
|
||||
(&_, 0, &_) => {},
|
||||
("foo", _, "bar") => {},
|
||||
(&_, _, &_) => {},
|
||||
}
|
||||
|
||||
match (&"foo", "bar") {
|
||||
(&"foo", &_) => {},
|
||||
(&&_, &_) => {},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue