Skip to content

Commit 7cfe3dc

Browse files
committed
Merge branch 'master' into needless-lifetime
2 parents c8e9e52 + 99483be commit 7cfe3dc

File tree

193 files changed

+4806
-1610
lines changed

Some content is hidden

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

193 files changed

+4806
-1610
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,7 @@ Released 2018-09-13
15471547
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
15481548
[`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain
15491549
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
1550+
[`create_dir`]: https://rust-lang.github.io/rust-clippy/master/index.html#create_dir
15501551
[`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute
15511552
[`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro
15521553
[`debug_assert_with_mut_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#debug_assert_with_mut_call
@@ -1558,6 +1559,7 @@ Released 2018-09-13
15581559
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
15591560
[`derive_hash_xor_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq
15601561
[`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
15611563
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
15621564
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
15631565
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
@@ -1671,10 +1673,12 @@ Released 2018-09-13
16711673
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
16721674
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
16731675
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
1676+
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
16741677
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
16751678
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
16761679
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
16771680
[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
1681+
[`map_err_ignore`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_err_ignore
16781682
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
16791683
[`map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_identity
16801684
[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
@@ -1754,6 +1758,7 @@ Released 2018-09-13
17541758
[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing
17551759
[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional
17561760
[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic
1761+
[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn
17571762
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
17581763
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
17591764
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
@@ -1773,6 +1778,7 @@ Released 2018-09-13
17731778
[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
17741779
[`range_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_step_by_zero
17751780
[`range_zip_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_zip_with_len
1781+
[`rc_buffer`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer
17761782
[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation
17771783
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
17781784
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ something. We appreciate any sort of contributions, and don't want a wall of rul
88

99
Clippy welcomes contributions from everyone. There are many ways to contribute to Clippy and the following document
1010
explains how you can contribute and how to get started. If you have any questions about contributing or need help with
11-
anything, feel free to ask questions on issues or visit the `#clippy` on [Discord].
11+
anything, feel free to ask questions on issues or visit the `#clippy` on [Zulip].
1212

1313
All contributors are expected to follow the [Rust Code of Conduct].
1414

@@ -23,7 +23,7 @@ All contributors are expected to follow the [Rust Code of Conduct].
2323
- [Bors and Homu](#bors-and-homu)
2424
- [Contributions](#contributions)
2525

26-
[Discord]: https://discord.gg/rust-lang
26+
[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/clippy
2727
[Rust Code of Conduct]: https://www.rust-lang.org/policies/code-of-conduct
2828

2929
## Getting started
@@ -242,7 +242,7 @@ to be run inside the `rust` directory):
242242
```
243243
3. Open a PR to `rust-lang/rust-clippy` and wait for it to get merged (to
244244
accelerate the process ping the `@rust-lang/clippy` team in your PR and/or
245-
~~annoy~~ ask them in the [Discord] channel.)
245+
~~annoy~~ ask them in the [Zulip] stream.)
246246

247247
### Syncing back changes in Clippy to [`rust-lang/rust`]
248248

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_dev/src/ra_setup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn run(rustc_path: Option<&str>) {
1414
// we can unwrap here because the arg is required here
1515
let rustc_path = PathBuf::from(rustc_path.unwrap());
1616
assert!(rustc_path.is_dir(), "path is not a directory");
17-
let rustc_source_basedir = rustc_path.join("src");
17+
let rustc_source_basedir = rustc_path.join("compiler");
1818
assert!(
1919
rustc_source_basedir.is_dir(),
2020
"are you sure the path leads to a rustc repo?"
@@ -61,7 +61,7 @@ fn inject_deps_into_manifest(
6161
let new_deps = extern_crates.map(|dep| {
6262
// format the dependencies that are going to be put inside the Cargo.toml
6363
format!(
64-
"{dep} = {{ path = \"{source_path}/lib{dep}\" }}\n",
64+
"{dep} = {{ path = \"{source_path}/{dep}\" }}\n",
6565
dep = dep,
6666
source_path = rustc_source_dir.display()
6767
)

clippy_lints/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cargo_metadata = "0.11.1"
2121
if_chain = "1.0.0"
2222
itertools = "0.9"
2323
lazy_static = "1.0.2"
24-
pulldown-cmark = { version = "0.7.1", default-features = false }
24+
pulldown-cmark = { version = "0.8", default-features = false }
2525
quine-mc_cluskey = "0.2.2"
2626
regex-syntax = "0.6"
2727
serde = { version = "1.0", features = ["derive"] }

clippy_lints/src/atomic_ordering.rs

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
88

99
declare_clippy_lint! {
1010
/// **What it does:** Checks for usage of invalid atomic
11-
/// ordering in atomic loads/stores and memory fences.
11+
/// ordering in atomic loads/stores/exchanges/updates and
12+
/// memory fences.
1213
///
1314
/// **Why is this bad?** Using an invalid atomic ordering
1415
/// will cause a panic at run-time.
@@ -17,22 +18,35 @@ declare_clippy_lint! {
1718
///
1819
/// **Example:**
1920
/// ```rust,no_run
20-
/// # use std::sync::atomic::{self, AtomicBool, Ordering};
21+
/// # use std::sync::atomic::{self, AtomicU8, Ordering};
2122
///
22-
/// let x = AtomicBool::new(true);
23+
/// let x = AtomicU8::new(0);
2324
///
25+
/// // Bad: `Release` and `AcqRel` cannot be used for `load`.
2426
/// let _ = x.load(Ordering::Release);
2527
/// let _ = x.load(Ordering::AcqRel);
2628
///
27-
/// x.store(false, Ordering::Acquire);
28-
/// x.store(false, Ordering::AcqRel);
29+
/// // Bad: `Acquire` and `AcqRel` cannot be used for `store`.
30+
/// x.store(1, Ordering::Acquire);
31+
/// x.store(2, Ordering::AcqRel);
2932
///
33+
/// // Bad: `Relaxed` cannot be used as a fence's ordering.
3034
/// atomic::fence(Ordering::Relaxed);
3135
/// atomic::compiler_fence(Ordering::Relaxed);
36+
///
37+
/// // Bad: `Release` and `AcqRel` are both always invalid
38+
/// // for the failure ordering (the last arg).
39+
/// let _ = x.compare_exchange(1, 2, Ordering::SeqCst, Ordering::Release);
40+
/// let _ = x.compare_exchange_weak(2, 3, Ordering::AcqRel, Ordering::AcqRel);
41+
///
42+
/// // Bad: The failure ordering is not allowed to be
43+
/// // stronger than the success order, and `SeqCst` is
44+
/// // stronger than `Relaxed`.
45+
/// let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |val| Some(val + val));
3246
/// ```
3347
pub INVALID_ATOMIC_ORDERING,
3448
correctness,
35-
"usage of invalid atomic ordering in atomic loads/stores and memory fences"
49+
"usage of invalid atomic ordering in atomic operations and memory fences"
3650
}
3751

3852
declare_lint_pass!(AtomicOrdering => [INVALID_ATOMIC_ORDERING]);
@@ -127,9 +141,89 @@ fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) {
127141
}
128142
}
129143

144+
fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option<DefId> {
145+
if let ExprKind::Path(ref ord_qpath) = ord_arg.kind {
146+
cx.qpath_res(ord_qpath, ord_arg.hir_id).opt_def_id()
147+
} else {
148+
None
149+
}
150+
}
151+
152+
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
153+
if_chain! {
154+
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
155+
let method = method_path.ident.name.as_str();
156+
if type_is_atomic(cx, &args[0]);
157+
if method == "compare_exchange" || method == "compare_exchange_weak" || method == "fetch_update";
158+
let (success_order_arg, failure_order_arg) = if method == "fetch_update" {
159+
(&args[1], &args[2])
160+
} else {
161+
(&args[3], &args[4])
162+
};
163+
if let Some(fail_ordering_def_id) = opt_ordering_defid(cx, failure_order_arg);
164+
then {
165+
// Helper type holding on to some checking and error reporting data. Has
166+
// - (success ordering name,
167+
// - list of failure orderings forbidden by the success order,
168+
// - suggestion message)
169+
type OrdLintInfo = (&'static str, &'static [&'static str], &'static str);
170+
let relaxed: OrdLintInfo = ("Relaxed", &["SeqCst", "Acquire"], "ordering mode `Relaxed`");
171+
let acquire: OrdLintInfo = ("Acquire", &["SeqCst"], "ordering modes `Acquire` or `Relaxed`");
172+
let seq_cst: OrdLintInfo = ("SeqCst", &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`");
173+
let release = ("Release", relaxed.1, relaxed.2);
174+
let acqrel = ("AcqRel", acquire.1, acquire.2);
175+
let search = [relaxed, acquire, seq_cst, release, acqrel];
176+
177+
let success_lint_info = opt_ordering_defid(cx, success_order_arg)
178+
.and_then(|success_ord_def_id| -> Option<OrdLintInfo> {
179+
search
180+
.iter()
181+
.find(|(ordering, ..)| {
182+
match_def_path(cx, success_ord_def_id,
183+
&["core", "sync", "atomic", "Ordering", ordering])
184+
})
185+
.copied()
186+
});
187+
188+
if match_ordering_def_path(cx, fail_ordering_def_id, &["Release", "AcqRel"]) {
189+
// If we don't know the success order is, use what we'd suggest
190+
// if it were maximally permissive.
191+
let suggested = success_lint_info.unwrap_or(seq_cst).2;
192+
span_lint_and_help(
193+
cx,
194+
INVALID_ATOMIC_ORDERING,
195+
failure_order_arg.span,
196+
&format!(
197+
"{}'s failure ordering may not be `Release` or `AcqRel`",
198+
method,
199+
),
200+
None,
201+
&format!("consider using {} instead", suggested),
202+
);
203+
} else if let Some((success_ord_name, bad_ords_given_success, suggested)) = success_lint_info {
204+
if match_ordering_def_path(cx, fail_ordering_def_id, bad_ords_given_success) {
205+
span_lint_and_help(
206+
cx,
207+
INVALID_ATOMIC_ORDERING,
208+
failure_order_arg.span,
209+
&format!(
210+
"{}'s failure ordering may not be stronger than the success ordering of `{}`",
211+
method,
212+
success_ord_name,
213+
),
214+
None,
215+
&format!("consider using {} instead", suggested),
216+
);
217+
}
218+
}
219+
}
220+
}
221+
}
222+
130223
impl<'tcx> LateLintPass<'tcx> for AtomicOrdering {
131224
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
132225
check_atomic_load_store(cx, expr);
133226
check_memory_fence(cx, expr);
227+
check_atomic_compare_exchange(cx, expr);
134228
}
135229
}

clippy_lints/src/await_holding_lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare_clippy_lint! {
1010
/// **What it does:** Checks for calls to await while holding a
1111
/// non-async-aware MutexGuard.
1212
///
13-
/// **Why is this bad?** The Mutex types found in syd::sync and parking_lot
13+
/// **Why is this bad?** The Mutex types found in std::sync and parking_lot
1414
/// are not designed to operate in an async context across await points.
1515
///
1616
/// There are two potential solutions. One is to use an asynx-aware Mutex

clippy_lints/src/bit_mask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ declare_clippy_lint! {
9090
/// if x & 0b1111 == 0 { }
9191
/// ```
9292
pub VERBOSE_BIT_MASK,
93-
style,
93+
pedantic,
9494
"expressions where a bit mask is less readable than the corresponding method call"
9595
}
9696

clippy_lints/src/bytecount.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::utils::{
2-
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability,
3-
span_lint_and_sugg, walk_ptrs_ty,
2+
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg,
43
};
54
use if_chain::if_chain;
65
use rustc_ast::ast::UintTy;
@@ -53,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
5352
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind;
5453
if op.node == BinOpKind::Eq;
5554
if match_type(cx,
56-
walk_ptrs_ty(cx.typeck_results().expr_ty(&filter_args[0])),
55+
cx.typeck_results().expr_ty(&filter_args[0]).peel_refs(),
5756
&paths::SLICE_ITER);
5857
then {
5958
let needle = match get_path_name(l) {
@@ -63,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
6362
_ => { return; }
6463
}
6564
};
66-
if ty::Uint(UintTy::U8) != *walk_ptrs_ty(cx.typeck_results().expr_ty(needle)).kind() {
65+
if ty::Uint(UintTy::U8) != *cx.typeck_results().expr_ty(needle).peel_refs().kind() {
6766
return;
6867
}
6968
let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) =

clippy_lints/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum Constant {
2121
/// A `String` (e.g., "abc").
2222
Str(String),
2323
/// A binary string (e.g., `b"abc"`).
24-
Binary(Lrc<Vec<u8>>),
24+
Binary(Lrc<[u8]>),
2525
/// A single `char` (e.g., `'a'`).
2626
Char(char),
2727
/// An integer's bit representation.
@@ -155,7 +155,7 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
155155
match *lit {
156156
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
157157
LitKind::Byte(b) => Constant::Int(u128::from(b)),
158-
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
158+
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::from(s.as_slice())),
159159
LitKind::Char(c) => Constant::Char(c),
160160
LitKind::Int(n, _) => Constant::Int(n),
161161
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {

0 commit comments

Comments
 (0)