Skip to content

Commit 3829f52

Browse files
committed
FEAT: Add error message for invalid syntax in s![]
Invalid syntax, like for example empty `s![]` or clearly invalid productions like `s![;;]` etc, end up in this new catch-all branch of the macro and produce a clearer error message. error: Invalid syntax in s![], expected at least one index or range --> src/foo.rs:11:13 | 11 | a.slice(s![]); | ^^^^
1 parent f489851 commit 3829f52

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/slice.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ macro_rules! s(
612612
(@convert $r:expr, $s:expr) => {
613613
<$crate::SliceOrIndex as ::std::convert::From<_>>::from($r).step_by($s as isize)
614614
};
615+
// Catch-all clause for syntax errors
616+
(@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![], expected at least one index or range") };
615617
($($t:tt)*) => {
616618
// The extra `*&` is a workaround for this compiler bug:
617619
// https://github.com/rust-lang/rust/issues/23014

0 commit comments

Comments
 (0)