Skip to content

Commit 5f49249

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rustup
2 parents 29d43f6 + 2ed5143 commit 5f49249

File tree

83 files changed

+1028
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1028
-414
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,7 @@ Released 2018-09-13
15591559
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
15601560
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
15611561
[`derive_ord_xor_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
1562+
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
15621563
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
15631564
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
15641565
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
@@ -1634,6 +1635,8 @@ Released 2018-09-13
16341635
[`inherent_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string
16351636
[`inherent_to_string_shadow_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string_shadow_display
16361637
[`inline_always`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_always
1638+
[`inline_asm_x86_att_syntax`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_asm_x86_att_syntax
1639+
[`inline_asm_x86_intel_syntax`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_asm_x86_intel_syntax
16371640
[`inline_fn_without_body`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_fn_without_body
16381641
[`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one
16391642
[`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic
@@ -1644,6 +1647,7 @@ Released 2018-09-13
16441647
[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref
16451648
[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex
16461649
[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
1650+
[`invisible_characters`]: https://rust-lang.github.io/rust-clippy/master/index.html#invisible_characters
16471651
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
16481652
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
16491653
[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop
@@ -1919,6 +1923,5 @@ Released 2018-09-13
19191923
[`zero_divided_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_divided_by_zero
19201924
[`zero_prefixed_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_prefixed_literal
19211925
[`zero_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_ptr
1922-
[`zero_width_space`]: https://rust-lang.github.io/rust-clippy/master/index.html#zero_width_space
19231926
[`zst_offset`]: https://rust-lang.github.io/rust-clippy/master/index.html#zst_offset
19241927
<!-- end autogenerated links to lint list -->

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

8-
[There are over 350 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
8+
[There are over 400 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
99

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

clippy_lints/src/asm_syntax.rs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
use std::fmt;
2+
3+
use crate::utils::span_lint_and_help;
4+
use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions};
5+
use rustc_lint::{EarlyContext, EarlyLintPass, Lint};
6+
use rustc_session::{declare_lint_pass, declare_tool_lint};
7+
8+
#[derive(Clone, Copy, PartialEq, Eq)]
9+
enum AsmStyle {
10+
Intel,
11+
Att,
12+
}
13+
14+
impl fmt::Display for AsmStyle {
15+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16+
match self {
17+
AsmStyle::Intel => f.write_str("Intel"),
18+
AsmStyle::Att => f.write_str("AT&T"),
19+
}
20+
}
21+
}
22+
23+
impl std::ops::Not for AsmStyle {
24+
type Output = AsmStyle;
25+
26+
fn not(self) -> AsmStyle {
27+
match self {
28+
AsmStyle::Intel => AsmStyle::Att,
29+
AsmStyle::Att => AsmStyle::Intel,
30+
}
31+
}
32+
}
33+
34+
fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr, check_for: AsmStyle) {
35+
if let ExprKind::InlineAsm(ref inline_asm) = expr.kind {
36+
let style = if inline_asm.options.contains(InlineAsmOptions::ATT_SYNTAX) {
37+
AsmStyle::Att
38+
} else {
39+
AsmStyle::Intel
40+
};
41+
42+
if style == check_for {
43+
span_lint_and_help(
44+
cx,
45+
lint,
46+
expr.span,
47+
&format!("{} x86 assembly syntax used", style),
48+
None,
49+
&format!("use {} x86 assembly syntax", !style),
50+
);
51+
}
52+
}
53+
}
54+
55+
declare_clippy_lint! {
56+
/// **What it does:** Checks for usage of Intel x86 assembly syntax.
57+
///
58+
/// **Why is this bad?** The lint has been enabled to indicate a preference
59+
/// for AT&T x86 assembly syntax.
60+
///
61+
/// **Known problems:** None.
62+
///
63+
/// **Example:**
64+
///
65+
/// ```rust,no_run
66+
/// # #![feature(asm)]
67+
/// # unsafe { let ptr = "".as_ptr();
68+
/// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr);
69+
/// # }
70+
/// ```
71+
/// Use instead:
72+
/// ```rust,no_run
73+
/// # #![feature(asm)]
74+
/// # unsafe { let ptr = "".as_ptr();
75+
/// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax));
76+
/// # }
77+
/// ```
78+
pub INLINE_ASM_X86_INTEL_SYNTAX,
79+
restriction,
80+
"prefer AT&T x86 assembly syntax"
81+
}
82+
83+
declare_lint_pass!(InlineAsmX86IntelSyntax => [INLINE_ASM_X86_INTEL_SYNTAX]);
84+
85+
impl EarlyLintPass for InlineAsmX86IntelSyntax {
86+
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
87+
check_expr_asm_syntax(Self::get_lints()[0], cx, expr, AsmStyle::Intel);
88+
}
89+
}
90+
91+
declare_clippy_lint! {
92+
/// **What it does:** Checks for usage of AT&T x86 assembly syntax.
93+
///
94+
/// **Why is this bad?** The lint has been enabled to indicate a preference
95+
/// for Intel x86 assembly syntax.
96+
///
97+
/// **Known problems:** None.
98+
///
99+
/// **Example:**
100+
///
101+
/// ```rust,no_run
102+
/// # #![feature(asm)]
103+
/// # unsafe { let ptr = "".as_ptr();
104+
/// asm!("lea ({}), {}", in(reg) ptr, lateout(reg) _, options(att_syntax));
105+
/// # }
106+
/// ```
107+
/// Use instead:
108+
/// ```rust,no_run
109+
/// # #![feature(asm)]
110+
/// # unsafe { let ptr = "".as_ptr();
111+
/// asm!("lea {}, [{}]", lateout(reg) _, in(reg) ptr);
112+
/// # }
113+
/// ```
114+
pub INLINE_ASM_X86_ATT_SYNTAX,
115+
restriction,
116+
"prefer Intel x86 assembly syntax"
117+
}
118+
119+
declare_lint_pass!(InlineAsmX86AttSyntax => [INLINE_ASM_X86_ATT_SYNTAX]);
120+
121+
impl EarlyLintPass for InlineAsmX86AttSyntax {
122+
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
123+
check_expr_asm_syntax(Self::get_lints()[0], cx, expr, AsmStyle::Att);
124+
}
125+
}

clippy_lints/src/disallowed_method.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use crate::utils::span_lint;
2+
3+
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_hir::{Expr, ExprKind};
5+
use rustc_lint::{LateContext, LateLintPass};
6+
use rustc_session::{declare_tool_lint, impl_lint_pass};
7+
use rustc_span::Symbol;
8+
9+
declare_clippy_lint! {
10+
/// **What it does:** Lints for specific trait methods defined in clippy.toml
11+
///
12+
/// **Why is this bad?** Some methods are undesirable in certain contexts,
13+
/// and it would be beneficial to lint for them as needed.
14+
///
15+
/// **Known problems:** None.
16+
///
17+
/// **Example:**
18+
///
19+
/// ```rust,ignore
20+
/// // example code where clippy issues a warning
21+
/// foo.bad_method(); // Foo::bad_method is disallowed in the configuration
22+
/// ```
23+
/// Use instead:
24+
/// ```rust,ignore
25+
/// // example code which does not raise clippy warning
26+
/// goodStruct.bad_method(); // GoodStruct::bad_method is not disallowed
27+
/// ```
28+
pub DISALLOWED_METHOD,
29+
nursery,
30+
"use of a disallowed method call"
31+
}
32+
33+
#[derive(Clone, Debug)]
34+
pub struct DisallowedMethod {
35+
disallowed: FxHashSet<Vec<Symbol>>,
36+
}
37+
38+
impl DisallowedMethod {
39+
pub fn new(disallowed: &FxHashSet<String>) -> Self {
40+
Self {
41+
disallowed: disallowed
42+
.iter()
43+
.map(|s| s.split("::").map(|seg| Symbol::intern(seg)).collect::<Vec<_>>())
44+
.collect(),
45+
}
46+
}
47+
}
48+
49+
impl_lint_pass!(DisallowedMethod => [DISALLOWED_METHOD]);
50+
51+
impl<'tcx> LateLintPass<'tcx> for DisallowedMethod {
52+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
53+
if let ExprKind::MethodCall(_path, _, _args, _) = &expr.kind {
54+
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
55+
56+
let method_call = cx.get_def_path(def_id);
57+
if self.disallowed.contains(&method_call) {
58+
let method = method_call
59+
.iter()
60+
.map(|s| s.to_ident_string())
61+
.collect::<Vec<_>>()
62+
.join("::");
63+
64+
span_lint(
65+
cx,
66+
DISALLOWED_METHOD,
67+
expr.span,
68+
&format!("use of a disallowed method `{}`", method),
69+
);
70+
}
71+
}
72+
}
73+
}

