From 3829f52b019ff6124a89648e36b7427cfb3111a8 Mon Sep 17 00:00:00 2001 From: bluss Date: Mon, 16 Sep 2019 19:51:59 +0200 Subject: [PATCH] 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![]); | ^^^^ --- src/slice.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slice.rs b/src/slice.rs index 85abfb8e0..53dbae0a3 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -612,6 +612,8 @@ macro_rules! s( (@convert $r:expr, $s:expr) => { <$crate::SliceOrIndex as ::std::convert::From<_>>::from($r).step_by($s as isize) }; + // Catch-all clause for syntax errors + (@parse $($t:tt)*) => { compile_error!("Invalid syntax in s![], expected at least one index or range") }; ($($t:tt)*) => { // The extra `*&` is a workaround for this compiler bug: // https://github.com/rust-lang/rust/issues/23014