|
15 | 15 | use rustc_abi::ExternAbi; |
16 | 16 | use rustc_ast as ast; |
17 | 17 | use rustc_ast::AttrStyle; |
18 | | -use rustc_ast::ast::{AttrKind, Attribute, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy}; |
| 18 | +use rustc_ast::ast::{ |
| 19 | + AttrKind, Attribute, GenericArgs, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy, |
| 20 | +}; |
19 | 21 | use rustc_ast::token::CommentKind; |
20 | 22 | use rustc_hir::intravisit::FnKind; |
21 | 23 | use rustc_hir::{ |
@@ -445,7 +447,52 @@ fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) { |
445 | 447 | TyKind::Tup([ty]) => ast_ty_search_pat(ty), |
446 | 448 | TyKind::Tup([head, .., tail]) => (ast_ty_search_pat(head).0, ast_ty_search_pat(tail).1), |
447 | 449 | TyKind::OpaqueDef(..) => (Pat::Str("impl"), Pat::Str("")), |
448 | | - TyKind::Path(qpath) => qpath_search_pat(&qpath), |
| 450 | + TyKind::Path(qself_path, path) => { |
| 451 | + let start = if qself_path.is_some() { |
| 452 | + Pat::Str("<") |
| 453 | + } else if let Some(first) = path.segments.first() { |
| 454 | + ident_search_pat(first.ident).0 |
| 455 | + } else { |
| 456 | + // this shouldn't be possible, but sure |
| 457 | + Pat::Str("") |
| 458 | + }; |
| 459 | + let end = if let Some(last) = path.segments.last() { |
| 460 | + match last.args.as_deref() { |
| 461 | + // last `>` in `std::foo::Bar<T>` |
| 462 | + Some(GenericArgs::AngleBracketed(_)) => Pat::Str(">"), |
| 463 | + Some(GenericArgs::Parenthesized(par_args)) => match &par_args.output { |
| 464 | + FnRetTy::Default(_) => { |
| 465 | + if let Some(last) = par_args.inputs.last() { |
| 466 | + // `B` in `(A, B)` -- `)` gets stripped |
| 467 | + ast_ty_search_pat(last).1 |
| 468 | + } else { |
| 469 | + // `(` in `()` -- `)` gets stripped |
| 470 | + Pat::Str("(") |
| 471 | + } |
| 472 | + }, |
| 473 | + // `C` in `(A, B) -> C` |
| 474 | + FnRetTy::Ty(ty) => ast_ty_search_pat(ty).1, |
| 475 | + }, |
| 476 | + // last `..` in `(..)` -- `)` gets stripped |
| 477 | + Some(GenericArgs::ParenthesizedElided(_)) => Pat::Str(".."), |
| 478 | + // `bar` in `std::foo::bar` |
| 479 | + None => ident_search_pat(last.ident).1, |
| 480 | + } |
| 481 | + } else { |
| 482 | + // this shouldn't be possible, but sure |
| 483 | + #[allow( |
| 484 | + clippy::collapsible_else_if, |
| 485 | + reason = "we want to keep these cases together, since they are both impossible" |
| 486 | + )] |
| 487 | + if qself_path.is_some() { |
| 488 | + // last `>` in `<Vec as IntoIterator>` |
| 489 | + Pat::Str(">") |
| 490 | + } else { |
| 491 | + Pat::Str("") |
| 492 | + } |
| 493 | + }; |
| 494 | + (start, end) |
| 495 | + }, |
449 | 496 | TyKind::Infer => (Pat::Str("_"), Pat::Str("_")), |
450 | 497 | TyKind::TraitObject(_, tagged_ptr) if let TraitObjectSyntax::Dyn = tagged_ptr.tag() => { |
451 | 498 | (Pat::Str("dyn"), Pat::Str("")) |
|
0 commit comments