Rollup merge of #120305 - clubby789:unused-import-line, r=estebank

Delete line if suggestion would replace it with an empty line

Fixes #120296
This commit is contained in:
Matthias Krüger 2024-03-01 22:38:45 +01:00 committed by GitHub
commit 3c89280684
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 67 additions and 27 deletions

View File

@ -428,7 +428,7 @@ impl DiagnosticSpan {
}
fn from_span_full(
span: Span,
mut span: Span,
is_primary: bool,
label: Option<String>,
suggestion: Option<(&String, Applicability)>,
@ -436,6 +436,16 @@ impl DiagnosticSpan {
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);

View File

@ -19,12 +19,10 @@ struct FooDefault<'a> {
}
#[derive(Default)]
struct TupleDefault(bool, i32, u64);
struct FooND1 {
a: bool,
}
@ -73,7 +71,6 @@ impl Default for FooNDVec {
struct StrDefault<'a>(&'a str);
#[derive(Default)]
struct AlreadyDerived(i32, bool);
@ -96,7 +93,6 @@ mac!(0);
#[derive(Default)]
struct Y(u32);
struct RustIssue26925<T> {
a: Option<T>,
}
@ -132,12 +128,10 @@ struct WithoutSelfCurly {
}
#[derive(Default)]
struct WithoutSelfParan(bool);
// https://github.com/rust-lang/rust-clippy/issues/7655
pub struct SpecializedImpl2<T> {
@ -184,7 +178,6 @@ pub struct RepeatDefault1 {
}
pub struct RepeatDefault2 {
a: [i8; 33],
}
@ -216,7 +209,6 @@ pub enum SimpleEnum {
}
pub enum NonExhaustiveEnum {
Foo,
#[non_exhaustive]

View File

@ -5,7 +5,6 @@
struct Foo;
// shouldn't cause an error
struct Bar;
@ -19,5 +18,4 @@ impl Drop for Bar {
struct Baz;
fn main() {}

View File

@ -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() {

View File

@ -4,7 +4,6 @@
use core;
use serde as edres;
pub use serde;

View File

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

View File

@ -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]

View File

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

View File

@ -2,7 +2,6 @@
#![deny(unused_imports)]
// Check that attributes get removed too. See #87973.
//~^ ERROR unused import
fn main() {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@
#[allow(unused_imports)]
use std::mem::transmute;
//~^ ERROR the name `transmute` is defined multiple times
fn main() {

View File

@ -9,7 +9,6 @@
#![deny(rust_2018_idioms)]
#![allow(dead_code)]
//~^ ERROR unused extern crate
// Shouldn't suggest changing to `use`, as `bar`

View File

@ -8,7 +8,6 @@
// The suggestion span should include the attribute.
//~^ ERROR unused extern crate
fn main() {}