Skip to content

Commit ddb9a3a

Browse files
committed
Update Clippy
1 parent 4b7e88e commit ddb9a3a

29 files changed

+314
-93
lines changed

CONTRIBUTING.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,28 @@ using that version of Rust.
145145

146146
You can use [rustup-toolchain-install-master][rtim] to do that:
147147

148-
```
148+
```bash
149149
cargo install rustup-toolchain-install-master
150150
rustup-toolchain-install-master -n master --force
151151
rustup override set master
152152
cargo test
153153
```
154154

155+
After fixing the build failure on this repository, we can submit a pull request
156+
to [`rust-lang/rust`] to fix the toolstate.
157+
158+
To submit a pull request, you should follow these steps:
159+
160+
```bash
161+
# Assuming you already cloned the rust-lang/rust repo and you're in the correct directory
162+
git submodule update --remote src/tools/clippy
163+
cargo update -p clippy
164+
git add -u
165+
git commit -m "Update Clippy"
166+
./x.py test -i --stage 1 src/tools/clippy # This is optional and should succeed anyway
167+
# Open a PR in rust-lang/rust
168+
```
169+
155170
## Issue and PR triage
156171

157172
Clippy is following the [Rust triage procedure][triage] for issues and pull
@@ -211,3 +226,4 @@ or the [MIT](http://opensource.org/licenses/MIT) license.
211226
[homu]: https://github.com/servo/homu
212227
[homu_instructions]: https://buildbot2.rust-lang.org/homu/
213228
[homu_queue]: https://buildbot2.rust-lang.org/homu/queue/clippy
229+
[`rust-lang/rust`]: https://github.com/rust-lang/rust

clippy_lints/src/attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
277277
line_span,
278278
"if you just forgot a `!`, use",
279279
sugg,
280-
Applicability::MachineApplicable,
280+
Applicability::MaybeIncorrect,
281281
);
282282
},
283283
);

clippy_lints/src/cognitive_complexity.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ impl CognitiveComplexity {
100100
cx,
101101
COGNITIVE_COMPLEXITY,
102102
span,
103-
&format!("the function has a cognitive complexity of {}", rust_cc),
103+
&format!(
104+
"the function has a cognitive complexity of ({}/{})",
105+
rust_cc,
106+
self.limit.limit()
107+
),
104108
"you could split it up into multiple smaller functions",
105109
);
106110
}

clippy_lints/src/int_plus_one.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl IntPlusOne {
158158
|db| {
159159
db.span_suggestion(
160160
block.span,
161-
"change `>= y + 1` to `> y` as shown",
161+
"change it to",
162162
recommendation,
163163
Applicability::MachineApplicable, // snippet
164164
);

clippy_lints/src/matches.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,24 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &
624624
} else {
625625
"as_mut"
626626
};
627+
628+
let output_ty = cx.tables.expr_ty(expr);
629+
let input_ty = cx.tables.expr_ty(ex);
630+
631+
let cast = if_chain! {
632+
if let ty::Adt(_, substs) = input_ty.sty;
633+
let input_ty = substs.type_at(0);
634+
if let ty::Adt(_, substs) = output_ty.sty;
635+
let output_ty = substs.type_at(0);
636+
if let ty::Ref(_, output_ty, _) = output_ty.sty;
637+
if input_ty != output_ty;
638+
then {
639+
".map(|x| x as _)"
640+
} else {
641+
""
642+
}
643+
};
644+
627645
let mut applicability = Applicability::MachineApplicable;
628646
span_lint_and_sugg(
629647
cx,
@@ -632,9 +650,10 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &
632650
&format!("use {}() instead", suggestion),
633651
"try this",
634652
format!(
635-
"{}.{}()",
653+
"{}.{}(){}",
636654
snippet_with_applicability(cx, ex.span, "_", &mut applicability),
637-
suggestion
655+
suggestion,
656+
cast,
638657
),
639658
applicability,
640659
)

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
1515
use rustc_errors::Applicability;
1616
use syntax::ast;
1717
use syntax::source_map::Span;
18-
use syntax::symbol::LocalInternedString;
18+
use syntax::symbol::{sym, LocalInternedString};
1919

2020
use crate::utils::sugg;
2121
use crate::utils::usage::mutated_variables;
@@ -2682,7 +2682,7 @@ fn get_error_type<'a>(cx: &LateContext<'_, '_>, ty: Ty<'a>) -> Option<Ty<'a>> {
26822682

26832683
/// This checks whether a given type is known to implement Debug.
26842684
fn has_debug_impl<'a, 'b>(ty: Ty<'a>, cx: &LateContext<'b, 'a>) -> bool {
2685-
match cx.tcx.lang_items().debug_trait() {
2685+
match cx.tcx.get_diagnostic_item(sym::debug_trait) {
26862686
Some(debug) => implements_trait(cx, ty, debug, &[]),
26872687
None => false,
26882688
}

clippy_lints/src/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
407407
lhs - rhs,
408408
if op == BinOpKind::Eq { '<' } else { '>' }
409409
),
410-
Applicability::MachineApplicable, // snippet
410+
Applicability::HasPlaceholders, // snippet
411411
);
412412
db.span_note(expr.span, "std::f32::EPSILON and std::f64::EPSILON are available.");
413413
});

clippy_lints/src/missing_const_for_fn.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use crate::utils::{is_entrypoint_fn, span_lint, trait_ref_of_method};
1+
use crate::utils::{has_drop, is_entrypoint_fn, span_lint, trait_ref_of_method};
22
use rustc::hir;
33
use rustc::hir::intravisit::FnKind;
4-
use rustc::hir::{Body, Constness, FnDecl, HirId};
4+
use rustc::hir::{Body, Constness, FnDecl, HirId, HirVec};
55
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass};
66
use rustc::{declare_lint_pass, declare_tool_lint};
77
use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
8+
use rustc_typeck::hir_ty_to_ty;
89
use syntax_pos::Span;
910

1011
declare_clippy_lint! {
@@ -94,7 +95,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
9495
}
9596
},
9697
FnKind::Method(_, sig, ..) => {
97-
if trait_ref_of_method(cx, hir_id).is_some() || already_const(sig.header) {
98+
if trait_ref_of_method(cx, hir_id).is_some()
99+
|| already_const(sig.header)
100+
|| method_accepts_dropable(cx, &sig.decl.inputs)
101+
{
98102
return;
99103
}
100104
},
@@ -113,6 +117,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
113117
}
114118
}
115119

120+
/// Returns true if any of the method parameters is a type that implements `Drop`. The method
121+
/// can't be made const then, because `drop` can't be const-evaluated.
122+
fn method_accepts_dropable(cx: &LateContext<'_, '_>, param_tys: &HirVec<hir::Ty>) -> bool {
123+
// If any of the params are dropable, return true
124+
param_tys.iter().any(|hir_ty| {
125+
let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty);
126+
has_drop(cx, ty_ty)
127+
})
128+
}
129+
116130
// We don't have to lint on something that's already `const`
117131
fn already_const(header: hir::FnHeader) -> bool {
118132
header.constness == Constness::Const

tests/ui/assign_ops.fixed

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-rustfix
2+
3+
#[allow(dead_code, unused_assignments)]
4+
#[warn(clippy::assign_op_pattern)]
5+
fn main() {
6+
let mut a = 5;
7+
a += 1;
8+
a += 1;
9+
a -= 1;
10+
a *= 99;
11+
a *= 42;
12+
a /= 2;
13+
a %= 5;
14+
a &= 1;
15+
a = 1 - a;
16+
a = 5 / a;
17+
a = 42 % a;
18+
a = 6 << a;
19+
let mut s = String::new();
20+
s += "bla";
21+
}

tests/ui/assign_ops.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
13
#[allow(dead_code, unused_assignments)]
24
#[warn(clippy::assign_op_pattern)]
35
fn main() {

0 commit comments

Comments
 (0)