Skip to content

Commit 08baec4

Browse files
committed
add a test for byte string literal pattern mutability mismatches
1 parent 191df20 commit 08baec4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Byte string literal patterns use the mutability of the literal, rather than the mutability of
2+
//! the pattern's scrutinee. Since byte string literals are always shared references, it's a
3+
//! mismatch to use a byte string literal pattern to match on a mutable array or slice reference.
4+
5+
fn main() {
6+
let mut val = [97u8, 10u8];
7+
match &mut val {
8+
b"a\n" => {},
9+
//~^ ERROR mismatched types
10+
//~| types differ in mutability
11+
_ => {},
12+
}
13+
match &mut val[..] {
14+
b"a\n" => {},
15+
//~^ ERROR mismatched types
16+
//~| types differ in mutability
17+
_ => {},
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/byte-string-mutability-mismatch.rs:8:9
3+
|
4+
LL | match &mut val {
5+
| -------- this expression has type `&mut [u8; 2]`
6+
LL | b"a\n" => {},
7+
| ^^^^^^ types differ in mutability
8+
|
9+
= note: expected mutable reference `&mut _`
10+
found reference `&'static _`
11+
12+
error[E0308]: mismatched types
13+
--> $DIR/byte-string-mutability-mismatch.rs:14:10
14+
|
15+
LL | match &mut val[..] {
16+
| ------------ this expression has type `&mut [u8]`
17+
LL | b"a\n" => {},
18+
| ^^^^^^ types differ in mutability
19+
|
20+
= note: expected mutable reference `&mut _`
21+
found reference `&'static _`
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)