@@ -98,7 +98,11 @@ impl<S> TokenStream<S> {
9898 groups. push ( ( proc_macro:: Delimiter :: Parenthesis , range, vec ! [ ] ) )
9999 }
100100 rustc_lexer:: TokenKind :: CloseParen if * open_delim != Delimiter :: Parenthesis => {
101- return Err ( "Expected ')'" . to_owned ( ) ) ;
101+ return if * open_delim == Delimiter :: None {
102+ Err ( "Unexpected ')'" . to_owned ( ) )
103+ } else {
104+ Err ( "Expected ')'" . to_owned ( ) )
105+ } ;
102106 }
103107 rustc_lexer:: TokenKind :: CloseParen => {
104108 let ( delimiter, open_range, stream) = groups. pop ( ) . unwrap ( ) ;
@@ -122,7 +126,11 @@ impl<S> TokenStream<S> {
122126 groups. push ( ( proc_macro:: Delimiter :: Brace , range, vec ! [ ] ) )
123127 }
124128 rustc_lexer:: TokenKind :: CloseBrace if * open_delim != Delimiter :: Brace => {
125- return Err ( "Expected '}'" . to_owned ( ) ) ;
129+ return if * open_delim == Delimiter :: None {
130+ Err ( "Unexpected '}'" . to_owned ( ) )
131+ } else {
132+ Err ( "Expected '}'" . to_owned ( ) )
133+ } ;
126134 }
127135 rustc_lexer:: TokenKind :: CloseBrace => {
128136 let ( delimiter, open_range, stream) = groups. pop ( ) . unwrap ( ) ;
@@ -146,7 +154,11 @@ impl<S> TokenStream<S> {
146154 groups. push ( ( proc_macro:: Delimiter :: Bracket , range, vec ! [ ] ) )
147155 }
148156 rustc_lexer:: TokenKind :: CloseBracket if * open_delim != Delimiter :: Bracket => {
149- return Err ( "Expected ']'" . to_owned ( ) ) ;
157+ return if * open_delim == Delimiter :: None {
158+ Err ( "Unexpected ']'" . to_owned ( ) )
159+ } else {
160+ Err ( "Expected ']'" . to_owned ( ) )
161+ } ;
150162 }
151163 rustc_lexer:: TokenKind :: CloseBracket => {
152164 let ( delimiter, open_range, stream) = groups. pop ( ) . unwrap ( ) ;
@@ -223,10 +235,14 @@ impl<S> TokenStream<S> {
223235 }
224236 rustc_lexer:: TokenKind :: Whitespace => continue ,
225237 rustc_lexer:: TokenKind :: Frontmatter { .. } => unreachable ! ( ) ,
226- rustc_lexer:: TokenKind :: Unknown => return Err ( "Unknown token" . to_owned ( ) ) ,
227- rustc_lexer:: TokenKind :: UnknownPrefix => return Err ( "Unknown prefix" . to_owned ( ) ) ,
238+ rustc_lexer:: TokenKind :: Unknown => {
239+ return Err ( format ! ( "Unknown token: `{}`" , & s[ range] ) ) ;
240+ }
241+ rustc_lexer:: TokenKind :: UnknownPrefix => {
242+ return Err ( format ! ( "Unknown prefix: `{}`" , & s[ range] ) ) ;
243+ }
228244 rustc_lexer:: TokenKind :: UnknownPrefixLifetime => {
229- return Err ( "Unknown lifetime prefix" . to_owned ( ) ) ;
245+ return Err ( format ! ( "Unknown lifetime prefix: `{}`" , & s [ range ] ) ) ;
230246 }
231247 // FIXME: Error on edition >= 2024 ... I dont think the proc-macro server can fetch editions currently
232248 // and whose edition is this?
@@ -247,7 +263,9 @@ impl<S> TokenStream<S> {
247263 is_raw : false ,
248264 span : span. derive_ranged ( range) ,
249265 } ) ) ,
250- rustc_lexer:: TokenKind :: InvalidIdent => return Err ( "Invalid identifier" . to_owned ( ) ) ,
266+ rustc_lexer:: TokenKind :: InvalidIdent => {
267+ return Err ( format ! ( "Invalid identifier: `{}`" , & s[ range] ) ) ;
268+ }
251269 rustc_lexer:: TokenKind :: RawIdent => {
252270 let range = range. start + 2 ..range. end ;
253271 tokenstream. push ( TokenTree :: Ident ( Ident {
0 commit comments