mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
If suggestion would leave an empty line, delete it
This commit is contained in:
parent
b0696a5160
commit
367126d49a
@ -428,7 +428,7 @@ impl DiagnosticSpan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn from_span_full(
|
fn from_span_full(
|
||||||
span: Span,
|
mut span: Span,
|
||||||
is_primary: bool,
|
is_primary: bool,
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
suggestion: Option<(&String, Applicability)>,
|
suggestion: Option<(&String, Applicability)>,
|
||||||
@ -436,6 +436,16 @@ impl DiagnosticSpan {
|
|||||||
je: &JsonEmitter,
|
je: &JsonEmitter,
|
||||||
) -> DiagnosticSpan {
|
) -> DiagnosticSpan {
|
||||||
let start = je.sm.lookup_char_pos(span.lo());
|
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 end = je.sm.lookup_char_pos(span.hi());
|
||||||
let backtrace_step = backtrace.next().map(|bt| {
|
let backtrace_step = backtrace.next().map(|bt| {
|
||||||
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
|
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);
|
||||||
|
@ -19,12 +19,10 @@ struct FooDefault<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct TupleDefault(bool, i32, u64);
|
struct TupleDefault(bool, i32, u64);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct FooND1 {
|
struct FooND1 {
|
||||||
a: bool,
|
a: bool,
|
||||||
}
|
}
|
||||||
@ -73,7 +71,6 @@ impl Default for FooNDVec {
|
|||||||
struct StrDefault<'a>(&'a str);
|
struct StrDefault<'a>(&'a str);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct AlreadyDerived(i32, bool);
|
struct AlreadyDerived(i32, bool);
|
||||||
|
|
||||||
@ -96,7 +93,6 @@ mac!(0);
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Y(u32);
|
struct Y(u32);
|
||||||
|
|
||||||
|
|
||||||
struct RustIssue26925<T> {
|
struct RustIssue26925<T> {
|
||||||
a: Option<T>,
|
a: Option<T>,
|
||||||
}
|
}
|
||||||
@ -132,12 +128,10 @@ struct WithoutSelfCurly {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct WithoutSelfParan(bool);
|
struct WithoutSelfParan(bool);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// https://github.com/rust-lang/rust-clippy/issues/7655
|
// https://github.com/rust-lang/rust-clippy/issues/7655
|
||||||
|
|
||||||
pub struct SpecializedImpl2<T> {
|
pub struct SpecializedImpl2<T> {
|
||||||
@ -184,7 +178,6 @@ pub struct RepeatDefault1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub struct RepeatDefault2 {
|
pub struct RepeatDefault2 {
|
||||||
a: [i8; 33],
|
a: [i8; 33],
|
||||||
}
|
}
|
||||||
@ -216,7 +209,6 @@ pub enum SimpleEnum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub enum NonExhaustiveEnum {
|
pub enum NonExhaustiveEnum {
|
||||||
Foo,
|
Foo,
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// shouldn't cause an error
|
// shouldn't cause an error
|
||||||
struct Bar;
|
struct Bar;
|
||||||
|
|
||||||
@ -19,5 +18,4 @@ impl Drop for Bar {
|
|||||||
struct Baz;
|
struct Baz;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -6,13 +6,10 @@
|
|||||||
extern crate proc_macros;
|
extern crate proc_macros;
|
||||||
use proc_macros::external;
|
use proc_macros::external;
|
||||||
|
|
||||||
|
|
||||||
pub fn must_use_default() {}
|
pub fn must_use_default() {}
|
||||||
|
|
||||||
|
|
||||||
pub fn must_use_unit() -> () {}
|
pub fn must_use_unit() -> () {}
|
||||||
|
|
||||||
|
|
||||||
pub fn must_use_with_note() {}
|
pub fn must_use_with_note() {}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
use core;
|
use core;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use serde as edres;
|
use serde as edres;
|
||||||
|
|
||||||
pub use serde;
|
pub use serde;
|
||||||
|
@ -21,7 +21,6 @@ impl Grault for () {
|
|||||||
|
|
||||||
impl<T: Grault> Grault for (T,)
|
impl<T: Grault> Grault for (T,)
|
||||||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||||
|
|
||||||
{
|
{
|
||||||
type A = ();
|
type A = ();
|
||||||
type B = bool;
|
type B = bool;
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![deny(no_mangle_generic_items)]
|
#![deny(no_mangle_generic_items)]
|
||||||
|
|
||||||
|
|
||||||
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
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
|
pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -27,10 +27,8 @@ use issue_52891::{l,
|
|||||||
use issue_52891::a::inner;
|
use issue_52891::a::inner;
|
||||||
use issue_52891::b::inner as other_inner; //~ ERROR `inner` is defined multiple times
|
use issue_52891::b::inner as other_inner; //~ ERROR `inner` is defined multiple times
|
||||||
|
|
||||||
|
|
||||||
//~^ ERROR `issue_52891` is defined multiple times
|
//~^ ERROR `issue_52891` is defined multiple times
|
||||||
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
use issue_52891::n; //~ ERROR `n` is defined multiple times
|
use issue_52891::n; //~ ERROR `n` is defined multiple times
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#![deny(unused_imports)]
|
#![deny(unused_imports)]
|
||||||
|
|
||||||
// Check that attributes get removed too. See #87973.
|
// Check that attributes get removed too. See #87973.
|
||||||
|
|
||||||
//~^ ERROR unused import
|
//~^ ERROR unused import
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -7,11 +7,9 @@
|
|||||||
// Check that we *reject* leading where-clauses on lazy type aliases.
|
// Check that we *reject* leading where-clauses on lazy type aliases.
|
||||||
|
|
||||||
pub type Leading0<T>
|
pub type Leading0<T>
|
||||||
|
|
||||||
= T where String: From<T>;
|
= T where String: From<T>;
|
||||||
|
|
||||||
pub type Leading1<T, U>
|
pub type Leading1<T, U>
|
||||||
|
|
||||||
= (T, U)
|
= (T, U)
|
||||||
where
|
where
|
||||||
U: Copy, String: From<T>;
|
U: Copy, String: From<T>;
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
//~^ ERROR const items should never be `#[no_mangle]`
|
//~^ ERROR const items should never be `#[no_mangle]`
|
||||||
//~| HELP try a static value
|
//~| HELP try a static value
|
||||||
|
|
||||||
|
|
||||||
//~^ HELP remove this attribute
|
//~^ HELP remove this attribute
|
||||||
pub fn defiant<T>(_t: T) {}
|
pub fn defiant<T>(_t: T) {}
|
||||||
//~^ WARN functions generic over types or consts must be mangled
|
//~^ WARN functions generic over types or consts must be mangled
|
||||||
|
11
tests/ui/lint/unused/import_remove_line.fixed
Normal file
11
tests/ui/lint/unused/import_remove_line.fixed
Normal 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
|
13
tests/ui/lint/unused/import_remove_line.rs
Normal file
13
tests/ui/lint/unused/import_remove_line.rs
Normal 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
|
32
tests/ui/lint/unused/import_remove_line.stderr
Normal file
32
tests/ui/lint/unused/import_remove_line.stderr
Normal 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
|
||||||
|
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
|
|
||||||
//~^ ERROR the name `transmute` is defined multiple times
|
//~^ ERROR the name `transmute` is defined multiple times
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
|
||||||
//~^ ERROR unused extern crate
|
//~^ ERROR unused extern crate
|
||||||
|
|
||||||
// Shouldn't suggest changing to `use`, as `bar`
|
// Shouldn't suggest changing to `use`, as `bar`
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
// The suggestion span should include the attribute.
|
// The suggestion span should include the attribute.
|
||||||
|
|
||||||
|
|
||||||
//~^ ERROR unused extern crate
|
//~^ ERROR unused extern crate
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user