clippy_lints/src/lib.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ mod utils;
153153
mod approx_const;
154154
mod arithmetic;
155155
mod as_conversions;
156+
mod asm_syntax;
156157
mod assertions_on_constants;
157158
mod assign_ops;
158159
mod async_yields_async;
@@ -176,6 +177,7 @@ mod dbg_macro;
176177
mod default_trait_access;
177178
mod dereference;
178179
mod derive;
180+
mod disallowed_method;
179181
mod doc;
180182
mod double_comparison;
181183
mod double_parens;
@@ -489,6 +491,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
489491
&arithmetic::FLOAT_ARITHMETIC,
490492
&arithmetic::INTEGER_ARITHMETIC,
491493
&as_conversions::AS_CONVERSIONS,
494+
&asm_syntax::INLINE_ASM_X86_ATT_SYNTAX,
495+
&asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX,
492496
&assertions_on_constants::ASSERTIONS_ON_CONSTANTS,
493497
&assign_ops::ASSIGN_OP_PATTERN,
494498
&assign_ops::MISREFACTORED_ASSIGN_OP,
@@ -529,6 +533,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
529533
&derive::DERIVE_ORD_XOR_PARTIAL_ORD,
530534
&derive::EXPL_IMPL_CLONE_ON_COPY,
531535
&derive::UNSAFE_DERIVE_DESERIALIZE,
536+
&disallowed_method::DISALLOWED_METHOD,
532537
&doc::DOC_MARKDOWN,
533538
&doc::MISSING_ERRORS_DOC,
534539
&doc::MISSING_SAFETY_DOC,
@@ -851,9 +856,9 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
851856
&types::UNIT_CMP,
852857
&types::UNNECESSARY_CAST,
853858
&types::VEC_BOX,
859+
&unicode::INVISIBLE_CHARACTERS,
854860
&unicode::NON_ASCII_LITERAL,
855861
&unicode::UNICODE_NOT_NFC,
856-
&unicode::ZERO_WIDTH_SPACE,
857862
&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD,
858863
&unnamed_address::FN_ADDRESS_COMPARISONS,
859864
&unnamed_address::VTABLE_ADDRESS_COMPARISONS,
@@ -1120,11 +1125,18 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11201125
store.register_late_pass(|| box async_yields_async::AsyncYieldsAsync);
11211126
store.register_late_pass(|| box manual_strip::ManualStrip);
11221127
store.register_late_pass(|| box utils::internal_lints::MatchTypeOnDiagItem);
1128+
let disallowed_methods = conf.disallowed_methods.iter().cloned().collect::<FxHashSet<_>>();
1129+
store.register_late_pass(move || box disallowed_method::DisallowedMethod::new(&disallowed_methods));
1130+
store.register_early_pass(|| box asm_syntax::InlineAsmX86AttSyntax);
1131+
store.register_early_pass(|| box asm_syntax::InlineAsmX86IntelSyntax);
1132+
11231133

