1
- use core:: panic;
2
1
use std:: fmt:: { Debug , Display } ;
3
2
use std:: iter:: Peekable ;
4
3
@@ -231,7 +230,7 @@ impl<'a> Debug for MetaItemParser<'a> {
231
230
232
231
impl < ' a > MetaItemParser < ' a > {
233
232
/// Create a new parser from a [`NormalAttr`], which is stored inside of any
234
- /// [`ast::Attribute`](Attribute)
233
+ /// [`ast::Attribute`](rustc_ast:: Attribute)
235
234
pub fn from_attr ( attr : & ' a NormalAttr , dcx : DiagCtxtHandle < ' a > ) -> Self {
236
235
Self {
237
236
path : PathParser :: Ast ( & attr. item . path ) ,
@@ -268,8 +267,6 @@ impl<'a> MetaItemParser<'a> {
268
267
/// - `#[rustfmt::skip]`: `rustfmt::skip` is a path
269
268
/// - `#[allow(clippy::complexity)]`: `clippy::complexity` is a path
270
269
/// - `#[inline]`: `inline` is a single segment path
271
- /// - `#[inline(always)]`: `always` is a single segment path, but `inline` is *not and
272
- /// should be parsed using [`list`](Self::list)
273
270
pub fn path ( & self ) -> ( PathParser < ' a > , & ArgParser < ' a > ) {
274
271
self . deconstruct ( )
275
272
}
@@ -291,11 +288,8 @@ impl<'a> MetaItemParser<'a> {
291
288
///
292
289
/// Some examples:
293
290
/// - `#[inline]`: `inline` is a word
294
- /// - `#[rustfmt::skip]`: `rustfmt::skip` is a path, and not a word
295
- /// - `#[inline(always)]`: `always` is a word, but `inline` is *not and should be parsed
296
- /// using [`path_list`](Self::path_list)
297
- /// - `#[allow(clippy::complexity)]`: `clippy::complexity` is *not* a word, and should instead be parsed
298
- /// using [`path`](Self::path)
291
+ /// - `#[rustfmt::skip]`: `rustfmt::skip` is a path,
292
+ /// and not a word and should instead be parsed using [`path`](Self::path)
299
293
pub fn word ( & self ) -> Option < ( Ident , & ArgParser < ' a > ) > {
300
294
let ( path, args) = self . deconstruct ( ) ;
301
295
Some ( ( path. word ( ) ?, args) )
@@ -406,7 +400,7 @@ impl<'a> MetaItemListParserContext<'a> {
406
400
{
407
401
segments. push ( Ident :: new ( name, span) ) ;
408
402
} else {
409
- unreachable ! ( )
403
+ return None ;
410
404
}
411
405
if let Some ( TokenTree :: Token ( Token { kind : token:: PathSep , .. } , _) ) =
412
406
self . inside_delimiters . peek ( )
@@ -422,16 +416,14 @@ impl<'a> MetaItemListParserContext<'a> {
422
416
Some ( TokenTree :: Token (
423
417
Token { kind : token:: OpenDelim ( _) | token:: CloseDelim ( _) , .. } ,
424
418
_,
425
- ) ) => {
426
- panic ! ( "Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}" , tt) ;
427
- }
428
- Some ( x) => {
419
+ ) ) => None ,
420
+ Some ( _) => {
429
421
// malformed attributes can get here. We can't crash, but somewhere else should've
430
422
// already warned for this.
431
- self . dcx . span_delayed_bug (
432
- x. span ( ) ,
433
- format ! ( "unexpected token {x:?} in built-in attribute path" ) ,
434
- ) ;
423
+ // self.dcx.span_delayed_bug(
424
+ // x.span(),
425
+ // format!("unexpected token {x:?} in built-in attribute path"),
426
+ // );
435
427
None
436
428
}
437
429
None => None ,
@@ -450,7 +442,7 @@ impl<'a> MetaItemListParserContext<'a> {
450
442
Some ( TokenTree :: Token ( ref token, _) ) => {
451
443
if let Some ( s) = MetaItemLit :: from_token ( token) { Some ( s) } else { None }
452
444
}
453
- x => unreachable ! ( "{x:?}" ) ,
445
+ x => None ,
454
446
}
455
447
}
456
448
@@ -532,9 +524,9 @@ impl<'a> MetaItemListParserContext<'a> {
532
524
) ) ,
533
525
}
534
526
}
535
- Some ( TokenTree :: Delimited ( span , ..) ) => {
527
+ Some ( TokenTree :: Delimited ( _ , ..) ) => {
536
528
self . inside_delimiters . next ( ) ;
537
- self . dcx . span_delayed_bug ( span. entire ( ) , "wrong delimiters" ) ;
529
+ // self.dcx.span_delayed_bug(span.entire(), "wrong delimiters");
538
530
return None ;
539
531
}
540
532
Some ( TokenTree :: Token ( Token { kind : token:: Eq , span } , _) ) => {
0 commit comments