Skip to content

Commit fcabfa9

Browse files
committed
add an help message when using an old-style slice pattern
1 parent 5cf4139 commit fcabfa9

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/librustc_typeck/check/_match.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,20 @@ impl<'a, 'gcx, 'tcx> PatCtxt<'a, 'gcx, 'tcx> {
345345
ty::TySlice(inner_ty) => (inner_ty, expected_ty),
346346
_ => {
347347
if !expected_ty.references_error() {
348-
span_err!(tcx.sess, pat.span, E0529,
349-
"expected an array or slice, found `{}`",
350-
expected_ty);
348+
let mut err = struct_span_err!(
349+
tcx.sess, pat.span, E0529,
350+
"expected an array or slice, found `{}`",
351+
expected_ty);
352+
if let ty::TyRef(_, ty::TypeAndMut { mutbl: _, ty }) = expected_ty.sty {
353+
match ty.sty {
354+
ty::TyArray(..) | ty::TySlice(..) => {
355+
err.help("the semantics of slice patterns changed \
356+
recently; see issue #23121");
357+
}
358+
_ => {}
359+
}
360+
}
361+
err.emit();
351362
}
352363
(tcx.types.err, tcx.types.err)
353364
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(slice_patterns)]
12+
13+
fn slice_pat(x: &[u8]) {
14+
// OLD!
15+
match x {
16+
[a, b..] => {}
17+
//~^ ERROR expected an array or slice, found `&[u8]`
18+
//~| HELP the semantics of slice patterns changed recently; see issue #23121
19+
}
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)