11241134
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
11251135
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
11261136
LintId::of(&arithmetic::INTEGER_ARITHMETIC),
11271137
LintId::of(&as_conversions::AS_CONVERSIONS),
1138+
LintId::of(&asm_syntax::INLINE_ASM_X86_ATT_SYNTAX),
1139+
LintId::of(&asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX),
11281140
LintId::of(&create_dir::CREATE_DIR),
11291141
LintId::of(&dbg_macro::DBG_MACRO),
11301142
LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE),
@@ -1499,7 +1511,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14991511
LintId::of(&types::UNIT_CMP),
15001512
LintId::of(&types::UNNECESSARY_CAST),
15011513
LintId::of(&types::VEC_BOX),
1502-
LintId::of(&unicode::ZERO_WIDTH_SPACE),
1514+
LintId::of(&unicode::INVISIBLE_CHARACTERS),
15031515
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
15041516
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
15051517
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
@@ -1592,6 +1604,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15921604
LintId::of(&mut_reference::UNNECESSARY_MUT_PASSED),
15931605
LintId::of(&neg_multiply::NEG_MULTIPLY),
15941606
LintId::of(&new_without_default::NEW_WITHOUT_DEFAULT),
1607+
LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
1608+
LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
15951609
LintId::of(&non_expressive_names::JUST_UNDERSCORES_AND_DIGITS),
15961610
LintId::of(&non_expressive_names::MANY_SINGLE_CHAR_NAMES),
15971611
LintId::of(&panic_unimplemented::PANIC_PARAMS),
@@ -1747,8 +1761,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17471761
LintId::of(&misc::FLOAT_CMP),
17481762
LintId::of(&misc::MODULO_ONE),
17491763
LintId::of(&mut_key::MUTABLE_KEY_TYPE),
1750-
LintId::of(&non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),
1751-
LintId::of(&non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
17521764
LintId::of(&open_options::NONSENSICAL_OPEN_OPTIONS),
17531765
LintId::of(&option_env_unwrap::OPTION_ENV_UNWRAP),
17541766
LintId::of(&ptr::MUT_FROM_REF),
@@ -1766,7 +1778,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17661778
LintId::of(&types::ABSURD_EXTREME_COMPARISONS),
17671779
LintId::of(&types::CAST_REF_TO_MUT),
17681780
LintId::of(&types::UNIT_CMP),
1769-
LintId::of(&unicode::ZERO_WIDTH_SPACE),
1781+
LintId::of(&unicode::INVISIBLE_CHARACTERS),
17701782
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
17711783
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
17721784
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
@@ -1807,6 +1819,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
18071819
store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
18081820
LintId::of(&attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
18091821
LintId::of(&cognitive_complexity::COGNITIVE_COMPLEXITY),
1822+
LintId::of(&disallowed_method::DISALLOWED_METHOD),
18101823
LintId::of(&fallible_impl_from::FALLIBLE_IMPL_FROM),
18111824
LintId::of(&floating_point_arithmetic::IMPRECISE_FLOPS),
18121825
LintId::of(&floating_point_arithmetic::SUBOPTIMAL_FLOPS),
@@ -1896,6 +1909,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
18961909
ls.register_renamed("clippy::for_loop_over_option", "clippy::for_loops_over_fallibles");
18971910
ls.register_renamed("clippy::for_loop_over_result", "clippy::for_loops_over_fallibles");
18981911
ls.register_renamed("clippy::identity_conversion", "clippy::useless_conversion");
1912+
ls.register_renamed("clippy::zero_width_space", "clippy::invisible_characters");
18991913
}
19001914

19011915
// only exists to let the dogfood integration test works.

0 commit comments

Comments
 (0)