diff options
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/context.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/internal.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/types.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 10 |
5 files changed, 56 insertions, 5 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 59540aaf18f..5b2100b5da9 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1288,7 +1288,7 @@ declare_lint! { } declare_lint_pass!( - /// Explains corresponding feature flag must be enabled for the `#[track_caller] attribute to + /// Explains corresponding feature flag must be enabled for the `#[track_caller]` attribute to /// do anything UngatedAsyncFnTrackCaller => [UNGATED_ASYNC_FN_TRACK_CALLER] ); diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index aace4974cc9..f5a711315ea 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -893,6 +893,23 @@ pub trait LintContext: Sized { BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive => { db.help("consider implementing the trait by hand, or remove the `packed` attribute"); } + BuiltinLintDiagnostics::UnusedExternCrate { removal_span }=> { + db.span_suggestion( + removal_span, + "remove it", + "", + Applicability::MachineApplicable, + ); + } + BuiltinLintDiagnostics::ExternCrateNotIdiomatic { vis_span, ident_span }=> { + let suggestion_span = vis_span.between(ident_span); + db.span_suggestion_verbose( + suggestion_span, + "convert it to a `use`", + if vis_span.is_empty() { "use " } else { " use " }, + Applicability::MachineApplicable, + ); + } } // Rewrap `db`, and pass control to the user. decorate(db) diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 2fd0ef3cda8..a14dc20fca3 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -17,6 +17,11 @@ use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; declare_tool_lint! { + /// The `default_hash_type` lint detects use of [`std::collections::HashMap`]/[`std::collections::HashSet`], + /// suggesting the use of `FxHashMap`/`FxHashSet`. + /// + /// This can help as `FxHasher` can perform better than the default hasher. DOS protection is not + /// required as input is assumed to be trusted. pub rustc::DEFAULT_HASH_TYPES, Allow, "forbid HashMap and HashSet and suggest the FxHash* variants", @@ -67,6 +72,12 @@ fn typeck_results_of_method_fn<'tcx>( } declare_tool_lint! { + /// The `potential_query_instability` lint detects use of methods which can lead to + /// potential query instability, such as iterating over a `HashMap`. + /// + /// Due to the [incremental compilation](https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html) model, + /// queries must return deterministic, stable results. `HashMap` iteration order can change between compilations, + /// and will introduce instability if query results expose the order. pub rustc::POTENTIAL_QUERY_INSTABILITY, Allow, "require explicit opt-in when using potentially unstable methods or functions", @@ -92,6 +103,8 @@ impl LateLintPass<'_> for QueryStability { } declare_tool_lint! { + /// The `usage_of_ty_tykind` lint detects usages of `ty::TyKind::<kind>`, + /// where `ty::<kind>` would suffice. pub rustc::USAGE_OF_TY_TYKIND, Allow, "usage of `ty::TyKind` outside of the `ty::sty` module", @@ -99,6 +112,8 @@ declare_tool_lint! { } declare_tool_lint! { + /// The `usage_of_qualified_ty` lint detects usages of `ty::TyKind`, + /// where `Ty` should be used instead. pub rustc::USAGE_OF_QUALIFIED_TY, Allow, "using `ty::{Ty,TyCtxt}` instead of importing it", @@ -254,6 +269,8 @@ fn gen_args(segment: &PathSegment<'_>) -> String { } declare_tool_lint! { + /// The `lint_pass_impl_without_macro` detects manual implementations of a lint + /// pass, without using [`declare_lint_pass`] or [`impl_lint_pass`]. pub rustc::LINT_PASS_IMPL_WITHOUT_MACRO, Allow, "`impl LintPass` without the `declare_lint_pass!` or `impl_lint_pass!` macros" @@ -285,6 +302,8 @@ impl EarlyLintPass for LintPassImpl { } declare_tool_lint! { + /// The `existing_doc_keyword` lint detects use `#[doc()]` keywords + /// that don't exist, e.g. `#[doc(keyword = "..")]`. pub rustc::EXISTING_DOC_KEYWORD, Allow, "Check that documented keywords in std and core actually exist", @@ -325,6 +344,10 @@ impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword { } declare_tool_lint! { + /// The `untranslatable_diagnostic` lint detects diagnostics created + /// without using translatable Fluent strings. + /// + /// More details on translatable diagnostics can be found [here](https://rustc-dev-guide.rust-lang.org/diagnostics/translation.html). pub rustc::UNTRANSLATABLE_DIAGNOSTIC, Allow, "prevent creation of diagnostics which cannot be translated", @@ -332,6 +355,11 @@ declare_tool_lint! { } declare_tool_lint! { + /// The `diagnostic_outside_of_impl` lint detects diagnostics created manually, + /// and inside an `IntoDiagnostic`/`AddToDiagnostic` implementation, + /// or a `#[derive(Diagnostic)]`/`#[derive(Subdiagnostic)]` expansion. + /// + /// More details on diagnostics implementations can be found [here](https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html). pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL, Allow, "prevent creation of diagnostics outside of `IntoDiagnostic`/`AddToDiagnostic` impls", @@ -396,6 +424,8 @@ impl LateLintPass<'_> for Diagnostics { } declare_tool_lint! { + /// The `bad_opt_access` lint detects accessing options by field instad of + /// the wrapper function. pub rustc::BAD_OPT_ACCESS, Deny, "prevent using options by field access when there is a wrapper function", diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 85958c41705..7ca50f5a2db 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -17,7 +17,7 @@ use rustc_hir::{is_range_literal, Expr, ExprKind, Node}; use rustc_middle::ty::layout::{IntegerExt, LayoutOf, SizeSkeleton}; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{ - self, AdtKind, DefIdTree, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, + self, AdtKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, }; use rustc_span::def_id::LocalDefId; use rustc_span::source_map; diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 3a92f5806c9..2ba365e298f 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -14,7 +14,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_infer::traits::util::elaborate_predicates_with_span; use rustc_middle::ty::adjustment; -use rustc_middle::ty::{self, DefIdTree, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::Symbol; use rustc_span::symbol::{kw, sym}; use rustc_span::{BytePos, Span}; @@ -1349,9 +1349,8 @@ declare_lint! { /// ### Example /// /// ```rust - /// #![feature(box_syntax)] /// fn main() { - /// let a = (box [1, 2, 3]).len(); + /// let a = Box::new([1, 2, 3]).len(); /// } /// ``` /// @@ -1373,6 +1372,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation { fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) { match e.kind { hir::ExprKind::Box(_) => {} + hir::ExprKind::Call(path_expr, [_]) + if let hir::ExprKind::Path(qpath) = &path_expr.kind + && let Some(did) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id() + && cx.tcx.is_diagnostic_item(sym::box_new, did) + => {} _ => return, } |
