Don't trigger semicolon_if_nothing_returned in expanded code#7789
Merged
bors merged 1 commit intorust-lang:masterfrom Oct 8, 2021
Merged
Don't trigger semicolon_if_nothing_returned in expanded code#7789bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
Before this lint didn't trigger on macros. With rust-lang/rust#88175 this isn't enough anymore. In this PR a `WhileLoop` desugaring kind was introduced. This overrides the span of expanded expressions when lowering the while loop. So if a while loop is in a macro, the expressions that it expands to are no longer marked with `ExpnKind::Macro`, but with `ExpnKind::Desugaring`. In general, this is the correct behavior and the same that is done for `ForLoop`s. It just tripped up this lint.
Contributor
|
@bors r+ I wonder if |
Contributor
|
📌 Commit b423b85 has been approved by |
Contributor
Contributor
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Member
Author
Doing this only makes 4 tests fail: diff --git a/tests/ui/blocks_in_if_conditions.stderr b/tests/ui/blocks_in_if_conditions.stderr
index 079f2feb5..6be6bc494 100644
--- a/tests/ui/blocks_in_if_conditions.stderr
+++ b/tests/ui/blocks_in_if_conditions.stderr
@@ -22,13 +22,5 @@ error: omit braces around single expression condition
LL | if { true } { 6 } else { 10 }
| ^^^^^^^^ help: try: `true`
-error: this boolean expression can be simplified
- --> $DIR/blocks_in_if_conditions.rs:40:8
- |
-LL | if true && x == 3 { 6 } else { 10 }
- | ^^^^^^^^^^^^^^ help: try: `x == 3`
- |
- = note: `-D clippy::nonminimal-bool` implied by `-D warnings`
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
diff --git a/tests/ui/from_iter_instead_of_collect.stderr b/tests/ui/from_iter_instead_of_collect.stderr
index 8f08ac8c3..5686e8c7a 100644
--- a/tests/ui/from_iter_instead_of_collect.stderr
+++ b/tests/ui/from_iter_instead_of_collect.stderr
@@ -78,17 +78,5 @@ error: usage of `FromIterator::from_iter`
LL | let _ = collections::BTreeSet::<u32>::from_iter(0..3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(0..3).collect::<collections::BTreeSet<u32>>()`
-error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:60:15
- |
-LL | for _i in Vec::from_iter([1, 2, 3].iter()) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::<Vec<_>>()`
-
-error: usage of `FromIterator::from_iter`
- --> $DIR/from_iter_instead_of_collect.rs:61:15
- |
-LL | for _i in Vec::<&i32>::from_iter([1, 2, 3].iter()) {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `[1, 2, 3].iter().collect::<Vec<&i32>>()`
-
-error: aborting due to 15 previous errors
+error: aborting due to 13 previous errors
diff --git a/tests/ui/nonminimal_bool_methods.stderr b/tests/ui/nonminimal_bool_methods.stderr
index a2df889d6..65d912982 100644
--- a/tests/ui/nonminimal_bool_methods.stderr
+++ b/tests/ui/nonminimal_bool_methods.stderr
@@ -54,29 +54,5 @@ error: this boolean expression can be simplified
LL | let _ = !c ^ c || !a.is_some();
| ^^^^^^^^^^^^ help: try: `a.is_none()`
-error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool_methods.rs:92:8
- |
-LL | if !res.is_ok() {}
- | ^^^^^^^^^^^^ help: try: `res.is_err()`
-
-error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool_methods.rs:93:8
- |
-LL | if !res.is_err() {}
- | ^^^^^^^^^^^^^ help: try: `res.is_ok()`
-
-error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool_methods.rs:96:8
- |
-LL | if !res.is_some() {}
- | ^^^^^^^^^^^^^^ help: try: `res.is_none()`
-
-error: this boolean expression can be simplified
- --> $DIR/nonminimal_bool_methods.rs:97:8
- |
-LL | if !res.is_none() {}
- | ^^^^^^^^^^^^^^ help: try: `res.is_some()`
-
-error: aborting due to 13 previous errors
+error: aborting due to 9 previous errors
diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr
index e14368a11..73bdad0aa 100644
--- a/tests/ui/use_self.stderr
+++ b/tests/ui/use_self.stderr
@@ -120,12 +120,6 @@ error: unnecessary structure name repetition
LL | TestStruct::from_something()
| ^^^^^^^^^^ help: use the applicable keyword: `Self`
-error: unnecessary structure name repetition
- --> $DIR/use_self.rs:258:25
- |
-LL | async fn g() -> S {
- | ^ help: use the applicable keyword: `Self`
-
error: unnecessary structure name repetition
--> $DIR/use_self.rs:259:13
|
@@ -168,5 +162,5 @@ error: unnecessary structure name repetition
LL | S2::new()
| ^^ help: use the applicable keyword: `Self`
-error: aborting due to 28 previous errors
+error: aborting due to 27 previous errorsSome of those might be bugs / inaccuracies in the lowering process of spans in rustc. |
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this pull request
Oct 22, 2021
…vidtwco Don't mark for loop iter expression as desugared We typically don't mark spans of lowered things as desugared. This helps Clippy rightly discern when code is (not) from expansion. This was discovered by `@flip1995` at rust-lang/rust-clippy#7789 (comment).
JohnTitor
added a commit
to JohnTitor/rust
that referenced
this pull request
Oct 22, 2021
…vidtwco Don't mark for loop iter expression as desugared We typically don't mark spans of lowered things as desugared. This helps Clippy rightly discern when code is (not) from expansion. This was discovered by ``@flip1995`` at rust-lang/rust-clippy#7789 (comment).
flip1995
pushed a commit
to flip1995/rust-clippy
that referenced
this pull request
Nov 4, 2021
Don't mark for loop iter expression as desugared We typically don't mark spans of lowered things as desugared. This helps Clippy rightly discern when code is (not) from expansion. This was discovered by ``@flip1995`` at rust-lang#7789 (comment).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7768
Before, this lint didn't trigger on macros. With rust-lang/rust#88175
this isn't enough anymore. In this PR a
WhileLoopdesugaring kind wasintroduced. This overrides the span of expanded expressions when
lowering the while loop. So if a while loop is in a macro, the
expressions that it expands to are no longer marked with
ExpnKind::Macro, but withExpnKind::Desugaring. In general, this isthe correct behavior and the same that is done for
ForLoops. It justtripped up this lint.
r? @camsteffen
changelog: [
semicolon_if_nothing_returned]: Fix regression on macros containing while loops