Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #5526

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions .github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ jobs:
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
# perform system upgrade to work around https://github.com/rust-lang/rust-clippy/issues/5477 , revert as soon as that is fixed
sudo apt-get -y upgrade
sudo apt-get install gcc-multilib libssl-dev:i386 libgit2-dev:i386
if: matrix.host == 'i686-unknown-linux-gnu'

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
- name: Set beta to true
if: github.ref == 'refs/heads/beta'
run: echo "::set-env name=BETA::true"

- name: Use scripts and templates from master branch
run: |
git fetch --no-tags --prune --depth=1 origin master
git checkout origin/master -- .github/deploy.sh util/gh-pages/ util/*.py

- name: Deploy
run: |
eval "$(ssh-agent -s)"
Expand Down
18 changes: 11 additions & 7 deletions clippy_lints/src/cargo_common_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use std::path::PathBuf;

use crate::utils::span_lint;
use rustc_ast::ast::Crate;
use rustc_lint::{EarlyContext, EarlyLintPass};
use crate::utils::{run_lints, span_lint};
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::DUMMY_SP;

Expand Down Expand Up @@ -35,11 +35,11 @@ declare_clippy_lint! {
"common metadata is defined in `Cargo.toml`"
}

fn warning(cx: &EarlyContext<'_>, message: &str) {
fn warning(cx: &LateContext<'_, '_>, message: &str) {
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message);
}

fn missing_warning(cx: &EarlyContext<'_>, package: &cargo_metadata::Package, field: &str) {
fn missing_warning(cx: &LateContext<'_, '_>, package: &cargo_metadata::Package, field: &str) {
let message = format!("package `{}` is missing `{}` metadata", package.name, field);
warning(cx, &message);
}
Expand All @@ -59,8 +59,12 @@ fn is_empty_vec(value: &[String]) -> bool {

declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]);

impl EarlyLintPass for CargoCommonMetadata {
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
impl LateLintPass<'_, '_> for CargoCommonMetadata {
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) {
return;
}

let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
metadata
} else {
Expand Down
21 changes: 10 additions & 11 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,8 @@ mod reexport {
/// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass.
///
/// Used in `./src/driver.rs`.
pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore, conf: &Conf) {
pub fn register_pre_expansion_lints(store: &mut rustc_lint::LintStore) {
store.register_pre_expansion_pass(|| box write::Write::default());
store.register_pre_expansion_pass(|| box redundant_field_names::RedundantFieldNames);
let single_char_binding_names_threshold = conf.single_char_binding_names_threshold;
store.register_pre_expansion_pass(move || box non_expressive_names::NonExpressiveNames {
single_char_binding_names_threshold,
});
store.register_pre_expansion_pass(|| box attrs::DeprecatedCfgAttribute);
store.register_pre_expansion_pass(|| box dbg_macro::DbgMacro);
}
Expand Down Expand Up @@ -1024,9 +1019,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_early_pass(|| box precedence::Precedence);
store.register_early_pass(|| box needless_continue::NeedlessContinue);
store.register_early_pass(|| box redundant_static_lifetimes::RedundantStaticLifetimes);
store.register_early_pass(|| box cargo_common_metadata::CargoCommonMetadata);
store.register_early_pass(|| box multiple_crate_versions::MultipleCrateVersions);
store.register_early_pass(|| box wildcard_dependencies::WildcardDependencies);
store.register_late_pass(|| box cargo_common_metadata::CargoCommonMetadata);
store.register_late_pass(|| box multiple_crate_versions::MultipleCrateVersions);
store.register_late_pass(|| box wildcard_dependencies::WildcardDependencies);
store.register_early_pass(|| box literal_representation::LiteralDigitGrouping);
let literal_representation_threshold = conf.literal_representation_threshold;
store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold));
Expand Down Expand Up @@ -1060,6 +1055,11 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box future_not_send::FutureNotSend);
store.register_late_pass(|| box utils::internal_lints::CollapsibleCalls);
store.register_late_pass(|| box if_let_mutex::IfLetMutex);
store.register_early_pass(|| box redundant_field_names::RedundantFieldNames);
let single_char_binding_names_threshold = conf.single_char_binding_names_threshold;
store.register_early_pass(move || box non_expressive_names::NonExpressiveNames {
single_char_binding_names_threshold,
});

store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
Expand Down Expand Up @@ -1134,6 +1134,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&loops::EXPLICIT_INTO_ITER_LOOP),
LintId::of(&loops::EXPLICIT_ITER_LOOP),
LintId::of(&macro_use::MACRO_USE_IMPORTS),
LintId::of(&matches::MATCH_BOOL),
LintId::of(&matches::SINGLE_MATCH_ELSE),
LintId::of(&methods::FILTER_MAP),
LintId::of(&methods::FILTER_MAP_NEXT),
Expand Down Expand Up @@ -1279,7 +1280,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN),
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
LintId::of(&matches::MATCH_AS_REF),
LintId::of(&matches::MATCH_BOOL),
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
LintId::of(&matches::MATCH_REF_PATS),
LintId::of(&matches::MATCH_SINGLE_BINDING),
Expand Down Expand Up @@ -1470,7 +1470,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&main_recursion::MAIN_RECURSION),
LintId::of(&map_clone::MAP_CLONE),
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
LintId::of(&matches::MATCH_BOOL),
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
LintId::of(&matches::MATCH_REF_PATS),
LintId::of(&matches::MATCH_WILD_ERR_ARM),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ declare_clippy_lint! {
/// }
/// ```
pub MATCH_BOOL,
style,
pedantic,
"a `match` on a boolean expression instead of an `if..else` block"
}

Expand Down
14 changes: 9 additions & 5 deletions clippy_lints/src/multiple_crate_versions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! lint on multiple versions of a crate being used

use crate::utils::span_lint;
use rustc_ast::ast::Crate;
use rustc_lint::{EarlyContext, EarlyLintPass};
use crate::utils::{run_lints, span_lint};
use rustc_hir::{Crate, CRATE_HIR_ID};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::DUMMY_SP;

Expand Down Expand Up @@ -33,8 +33,12 @@ declare_clippy_lint! {

declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]);

impl EarlyLintPass for MultipleCrateVersions {
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
impl LateLintPass<'_, '_> for MultipleCrateVersions {
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
if !run_lints(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) {
return;
}

let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().exec() {
metadata
} else {
Expand Down
32 changes: 25 additions & 7 deletions clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::SpanlessEq;
use crate::utils::{
is_expn_of, match_def_path, match_qpath, match_type, method_calls, paths, snippet, span_lint, span_lint_and_help,
span_lint_and_sugg, walk_ptrs_ty,
is_expn_of, match_def_path, match_qpath, match_type, method_calls, paths, run_lints, snippet, span_lint,
span_lint_and_help, span_lint_and_sugg, walk_ptrs_ty,
};
use if_chain::if_chain;
use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId};
Expand All @@ -10,7 +10,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc_hir::hir_id::CRATE_HIR_ID;
use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
use rustc_hir::{Crate, Expr, ExprKind, HirId, Item, MutTy, Mutability, Path, StmtKind, Ty, TyKind};
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
use rustc_middle::hir::map::Map;
Expand Down Expand Up @@ -252,6 +253,10 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
if !run_lints(cx, &[DEFAULT_LINT], item.hir_id) {
return;
}

if let hir::ItemKind::Static(ref ty, Mutability::Not, body_id) = item.kind {
if is_lint_ref_type(cx, ty) {
let expr = &cx.tcx.hir().body(body_id).value;
Expand Down Expand Up @@ -306,6 +311,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
}

fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate<'_>) {
if !run_lints(cx, &[LINT_WITHOUT_LINT_PASS], CRATE_HIR_ID) {
return;
}

for (lint_name, &lint_span) in &self.declared_lints {
// When using the `declare_tool_lint!` macro, the original `lint_span`'s
// file points to "<rustc macros>".
Expand Down Expand Up @@ -355,15 +364,12 @@ struct LintCollector<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> {
type Map = Map<'tcx>;

fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
walk_expr(self, expr);
}

fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) {
if path.segments.len() == 1 {
self.output.insert(path.segments[0].ident.name);
}
}

fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
NestedVisitorMap::All(self.cx.tcx.hir())
}
Expand Down Expand Up @@ -391,6 +397,10 @@ impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
if !run_lints(cx, &[COMPILER_LINT_FUNCTIONS], expr.hir_id) {
return;
}

if_chain! {
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind;
let fn_name = path.ident;
Expand All @@ -416,6 +426,10 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
if !run_lints(cx, &[OUTER_EXPN_EXPN_DATA], expr.hir_id) {
return;
}

let (method_names, arg_lists, spans) = method_calls(expr, 2);
let method_names: Vec<SymbolStr> = method_names.iter().map(|s| s.as_str()).collect();
let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect();
Expand Down Expand Up @@ -462,6 +476,10 @@ declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CollapsibleCalls {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
if !run_lints(cx, &[COLLAPSIBLE_SPAN_LINT_CALLS], expr.hir_id) {
return;
}

if_chain! {
if let ExprKind::Call(ref func, ref and_then_args) = expr.kind;
if let ExprKind::Path(ref path) = func.kind;
Expand Down
9 changes: 9 additions & 0 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,15 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_, '_>, did: DefId) -> bool
)
}

pub fn run_lints(cx: &LateContext<'_, '_>, lints: &[&'static Lint], id: HirId) -> bool {
lints.iter().any(|lint| {
matches!(
cx.tcx.lint_level_at_node(lint, id),
(Level::Forbid | Level::Deny | Level::Warn, _)
)
})
}

#[cfg(test)]
mod test {
use super::{trim_multiline, without_block_comments};
Expand Down
14 changes: 9 additions & 5 deletions clippy_lints/src/wildcard_dependencies.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::utils::span_lint;
use rustc_ast::ast::Crate;
use rustc_lint::{EarlyContext, EarlyLintPass};
use crate::utils::{run_lints, span_lint};
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::DUMMY_SP;

Expand Down Expand Up @@ -28,8 +28,12 @@ declare_clippy_lint! {

declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]);

impl EarlyLintPass for WildcardDependencies {
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
impl LateLintPass<'_, '_> for WildcardDependencies {
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
if !run_lints(cx, &[WILDCARD_DEPENDENCIES], CRATE_HIR_ID) {
return;
}

let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
metadata
} else {
Expand Down
12 changes: 11 additions & 1 deletion doc/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ to the beta Rust release. The remerge is then necessary, to make sure that the
Clippy commit, that was used by the now stable Rust release, persists in the
tree of the Clippy repository.

To find out if this step is necessary run

```bash
# Assumes that the local master branch is up-to-date
$ git fetch upstream
$ git branch master --contains upstream/beta
```

If this command outputs `master`, this step is **not** necessary.

```bash
# Assuming `HEAD` is the current `master` branch of rust-lang/rust-clippy
$ git checkout -b backport_remerge
Expand Down Expand Up @@ -97,5 +107,5 @@ be updated.
# Assuming the current directory corresponds to the Clippy repository
$ git checkout beta
$ git rebase $BETA_SHA
$ git push upstream beta [-f] # This requires a force push, if a remerge was done
$ git push upstream beta
```
2 changes: 1 addition & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {

let conf = clippy_lints::read_conf(&[], &sess);
clippy_lints::register_plugins(&mut lint_store, &sess, &conf);
clippy_lints::register_pre_expansion_lints(&mut lint_store, &conf);
clippy_lints::register_pre_expansion_lints(&mut lint_store);
clippy_lints::register_renamed(&mut lint_store);
}));

Expand Down
2 changes: 1 addition & 1 deletion src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
},
Lint {
name: "match_bool",
group: "style",
group: "pedantic",
desc: "a `match` on a boolean expression instead of an `if..else` block",
deprecation: None,
module: "matches",
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/implicit_return.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ fn test_if_block() -> bool {
}
}

#[allow(clippy::match_bool)]
#[rustfmt::skip]
fn test_match(x: bool) -> bool {
match x {
Expand All @@ -30,7 +29,7 @@ fn test_match(x: bool) -> bool {
}
}

#[allow(clippy::match_bool, clippy::needless_return)]
#[allow(clippy::needless_return)]
fn test_match_with_unreachable(x: bool) -> bool {
match x {
true => return false,
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/implicit_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ fn test_if_block() -> bool {
}
}

#[allow(clippy::match_bool)]
#[rustfmt::skip]
fn test_match(x: bool) -> bool {
match x {
Expand All @@ -30,7 +29,7 @@ fn test_match(x: bool) -> bool {
}
}

#[allow(clippy::match_bool, clippy::needless_return)]
#[allow(clippy::needless_return)]
fn test_match_with_unreachable(x: bool) -> bool {
match x {
true => return false,
Expand Down
Loading