Skip to content

Commit a434a77

Browse files
committed
impl WithSearchPat for Ty
1 parent e97f190 commit a434a77

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

clippy_lints/src/trait_bounds.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
22
use clippy_utils::source::{snippet, snippet_opt, snippet_with_applicability};
3-
use clippy_utils::{SpanlessEq, SpanlessHash};
3+
use clippy_utils::{is_from_proc_macro, SpanlessEq, SpanlessHash};
44
use core::hash::{Hash, Hasher};
55
use if_chain::if_chain;
66
use itertools::Itertools;
@@ -260,10 +260,7 @@ impl TraitBounds {
260260
SpanlessTy { ty: p.bounded_ty, cx },
261261
p.bounds.iter().collect::<Vec<_>>()
262262
);
263-
let bounded_ty = snippet(cx, p.bounded_ty.span, "_");
264-
if let TyKind::Path(qpath) = p.bounded_ty.kind;
265-
if format!("{}:", rustc_hir_pretty::qpath_to_string(&qpath)) == format!("{bounded_ty}:");
266-
263+
if !is_from_proc_macro(cx, p.bounded_ty);
267264
then {
268265
let trait_bounds = v
269266
.iter()
@@ -272,7 +269,10 @@ impl TraitBounds {
272269
.filter_map(get_trait_info_from_bound)
273270
.map(|(_, _, span)| snippet_with_applicability(cx, span, "..", &mut applicability))
274271
.join(" + ");
275-
let hint_string = format!("consider combining the bounds: `{bounded_ty}: {trait_bounds}`");
272+
let hint_string = format!(
273+
"consider combining the bounds: `{}: {trait_bounds}`",
274+
snippet(cx, p.bounded_ty.span, "_"),
275+
);
276276
span_lint_and_help(
277277
cx,
278278
TYPE_REPETITION_IN_BOUNDS,

clippy_utils/src/check_proc_macro.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) {
351351
TyKind::Never => (Pat::Str("!"), Pat::Str("")),
352352
TyKind::Tup(..) => (Pat::Str("("), Pat::Str(")")),
353353
TyKind::OpaqueDef(..) => (Pat::Str("impl"), Pat::Str("")),
354-
// NOTE: This is missing `TraitObject` and `Path` here. It always return true then.
354+
TyKind::Path(qpath) => qpath_search_pat(&qpath),
355+
// NOTE: This is missing `TraitObject`. It always return true then.
355356
_ => (Pat::Str(""), Pat::Str("")),
356357
}
357358
}

0 commit comments

Comments
 (0)