Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7650bd1
Add cpass to incremental tests
Dec 16, 2022
97915ab
Add note for mismatched types with circular dependencies
Dec 16, 2022
dfe4c49
Use Edition 2021 :pat in matches macro
sugar700 Mar 6, 2023
c21f1d0
read_buf_exact: on error, all read bytes are appended to the buffer
tmiasko Mar 11, 2023
2df7770
Add lint for useless anonymous reexports
GuillaumeGomez Mar 10, 2023
ac4ea52
Add test for useless_anonymous_reexport lint
GuillaumeGomez Mar 10, 2023
7b0fa08
Update failing ui tests
GuillaumeGomez Mar 12, 2023
f663f09
Beautify pin! docs
est31 Mar 10, 2023
c22f154
Do not ICE for native_lib without name
chenyukang Mar 16, 2023
7bc67ef
Make the `Step` implementations const.
onestacked Feb 4, 2023
0dc36fc
fix: don't suggest similar method when unstable
Ezrashaw Mar 16, 2023
d1712f4
move default backtrace setting to sys
devsnek Mar 6, 2023
3ae03c7
review
devsnek Mar 18, 2023
8a9d6bf
Mark DoubleEndedIterator as #[const_trait] using rustc_do_not_const_c…
onestacked Feb 4, 2023
38be6f2
Implement FixedSizeEncoding for UnusedGenericParams.
cjgillot Mar 18, 2023
d5558e6
The name of NativeLib will be presented
chenyukang Mar 17, 2023
993b775
Rollup merge of #104100 - ink-feather-org:const_iter_range, r=the8472…
Dylan-DPC Mar 19, 2023
e9c25b4
Rollup merge of #105793 - lukas-code:circular-deps, r=Mark-Simulacrum
Dylan-DPC Mar 19, 2023
e458a79
Rollup merge of #108798 - devsnek:panic-pal-exception, r=workingjubilee
Dylan-DPC Mar 19, 2023
acaae90
Rollup merge of #108829 - xfix:use-edition-2021-pat-in-matches, r=Mar…
Dylan-DPC Mar 19, 2023
c8e112a
Rollup merge of #108973 - est31:pin_docs, r=Mark-Simulacrum
Dylan-DPC Mar 19, 2023
462e7e7
Rollup merge of #109003 - GuillaumeGomez:useless-anonymous-reexport-l…
Dylan-DPC Mar 19, 2023
654204f
Rollup merge of #109022 - tmiasko:read-buf-exact, r=dtolnay
Dylan-DPC Mar 19, 2023
879d6f2
Rollup merge of #109212 - Ezrashaw:no-similar-sugg-for-unstable, r=es…
Dylan-DPC Mar 19, 2023
1f0fcf1
Rollup merge of #109243 - chenyukang:yukang/fix-ice-109144, r=petroch…
Dylan-DPC Mar 19, 2023
881c989
Rollup merge of #109324 - cjgillot:fixed-unused-params, r=Nilstrieb
Dylan-DPC Mar 19, 2023
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
Prev Previous commit
Next Next commit
Add lint for useless anonymous reexports
  • Loading branch information
GuillaumeGomez committed Mar 12, 2023
commit 2df7770d5e8e32728e0add987c65ce8a95fc475d
3 changes: 3 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,6 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass
.specifically = this associated type bound is unsatisfied for `{$proj_ty}`

lint_opaque_hidden_inferred_bound_sugg = add this bound

lint_useless_anonymous_reexport = useless anonymous re-export
.note = only anonymous re-exports of traits are useful, this is {$article} `${desc}`
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod opaque_hidden_inferred_bound;
mod pass_by_value;
mod passes;
mod redundant_semicolon;
mod reexports;
mod traits;
mod types;
mod unused;
Expand Down Expand Up @@ -111,6 +112,7 @@ use noop_method_call::*;
use opaque_hidden_inferred_bound::*;
use pass_by_value::*;
use redundant_semicolon::*;
use reexports::*;
use traits::*;
use types::*;
use unused::*;
Expand Down Expand Up @@ -242,6 +244,7 @@ late_lint_methods!(
OpaqueHiddenInferredBound: OpaqueHiddenInferredBound,
MultipleSupertraitUpcastable: MultipleSupertraitUpcastable,
MapUnitFn: MapUnitFn,
UselessAnonymousReexport: UselessAnonymousReexport,
]
]
);
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,3 +1530,10 @@ pub struct UnusedAllocationDiag;
#[derive(LintDiagnostic)]
#[diag(lint_unused_allocation_mut)]
pub struct UnusedAllocationMutDiag;

#[derive(LintDiagnostic)]
#[diag(lint_useless_anonymous_reexport)]
pub struct UselessAnonymousReexportDiag {
pub article: &'static str,
pub desc: &'static str,
}
82 changes: 82 additions & 0 deletions compiler/rustc_lint/src/reexports.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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;
}
}
}
}
}
}