Skip to content

Commit 66e4037

Browse files
committed
submodules: update clippy from a20599a to 71ec4ff
Should fix clippy toolstat. Changes: ```` rustup rust-lang/rust#55330 Update stderr Rename test files Also lint cfg_attr(.., rustfmt::skip) Add tests from rustfmt::skip test file Run update_lints.py script Add test for non-crate-level inner attributes Differ between inner and outer attributes Add tests Add cfg_attr(rustfmt) lint Addressed comments. Fix dogfood error. Added lints `into_iter_on_ref` and `into_iter_on_array`. Fix rust-lang#1565. Allow single_match_else Update stderr Add copyright statement© Fix typos Fix dogfood error Fix typo and indentation run update_lints script Add tests for unknwon_clippy_lints lint Add new lint: unknwon_clippy_lintsg clippy: fix pedantic warnings and run clippy::pedantic lints on the codebase. Fix a false-positive of needless_borrow UI test cleanup: Extract match_overlapping_arm tests UI test cleanup: Extract expect_fun_call tests Add missing code of conduct file Use slice patterns instead of padding Fix dogfood and pedantic lints ci: when installing rust-toolchain-installer-master, install it in debug mode to save some time in ci. RIIR update lints: Generate deprecated lints Replace big if/else expression with match ````
1 parent 2b06765 commit 66e4037

37 files changed

