Skip to content

Commit

Permalink
Auto merge of rust-lang#12780 - future-highway:str-to-string-expansio…
Browse files Browse the repository at this point in the history
…ns, r=Manishearth

Ignore `_to_string` lints in code `from_expansion`

Includes the `string_to_string` and `str_to_string` lints.

changelog: [`str_to_string`]: Ignore code from expansion
changelog: [`string_to_string`]: Ignore code from expansion
  • Loading branch information
bors committed May 9, 2024
2 parents baf2a23 + cd00f5b commit 68dbc84
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clippy_lints/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ declare_lint_pass!(StrToString => [STR_TO_STRING]);

impl<'tcx> LateLintPass<'tcx> for StrToString {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
if expr.span.from_expansion() {
return;
}

if let ExprKind::MethodCall(path, self_arg, ..) = &expr.kind
&& path.ident.name == sym::to_string
&& let ty = cx.typeck_results().expr_ty(self_arg)
Expand Down Expand Up @@ -437,6 +441,10 @@ declare_lint_pass!(StringToString => [STRING_TO_STRING]);

impl<'tcx> LateLintPass<'tcx> for StringToString {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
if expr.span.from_expansion() {
return;
}

if let ExprKind::MethodCall(path, self_arg, ..) = &expr.kind
&& path.ident.name == sym::to_string
&& let ty = cx.typeck_results().expr_ty(self_arg)
Expand Down

0 comments on commit 68dbc84

Please sign in to comment.