Skip to content

Delete line if suggestion would replace it with an empty line #120305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,24 @@ impl DiagnosticSpan {
}

fn from_span_full(
span: Span,
mut span: Span,
is_primary: bool,
label: Option<String>,
suggestion: Option<(&String, Applicability)>,
mut backtrace: impl Iterator<Item = ExpnData>,
je: &JsonEmitter,
) -> DiagnosticSpan {
let start = je.sm.lookup_char_pos(span.lo());
// If this goes from the start of a line to the end and the replacement
// is an empty string, increase the length to include the newline so we don't
// leave an empty line
if start.col.0 == 0
&& suggestion.map_or(false, |(s, _)| s.is_empty())
&& let Ok(after) = je.sm.span_to_next_source(span)
&& after.starts_with('\n')
{
span = span.with_hi(span.hi() + rustc_span::BytePos(1));
}
let end = je.sm.lookup_char_pos(span.hi());
let backtrace_step = backtrace.next().map(|bt| {
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
Expand Down
8 changes: 0 additions & 8 deletions src/tools/clippy/tests/ui/derivable_impls.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ struct FooDefault<'a> {
}



#[derive(Default)]
struct TupleDefault(bool, i32, u64);



struct FooND1 {
a: bool,
}
Expand Down Expand Up @@ -73,7 +71,6 @@ impl Default for FooNDVec {
struct StrDefault<'a>(&'a str);



#[derive(Default)]
struct AlreadyDerived(i32, bool);

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


struct RustIssue26925<T> {
a: Option<T>,
}
Expand Down Expand Up @@ -132,12 +128,10 @@ struct WithoutSelfCurly {
}



#[derive(Default)]
struct WithoutSelfParan(bool);



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

pub struct SpecializedImpl2<T> {
Expand Down Expand Up @@ -184,7 +178,6 @@ pub struct RepeatDefault1 {
}



pub struct RepeatDefault2 {
a: [i8; 33],
}
Expand Down Expand Up @@ -216,7 +209,6 @@ pub enum SimpleEnum {
}



pub enum NonExhaustiveEnum {
Foo,
#[non_exhaustive]
Expand Down
2 changes: 0 additions & 2 deletions src/tools/clippy/tests/ui/empty_drop.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
struct Foo;



// shouldn't cause an error
struct Bar;

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



fn main() {}
3 changes: 0 additions & 3 deletions src/tools/clippy/tests/ui/must_use_unit.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
extern crate proc_macros;
use proc_macros::external;


pub fn must_use_default() {}


pub fn must_use_unit() -> () {}


pub fn must_use_with_note() {}

fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use core;



use serde as edres;

pub use serde;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/associated-types/impl-wf-cycle-6.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl Grault for () {

impl<T: Grault> Grault for (T,)
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`

{
type A = ();
type B = bool;
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/generics/generic-no-mangle.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
#![allow(dead_code)]
#![deny(no_mangle_generic_items)]


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


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

#[no_mangle]
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/imports/issue-52891.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ use issue_52891::{l,
use issue_52891::a::inner;
use issue_52891::b::inner as other_inner; //~ ERROR `inner` is defined multiple times


//~^ ERROR `issue_52891` is defined multiple times


#[macro_use]
use issue_52891::n; //~ ERROR `n` is defined multiple times

Expand Down
1 change: 0 additions & 1 deletion tests/ui/imports/unused-import-issue-87973.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![deny(unused_imports)]

// Check that attributes get removed too. See #87973.

//~^ ERROR unused import

fn main() {}
2 changes: 0 additions & 2 deletions tests/ui/lazy-type-alias/leading-where-clause.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
// Check that we *reject* leading where-clauses on lazy type aliases.

pub type Leading0<T>

= T where String: From<T>;

pub type Leading1<T, U>

= (T, U)
where
U: Copy, String: From<T>;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/lint/suggestions.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//~^ ERROR const items should never be `#[no_mangle]`
//~| HELP try a static value


//~^ HELP remove this attribute
pub fn defiant<T>(_t: T) {}
//~^ WARN functions generic over types or consts must be mangled
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/lint/unused/import_remove_line.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ run-rustfix
//@ check-pass

#![crate_type = "lib"]
#![warn(unused_imports)]

//~^ WARN unused imports
//~^ WARN unused import

//~^ WARN unused import
//~| WARN unused import
13 changes: 13 additions & 0 deletions tests/ui/lint/unused/import_remove_line.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ run-rustfix
//@ check-pass

#![crate_type = "lib"]
#![warn(unused_imports)]

use std::time::{Duration, Instant};
//~^ WARN unused imports
use std::time::SystemTime;
//~^ WARN unused import
use std::time::SystemTimeError;use std::time::TryFromFloatSecsError;
//~^ WARN unused import
//~| WARN unused import
32 changes: 32 additions & 0 deletions tests/ui/lint/unused/import_remove_line.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
warning: unused imports: `Duration`, `Instant`
--> $DIR/import_remove_line.rs:7:17
|
LL | use std::time::{Duration, Instant};
| ^^^^^^^^ ^^^^^^^
|
note: the lint level is defined here
--> $DIR/import_remove_line.rs:5:9
|
LL | #![warn(unused_imports)]
| ^^^^^^^^^^^^^^

warning: unused import: `std::time::SystemTime`
--> $DIR/import_remove_line.rs:9:5
|
LL | use std::time::SystemTime;
| ^^^^^^^^^^^^^^^^^^^^^

warning: unused import: `std::time::SystemTimeError`
--> $DIR/import_remove_line.rs:11:5
|
LL | use std::time::SystemTimeError;use std::time::TryFromFloatSecsError;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused import: `std::time::TryFromFloatSecsError`
--> $DIR/import_remove_line.rs:11:36
|
LL | use std::time::SystemTimeError;use std::time::TryFromFloatSecsError;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: 4 warnings emitted

1 change: 0 additions & 1 deletion tests/ui/resolve/resolve-conflict-import-vs-import.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#[allow(unused_imports)]
use std::mem::transmute;

//~^ ERROR the name `transmute` is defined multiple times

fn main() {
Expand Down
1 change: 0 additions & 1 deletion tests/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#![deny(rust_2018_idioms)]
#![allow(dead_code)]


//~^ ERROR unused extern crate

// Shouldn't suggest changing to `use`, as `bar`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

// The suggestion span should include the attribute.


//~^ ERROR unused extern crate

fn main() {}