|
13 | 13 | //! if the span is not from a `macro_rules` based macro.
|
14 | 14 |
|
15 | 15 | use rustc_abi::ExternAbi;
|
| 16 | +use rustc_ast as ast; |
16 | 17 | use rustc_ast::AttrStyle;
|
17 | 18 | use rustc_ast::ast::{AttrKind, Attribute, IntTy, LitIntType, LitKind, StrStyle, TraitObjectSyntax, UintTy};
|
18 | 19 | use rustc_ast::token::CommentKind;
|
@@ -408,6 +409,47 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
|
408 | 409 | }
|
409 | 410 | }
|
410 | 411 |
|
| 412 | +fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) { |
| 413 | + match ty.kind { |
| 414 | + TyKind::Slice(..) | TyKind::Array(..) => (Pat::Str("["), Pat::Str("]")), |
| 415 | + TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ty_search_pat(ty).1), |
| 416 | + TyKind::Ref(_, MutTy { ty, .. }) => (Pat::Str("&"), ty_search_pat(ty).1), |
| 417 | + TyKind::FnPtr(fn_ptr) => ( |
| 418 | + if fn_ptr.safety.is_unsafe() { |
| 419 | + Pat::Str("unsafe") |
| 420 | + } else if fn_ptr.abi != ExternAbi::Rust { |
| 421 | + Pat::Str("extern") |
| 422 | + } else { |
| 423 | + Pat::MultiStr(&["fn", "extern"]) |
| 424 | + }, |
| 425 | + match fn_ptr.decl.output { |
| 426 | + FnRetTy::DefaultReturn(_) => { |
| 427 | + if let [.., ty] = fn_ptr.decl.inputs { |
| 428 | + ty_search_pat(ty).1 |
| 429 | + } else { |
| 430 | + Pat::Str("(") |
| 431 | + } |
| 432 | + }, |
| 433 | + FnRetTy::Return(ty) => ty_search_pat(ty).1, |
| 434 | + }, |
| 435 | + ), |
| 436 | + TyKind::Never => (Pat::Str("!"), Pat::Str("!")), |
| 437 | + // Parenthesis are trimmed from the text before the search patterns are matched. |
| 438 | + // See: `span_matches_pat` |
| 439 | + TyKind::Tup([]) => (Pat::Str(")"), Pat::Str("(")), |
| 440 | + TyKind::Tup([ty]) => ty_search_pat(ty), |
| 441 | + TyKind::Tup([head, .., tail]) => (ty_search_pat(head).0, ty_search_pat(tail).1), |
| 442 | + TyKind::OpaqueDef(..) => (Pat::Str("impl"), Pat::Str("")), |
| 443 | + TyKind::Path(qpath) => qpath_search_pat(&qpath), |
| 444 | + TyKind::Infer(()) => (Pat::Str("_"), Pat::Str("_")), |
| 445 | + TyKind::TraitObject(_, tagged_ptr) if let TraitObjectSyntax::Dyn = tagged_ptr.tag() => { |
| 446 | + (Pat::Str("dyn"), Pat::Str("")) |
| 447 | + }, |
| 448 | + // NOTE: `TraitObject` is incomplete. It will always return true then. |
| 449 | + _ => (Pat::Str(""), Pat::Str("")), |
| 450 | + } |
| 451 | +} |
| 452 | + |
411 | 453 | fn ident_search_pat(ident: Ident) -> (Pat, Pat) {
|
412 | 454 | (Pat::Sym(ident.name), Pat::Sym(ident.name))
|
413 | 455 | }
|
|
0 commit comments