|
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::{
|
@@ -442,7 +444,45 @@ fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) {
|
442 | 444 | TyKind::Tup([ty]) => ast_ty_search_pat(ty),
|
443 | 445 | TyKind::Tup([head, .., tail]) => (ast_ty_search_pat(head).0, ast_ty_search_pat(tail).1),
|
444 | 446 | TyKind::OpaqueDef(..) => (Pat::Str("impl"), Pat::Str("")),
|
445 |
| - TyKind::Path(qpath) => qpath_search_pat(&qpath), |
| 447 | + TyKind::Path(qself_path, path) => { |
| 448 | + let start = if qself_path.is_some() { |
| 449 | + Pat::Str("<") |
| 450 | + } else if let Some(first) = path.segments.first() { |
| 451 | + ident_search_pat(first.ident).0 |
| 452 | + } else { |
| 453 | + // this shouldn't be possible, but sure |
| 454 | + Pat::Str("") |
| 455 | + }; |
| 456 | + let end = if let Some(last) = path.segments.last() { |
| 457 | + match last.args.as_deref() { |
| 458 | + // last `>` in `std::foo::Bar<T>` |
| 459 | + Some(GenericArgs::AngleBracketed(_)) => Pat::Str(">"), |
| 460 | + Some(GenericArgs::Parenthesized(par_args)) => match &par_args.output { |
| 461 | + // last `)` in `(A, B)` |
| 462 | + FnRetTy::Default(_) => Pat::Str(")"), |
| 463 | + // `C` in `(A, B) -> C` |
| 464 | + FnRetTy::Ty(ty) => ast_ty_search_pat(ty).1, |
| 465 | + }, |
| 466 | + // last `)` in `(..)` |
| 467 | + Some(GenericArgs::ParenthesizedElided(_)) => Pat::Str(")"), |
| 468 | + // `bar` in `std::foo::bar` |
| 469 | + None => ident_search_pat(last.ident).1, |
| 470 | + } |
| 471 | + } else { |
| 472 | + // this shouldn't be possible, but sure |
| 473 | + #[allow( |
| 474 | + clippy::collapsible_else_if, |
| 475 | + reason = "we want to keep these cases together, since they are both impossible" |
| 476 | + )] |
| 477 | + if qself_path.is_some() { |
| 478 | + // last `>` in `<Vec as IntoIterator>` |
| 479 | + Pat::Str(">") |
| 480 | + } else { |
| 481 | + Pat::Str("") |
| 482 | + } |
| 483 | + }; |
| 484 | + (start, end) |
| 485 | + }, |
446 | 486 | TyKind::Infer => (Pat::Str("_"), Pat::Str("_")),
|
447 | 487 | TyKind::TraitObject(_, tagged_ptr) if let TraitObjectSyntax::Dyn = tagged_ptr.tag() => {
|
448 | 488 | (Pat::Str("dyn"), Pat::Str(""))
|
|
0 commit comments