Skip to content

Update Clippy #77144

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

Merged
merged 104 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
459969f
added restriction lint that prohibits the usage of unimplemented, unr…
Aug 27, 2020
ceab1a9
removed unnecessary comment
Aug 27, 2020
8462cce
edited documentation
Aug 27, 2020
b2d8ca9
ran cargo dev update lints
Aug 27, 2020
b006522
added lint for todo and removed option
Aug 27, 2020
a424a2c
changed check_impl_item to check_fn and added a few more test cases
Aug 29, 2020
73a3288
uncommented fn
Aug 29, 2020
f9fcbbe
fixed bug
Aug 31, 2020
e49a299
Working map_err_ignore lint
Sep 1, 2020
202a80c
Added tests for map_err, ignored map_err lint on drop_ref tests
Sep 1, 2020
3377291
Ran cargo dev update_lints
Sep 1, 2020
2387f68
Removed map_err suggestion in lint, and updated lint documentation ex…
Sep 2, 2020
c31d473
update example to be more idiomatic
yaahc Sep 4, 2020
4f1c4a9
Fixed typo in lint and test
Sep 8, 2020
d719b48
Move map_err_ignore from style to pedantic
Sep 8, 2020
d712d7f
Improve "known problems" of `interior_mutable_key`
rail-rain Sep 9, 2020
46b1643
update cargo dev ra-setup to changed rustc source paths
matthiaskrgr Sep 9, 2020
3550568
removing if chain and renaming lint
Sep 9, 2020
f90b1fc
cargo dev update-lints
Sep 9, 2020
6211599
Extend invalid_atomic_ordering to detect misuse of compare_exchange{,…
thomcc Sep 9, 2020
61671a2
Detect fetch_update misuse in invalid_atomic_ordering too
thomcc Sep 9, 2020
159178e
Separate compare_exchange and compare_exchange_weak uitests
thomcc Sep 9, 2020
b657455
Use AtomicU8 in ordering example so all operations can be demonstrated
thomcc Sep 9, 2020
4b5326b
Address small review comments
thomcc Sep 10, 2020
3a07213
Ah, right, rerun the scripts
thomcc Sep 10, 2020
f3489d4
fix some use of `snippet` in `types.rs`
rail-rain Sep 8, 2020
f1775f0
Fix typo
giraffate Sep 10, 2020
fd42ab4
Auto merge of #6020 - matthiaskrgr:ra_dev_setup_update, r=flip1995
bors Sep 10, 2020
36a8648
Fix spelling of "Known problems section" of `interior_mutable_key`
flip1995 Sep 10, 2020
99374ae
Auto merge of #6019 - rail-rain:improve_known_probs_mut_key, r=flip1995
bors Sep 10, 2020
df6d7bf
Auto merge of #6028 - giraffate:fix_typo, r=flip1995
bors Sep 10, 2020
a12828a
Merge commit '5034d47f721ff4c3a3ff2aca9ef2ef3e1d067f9f' into clippyup
flip1995 Sep 10, 2020
0ab75c3
Auto merge of #5977 - xvschneider:AddLintPanicInResult, r=matthiaskrgr
bors Sep 10, 2020
09f7a37
Add comments to the invalid_atomic_ordering example
thomcc Sep 10, 2020
8808dc6
Fully integrate token collection for additional AST structs
Aaron1011 Aug 22, 2020
519799f
Auto merge of #75800 - Aaron1011:feature/full-nt-tokens, r=petrochenkov
bors Sep 11, 2020
2487f8f
into_iter_on_ref: rephrase lint message: will not move the x -> will …
matthiaskrgr Sep 11, 2020
4df2069
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Sep 12, 2020
f2ecf39
Auto merge of #6033 - flip1995:rustup, r=flip1995
bors Sep 13, 2020
c057621
Auto merge of #6030 - rail-rain:fix_use_snippet_in_types, r=matthiaskrgr
bors Sep 13, 2020
21c3518
Auto merge of #6032 - matthiaskrgr:move_consume, r=flip1995
bors Sep 13, 2020
7ba1a8f
useless_conversion: show type in error message.
matthiaskrgr Sep 13, 2020
9ff7e5d
Downgrade `verbose_bit_mask` to pedantic
giraffate Sep 13, 2020
f96c47e
Merge pull request #6036 from giraffate/update_verbose_bit_mask_to_pe…
Manishearth Sep 13, 2020
231444d
Auto merge of #6035 - matthiaskrgr:try_into_show_type, r=flip1995
bors Sep 13, 2020
d1f0f04
New lint: `manual-strip`
Sep 14, 2020
15244a8
Fix `manual-strip` dogfood errors
Sep 14, 2020
f82e84c
Auto merge of #5998 - deg4uss3r:master, r=yaahc
bors Sep 14, 2020
1b5317f
Add rc_buffer lint for Rc<String> and other buffer types
rschoon Sep 14, 2020
2dd7175
Apply rc_buffer lint to Arc<T>
rschoon Sep 14, 2020
4d73cca
clarify margin of error in wording of float comparison operator lint …
Sep 14, 2020
fd151f5
Remove an extra blank line in `shadow_same`
giraffate Sep 14, 2020
8afa7ed
Add internal lint MatchTypeOnDiagItem
ebroto Sep 6, 2020
332c2dc
Fix dogfood after MatchTypeOnDiagItem
ebroto Sep 6, 2020
c86a7e5
Misc doc updates
ebroto Sep 6, 2020
d0b5663
Fix usage of backquotes in suggestion
ebroto Sep 15, 2020
12ce312
Auto merge of #6013 - ebroto:diagnostic_item_restriction, r=flip1995
bors Sep 15, 2020
78f9ea5
Fix clippy hard-code slice::Iter path
tesuji Sep 15, 2020
9f0f035
Auto merge of #6045 - giraffate:remove_extra_blank_line, r=flip1995
bors Sep 15, 2020
44eb66d
Add note to `shadow_unrelated`
giraffate Sep 15, 2020
16b6ceb
update lint docs
Sep 15, 2020
190c6ea
Auto merge of #6049 - flip1995:rustup, r=flip1995
bors Sep 15, 2020
0695f21
Auto merge of #6043 - HaramanJohal:margin_of_error, r=matthiaskrgr
bors Sep 15, 2020
8b04c2d
Merge branch 'master' into lint-5734
Sep 15, 2020
ecbe9ac
manual-strip: Add additional test
Sep 15, 2020
79a0e51
manual-strip: Fix formatting
Sep 15, 2020
6ba36bc
option_if_let_else - distinguish pure from impure else expressions
tnielens Aug 21, 2020
d0ddbb9
Extend testing of rc_buffer lint
rschoon Sep 16, 2020
ad6f8c6
bump pulldown-cmark v0.8
tesuji Sep 16, 2020
74051c4
Auto merge of #6055 - lzutao:bump-cmark, r=phansch
bors Sep 16, 2020
9c546b5
Add S-* label modifier to triagebot
flip1995 Sep 16, 2020
4f6d4e6
Auto merge of #6056 - rust-lang:flip1995/triagebot, r=flip1995
bors Sep 16, 2020
b37e3cd
Update documentation about moving from Discord to Zulip
giraffate Sep 16, 2020
0261e34
{print,write}-with-newline: do not suggest empty format string
euclio Sep 14, 2020
e7bff50
Auto merge of #6057 - giraffate:update_doc_about_moving_to_zulip, r=f…
bors Sep 16, 2020
61dd007
Auto merge of #6042 - euclio:println-empty, r=flip1995
bors Sep 16, 2020
b08bbe5
Auto merge of #6048 - giraffate:add_note_to_shadow_unrelated, r=matth…
bors Sep 16, 2020
79da747
option_if_let_else - change misleading test file section
tnielens Sep 16, 2020
5e60497
Auto merge of #6038 - mikerite:lint-5734, r=matthiaskrgr
bors Sep 16, 2020
44d6439
Auto merge of #6025 - thomcc:compare_exchange_atomics, r=flip1995
bors Sep 16, 2020
06f1902
Auto merge of #5937 - montrivo:option_if_let_else, r=flip1995
bors Sep 16, 2020
2ce2d6b
fix a FP in `indexing_slicing`
rail-rain Sep 11, 2020
ce06472
replace `walk_ptrs_ty` with `peel_refs`
rail-rain Sep 11, 2020
5af88e3
Auto merge of #6034 - rail-rain:fix_fp_in_indexing_slicing, r=flip1995
bors Sep 16, 2020
2720085
Move rc_buffer lint into perf category
rschoon Sep 16, 2020
d655c0a
Change the criteria of `interior_mutable_const`
rail-rain Aug 25, 2020
2fc9064
rewrite the test and fix a minor fp
rail-rain Sep 17, 2020
d5af360
add `WRAPPED_SELF: Option<Self>` in the test
rail-rain Sep 17, 2020
d88b9b7
Auto merge of #6046 - rail-rain:change_criteria_non_copy_const, r=fli…
bors Sep 18, 2020
10d272b
Update Clippy testcases
CDirkx Sep 20, 2020
292e2f7
Remove `can_suggest` check for `is_ok` and `is_err`.
CDirkx Sep 20, 2020
ac0d069
Update src/tools/clippy/clippy_lints/src/matches.rs
CDirkx Sep 20, 2020
a334ae6
Auto merge of #76136 - CDirkx:const-result, r=dtolnay
bors Sep 20, 2020
ed43385
Update Clippy testcases
CDirkx Sep 20, 2020
141b9c2
Remove `can_suggest` from Clippy.
CDirkx Sep 20, 2020
6e07247
Merge remote-tracking branch 'upstream/master' into rustup
ebroto Sep 21, 2020
4117ae1
Split redundant_pattern_matching tests
ebroto Sep 21, 2020
78fbb04
Auto merge of #6071 - ebroto:rustup, r=ebroto
bors Sep 21, 2020
d4f158f
Forbid redundant_pattern_matching triggering in macros
alex-700 Sep 20, 2020
29b12f2
Auto merge of #6069 - alex-700:redundant-pattern-matching-in-macro, r…
bors Sep 22, 2020
6c056d3
Satisfy rc_buffer lint in Constant::Binary byte string by copying data
rschoon Sep 23, 2020
e636b88
Auto merge of #6044 - rschoon:rc-buffer, r=yaahc
bors Sep 23, 2020
f1f1e0b
Merge commit 'e636b88aa180e8cab9e28802aac90adbc984234d' into clippyup
flip1995 Sep 24, 2020
d445493
Update Cargo.lock
flip1995 Sep 24, 2020
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: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ dependencies = [
"if_chain",
"itertools 0.9.0",
"lazy_static",
"pulldown-cmark 0.7.2",
"pulldown-cmark 0.8.0",
"quine-mc_cluskey",
"quote",
"regex-syntax",
Expand Down
4 changes: 4 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1672,10 +1672,12 @@ Released 2018-09-13
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
[`map_err_ignore`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_err_ignore
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
[`map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_identity
[`map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or
Expand Down Expand Up @@ -1755,6 +1757,7 @@ Released 2018-09-13
[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing
[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional
[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic
[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
Expand All @@ -1774,6 +1777,7 @@ Released 2018-09-13
[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
[`range_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_step_by_zero
[`range_zip_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_zip_with_len
[`rc_buffer`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer
[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation
[`redundant_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
[`redundant_closure`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ something. We appreciate any sort of contributions, and don't want a wall of rul

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

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

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

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_dev/src/ra_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn run(rustc_path: Option<&str>) {
// we can unwrap here because the arg is required here
let rustc_path = PathBuf::from(rustc_path.unwrap());
assert!(rustc_path.is_dir(), "path is not a directory");
let rustc_source_basedir = rustc_path.join("src");
let rustc_source_basedir = rustc_path.join("compiler");
assert!(
rustc_source_basedir.is_dir(),
"are you sure the path leads to a rustc repo?"
Expand Down Expand Up @@ -61,7 +61,7 @@ fn inject_deps_into_manifest(
let new_deps = extern_crates.map(|dep| {
// format the dependencies that are going to be put inside the Cargo.toml
format!(
"{dep} = {{ path = \"{source_path}/lib{dep}\" }}\n",
"{dep} = {{ path = \"{source_path}/{dep}\" }}\n",
dep = dep,
source_path = rustc_source_dir.display()
)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cargo_metadata = "0.11.1"
if_chain = "1.0.0"
itertools = "0.9"
lazy_static = "1.0.2"
pulldown-cmark = { version = "0.7.1", default-features = false }
pulldown-cmark = { version = "0.8", default-features = false }
quine-mc_cluskey = "0.2.2"
regex-syntax = "0.6"
serde = { version = "1.0", features = ["derive"] }
Expand Down
106 changes: 100 additions & 6 deletions src/tools/clippy/clippy_lints/src/atomic_ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};

declare_clippy_lint! {
/// **What it does:** Checks for usage of invalid atomic
/// ordering in atomic loads/stores and memory fences.
/// ordering in atomic loads/stores/exchanges/updates and
/// memory fences.
///
/// **Why is this bad?** Using an invalid atomic ordering
/// will cause a panic at run-time.
Expand All @@ -17,22 +18,35 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust,no_run
/// # use std::sync::atomic::{self, AtomicBool, Ordering};
/// # use std::sync::atomic::{self, AtomicU8, Ordering};
///
/// let x = AtomicBool::new(true);
/// let x = AtomicU8::new(0);
///
/// // Bad: `Release` and `AcqRel` cannot be used for `load`.
/// let _ = x.load(Ordering::Release);
/// let _ = x.load(Ordering::AcqRel);
///
/// x.store(false, Ordering::Acquire);
/// x.store(false, Ordering::AcqRel);
/// // Bad: `Acquire` and `AcqRel` cannot be used for `store`.
/// x.store(1, Ordering::Acquire);
/// x.store(2, Ordering::AcqRel);
///
/// // Bad: `Relaxed` cannot be used as a fence's ordering.
/// atomic::fence(Ordering::Relaxed);
/// atomic::compiler_fence(Ordering::Relaxed);
///
/// // Bad: `Release` and `AcqRel` are both always invalid
/// // for the failure ordering (the last arg).
/// let _ = x.compare_exchange(1, 2, Ordering::SeqCst, Ordering::Release);
/// let _ = x.compare_exchange_weak(2, 3, Ordering::AcqRel, Ordering::AcqRel);
///
/// // Bad: The failure ordering is not allowed to be
/// // stronger than the success order, and `SeqCst` is
/// // stronger than `Relaxed`.
/// let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |val| Some(val + val));
/// ```
pub INVALID_ATOMIC_ORDERING,
correctness,
"usage of invalid atomic ordering in atomic loads/stores and memory fences"
"usage of invalid atomic ordering in atomic operations and memory fences"
}

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

fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option<DefId> {
if let ExprKind::Path(ref ord_qpath) = ord_arg.kind {
cx.qpath_res(ord_qpath, ord_arg.hir_id).opt_def_id()
} else {
None
}
}

fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
let method = method_path.ident.name.as_str();
if type_is_atomic(cx, &args[0]);
if method == "compare_exchange" || method == "compare_exchange_weak" || method == "fetch_update";
let (success_order_arg, failure_order_arg) = if method == "fetch_update" {
(&args[1], &args[2])
} else {
(&args[3], &args[4])
};
if let Some(fail_ordering_def_id) = opt_ordering_defid(cx, failure_order_arg);
then {
// Helper type holding on to some checking and error reporting data. Has
// - (success ordering name,
// - list of failure orderings forbidden by the success order,
// - suggestion message)
type OrdLintInfo = (&'static str, &'static [&'static str], &'static str);
let relaxed: OrdLintInfo = ("Relaxed", &["SeqCst", "Acquire"], "ordering mode `Relaxed`");
let acquire: OrdLintInfo = ("Acquire", &["SeqCst"], "ordering modes `Acquire` or `Relaxed`");
let seq_cst: OrdLintInfo = ("SeqCst", &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`");
let release = ("Release", relaxed.1, relaxed.2);
let acqrel = ("AcqRel", acquire.1, acquire.2);
let search = [relaxed, acquire, seq_cst, release, acqrel];

let success_lint_info = opt_ordering_defid(cx, success_order_arg)
.and_then(|success_ord_def_id| -> Option<OrdLintInfo> {
search
.iter()
.find(|(ordering, ..)| {
match_def_path(cx, success_ord_def_id,
&["core", "sync", "atomic", "Ordering", ordering])
})
.copied()
});

if match_ordering_def_path(cx, fail_ordering_def_id, &["Release", "AcqRel"]) {
// If we don't know the success order is, use what we'd suggest
// if it were maximally permissive.
let suggested = success_lint_info.unwrap_or(seq_cst).2;
span_lint_and_help(
cx,
INVALID_ATOMIC_ORDERING,
failure_order_arg.span,
&format!(
"{}'s failure ordering may not be `Release` or `AcqRel`",
method,
),
None,
&format!("consider using {} instead", suggested),
);
} else if let Some((success_ord_name, bad_ords_given_success, suggested)) = success_lint_info {
if match_ordering_def_path(cx, fail_ordering_def_id, bad_ords_given_success) {
span_lint_and_help(
cx,
INVALID_ATOMIC_ORDERING,
failure_order_arg.span,
&format!(
"{}'s failure ordering may not be stronger than the success ordering of `{}`",
method,
success_ord_name,
),
None,
&format!("consider using {} instead", suggested),
);
}
}
}
}
}

impl<'tcx> LateLintPass<'tcx> for AtomicOrdering {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
check_atomic_load_store(cx, expr);
check_memory_fence(cx, expr);
check_atomic_compare_exchange(cx, expr);
}
}
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/await_holding_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare_clippy_lint! {
/// **What it does:** Checks for calls to await while holding a
/// non-async-aware MutexGuard.
///
/// **Why is this bad?** The Mutex types found in syd::sync and parking_lot
/// **Why is this bad?** The Mutex types found in std::sync and parking_lot
/// are not designed to operate in an async context across await points.
///
/// There are two potential solutions. One is to use an asynx-aware Mutex
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/bit_mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ declare_clippy_lint! {
/// if x & 0b1111 == 0 { }
/// ```
pub VERBOSE_BIT_MASK,
style,
pedantic,
"expressions where a bit mask is less readable than the corresponding method call"
}

Expand Down
7 changes: 3 additions & 4 deletions src/tools/clippy/clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::utils::{
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability,
span_lint_and_sugg, walk_ptrs_ty,
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg,
};
use if_chain::if_chain;
use rustc_ast::ast::UintTy;
Expand Down Expand Up @@ -53,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind;
if op.node == BinOpKind::Eq;
if match_type(cx,
walk_ptrs_ty(cx.typeck_results().expr_ty(&filter_args[0])),
cx.typeck_results().expr_ty(&filter_args[0]).peel_refs(),
&paths::SLICE_ITER);
then {
let needle = match get_path_name(l) {
Expand All @@ -63,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
_ => { return; }
}
};
if ty::Uint(UintTy::U8) != *walk_ptrs_ty(cx.typeck_results().expr_ty(needle)).kind() {
if ty::Uint(UintTy::U8) != *cx.typeck_results().expr_ty(needle).peel_refs().kind() {
return;
}
let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) =
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum Constant {
/// A `String` (e.g., "abc").
Str(String),
/// A binary string (e.g., `b"abc"`).
Binary(Lrc<Vec<u8>>),
Binary(Lrc<[u8]>),
/// A single `char` (e.g., `'a'`).
Char(char),
/// An integer's bit representation.
Expand Down Expand Up @@ -155,7 +155,7 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
match *lit {
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
LitKind::Byte(b) => Constant::Int(u128::from(b)),
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::from(s.as_slice())),
LitKind::Char(c) => Constant::Char(c),
LitKind::Int(n, _) => Constant::Int(n),
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
return false;
}

let s = if s.ends_with('s') { &s[..s.len() - 1] } else { s };
let s = s.strip_suffix('s').unwrap_or(s);

s.chars().all(char::is_alphanumeric)
&& s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/duration_subsec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_span::source_map::Spanned;

use crate::consts::{constant, Constant};
use crate::utils::paths;
use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg, walk_ptrs_ty};
use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg};

declare_clippy_lint! {
/// **What it does:** Checks for calculation of subsecond microseconds or milliseconds
Expand Down Expand Up @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
if_chain! {
if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind;
if let ExprKind::MethodCall(ref method_path, _ , ref args, _) = left.kind;
if match_type(cx, walk_ptrs_ty(cx.typeck_results().expr_ty(&args[0])), &paths::DURATION);
if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION);
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right);
then {
let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::utils::SpanlessEq;
use crate::utils::{get_item_name, higher, is_type_diagnostic_item, match_type, paths, snippet, snippet_opt};
use crate::utils::{snippet_with_applicability, span_lint_and_then, walk_ptrs_ty};
use crate::utils::{snippet_with_applicability, span_lint_and_then};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
Expand Down Expand Up @@ -106,7 +106,7 @@ fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind;
then {
let map = &params[0];
let obj_ty = walk_ptrs_ty(cx.typeck_results().expr_ty(map));
let obj_ty = cx.typeck_results().expr_ty(map).peel_refs();

return if match_type(cx, obj_ty, &paths::BTREEMAP) {
Some(("BTreeMap", map, key))
Expand Down
6 changes: 2 additions & 4 deletions src/tools/clippy/clippy_lints/src/fallible_impl_from.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT};
use crate::utils::{
is_expn_of, is_type_diagnostic_item, match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty,
};
use crate::utils::{is_expn_of, is_type_diagnostic_item, match_def_path, method_chain_args, span_lint_and_then};
use if_chain::if_chain;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
Expand Down Expand Up @@ -96,7 +94,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h

// check for `unwrap`
if let Some(arglists) = method_chain_args(expr, &["unwrap"]) {
let reciever_ty = walk_ptrs_ty(self.typeck_results.expr_ty(&arglists[0][0]));
let reciever_ty = self.typeck_results.expr_ty(&arglists[0][0]).peel_refs();
if is_type_diagnostic_item(self.lcx, reciever_ty, sym!(option_type))
|| is_type_diagnostic_item(self.lcx, reciever_ty, sym!(result_type))
{
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils::paths;
use crate::utils::{
is_expn_of, is_type_diagnostic_item, last_path_segment, match_def_path, match_function_call, snippet,
span_lint_and_then, walk_ptrs_ty,
span_lint_and_then,
};
use if_chain::if_chain;
use rustc_ast::ast::LitKind;
Expand Down Expand Up @@ -90,7 +90,7 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: &
if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind;
if pats.len() == 1;
then {
let ty = walk_ptrs_ty(cx.typeck_results().pat_ty(&pats[0]));
let ty = cx.typeck_results().pat_ty(&pats[0]).peel_refs();
if *ty.kind() != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym!(string_type)) {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/indexing_slicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]
impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Index(ref array, ref index) = &expr.kind {
let ty = cx.typeck_results().expr_ty(array);
let ty = cx.typeck_results().expr_ty(array).peel_refs();
if let Some(range) = higher::range(index) {
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]
if let ty::Array(_, s) = ty.kind() {
Expand Down
Loading