Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rust-clippy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 147cb29fe0ab683ef56ad8fba1e0519511c799c4
Choose a base ref
..
head repository: rust-lang/rust-clippy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a0ce3b02adc61296952135114dcedd90007a6de1
Choose a head ref
Showing with 15 additions and 30 deletions.
  1. +2 −2 CHANGELOG.md
  2. +10 −25 clippy_lints/src/recursive_display_impl.rs
  3. +3 −3 tests/ui/recursive_display_impl.stderr
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1267,7 +1267,7 @@ Released 2020-11-19
* [`manual_strip`] [#6038](https://github.com/rust-lang/rust-clippy/pull/6038)
* [`map_err_ignore`] [#5998](https://github.com/rust-lang/rust-clippy/pull/5998)
* [`rc_buffer`] [#6044](https://github.com/rust-lang/rust-clippy/pull/6044)
* [`to_string_in_display`] [#5831](https://github.com/rust-lang/rust-clippy/pull/5831)
* `to_string_in_display` [#5831](https://github.com/rust-lang/rust-clippy/pull/5831)
* `single_char_push_str` [#5881](https://github.com/rust-lang/rust-clippy/pull/5881)

### Moves and Deprecations
@@ -1310,7 +1310,7 @@ Released 2020-11-19
[#5949](https://github.com/rust-lang/rust-clippy/pull/5949)
* [`doc_markdown`]: allow using "GraphQL" without backticks
[#5996](https://github.com/rust-lang/rust-clippy/pull/5996)
* [`to_string_in_display`]: avoid linting when calling `to_string()` on anything that is not `self`
* `to_string_in_display`: avoid linting when calling `to_string()` on anything that is not `self`
[#5971](https://github.com/rust-lang/rust-clippy/pull/5971)
* [`indexing_slicing`] and [`out_of_bounds_indexing`] treat references to arrays as arrays
[#6034](https://github.com/rust-lang/rust-clippy/pull/6034)
35 changes: 10 additions & 25 deletions clippy_lints/src/recursive_display_impl.rs
Original file line number Diff line number Diff line change
@@ -177,31 +177,16 @@ fn check_self_in_format_args(cx: &LateContext<'_>, expr: &Expr<'_>, self_hir_id:
}

fn check_format_arg_self(cx: &LateContext<'_>, expr: &Expr<'_>, self_hir_id: HirId, arg: &FormatArgsArg<'_>) {
if_chain! {
let reference = deref_expr(arg.value);
if path_to_local_id(reference, self_hir_id);
then {
span_lint(
cx,
RECURSIVE_DISPLAY_IMPL,
expr.span,
"using reference to `self` in `fmt::Display` implementation might lead to infinite recursion",);
}
else {
if_chain! {
let arg_ty = cx.typeck_results().expr_ty_adjusted(arg.value);
let self_ty = cx.typeck_results().node_type(self_hir_id);
if self_ty == arg_ty;
then {
span_lint(
cx,
RECURSIVE_DISPLAY_IMPL,
expr.span,
"using `self` in `fmt::Display` implementation might lead to infinite recursion",
);
}
}
}
let reference = deref_expr(arg.value);
let arg_ty = cx.typeck_results().expr_ty_adjusted(arg.value);
let self_ty = cx.typeck_results().node_type(self_hir_id);
if path_to_local_id(reference, self_hir_id) || self_ty == arg_ty {
span_lint(
cx,
RECURSIVE_DISPLAY_IMPL,
expr.span,
"using `self` in `fmt::Display` implementation might lead to infinite recursion",
);
}
}

6 changes: 3 additions & 3 deletions tests/ui/recursive_display_impl.stderr
Original file line number Diff line number Diff line change
@@ -6,23 +6,23 @@ LL | write!(f, "{}", self.to_string())
|
= note: `-D clippy::recursive-display-impl` implied by `-D warnings`

error: using reference to `self` in `fmt::Display` implementation might lead to infinite recursion
error: using `self` in `fmt::Display` implementation might lead to infinite recursion
--> $DIR/recursive_display_impl.rs:69:9
|
LL | write!(f, "{}", self)
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

error: using reference to `self` in `fmt::Display` implementation might lead to infinite recursion
error: using `self` in `fmt::Display` implementation might lead to infinite recursion
--> $DIR/recursive_display_impl.rs:78:9
|
LL | write!(f, "{}", &self)
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

error: using reference to `self` in `fmt::Display` implementation might lead to infinite recursion
error: using `self` in `fmt::Display` implementation might lead to infinite recursion
--> $DIR/recursive_display_impl.rs:87:9
|
LL | write!(f, "{}", &&&self)