Skip to content

Commit

Permalink
Auto merge of rust-lang#103344 - Dylan-DPC:rollup-d1rpfvx, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - rust-lang#102287 (Elaborate supertrait bounds when triggering `unused_must_use` on `impl Trait`)
 - rust-lang#102922 (Filtering spans when emitting json)
 - rust-lang#103051 (translation: doc comments with derives, subdiagnostic-less enum variants, more derive use)
 - rust-lang#103111 (Account for hygiene in typo suggestions, and use them to point to shadowed names)
 - rust-lang#103260 (Fixup a few tests needing asm support)
 - rust-lang#103321 (rustdoc: improve appearance of source page navigation bar)

Failed merges:

 - rust-lang#103209 (Diagnostic derives: allow specifying multiple alternative suggestions)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 21, 2022
2 parents 059e52b + 0569f56 commit 46cf1ea
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 137 deletions.
12 changes: 7 additions & 5 deletions clippy_lints/src/manual_assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
"only a `panic!` in `if`-then statement",
|diag| {
// comments can be noisy, do not show them to the user
diag.tool_only_span_suggestion(
expr.span.shrink_to_lo(),
"add comments back",
comments,
applicability);
if !comments.is_empty() {
diag.tool_only_span_suggestion(
expr.span.shrink_to_lo(),
"add comments back",
comments,
applicability);
}
diag.span_suggestion(
expr.span,
"try instead",
Expand Down
11 changes: 7 additions & 4 deletions clippy_lints/src/needless_late_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,13 @@ fn assignment_suggestions<'tcx>(
let suggestions = assignments
.iter()
.flat_map(|assignment| {
[
assignment.span.until(assignment.rhs_span),
assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()),
]
let mut spans = vec![assignment.span.until(assignment.rhs_span)];

if assignment.rhs_span.hi() != assignment.span.hi() {
spans.push(assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()));
}

spans
})
.map(|span| (span, String::new()))
.collect::<Vec<(Span, String)>>();
Expand Down
1 change: 1 addition & 0 deletions tests/ui/entry.fixed
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// needs-asm-support
// run-rustfix

#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
Expand Down
1 change: 1 addition & 0 deletions tests/ui/entry.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// needs-asm-support
// run-rustfix

