about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-23 19:55:46 +0100
committerGitHub <noreply@github.com>2023-03-23 19:55:46 +0100
commit3961ef5bc84f8f6057e34bf61b92561bef5c8e64 (patch)
treed0023d3f23f36ec4e7a2d48dd2b1e94af11a4a38 /compiler/rustc_lint/src
parentdddede4a2472127268295065c8496fa554237e93 (diff)
parente03b13ccb7726005a49c5a9c6a3b47c8ba6804e6 (diff)
downloadrust-3961ef5bc84f8f6057e34bf61b92561bef5c8e64.tar.gz
rust-3961ef5bc84f8f6057e34bf61b92561bef5c8e64.zip
Rollup merge of #109487 - GuillaumeGomez:move-useless-reexport-check, r=petrochenkov
Move useless_anynous_reexport lint into unused_imports

As mentioned in https://github.com/rust-lang/rust/pull/109003, this check should have been merged with `unused_imports` in the start.

r? `@petrochenkov`
Diffstat (limited to 'compiler/rustc_lint/src')
-rw-r--r--compiler/rustc_lint/src/lib.rs3
-rw-r--r--compiler/rustc_lint/src/lints.rs8
-rw-r--r--compiler/rustc_lint/src/reexports.rs82
3 files changed, 0 insertions, 93 deletions
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs
index c2cc2fcdf55..b3578540516 100644
--- a/compiler/rustc_lint/src/lib.rs
+++ b/compiler/rustc_lint/src/lib.rs
@@ -74,7 +74,6 @@ mod opaque_hidden_inferred_bound;
 mod pass_by_value;
 mod passes;
 mod redundant_semicolon;
-mod reexports;
 mod traits;
 mod types;
 mod unused;
@@ -112,7 +111,6 @@ use noop_method_call::*;
 use opaque_hidden_inferred_bound::*;
 use pass_by_value::*;
 use redundant_semicolon::*;
-use reexports::*;
 use traits::*;
 use types::*;
 use unused::*;
@@ -244,7 +242,6 @@ late_lint_methods!(
             OpaqueHiddenInferredBound: OpaqueHiddenInferredBound,
             MultipleSupertraitUpcastable: MultipleSupertraitUpcastable,
             MapUnitFn: MapUnitFn,
-            UselessAnonymousReexport: UselessAnonymousReexport,
         ]
     ]
 );
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 46a025f41e0..308c02929ca 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -1528,11 +1528,3 @@ pub struct UnusedAllocationDiag;
 #[derive(LintDiagnostic)]
 #[diag(lint_unused_allocation_mut)]
 pub struct UnusedAllocationMutDiag;
-
-#[derive(LintDiagnostic)]
-#[diag(lint_useless_anonymous_reexport)]
-#[note]
-pub struct UselessAnonymousReexportDiag {
-    pub article: &'static str,
-    pub desc: &'static str,
-}
diff --git a/compiler/rustc_lint/src/reexports.rs b/compiler/rustc_lint/src/reexports.rs
deleted file mode 100644
index 8737a57ea02..00000000000
--- a/compiler/rustc_lint/src/reexports.rs
+++ /dev/null
@@ -1,82 +0,0 @@
-use crate::lints::UselessAnonymousReexportDiag;
-use crate::{LateContext, LateLintPass, LintContext};
-use rustc_hir::def::DefKind;
-use rustc_hir::def_id::DefId;
-use rustc_hir::{Item, ItemKind, UseKind};
-use rustc_middle::ty::Visibility;
-use rustc_span::symbol::kw;
-use rustc_span::Span;
-
-declare_lint! {
-    /// The `useless_anonymous_reexport` lint checks if anonymous re-exports
-    /// are re-exports of traits.
-    ///
-    /// ### Example
-    ///
-    /// ```rust,compile_fail
-    /// #![deny(useless_anonymous_reexport)]
-    ///
-    /// mod sub {
-    ///     pub struct Bar;
-    /// }
-    ///
-    /// pub use self::sub::Bar as _;
-    /// # fn main() {}
-    /// ```
-    ///
-    /// {{produces}}
-    ///
-    /// ### Explanation
-    ///
-    /// Anonymous re-exports are only useful if it's a re-export of a trait
-    /// in case you want to give access to it. If you re-export any other kind,
-    /// you won't be able to use it since its name won't be accessible.
-    pub USELESS_ANONYMOUS_REEXPORT,
-    Warn,
-    "useless anonymous re-export"
-}
-
-declare_lint_pass!(UselessAnonymousReexport => [USELESS_ANONYMOUS_REEXPORT]);
-
-fn emit_err(cx: &LateContext<'_>, span: Span, def_id: DefId) {
-    let article = cx.tcx.def_descr_article(def_id);
-    let desc = cx.tcx.def_descr(def_id);
-    cx.emit_spanned_lint(
-        USELESS_ANONYMOUS_REEXPORT,
-        span,
-        UselessAnonymousReexportDiag { article, desc },
-    );
-}
-
-impl<'tcx> LateLintPass<'tcx> for UselessAnonymousReexport {
-    fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
-        if let ItemKind::Use(path, kind) = item.kind &&
-            !matches!(kind, UseKind::Glob) &&
-            item.ident.name == kw::Underscore &&
-            // We only want re-exports. If it's just a `use X;`, then we ignore it.
-            match cx.tcx.local_visibility(item.owner_id.def_id) {
-                Visibility::Public => true,
-                Visibility::Restricted(level) => {
-                    level != cx.tcx.parent_module_from_def_id(item.owner_id.def_id)
-                }
-            }
-        {
-            for def_id in path.res.iter().filter_map(|r| r.opt_def_id()) {
-                match cx.tcx.def_kind(def_id) {
-                    DefKind::Trait | DefKind::TraitAlias => {}
-                    DefKind::TyAlias => {
-                        let ty = cx.tcx.type_of(def_id);
-                        if !ty.0.is_trait() {
-                            emit_err(cx, item.span, def_id);
-                            break;
-                        }
-                    }
-                    _ => {
-                        emit_err(cx, item.span, def_id);
-                        break;
-                    }
-                }
-            }
-        }
-    }
-}