Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 367126d

Browse files
committed
If suggestion would leave an empty line, delete it
1 parent b0696a5 commit 367126d

17 files changed

+67
-27
lines changed

compiler/rustc_errors/src/json.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,24 @@ impl DiagnosticSpan {
428428
}
429429

430430
fn from_span_full(
431-
span: Span,
431+
mut span: Span,
432432
is_primary: bool,
433433
label: Option<String>,
434434
suggestion: Option<(&String, Applicability)>,
435435
mut backtrace: impl Iterator<Item = ExpnData>,
436436
je: &JsonEmitter,
437437
) -> DiagnosticSpan {
438438
let start = je.sm.lookup_char_pos(span.lo());
439+
// If this goes from the start of a line to the end and the replacement
440+
// is an empty string, increase the length to include the newline so we don't
441+
// leave an empty line
442+
if start.col.0 == 0
443+
&& suggestion.map_or(false, |(s, _)| s.is_empty())
444+
&& let Ok(after) = je.sm.span_to_next_source(span)
445+
&& after.starts_with('\n')
446+
{
447+
span = span.with_hi(span.hi() + rustc_span::BytePos(1));
448+
}
439449
let end = je.sm.lookup_char_pos(span.hi());
440450
let backtrace_step = backtrace.next().map(|bt| {
441451
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);

src/tools/clippy/tests/ui/derivable_impls.fixed

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ struct FooDefault<'a> {
1919
}
2020

2121

22-
2322
#[derive(Default)]
2423
struct TupleDefault(bool, i32, u64);
2524

2625

27-
2826
struct FooND1 {
2927
a: bool,
3028
}
@@ -73,7 +71,6 @@ impl Default for FooNDVec {
7371
struct StrDefault<'a>(&'a str);
7472

7573

76-
7774
#[derive(Default)]
7875
struct AlreadyDerived(i32, bool);
7976

@@ -96,7 +93,6 @@ mac!(0);
9693
#[derive(Default)]
9794
struct Y(u32);
9895

99-
10096
struct RustIssue26925<T> {
10197
a: Option<T>,
10298
}
@@ -132,12 +128,10 @@ struct WithoutSelfCurly {
132128
}
133129

134130

135-
136131
#[derive(Default)]
137132
struct WithoutSelfParan(bool);
138133

139134

140-
141135
// https://github.com/rust-lang/rust-clippy/issues/7655
142136

143137
pub struct SpecializedImpl2<T> {
@@ -184,7 +178,6 @@ pub struct RepeatDefault1 {
184178
}
185179

186180

187-
188181
pub struct RepeatDefault2 {
189182
a: [i8; 33],
190183
}
@@ -216,7 +209,6 @@ pub enum SimpleEnum {
216209
}
217210

218211

219-
220212
pub enum NonExhaustiveEnum {
221213
Foo,
222214
#[non_exhaustive]

src/tools/clippy/tests/ui/empty_drop.fixed

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
struct Foo;
66

77

8-
98
// shouldn't cause an error
109
struct Bar;
1110

@@ -19,5 +18,4 @@ impl Drop for Bar {
1918
struct Baz;
2019

2120

22-
2321
fn main() {}

src/tools/clippy/tests/ui/must_use_unit.fixed

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
extern crate proc_macros;
77
use proc_macros::external;
88

9-
109
pub fn must_use_default() {}
1110

12-
1311
pub fn must_use_unit() -> () {}
1412

15-
1613
pub fn must_use_with_note() {}
1714

1815
fn main() {

src/tools/clippy/tests/ui/single_component_path_imports.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use core;
55

66

7-
87
use serde as edres;
98

109
pub use serde;

tests/ui/associated-types/impl-wf-cycle-6.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ impl Grault for () {
2121

2222
impl<T: Grault> Grault for (T,)
2323
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
24-
2524
{
2625
type A = ();
2726
type B = bool;

tests/ui/generics/generic-no-mangle.fixed

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#![allow(dead_code)]
33
#![deny(no_mangle_generic_items)]
44

5-
65
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
76

8-
97
pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
108

119
#[no_mangle]

tests/ui/imports/issue-52891.fixed

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ use issue_52891::{l,
2727
use issue_52891::a::inner;
2828
use issue_52891::b::inner as other_inner; //~ ERROR `inner` is defined multiple times
2929

30-
3130
//~^ ERROR `issue_52891` is defined multiple times
3231

33-
3432
#[macro_use]
3533
use issue_52891::n; //~ ERROR `n` is defined multiple times
3634

tests/ui/imports/unused-import-issue-87973.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![deny(unused_imports)]
33

44
// Check that attributes get removed too. See #87973.
5-
65
//~^ ERROR unused import
76

87
fn main() {}

tests/ui/lazy-type-alias/leading-where-clause.fixed

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
// Check that we *reject* leading where-clauses on lazy type aliases.
88

99
pub type Leading0<T>
10-
1110
= T where String: From<T>;
1211

1312
pub type Leading1<T, U>
14-
1513
= (T, U)
1614
where
1715
U: Copy, String: From<T>;

0 commit comments

Comments
 (0)