#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/entry.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:24:5
--> $DIR/entry.rs:25:5
|
LL | / if !m.contains_key(&k) {
LL | | m.insert(k, v);
Expand All @@ -9,7 +9,7 @@ LL | | }
= note: `-D clippy::map-entry` implied by `-D warnings`

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:29:5
--> $DIR/entry.rs:30:5
|
LL | / if !m.contains_key(&k) {
LL | | if true {
Expand All @@ -32,7 +32,7 @@ LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:38:5
--> $DIR/entry.rs:39:5
|
LL | / if !m.contains_key(&k) {
LL | | if true {
Expand All @@ -55,7 +55,7 @@ LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:47:5
--> $DIR/entry.rs:48:5
|
LL | / if !m.contains_key(&k) {
LL | | if true {
Expand All @@ -79,7 +79,7 @@ LL + }
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:57:5
--> $DIR/entry.rs:58:5
|
LL | / if !m.contains_key(&k) {
LL | | foo();
Expand All @@ -96,7 +96,7 @@ LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:63:5
--> $DIR/entry.rs:64:5
|
LL | / if !m.contains_key(&k) {
LL | | match 0 {
Expand All @@ -122,7 +122,7 @@ LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:75:5
--> $DIR/entry.rs:76:5
|
LL | / if !m.contains_key(&k) {
LL | | match 0 {
Expand All @@ -146,7 +146,7 @@ LL + }
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:85:5
--> $DIR/entry.rs:86:5
|
LL | / if !m.contains_key(&k) {
LL | | foo();
Expand Down Expand Up @@ -187,15 +187,15 @@ LL + });
|

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:119:5
--> $DIR/entry.rs:120:5
|
LL | / if !m.contains_key(&m!(k)) {
LL | | m.insert(m!(k), m!(v));
LL | | }
| |_____^ help: try this: `m.entry(m!(k)).or_insert_with(|| m!(v));`

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> $DIR/entry.rs:151:5
--> $DIR/entry.rs:152:5
|
LL | / if !m.contains_key(&k) {
LL | | let x = (String::new(), String::new());
Expand Down
55 changes: 8 additions & 47 deletions tests/ui/manual_assert.edition2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,65 @@ error: only a `panic!` in `if`-then statement
LL | / if !a.is_empty() {
LL | | panic!("qaqaq{:?}", a);
LL | | }
| |_____^
| |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
|
= note: `-D clippy::manual-assert` implied by `-D warnings`
help: try instead
|
LL | assert!(a.is_empty(), "qaqaq{:?}", a);
|

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:34:5
|
LL | / if !a.is_empty() {
LL | | panic!("qwqwq");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(a.is_empty(), "qwqwq");
|
| |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:51:5
|
LL | / if b.is_empty() {
LL | | panic!("panic1");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!b.is_empty(), "panic1");
|
| |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:54:5
|
LL | / if b.is_empty() && a.is_empty() {
LL | | panic!("panic2");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(b.is_empty() && a.is_empty()), "panic2");
|
| |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:57:5
|
LL | / if a.is_empty() && !b.is_empty() {
LL | | panic!("panic3");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3");
|
| |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:60:5
|
LL | / if b.is_empty() || a.is_empty() {
LL | | panic!("panic4");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(b.is_empty() || a.is_empty()), "panic4");
|
| |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:63:5
|
LL | / if a.is_empty() || !b.is_empty() {
LL | | panic!("panic5");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5");
|
| |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:66:5
|
LL | / if a.is_empty() {
LL | | panic!("with expansion {}", one!())
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!a.is_empty(), "with expansion {}", one!());
|
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:73:5
Expand Down
55 changes: 8 additions & 47 deletions tests/ui/manual_assert.edition2021.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,65 @@ error: only a `panic!` in `if`-then statement
LL | / if !a.is_empty() {
LL | | panic!("qaqaq{:?}", a);
LL | | }
| |_____^
| |_____^ help: try instead: `assert!(a.is_empty(), "qaqaq{:?}", a);`
|
= note: `-D clippy::manual-assert` implied by `-D warnings`
help: try instead
|
LL | assert!(a.is_empty(), "qaqaq{:?}", a);
|

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:34:5
|
LL | / if !a.is_empty() {
LL | | panic!("qwqwq");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(a.is_empty(), "qwqwq");
|
| |_____^ help: try instead: `assert!(a.is_empty(), "qwqwq");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:51:5
|
LL | / if b.is_empty() {
LL | | panic!("panic1");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!b.is_empty(), "panic1");
|
| |_____^ help: try instead: `assert!(!b.is_empty(), "panic1");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:54:5
|
LL | / if b.is_empty() && a.is_empty() {
LL | | panic!("panic2");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(b.is_empty() && a.is_empty()), "panic2");
|
| |_____^ help: try instead: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:57:5
|
LL | / if a.is_empty() && !b.is_empty() {
LL | | panic!("panic3");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(a.is_empty() && !b.is_empty()), "panic3");
|
| |_____^ help: try instead: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:60:5
|
LL | / if b.is_empty() || a.is_empty() {
LL | | panic!("panic4");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(b.is_empty() || a.is_empty()), "panic4");
|
| |_____^ help: try instead: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:63:5
|
LL | / if a.is_empty() || !b.is_empty() {
LL | | panic!("panic5");
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!(a.is_empty() || !b.is_empty()), "panic5");
|
| |_____^ help: try instead: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:66:5
|
LL | / if a.is_empty() {
LL | | panic!("with expansion {}", one!())
LL | | }
| |_____^
|
help: try instead
|
LL | assert!(!a.is_empty(), "with expansion {}", one!());
|
| |_____^ help: try instead: `assert!(!a.is_empty(), "with expansion {}", one!());`

error: only a `panic!` in `if`-then statement
--> $DIR/manual_assert.rs:73:5
Expand Down
1 change: 1 addition & 0 deletions tests/ui/missing_doc.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// needs-asm-support
// aux-build: proc_macro_with_span.rs

#![warn(clippy::missing_docs_in_private_items)]
Expand Down
Loading

0 comments on commit 46cf1ea

Please sign in to comment.