Skip to content

Commit 5d0c450

Browse files
committed
fix Path
1 parent 09506c4 commit 5d0c450

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

clippy_utils/src/check_proc_macro.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
use rustc_abi::ExternAbi;
1616
use rustc_ast as ast;
1717
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+
};
1921
use rustc_ast::token::CommentKind;
2022
use rustc_hir::intravisit::FnKind;
2123
use rustc_hir::{
@@ -442,7 +444,45 @@ fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) {
442444
TyKind::Tup([ty]) => ast_ty_search_pat(ty),
443445
TyKind::Tup([head, .., tail]) => (ast_ty_search_pat(head).0, ast_ty_search_pat(tail).1),
444446
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+
},
446486
TyKind::Infer => (Pat::Str("_"), Pat::Str("_")),
447487
TyKind::TraitObject(_, tagged_ptr) if let TraitObjectSyntax::Dyn = tagged_ptr.tag() => {
448488
(Pat::Str("dyn"), Pat::Str(""))

0 commit comments

Comments
 (0)