Skip to content

Commit 77c23b7

Browse files
committed
Auto merge of rust-lang#5527 - flip1995:rollup-pr2htfd, r=flip1995
Rollup of 5 pull requests Successful merges: - rust-lang#5408 (Downgrade match_bool to pedantic) - rust-lang#5505 (Avoid running cargo+internal lints when not enabled) - rust-lang#5516 (Add a note to the beta sections of release.md) - rust-lang#5517 (Deploy time travel) - rust-lang#5523 (Add lifetime test case for `new_ret_no_self`) Failed merges: r? @ghost changelog: rollup
2 parents 6ffe725 + 9b882ba commit 77c23b7

19 files changed

+124
-57
lines changed

.github/workflows/clippy_bors.yml

-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ jobs:
7777
run: |
7878
sudo dpkg --add-architecture i386
7979
sudo apt-get update
80-
# perform system upgrade to work around https://github.com/rust-lang/rust-clippy/issues/5477 , revert as soon as that is fixed
81-
sudo apt-get -y upgrade
8280
sudo apt-get install gcc-multilib libssl-dev:i386 libgit2-dev:i386
8381
if: matrix.host == 'i686-unknown-linux-gnu'
8482

.github/workflows/deploy.yml

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ jobs:
3838
- name: Set beta to true
3939
if: github.ref == 'refs/heads/beta'
4040
run: echo "::set-env name=BETA::true"
41+
42+
- name: Use scripts and templates from master branch
43+
run: |
44+
git fetch --no-tags --prune --depth=1 origin master
45+
git checkout origin/master -- .github/deploy.sh util/gh-pages/ util/*.py
46+
4147
- name: Deploy
4248
run: |
4349
eval "$(ssh-agent -s)"

clippy_lints/src/cargo_common_metadata.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
33
use std::path::PathBuf;
44

5-
use crate::utils::span_lint;
6-
use rustc_ast::ast::Crate;
7-
use rustc_lint::{EarlyContext, EarlyLintPass};
5+
use crate::utils::{run_lints, span_lint};
6+
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
7+
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::source_map::DUMMY_SP;
1010

@@ -35,11 +35,11 @@ declare_clippy_lint! {
3535
"common metadata is defined in `Cargo.toml`"
3636
}
3737

38-
fn warning(cx: &EarlyContext<'_>, message: &str) {
38+
fn warning(cx: &LateContext<'_, '_>, message: &str) {
3939
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message);
4040
}
4141

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

6060
declare_lint_pass!(CargoCommonMetadata => [CARGO_COMMON_METADATA]);
6161

62-
impl EarlyLintPass for CargoCommonMetadata {
63-
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
62+
impl LateLintPass<'_, '_> for CargoCommonMetadata {
63+
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
64+
if !run_lints(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) {
65+
return;
66+
}
67+
6468
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
6569
metadata
6670
} else {

clippy_lints/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1024,9 +1024,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10241024
store.register_early_pass(|| box precedence::Precedence);
10251025
store.register_early_pass(|| box needless_continue::NeedlessContinue);
10261026
store.register_early_pass(|| box redundant_static_lifetimes::RedundantStaticLifetimes);
1027-
store.register_early_pass(|| box cargo_common_metadata::CargoCommonMetadata);
1028-
store.register_early_pass(|| box multiple_crate_versions::MultipleCrateVersions);
1029-
store.register_early_pass(|| box wildcard_dependencies::WildcardDependencies);
1027+
store.register_late_pass(|| box cargo_common_metadata::CargoCommonMetadata);
1028+
store.register_late_pass(|| box multiple_crate_versions::MultipleCrateVersions);
1029+
store.register_late_pass(|| box wildcard_dependencies::WildcardDependencies);
10301030
store.register_early_pass(|| box literal_representation::LiteralDigitGrouping);
10311031
let literal_representation_threshold = conf.literal_representation_threshold;
10321032
store.register_early_pass(move || box literal_representation::DecimalLiteralRepresentation::new(literal_representation_threshold));
@@ -1134,6 +1134,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11341134
LintId::of(&loops::EXPLICIT_INTO_ITER_LOOP),
11351135
LintId::of(&loops::EXPLICIT_ITER_LOOP),
11361136
LintId::of(&macro_use::MACRO_USE_IMPORTS),
1137+
LintId::of(&matches::MATCH_BOOL),
11371138
LintId::of(&matches::SINGLE_MATCH_ELSE),
11381139
LintId::of(&methods::FILTER_MAP),
11391140
LintId::of(&methods::FILTER_MAP_NEXT),
@@ -1279,7 +1280,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12791280
LintId::of(&map_unit_fn::RESULT_MAP_UNIT_FN),
12801281
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
12811282
LintId::of(&matches::MATCH_AS_REF),
1282-
LintId::of(&matches::MATCH_BOOL),
12831283
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
12841284
LintId::of(&matches::MATCH_REF_PATS),
12851285
LintId::of(&matches::MATCH_SINGLE_BINDING),
@@ -1470,7 +1470,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14701470
LintId::of(&main_recursion::MAIN_RECURSION),
14711471
LintId::of(&map_clone::MAP_CLONE),
14721472
LintId::of(&matches::INFALLIBLE_DESTRUCTURING_MATCH),
1473-
LintId::of(&matches::MATCH_BOOL),
14741473
LintId::of(&matches::MATCH_OVERLAPPING_ARM),
14751474
LintId::of(&matches::MATCH_REF_PATS),
14761475
LintId::of(&matches::MATCH_WILD_ERR_ARM),

clippy_lints/src/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ declare_clippy_lint! {
138138
/// }
139139
/// ```
140140
pub MATCH_BOOL,
141-
style,
141+
pedantic,
142142
"a `match` on a boolean expression instead of an `if..else` block"
143143
}
144144

clippy_lints/src/multiple_crate_versions.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! lint on multiple versions of a crate being used
22
3-
use crate::utils::span_lint;
4-
use rustc_ast::ast::Crate;
5-
use rustc_lint::{EarlyContext, EarlyLintPass};
3+
use crate::utils::{run_lints, span_lint};
4+
use rustc_hir::{Crate, CRATE_HIR_ID};
5+
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77
use rustc_span::source_map::DUMMY_SP;
88

@@ -33,8 +33,12 @@ declare_clippy_lint! {
3333

3434
declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]);
3535

36-
impl EarlyLintPass for MultipleCrateVersions {
37-
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
36+
impl LateLintPass<'_, '_> for MultipleCrateVersions {
37+
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
38+
if !run_lints(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) {
39+
return;
40+
}
41+
3842
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().exec() {
3943
metadata
4044
} else {

clippy_lints/src/utils/internal_lints.rs

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::SpanlessEq;
22
use crate::utils::{
3-
is_expn_of, match_def_path, match_qpath, match_type, method_calls, paths, snippet, span_lint, span_lint_and_help,
4-
span_lint_and_sugg, walk_ptrs_ty,
3+
is_expn_of, match_def_path, match_qpath, match_type, method_calls, paths, run_lints, snippet, span_lint,
4+
span_lint_and_help, span_lint_and_sugg, walk_ptrs_ty,
55
};
66
use if_chain::if_chain;
77
use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId};
@@ -10,7 +10,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_errors::Applicability;
1111
use rustc_hir as hir;
1212
use rustc_hir::def::{DefKind, Res};
13-
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
13+
use rustc_hir::hir_id::CRATE_HIR_ID;
14+
use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
1415
use rustc_hir::{Crate, Expr, ExprKind, HirId, Item, MutTy, Mutability, Path, StmtKind, Ty, TyKind};
1516
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
1617
use rustc_middle::hir::map::Map;
@@ -252,6 +253,10 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]);
252253

253254
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
254255
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'_>) {
256+
if !run_lints(cx, &[DEFAULT_LINT], item.hir_id) {
257+
return;
258+
}
259+
255260
if let hir::ItemKind::Static(ref ty, Mutability::Not, body_id) = item.kind {
256261
if is_lint_ref_type(cx, ty) {
257262
let expr = &cx.tcx.hir().body(body_id).value;
@@ -306,6 +311,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
306311
}
307312

308313
fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate<'_>) {
314+
if !run_lints(cx, &[LINT_WITHOUT_LINT_PASS], CRATE_HIR_ID) {
315+
return;
316+
}
317+
309318
for (lint_name, &lint_span) in &self.declared_lints {
310319
// When using the `declare_tool_lint!` macro, the original `lint_span`'s
311320
// file points to "<rustc macros>".
@@ -355,15 +364,12 @@ struct LintCollector<'a, 'tcx> {
355364
impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> {
356365
type Map = Map<'tcx>;
357366

358-
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
359-
walk_expr(self, expr);
360-
}
361-
362367
fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) {
363368
if path.segments.len() == 1 {
364369
self.output.insert(path.segments[0].ident.name);
365370
}
366371
}
372+
367373
fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
368374
NestedVisitorMap::All(self.cx.tcx.hir())
369375
}
@@ -391,6 +397,10 @@ impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
391397

392398
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CompilerLintFunctions {
393399
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
400+
if !run_lints(cx, &[COMPILER_LINT_FUNCTIONS], expr.hir_id) {
401+
return;
402+
}
403+
394404
if_chain! {
395405
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind;
396406
let fn_name = path.ident;
@@ -416,6 +426,10 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]);
416426

417427
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass {
418428
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
429+
if !run_lints(cx, &[OUTER_EXPN_EXPN_DATA], expr.hir_id) {
430+
return;
431+
}
432+
419433
let (method_names, arg_lists, spans) = method_calls(expr, 2);
420434
let method_names: Vec<SymbolStr> = method_names.iter().map(|s| s.as_str()).collect();
421435
let method_names: Vec<&str> = method_names.iter().map(|s| &**s).collect();
@@ -462,6 +476,10 @@ declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]);
462476

463477
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CollapsibleCalls {
464478
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
479+
if !run_lints(cx, &[COLLAPSIBLE_SPAN_LINT_CALLS], expr.hir_id) {
480+
return;
481+
}
482+
465483
if_chain! {
466484
if let ExprKind::Call(ref func, ref and_then_args) = expr.kind;
467485
if let ExprKind::Path(ref path) = func.kind;

clippy_lints/src/utils/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,15 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_, '_>, did: DefId) -> bool
13991399
)
14001400
}
14011401

1402+
pub fn run_lints(cx: &LateContext<'_, '_>, lints: &[&'static Lint], id: HirId) -> bool {
1403+
lints.iter().any(|lint| {
1404+
matches!(
1405+
cx.tcx.lint_level_at_node(lint, id),
1406+
(Level::Forbid | Level::Deny | Level::Warn, _)
1407+
)
1408+
})
1409+
}
1410+
14021411
#[cfg(test)]
14031412
mod test {
14041413
use super::{trim_multiline, without_block_comments};

clippy_lints/src/wildcard_dependencies.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::utils::span_lint;
2-
use rustc_ast::ast::Crate;
3-
use rustc_lint::{EarlyContext, EarlyLintPass};
1+
use crate::utils::{run_lints, span_lint};
2+
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
3+
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_session::{declare_lint_pass, declare_tool_lint};
55
use rustc_span::source_map::DUMMY_SP;
66

@@ -28,8 +28,12 @@ declare_clippy_lint! {
2828

2929
declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]);
3030

31-
impl EarlyLintPass for WildcardDependencies {
32-
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
31+
impl LateLintPass<'_, '_> for WildcardDependencies {
32+
fn check_crate(&mut self, cx: &LateContext<'_, '_>, _: &Crate<'_>) {
33+
if !run_lints(cx, &[WILDCARD_DEPENDENCIES], CRATE_HIR_ID) {
34+
return;
35+
}
36+
3337
let metadata = if let Ok(metadata) = cargo_metadata::MetadataCommand::new().no_deps().exec() {
3438
metadata
3539
} else {

doc/release.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ to the beta Rust release. The remerge is then necessary, to make sure that the
6363
Clippy commit, that was used by the now stable Rust release, persists in the
6464
tree of the Clippy repository.
6565

66+
To find out if this step is necessary run
67+
68+
```bash
69+
# Assumes that the local master branch is up-to-date
70+
$ git fetch upstream
71+
$ git branch master --contains upstream/beta
72+
```
73+
74+
If this command outputs `master`, this step is **not** necessary.
75+
6676
```bash
6777
# Assuming `HEAD` is the current `master` branch of rust-lang/rust-clippy
6878
$ git checkout -b backport_remerge
@@ -97,5 +107,5 @@ be updated.
97107
# Assuming the current directory corresponds to the Clippy repository
98108
$ git checkout beta
99109
$ git rebase $BETA_SHA
100-
$ git push upstream beta [-f] # This requires a force push, if a remerge was done
110+
$ git push upstream beta
101111
```

src/lintlist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
11391139
},
11401140
Lint {
11411141
name: "match_bool",
1142-
group: "style",
1142+
group: "pedantic",
11431143
desc: "a `match` on a boolean expression instead of an `if..else` block",
11441144
deprecation: None,
11451145
module: "matches",

tests/ui/implicit_return.fixed

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ fn test_if_block() -> bool {
2121
}
2222
}
2323

24-
#[allow(clippy::match_bool)]
2524
#[rustfmt::skip]
2625
fn test_match(x: bool) -> bool {
2726
match x {
@@ -30,7 +29,7 @@ fn test_match(x: bool) -> bool {
3029
}
3130
}
3231

33-
#[allow(clippy::match_bool, clippy::needless_return)]
32+
#[allow(clippy::needless_return)]
3433
fn test_match_with_unreachable(x: bool) -> bool {
3534
match x {
3635
true => return false,

tests/ui/implicit_return.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ fn test_if_block() -> bool {
2121
}
2222
}
2323

24-
#[allow(clippy::match_bool)]
2524
#[rustfmt::skip]
2625
fn test_match(x: bool) -> bool {
2726
match x {
@@ -30,7 +29,7 @@ fn test_match(x: bool) -> bool {
3029
}
3130
}
3231

33-
#[allow(clippy::match_bool, clippy::needless_return)]
32+
#[allow(clippy::needless_return)]
3433
fn test_match_with_unreachable(x: bool) -> bool {
3534
match x {
3635
true => return false,

tests/ui/implicit_return.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,49 @@ LL | false
1919
| ^^^^^ help: add `return` as shown: `return false`
2020

2121
error: missing `return` statement
22-
--> $DIR/implicit_return.rs:28:17
22+
--> $DIR/implicit_return.rs:27:17
2323
|
2424
LL | true => false,
2525
| ^^^^^ help: add `return` as shown: `return false`
2626

2727
error: missing `return` statement
28-
--> $DIR/implicit_return.rs:29:20
28+
--> $DIR/implicit_return.rs:28:20
2929
|
3030
LL | false => { true },
3131
| ^^^^ help: add `return` as shown: `return true`
3232

3333
error: missing `return` statement
34-
--> $DIR/implicit_return.rs:44:9
34+
--> $DIR/implicit_return.rs:43:9
3535
|
3636
LL | break true;
3737
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
3838

3939
error: missing `return` statement
40-
--> $DIR/implicit_return.rs:52:13
40+
--> $DIR/implicit_return.rs:51:13
4141
|
4242
LL | break true;
4343
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
4444

4545
error: missing `return` statement
46-
--> $DIR/implicit_return.rs:61:13
46+
--> $DIR/implicit_return.rs:60:13
4747
|
4848
LL | break true;
4949
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
5050

5151
error: missing `return` statement
52-
--> $DIR/implicit_return.rs:79:18
52+
--> $DIR/implicit_return.rs:78:18
5353
|
5454
LL | let _ = || { true };
5555
| ^^^^ help: add `return` as shown: `return true`
5656

5757
error: missing `return` statement
58-
--> $DIR/implicit_return.rs:80:16
58+
--> $DIR/implicit_return.rs:79:16
5959
|
6060
LL | let _ = || true;
6161
| ^^^^ help: add `return` as shown: `return true`
6262

6363
error: missing `return` statement
64-
--> $DIR/implicit_return.rs:88:5
64+
--> $DIR/implicit_return.rs:87:5
6565
|
6666
LL | format!("test {}", "test")
6767
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`

0 commit comments

Comments
 (0)