Skip to content

Commit a670466

Browse files
authored
Unrolled build for rust-lang#120305
Rollup merge of rust-lang#120305 - clubby789:unused-import-line, r=estebank Delete line if suggestion would replace it with an empty line Fixes rust-lang#120296
2 parents e612d07 + 367126d commit a670466

17 files changed

+67
-27
lines changed

compiler/rustc_errors/src/json.rs

+11-1
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

-8
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

-2
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

-3
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

-1
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

-1
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

-2
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

-2
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

-1
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

-2
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>;

tests/ui/lint/suggestions.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//~^ ERROR const items should never be `#[no_mangle]`
88
//~| HELP try a static value
99

10-
1110
//~^ HELP remove this attribute
1211
pub fn defiant<T>(_t: T) {}
1312
//~^ WARN functions generic over types or consts must be mangled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ run-rustfix
2+
//@ check-pass
3+
4+
#![crate_type = "lib"]
5+
#![warn(unused_imports)]
6+
7+
//~^ WARN unused imports
8+
//~^ WARN unused import
9+
10+
//~^ WARN unused import
11+
//~| WARN unused import
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-rustfix
2+
//@ check-pass
3+
4+
#![crate_type = "lib"]
5+
#![warn(unused_imports)]
6+
7+
use std::time::{Duration, Instant};
8+
//~^ WARN unused imports
9+
use std::time::SystemTime;
10+
//~^ WARN unused import
11+
use std::time::SystemTimeError;use std::time::TryFromFloatSecsError;
12+
//~^ WARN unused import
13+
//~| WARN unused import
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
warning: unused imports: `Duration`, `Instant`
2+
--> $DIR/import_remove_line.rs:7:17
3+
|
4+
LL | use std::time::{Duration, Instant};
5+
| ^^^^^^^^ ^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/import_remove_line.rs:5:9
9+
|
10+
LL | #![warn(unused_imports)]
11+
| ^^^^^^^^^^^^^^
12+
13+
warning: unused import: `std::time::SystemTime`
14+
--> $DIR/import_remove_line.rs:9:5
15+
|
16+
LL | use std::time::SystemTime;
17+
| ^^^^^^^^^^^^^^^^^^^^^
18+
19+
warning: unused import: `std::time::SystemTimeError`
20+
--> $DIR/import_remove_line.rs:11:5
21+
|
22+
LL | use std::time::SystemTimeError;use std::time::TryFromFloatSecsError;
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
warning: unused import: `std::time::TryFromFloatSecsError`
26+
--> $DIR/import_remove_line.rs:11:36
27+
|
28+
LL | use std::time::SystemTimeError;use std::time::TryFromFloatSecsError;
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
31+
warning: 4 warnings emitted
32+

tests/ui/resolve/resolve-conflict-import-vs-import.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#[allow(unused_imports)]
44
use std::mem::transmute;
5-
65
//~^ ERROR the name `transmute` is defined multiple times
76

87
fn main() {

tests/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#![deny(rust_2018_idioms)]
1010
#![allow(dead_code)]
1111

12-
1312
//~^ ERROR unused extern crate
1413

1514
// Shouldn't suggest changing to `use`, as `bar`

tests/ui/rust-2018/issue-54400-unused-extern-crate-attr-span.fixed

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
// The suggestion span should include the attribute.
1010

11-
1211
//~^ ERROR unused extern crate
1312

1413
fn main() {}

0 commit comments

Comments
 (0)