+1192
-480
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ matrix:
7676
script:
7777
- |
7878
rm rust-toolchain
79-
cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
79+
cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
8080
RUSTC_HASH=$(git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}')
8181
travis_retry rustup-toolchain-install-master -f -n master $RUSTC_HASH
8282
rustup default master

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ All notable changes to this project will be documented in this file.
651651
[`decimal_literal_representation`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#decimal_literal_representation
652652
[`declare_interior_mutable_const`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
653653
[`default_trait_access`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#default_trait_access
654+
[`deprecated_cfg_attr`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#deprecated_cfg_attr
654655
[`deprecated_semver`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#deprecated_semver
655656
[`deref_addrof`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#deref_addrof
656657
[`derive_hash_xor_eq`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
@@ -713,6 +714,8 @@ All notable changes to this project will be documented in this file.
713714
[`inline_fn_without_body`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#inline_fn_without_body
714715
[`int_plus_one`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#int_plus_one
715716
[`integer_arithmetic`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#integer_arithmetic
717+
[`into_iter_on_array`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#into_iter_on_array
718+
[`into_iter_on_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#into_iter_on_ref
716719
[`invalid_ref`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_ref
717720
[`invalid_regex`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_regex
718721
[`invalid_upcast_comparisons`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
@@ -866,6 +869,7 @@ All notable changes to this project will be documented in this file.
866869
[`unimplemented`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unimplemented
867870
[`unit_arg`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unit_arg
868871
[`unit_cmp`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unit_cmp
872+
[`unknown_clippy_lints`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unknown_clippy_lints
869873
[`unnecessary_cast`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unnecessary_cast
870874
[`unnecessary_filter_map`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unnecessary_filter_map
871875
[`unnecessary_fold`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unnecessary_fold

CODE_OF_CONDUCT.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# The Rust Code of Conduct
2+
3+
A version of this document [can be found online](https://www.rust-lang.org/conduct.html).
4+
5+
## Conduct
6+
7+
**Contact**: [[email protected]](mailto:[email protected])
8+
9+
* We are committed to providing a friendly, safe and welcoming environment for all, regardless of level of experience, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, nationality, or other similar characteristic.
10+
* On IRC, please avoid using overtly sexual nicknames or other nicknames that might detract from a friendly, safe and welcoming environment for all.
11+
* Please be kind and courteous. There's no need to be mean or rude.
12+
* Respect that people have differences of opinion and that every design or implementation choice carries a trade-off and numerous costs. There is seldom a right answer.
13+
* Please keep unstructured critique to a minimum. If you have solid ideas you want to experiment with, make a fork and see how it works.
14+
* We will exclude you from interaction if you insult, demean or harass anyone. That is not welcome behavior. We interpret the term "harassment" as including the definition in the <a href="http://citizencodeofconduct.org/">Citizen Code of Conduct</a>; if you have any lack of clarity about what might be included in that concept, please read their definition. In particular, we don't tolerate behavior that excludes people in socially marginalized groups.
15+
* Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or made uncomfortable by a community member, please contact one of the channel ops or any of the [Rust moderation team][mod_team] immediately. Whether you're a regular contributor or a newcomer, we care about making this community a safe place for you and we've got your back.
16+
* Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome.
17+
18+
## Moderation
19+
20+
21+
These are the policies for upholding our community's standards of conduct. If you feel that a thread needs moderation, please contact the [Rust moderation team][mod_team].
22+
23+
1. Remarks that violate the Rust standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner.)
24+
2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed.
25+
3. Moderators will first respond to such remarks with a warning.
26+
4. If the warning is unheeded, the user will be "kicked," i.e., kicked out of the communication channel to cool off.
27+
5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded.
28+
6. Moderators may choose at their discretion to un-ban the user if it was a first offense and they offer the offended party a genuine apology.
29+
7. If a moderator bans someone and you think it was unjustified, please take it up with that moderator, or with a different moderator, **in private**. Complaints about bans in-channel are not allowed.
30+
8. Moderators are held to a higher standard than other community members. If a moderator creates an inappropriate situation, they should expect less leeway than others.
31+
32+
In the Rust community we strive to go the extra step to look out for each other. Don't just aim to be technically unimpeachable, try to be your best self. In particular, avoid flirting with offensive or sensitive issues, particularly if they're off-topic; this all too often leads to unnecessary fights, hurt feelings, and damaged trust; worse, it can drive people away from the community entirely.
33+
34+
And if someone takes issue with something you said or did, resist the urge to be defensive. Just stop doing what it was they complained about and apologize. Even if you feel you were misinterpreted or unfairly accused, chances are good there was something you could've communicated better — remember that it's your responsibility to make your fellow Rustaceans comfortable. Everyone wants to get along and we are all here first and foremost because we want to talk about cool technology. You will find that people will be eager to assume good intent and forgive as long as you earn their trust.
35+
36+
The enforcement policies listed above apply to all official Rust venues; including official IRC channels (#rust, #rust-internals, #rust-tools, #rust-libs, #rustc, #rust-beginners, #rust-docs, #rust-community, #rust-lang, and #cargo); GitHub repositories under rust-lang, rust-lang-nursery, and rust-lang-deprecated; and all forums under rust-lang.org (users.rust-lang.org, internals.rust-lang.org). For other projects adopting the Rust Code of Conduct, please contact the maintainers of those projects for enforcement. If you wish to use this code of conduct for your own project, consider explicitly mentioning your moderation policy or making a copy with your own moderation policy so as to avoid confusion.
37+
38+
*Adapted from the [Node.js Policy on Trolling](http://blog.izs.me/post/30036893703/policy-on-trolling) as well as the [Contributor Covenant v1.3.0](https://www.contributor-covenant.org/version/1/3/0/).*
39+
40+
[mod_team]: https://www.rust-lang.org/team.html#Moderation-team

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We are currently in the process of discussing Clippy 1.0 via the RFC process in
99

1010
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
1111

12-
[There are 283 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
12+
[There are 287 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
1313

1414
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1515

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ install:
2121
- git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}' >rustc-hash.txt
2222
- set /p RUSTC_HASH=<rustc-hash.txt
2323
- del rust-toolchain
24-
- cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
24+
- cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
2525
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
2626
- rustup default master
2727
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin

ci/base-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ cd rustc_tools_util && cargo test && cd ..
2727

2828
CLIPPY="`pwd`/target/debug/cargo-clippy clippy"
2929
# run clippy on its own codebase...
30-
${CLIPPY} --all-targets --all-features -- -D clippy::all -D clippy::internal
30+
${CLIPPY} --all-targets --all-features -- -D clippy::all -D clippy::internal -Dclippy::pedantic
3131
# ... and some test directories
3232
for dir in clippy_workspace_tests clippy_workspace_tests/src clippy_workspace_tests/subcrate clippy_workspace_tests/subcrate/src clippy_dev rustc_tools_util
3333
do
3434
cd ${dir}
35-
${CLIPPY} -- -D clippy::all
35+
${CLIPPY} -- -D clippy::all -D clippy::pedantic
3636
cd -
3737
done
3838

clippy_dev/src/lib.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// except according to those terms.
99

1010

11-
1211
#![allow(clippy::default_hash_types)]
1312

1413
use itertools::Itertools;
@@ -72,14 +71,34 @@ impl Lint {
7271
}
7372
}
7473

74+
/// Generates the list of lint links at the bottom of the README
7575
pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
7676
let mut lint_list_sorted: Vec<Lint> = lints;
7777
lint_list_sorted.sort_by_key(|l| l.name.clone());
7878
lint_list_sorted
7979
.iter()
80-
.filter(|l| !l.is_internal())
81-
.map(|l| {
82-
format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name)
80+
.filter_map(|l| {
81+
if l.is_internal() {
82+
None
83+
} else {
84+
Some(format!("[`{}`]: {}#{}", l.name, DOCS_LINK.clone(), l.name))
85+
}
86+
}).collect()
87+
}
88+
89+
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
90+
pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
91+
lints.iter()
92+
.filter_map(|l| {
93+
l.clone().deprecation.and_then(|depr_text| {
94+
Some(
95+
format!(
96+
" store.register_removed(\n \"{}\",\n \"{}\",\n );",
97+
l.name,
98+
depr_text
99+
)
100+
)
101+
})
83102
})
84103
.collect()
85104
}
@@ -321,3 +340,18 @@ fn test_gen_changelog_lint_list() {
321340
];
322341
assert_eq!(expected, gen_changelog_lint_list(lints));
323342
}
343+
344+
#[test]
345+
fn test_gen_deprecated() {
346+
let lints = vec![
347+
Lint::new("should_assert_eq", "group1", "abc", Some("has been superseeded by should_assert_eq2"), "module_name"),
348+
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")
349+
];
350+
let expected: Vec<String> = vec![
351+
r#" store.register_removed(
352+
"should_assert_eq",
353+
"has been superseeded by should_assert_eq2",
354+
);"#.to_string()
355+
];
356+
assert_eq!(expected, gen_deprecated(&lints));
357+
}

clippy_dev/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,12 @@ fn update_lints() {
8282
false,
8383
|| { gen_changelog_lint_list(lint_list.clone()) }
8484
);
85+
86+
replace_region_in_file(
87+
"../clippy_lints/src/lib.rs",
88+
"begin deprecated lints",
89+
"end deprecated lints",
90+
false,
91+
|| { gen_deprecated(&lint_list) }
92+
);
8593
}

clippy_lints/src/attrs.rs

Lines changed: 158 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212
1313
use crate::reexport::*;
1414
use crate::utils::{
15-
in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_then,
16-
without_block_comments,
15+
in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_sugg,
16+
span_lint_and_then, without_block_comments,
1717
};
18-
use crate::rustc::hir::*;
19-
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
20-
use crate::rustc::{declare_tool_lint, lint_array};
2118
use if_chain::if_chain;
19+
use crate::rustc::hir::*;
20+
use crate::rustc::lint::{
21+
CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
22+
};
2223
use crate::rustc::ty::{self, TyCtxt};
24+
use crate::rustc::{declare_tool_lint, lint_array};
2325
use semver::Version;
24-
use crate::syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
26+
use crate::syntax::ast::{
27+
AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind,
28+
};
2529
use crate::syntax::source_map::Span;
2630
use crate::rustc_errors::Applicability;
2731

@@ -138,6 +142,62 @@ declare_clippy_lint! {
138142
"empty line after outer attribute"
139143
}
140144

145+
/// **What it does:** Checks for `allow`/`warn`/`deny`/`forbid` attributes with scoped clippy
146+
/// lints and if those lints exist in clippy. If there is a uppercase letter in the lint name
147+
/// (not the tool name) and a lowercase version of this lint exists, it will suggest to lowercase
148+
/// the lint name.
149+
///
150+
/// **Why is this bad?** A lint attribute with a mistyped lint name won't have an effect.
151+
///
152+
/// **Known problems:** None.
153+
///
154+
/// **Example:**
155+
/// Bad:
156+
/// ```rust
157+
/// #![warn(if_not_els)]
158+
/// #![deny(clippy::All)]
159+
/// ```
160+
///
161+
/// Good:
162+
/// ```rust
163+
/// #![warn(if_not_else)]
164+
/// #![deny(clippy::all)]
165+
/// ```
166+
declare_clippy_lint! {
167+
pub UNKNOWN_CLIPPY_LINTS,
168+
style,
169+
"unknown_lints for scoped Clippy lints"
170+
}
171+
172+
/// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it
173+
/// with `#[rustfmt::skip]`.
174+
///
175+
/// **Why is this bad?** Since tool_attributes ([rust-lang/rust#44690](https://github.com/rust-lang/rust/issues/44690))
176+
/// are stable now, they should be used instead of the old `cfg_attr(rustfmt)` attributes.
177+
///
178+
/// **Known problems:** This lint doesn't detect crate level inner attributes, because they get
179+
/// processed before the PreExpansionPass lints get executed. See
180+
/// [#3123](https://github.com/rust-lang-nursery/rust-clippy/pull/3123#issuecomment-422321765)
181+
///
182+
/// **Example:**
183+
///
184+
/// Bad:
185+
/// ```rust
186+
/// #[cfg_attr(rustfmt, rustfmt_skip)]
187+
/// fn main() { }
188+
/// ```
189+
///
190+
/// Good:
191+
/// ```rust
192+
/// #[rustfmt::skip]
193+
/// fn main() { }
194+
/// ```
195+
declare_clippy_lint! {
196+
pub DEPRECATED_CFG_ATTR,
197+
complexity,
198+
"usage of `cfg_attr(rustfmt)` instead of `tool_attributes`"
199+
}
200+
141201
#[derive(Copy, Clone)]
142202
pub struct AttrPass;
143203

@@ -147,14 +207,21 @@ impl LintPass for AttrPass {
147207
INLINE_ALWAYS,
148208
DEPRECATED_SEMVER,
149209
USELESS_ATTRIBUTE,
150-
EMPTY_LINE_AFTER_OUTER_ATTR
210+
EMPTY_LINE_AFTER_OUTER_ATTR,
211+
UNKNOWN_CLIPPY_LINTS,
151212
)
152213
}
153214
}
154215

155216
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
156217
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
157218
if let Some(ref items) = attr.meta_item_list() {
219+
match &*attr.name().as_str() {
220+
"allow" | "warn" | "deny" | "forbid" => {
221+
check_clippy_lint_names(cx, items);
222+
}
223+
_ => {}
224+
}
158225
if items.is_empty() || attr.name() != "deprecated" {
159226
return;
160227
}
@@ -247,6 +314,47 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
247314
}
248315
}
249316

317+
#[allow(clippy::single_match_else)]
318+
fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
319+
let lint_store = cx.lints();
320+
for lint in items {
321+
if_chain! {
322+
if let Some(word) = lint.word();
323+
if let Some(tool_name) = word.is_scoped();
324+
if tool_name.as_str() == "clippy";
325+
let name = word.name();
326+
if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(
327+
&name.as_str(),
328+
Some(tool_name.as_str()),
329+
);
330+
then {
331+
span_lint_and_then(
332+
cx,
333+
UNKNOWN_CLIPPY_LINTS,
334+
lint.span,
335+
&format!("unknown clippy lint: clippy::{}", name),
336+
|db| {
337+
if name.as_str().chars().any(|c| c.is_uppercase()) {
338+
let name_lower = name.as_str().to_lowercase().to_string();
339+
match lint_store.check_lint_name(
340+
&name_lower,
341+
Some(tool_name.as_str())
342+
) {
343+
CheckLintNameResult::NoLint => (),
344+
_ => {
345+
db.span_suggestion(lint.span,
346+
"lowercase the lint name",
347+
name_lower);
348+
}
349+
}
350+
}
351+
}
352+
);
353+
}
354+
};
355+
}
356+
}
357+
250358
fn is_relevant_item(tcx: TyCtxt<'_, '_, '_>, item: &Item) -> bool {
251359
if let ItemKind::Fn(_, _, _, eid) = item.node {
252360
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)
@@ -387,3 +495,46 @@ fn is_present_in_source(cx: &LateContext<'_, '_>, span: Span) -> bool {
387495
}
388496
true
389497
}
498+
499+
#[derive(Copy, Clone)]
500+
pub struct CfgAttrPass;
501+
502+
impl LintPass for CfgAttrPass {
503+
fn get_lints(&self) -> LintArray {
504+
lint_array!(
505+
DEPRECATED_CFG_ATTR,
506+
)
507+
}
508+
}
509+
510+
impl EarlyLintPass for CfgAttrPass {
511+
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
512+
if_chain! {
513+
// check cfg_attr
514+
if attr.name() == "cfg_attr";
515+
if let Some(ref items) = attr.meta_item_list();
516+
if items.len() == 2;
517+
// check for `rustfmt`
518+
if let Some(feature_item) = items[0].meta_item();
519+
if feature_item.name() == "rustfmt";
520+
// check for `rustfmt_skip` and `rustfmt::skip`
521+
if let Some(skip_item) = &items[1].meta_item();
522+
if skip_item.name() == "rustfmt_skip" || skip_item.name() == "skip";
523+
then {
524+
let attr_style = match attr.style {
525+
AttrStyle::Outer => "#[",
526+
AttrStyle::Inner => "#![",
527+
};
528+
span_lint_and_sugg(
529+
cx,
530+
DEPRECATED_CFG_ATTR,
531+
attr.span,
532+
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
533+
"use",
534+
format!("{}rustfmt::skip]", attr_style),
535+
);
536+
}
537+
}
538+
}
539+
}
540+

0 commit comments

Comments
 (0)