Skip to content

Commit dffdd8f

Browse files
authored
Rollup merge of rust-lang#58805 - fabric-and-ink:redundant_import, r=petrochenkov
Lint for redundant imports Add lint for redundant imports. The changes are suggested by @petrochenkov. Closes rust-lang#10178.
2 parents a89c03a + c1d5314 commit dffdd8f

File tree

30 files changed

+198
-42
lines changed

30 files changed

+198
-42
lines changed

src/liballoc/borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<T> ToOwned for T
135135
/// Another example showing how to keep `Cow` in a struct:
136136
///
137137
/// ```
138-
/// use std::borrow::{Cow, ToOwned};
138+
/// use std::borrow::Cow;
139139
///
140140
/// struct Items<'a, X: 'a> where [X]: ToOwned<Owned = Vec<X>> {
141141
/// values: Cow<'a, [X]>,

src/libcore/cell.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,6 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
14211421
///
14221422
/// ```
14231423
/// use std::cell::UnsafeCell;
1424-
/// use std::marker::Sync;
14251424
///
14261425
/// # #[allow(dead_code)]
14271426
/// struct NotThreadSafe<T> {

src/librustc/lint/builtin.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ pub enum BuiltinLintDiagnostics {
483483
UnknownCrateTypes(Span, String, String),
484484
UnusedImports(String, Vec<(Span, String)>),
485485
NestedImplTrait { outer_impl_trait_span: Span, inner_impl_trait_span: Span },
486+
RedundantImport(Vec<(Span, bool)>, ast::Ident),
486487
}
487488

488489
impl BuiltinLintDiagnostics {
@@ -579,6 +580,15 @@ impl BuiltinLintDiagnostics {
579580
db.span_label(outer_impl_trait_span, "outer `impl Trait`");
580581
db.span_label(inner_impl_trait_span, "nested `impl Trait` here");
581582
}
583+
BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
584+
for (span, is_imported) in spans {
585+
let introduced = if is_imported { "imported" } else { "defined" };
586+
db.span_label(
587+
span,
588+
format!("the item `{}` is already {} here", ident, introduced)
589+
);
590+
}
591+
}
582592
}
583593
}
584594
}

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@ impl<'enc, 'a, 'tcx, E> CacheEncoder<'enc, 'a, 'tcx, E>
777777
value: &V)
778778
-> Result<(), E::Error>
779779
{
780-
use crate::ty::codec::TyEncoder;
781780
let start_pos = self.position();
782781

783782
tag.encode(self)?;

src/librustc_codegen_llvm/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
372372
// Returns a Value of the "eh_unwind_resume" lang item if one is defined,
373373
// otherwise declares it as an external function.
374374
fn eh_unwind_resume(&self) -> &'ll Value {
375-
use crate::attributes;
376375
let unwresume = &self.eh_unwind_resume;
377376
if let Some(llfn) = unwresume.get() {
378377
return llfn;

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,6 @@ fn cast_int_to_float<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
732732
// All inputs greater or equal to (f32::MAX + 0.5 ULP) are rounded to infinity,
733733
// and for everything else LLVM's uitofp works just fine.
734734
use rustc_apfloat::ieee::Single;
735-
use rustc_apfloat::Float;
736735
const MAX_F32_PLUS_HALF_ULP: u128 = ((1 << (Single::PRECISION + 1)) - 1)
737736
<< (Single::MAX_EXP - Single::PRECISION as i16);
738737
let max = bx.cx().const_uint_big(int_ty, MAX_F32_PLUS_HALF_ULP);

src/librustc_codegen_ssa/traits/type_.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
7777
}
7878

7979
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
80-
use syntax_pos::DUMMY_SP;
8180
if ty.is_sized(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all()) {
8281
return false;
8382
}

src/librustc_errors/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl CodeSuggestion {
155155
/// Returns the assembled code suggestions and whether they should be shown with an underline.
156156
pub fn splice_lines(&self, cm: &SourceMapperDyn)
157157
-> Vec<(String, Vec<SubstitutionPart>)> {
158-
use syntax_pos::{CharPos, Loc, Pos};
158+
use syntax_pos::{CharPos, Pos};
159159

160160
fn push_trailing(buf: &mut String,
161161
line_opt: Option<&Cow<'_, str>>,

src/librustc_interface/profile/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ fn total_duration(traces: &[trace::Rec]) -> Duration {
6262
fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
6363
use self::trace::*;
6464
use std::fs::File;
65-
use std::time::{Instant};
6665

6766
let mut profq_msgs: Vec<ProfileQueriesMsg> = vec![];
6867
let mut frame: StackFrame = StackFrame { parse_st: ParseState::Clear, traces: vec![] };

src/librustc_mir/hair/pattern/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
427427

428428
let mut kind = match (lo, hi) {
429429
(PatternKind::Constant { value: lo }, PatternKind::Constant { value: hi }) => {
430-
use std::cmp::Ordering;
431430
let cmp = compare_const_vals(
432431
self.tcx,
433432
lo,

0 commit comments

Comments
 (0)