Merge remote-tracking branch 'upstream/master' into rustup

This commit is contained in:
flip1995 2020-07-18 15:06:44 +02:00
commit 0f501ac1db
No known key found for this signature in database
GPG key ID: 2CEFCDB27ED0BE79
34 changed files with 464 additions and 65 deletions

21
.github/deploy.sh vendored
View file

@ -19,7 +19,7 @@ fi
if [[ $BETA = "true" ]]; then
echo "Update documentation for the beta release"
cp -r out/master out/beta
cp -r out/master/* out/beta
fi
# Generate version index that is shown as root index page
@ -33,12 +33,13 @@ cd out
git config user.name "GHA CI"
git config user.email "gha@ci.invalid"
if git diff --exit-code --quiet; then
echo "No changes to the output on this push; exiting."
exit 0
fi
if [[ -n $TAG_NAME ]]; then
# track files, so that the following check works
git add --intent-to-add "$TAG_NAME"
if git diff --exit-code --quiet -- $TAG_NAME/; then
echo "No changes to the output on this push; exiting."
exit 0
fi
# Add the new dir
git add "$TAG_NAME"
# Update the symlink
@ -47,9 +48,17 @@ if [[ -n $TAG_NAME ]]; then
git add versions.json
git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}"
elif [[ $BETA = "true" ]]; then
if git diff --exit-code --quiet -- beta/; then
echo "No changes to the output on this push; exiting."
exit 0
fi
git add beta
git commit -m "Automatic deploy to GitHub Pages (beta): ${SHA}"
else
if git diff --exit-code --quiet; then
echo "No changes to the output on this push; exiting."
exit 0
fi
git add .
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
fi

View file

@ -1,4 +1,4 @@
# Change Log
# Changelog
All notable changes to this project will be documented in this file.
See [Changelog Update](doc/changelog_update.md) if you want to update this
@ -6,11 +6,73 @@ document.
## Unreleased / In Rust Nightly
[7ea7cd1...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
[c2c07fa...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
## Rust 1.46
Current beta, release 2020-08-27
[7ea7cd1...c2c07fa](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
### New lints
* [`unnested_or_patterns`] [#5378](https://github.com/rust-lang/rust-clippy/pull/5378)
* [`iter_next_slice`] [#5597](https://github.com/rust-lang/rust-clippy/pull/5597)
* [`unnecessary_sort_by`] [#5623](https://github.com/rust-lang/rust-clippy/pull/5623)
* [`vec_resize_to_zero`] [#5637](https://github.com/rust-lang/rust-clippy/pull/5637)
### Moves and Deprecations
* Move [`cast_ptr_alignment`] to pedantic [#5667](https://github.com/rust-lang/rust-clippy/pull/5667)
### Enhancements
* Improve [`mem_replace_with_uninit`] lint [#5695](https://github.com/rust-lang/rust-clippy/pull/5695)
### False Positive Fixes
* [`len_zero`]: Avoid linting ranges when the `range_is_empty` feature is not enabled
[#5656](https://github.com/rust-lang/rust-clippy/pull/5656)
* [`let_and_return`]: Don't lint if a temporary borrow is involved
[#5680](https://github.com/rust-lang/rust-clippy/pull/5680)
* [`reversed_empty_ranges`]: Avoid linting `N..N` in for loop arguments in
[#5692](https://github.com/rust-lang/rust-clippy/pull/5692)
* [`if_same_then_else`]: Don't assume multiplication is always commutative
[#5702](https://github.com/rust-lang/rust-clippy/pull/5702)
* [`blacklisted_name`]: Remove `bar` from the default configuration
[#5712](https://github.com/rust-lang/rust-clippy/pull/5712)
* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts
[#5724](https://github.com/rust-lang/rust-clippy/pull/5724)
### Suggestion Fixes/Improvements
* Fix suggestion of [`unit_arg`] lint, so that it suggest semantic equivalent code
[#4455](https://github.com/rust-lang/rust-clippy/pull/4455)
* Add auto applicable suggestion to [`macro_use_imports`]
[#5279](https://github.com/rust-lang/rust-clippy/pull/5279)
### ICE Fixes
* Fix ICE in the `consts` module of Clippy [#5709](https://github.com/rust-lang/rust-clippy/pull/5709)
### Documentation Improvements
* Improve code examples across multiple lints [#5664](https://github.com/rust-lang/rust-clippy/pull/5664)
### Others
* Introduce a `--rustc` flag to `clippy-driver`, which turns `clippy-driver`
into `rustc` and passes all the given arguments to `rustc`. This is especially
useful for tools that need the `rustc` version Clippy was compiled with,
instead of the Clippy version. E.g. `clippy-driver --rustc --version` will
print the output of `rustc --version`.
[#5178](https://github.com/rust-lang/rust-clippy/pull/5178)
* New issue templates now make it easier to complain if Clippy is too annoying
or not annoying enough! [#5735](https://github.com/rust-lang/rust-clippy/pull/5735)
## Rust 1.45
Current beta, release 2020-07-16
Current stable, released 2020-07-16
[891e1a8...7ea7cd1](https://github.com/rust-lang/rust-clippy/compare/891e1a8...7ea7cd1)
@ -87,7 +149,7 @@ and [`similar_names`]. [#5651](https://github.com/rust-lang/rust-clippy/pull/565
## Rust 1.44
Current stable, released 2020-06-04
Released 2020-06-04
[204bb9b...891e1a8](https://github.com/rust-lang/rust-clippy/compare/204bb9b...891e1a8)
@ -1679,6 +1741,7 @@ Released 2018-09-13
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord
[`unknown_clippy_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#unknown_clippy_lints
[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map

View file

@ -153,7 +153,7 @@ declare_deprecated_lint! {
///
/// **Deprecation reason:** Associated-constants are now preferred.
pub REPLACE_CONSTS,
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants"
"associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants"
}
declare_deprecated_lint! {

View file

@ -10,7 +10,7 @@ use rustc_span::source_map::Span;
declare_clippy_lint! {
/// **What it does:** Checks for explicit `deref()` or `deref_mut()` method calls.
///
/// **Why is this bad?** Derefencing by `&*x` or `&mut *x` is clearer and more concise,
/// **Why is this bad?** Dereferencing by `&*x` or `&mut *x` is clearer and more concise,
/// when not part of a method chain.
///
/// **Example:**

View file

@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
..
} = item.kind
{
// Remember for each inherent implementation encoutered its span and generics
// Remember for each inherent implementation encountered its span and generics
// but filter out implementations that have generic params (type or lifetime)
// or are derived from a macro
if !in_macro(item.span) && generics.params.is_empty() {

View file

@ -300,6 +300,7 @@ mod trivially_copy_pass_by_ref;
mod try_err;
mod types;
mod unicode;
mod unit_return_expecting_ord;
mod unnamed_address;
mod unnecessary_sort_by;
mod unnested_or_patterns;
@ -462,7 +463,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
);
store.register_removed(
"clippy::replace_consts",
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants",
"associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants",
);
store.register_removed(
"clippy::regex_macro",
@ -826,6 +827,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
&unicode::NON_ASCII_LITERAL,
&unicode::UNICODE_NOT_NFC,
&unicode::ZERO_WIDTH_SPACE,
&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD,
&unnamed_address::FN_ADDRESS_COMPARISONS,
&unnamed_address::VTABLE_ADDRESS_COMPARISONS,
&unnecessary_sort_by::UNNECESSARY_SORT_BY,
@ -891,6 +893,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
store.register_late_pass(|| box attrs::Attributes);
store.register_late_pass(|| box blocks_in_if_conditions::BlocksInIfConditions);
store.register_late_pass(|| box unicode::Unicode);
store.register_late_pass(|| box unit_return_expecting_ord::UnitReturnExpectingOrd);
store.register_late_pass(|| box strings::StringAdd);
store.register_late_pass(|| box implicit_return::ImplicitReturn);
store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub);
@ -1436,6 +1439,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::UNNECESSARY_CAST),
LintId::of(&types::VEC_BOX),
LintId::of(&unicode::ZERO_WIDTH_SPACE),
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
@ -1692,6 +1696,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(&types::CAST_REF_TO_MUT),
LintId::of(&types::UNIT_CMP),
LintId::of(&unicode::ZERO_WIDTH_SPACE),
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),

View file

@ -2354,8 +2354,8 @@ fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_ar
cx,
ITER_NTH_ZERO,
expr.span,
"called `.nth(0)` on a `std::iter::Iterator`",
"try calling",
"called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent",
"try calling `.next()` instead of `.nth(0)`",
format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
applicability,
);
@ -3290,7 +3290,12 @@ fn lint_option_as_ref_deref<'tcx>(
if let hir::ExprKind::Path(qpath) = &args[0].kind;
if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id);
if closure_body.params[0].pat.hir_id == local_id;
let adj = cx.typeck_results().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
let adj = cx
.typeck_results()
.expr_adjustments(&args[0])
.iter()
.map(|x| &x.kind)
.collect::<Box<[_]>>();
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
then {
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();

View file

@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
/// Returns true if any of the method parameters is a type that implements `Drop`. The method
/// can't be made const then, because `drop` can't be const-evaluated.
fn method_accepts_dropable(cx: &LateContext<'_>, param_tys: &[hir::Ty<'_>]) -> bool {
// If any of the params are dropable, return true
// If any of the params are droppable, return true
param_tys.iter().any(|hir_ty| {
let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty);
has_drop(cx, ty_ty)

View file

@ -8,7 +8,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
use std::fmt::Display;
declare_clippy_lint! {
/// **What it does:** Checks for modulo arithemtic.
/// **What it does:** Checks for modulo arithmetic.
///
/// **Why is this bad?** The results of modulo (%) operation might differ
/// depending on the language, when negative numbers are involved.

View file

@ -40,9 +40,8 @@ declare_clippy_lint! {
/// assert_eq!(v.len(), 42);
/// }
/// ```
///
/// should be
/// ```rust
/// // should be
/// fn foo(v: &[i32]) {
/// assert_eq!(v.len(), 42);
/// }

View file

@ -218,12 +218,16 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
let mut split_at = None;
match existing_name.len.cmp(&count) {
Ordering::Greater => {
if existing_name.len - count != 1 || levenstein_not_1(&interned_name, &existing_name.interned.as_str()) {
if existing_name.len - count != 1
|| levenstein_not_1(&interned_name, &existing_name.interned.as_str())
{
continue;
}
},
Ordering::Less => {
if count - existing_name.len != 1 || levenstein_not_1(&existing_name.interned.as_str(), &interned_name) {
if count - existing_name.len != 1
|| levenstein_not_1(&existing_name.interned.as_str(), &interned_name)
{
continue;
}
},

View file

@ -79,7 +79,7 @@ fn is_result_ok(cx: &LateContext<'_>, expr: &'_ Expr<'_>) -> bool {
}
}
/// A struct containing information about occurences of the
/// A struct containing information about occurrences of the
/// `if let Some(..) = .. else` construct that this lint detects.
struct OptionIfLetElseOccurence {
option: String,

View file

@ -96,23 +96,20 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
if_chain! {
if let ExprKind::Block(ref block, _) = expr.kind;
if let Some(ref ex) = block.expr;
if let Some(params) = match_function_call(cx, ex, &paths::BEGIN_PANIC);
if params.len() == 1;
if let Some(params) = match_function_call(cx, ex, &paths::BEGIN_PANIC)
.or_else(|| match_function_call(cx, ex, &paths::BEGIN_PANIC_FMT));
then {
let span = get_outer_span(expr);
if is_expn_of(expr.span, "unimplemented").is_some() {
let span = get_outer_span(expr);
span_lint(cx, UNIMPLEMENTED, span,
"`unimplemented` should not be present in production code");
} else if is_expn_of(expr.span, "todo").is_some() {
let span = get_outer_span(expr);
span_lint(cx, TODO, span,
"`todo` should not be present in production code");
} else if is_expn_of(expr.span, "unreachable").is_some() {
let span = get_outer_span(expr);
span_lint(cx, UNREACHABLE, span,
"`unreachable` should not be present in production code");
} else if is_expn_of(expr.span, "panic").is_some() {
let span = get_outer_span(expr);
span_lint(cx, PANIC, span,
"`panic` should not be present in production code");
match_panic(params, expr, cx);

View file

@ -295,11 +295,7 @@ fn lint_shadow<'tcx>(
cx,
SHADOW_UNRELATED,
pattern_span,
&format!(
"`{}` is shadowed by `{}`",
snippet(cx, pattern_span, "_"),
snippet(cx, expr.span, "..")
),
&format!("`{}` is being shadowed", snippet(cx, pattern_span, "_")),
|diag| {
diag.span_note(expr.span, "initialization happens here");
diag.span_note(prev_span, "previous binding is here");

View file

@ -0,0 +1,177 @@
use crate::utils::{get_trait_def_id, paths, span_lint, span_lint_and_help};
use if_chain::if_chain;
use rustc_hir::def_id::DefId;
use rustc_hir::{Expr, ExprKind, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_middle::ty::{GenericPredicates, PredicateKind, ProjectionPredicate, TraitPredicate};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{BytePos, Span};
declare_clippy_lint! {
/// **What it does:** Checks for functions that expect closures of type
/// Fn(...) -> Ord where the implemented closure returns the unit type.
/// The lint also suggests to remove the semi-colon at the end of the statement if present.
///
/// **Why is this bad?** Likely, returning the unit type is unintentional, and
/// could simply be caused by an extra semi-colon. Since () implements Ord
/// it doesn't cause a compilation error.
/// This is the same reasoning behind the unit_cmp lint.
///
/// **Known problems:** If returning unit is intentional, then there is no
/// way of specifying this without triggering needless_return lint
///
/// **Example:**
///
/// ```rust
/// let mut twins = vec!((1,1), (2,2));
/// twins.sort_by_key(|x| { x.1; });
/// ```
pub UNIT_RETURN_EXPECTING_ORD,
correctness,
"fn arguments of type Fn(...) -> Ord returning the unit type ()."
}
declare_lint_pass!(UnitReturnExpectingOrd => [UNIT_RETURN_EXPECTING_ORD]);
fn get_trait_predicates_for_trait_id<'tcx>(
cx: &LateContext<'tcx>,
generics: GenericPredicates<'tcx>,
trait_id: Option<DefId>,
) -> Vec<TraitPredicate<'tcx>> {
let mut preds = Vec::new();
for (pred, _) in generics.predicates {
if_chain! {
if let PredicateKind::Trait(poly_trait_pred, _) = pred.kind();
let trait_pred = cx.tcx.erase_late_bound_regions(&poly_trait_pred);
if let Some(trait_def_id) = trait_id;
if trait_def_id == trait_pred.trait_ref.def_id;
then {
preds.push(trait_pred);
}
}
}
preds
}
fn get_projection_pred<'tcx>(
cx: &LateContext<'tcx>,
generics: GenericPredicates<'tcx>,
pred: TraitPredicate<'tcx>,
) -> Option<ProjectionPredicate<'tcx>> {
generics.predicates.iter().find_map(|(proj_pred, _)| {
if let PredicateKind::Projection(proj_pred) = proj_pred.kind() {
let projection_pred = cx.tcx.erase_late_bound_regions(proj_pred);
if projection_pred.projection_ty.substs == pred.trait_ref.substs {
return Some(projection_pred);
}
}
None
})
}
fn get_args_to_check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Vec<(usize, String)> {
let mut args_to_check = Vec::new();
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) {
let fn_sig = cx.tcx.fn_sig(def_id);
let generics = cx.tcx.predicates_of(def_id);
let fn_mut_preds = get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().fn_mut_trait());
let ord_preds = get_trait_predicates_for_trait_id(cx, generics, get_trait_def_id(cx, &paths::ORD));
let partial_ord_preds =
get_trait_predicates_for_trait_id(cx, generics, cx.tcx.lang_items().partial_ord_trait());
// Trying to call erase_late_bound_regions on fn_sig.inputs() gives the following error
// The trait `rustc::ty::TypeFoldable<'_>` is not implemented for `&[&rustc::ty::TyS<'_>]`
let inputs_output = cx.tcx.erase_late_bound_regions(&fn_sig.inputs_and_output());
inputs_output
.iter()
.rev()
.skip(1)
.rev()
.enumerate()
.for_each(|(i, inp)| {
for trait_pred in &fn_mut_preds {
if_chain! {
if trait_pred.self_ty() == inp;
if let Some(return_ty_pred) = get_projection_pred(cx, generics, *trait_pred);
then {
if ord_preds.iter().any(|ord| ord.self_ty() == return_ty_pred.ty) {
args_to_check.push((i, "Ord".to_string()));
} else if partial_ord_preds.iter().any(|pord| pord.self_ty() == return_ty_pred.ty) {
args_to_check.push((i, "PartialOrd".to_string()));
}
}
}
}
});
}
args_to_check
}
fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Span, Option<Span>)> {
if_chain! {
if let ExprKind::Closure(_, _fn_decl, body_id, span, _) = arg.kind;
if let ty::Closure(_def_id, substs) = &cx.typeck_results().node_type(arg.hir_id).kind;
let ret_ty = substs.as_closure().sig().output();
let ty = cx.tcx.erase_late_bound_regions(&ret_ty);
if ty.is_unit();
then {
if_chain! {
let body = cx.tcx.hir().body(body_id);
if let ExprKind::Block(block, _) = body.value.kind;
if block.expr.is_none();
if let Some(stmt) = block.stmts.last();
if let StmtKind::Semi(_) = stmt.kind;
then {
let data = stmt.span.data();
// Make a span out of the semicolon for the help message
Some((span, Some(Span::new(data.hi-BytePos(1), data.hi, data.ctxt))))
} else {
Some((span, None))
}
}
} else {
None
}
}
}
impl<'tcx> LateLintPass<'tcx> for UnitReturnExpectingOrd {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if let ExprKind::MethodCall(_, _, ref args, _) = expr.kind {
let arg_indices = get_args_to_check(cx, expr);
for (i, trait_name) in arg_indices {
if i < args.len() {
match check_arg(cx, &args[i]) {
Some((span, None)) => {
span_lint(
cx,
UNIT_RETURN_EXPECTING_ORD,
span,
&format!(
"this closure returns \
the unit type which also implements {}",
trait_name
),
);
},
Some((span, Some(last_semi))) => {
span_lint_and_help(
cx,
UNIT_RETURN_EXPECTING_ORD,
span,
&format!(
"this closure returns \
the unit type which also implements {}",
trait_name
),
Some(last_semi),
&"probably caused by this trailing semicolon".to_string(),
);
},
None => {},
}
}
}
}
}
}

View file

@ -36,7 +36,7 @@ pub struct NumericLiteral<'a> {
pub integer: &'a str,
/// The fraction part of the number.
pub fraction: Option<&'a str>,
/// The character used as exponent seperator (b'e' or b'E') and the exponent part.
/// The character used as exponent separator (b'e' or b'E') and the exponent part.
pub exponent: Option<(char, &'a str)>,
/// The type suffix, including preceding underscore if present.

View file

@ -11,7 +11,7 @@ use rustc_ast::ast::LitKind;
use rustc_hir as hir;
declare_clippy_lint! {
/// **What it does:** Finds occurences of `Vec::resize(0, an_int)`
/// **What it does:** Finds occurrences of `Vec::resize(0, an_int)`
///
/// **Why is this bad?** This is probably an argument inversion mistake.
///

View file

@ -2292,6 +2292,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
deprecation: None,
module: "types",
},
Lint {
name: "unit_return_expecting_ord",
group: "correctness",
desc: "fn arguments of type Fn(...) -> Ord returning the unit type ().",
deprecation: None,
module: "unit_return_expecting_ord",
},
Lint {
name: "unknown_clippy_lints",
group: "style",

View file

@ -147,9 +147,6 @@ fn run_ui_toml(config: &mut compiletest::Config) {
}
fn run_ui_cargo(config: &mut compiletest::Config) {
if cargo::is_rustc_test_suite() {
return;
}
fn run_tests(
config: &compiletest::Config,
filter: &Option<String>,

View file

@ -1,22 +1,22 @@
error: called `.nth(0)` on a `std::iter::Iterator`
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
--> $DIR/iter_nth_zero.rs:20:14
|
LL | let _x = s.iter().nth(0);
| ^^^^^^^^^^^^^^^ help: try calling: `s.iter().next()`
| ^^^^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `s.iter().next()`
|
= note: `-D clippy::iter-nth-zero` implied by `-D warnings`
error: called `.nth(0)` on a `std::iter::Iterator`
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
--> $DIR/iter_nth_zero.rs:25:14
|
LL | let _y = iter.nth(0);
| ^^^^^^^^^^^ help: try calling: `iter.next()`
| ^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter.next()`
error: called `.nth(0)` on a `std::iter::Iterator`
error: called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent
--> $DIR/iter_nth_zero.rs:30:22
|
LL | let _unwrapped = iter2.nth(0).unwrap();
| ^^^^^^^^^^^^ help: try calling: `iter2.next()`
| ^^^^^^^^^^^^ help: try calling `.next()` instead of `.nth(0)`: `iter2.next()`
error: aborting due to 3 previous errors

View file

@ -30,7 +30,7 @@ async fn already_async() -> impl Future<Output = i32> {
struct S {}
impl S {
async fn inh_fut() -> i32 {
// NOTE: this code is here just to check that the identation is correct in the suggested fix
// NOTE: this code is here just to check that the indentation is correct in the suggested fix
let a = 42;
let b = 21;
if a < b {

View file

@ -37,7 +37,7 @@ struct S {}
impl S {
fn inh_fut() -> impl Future<Output = i32> {
async {
// NOTE: this code is here just to check that the identation is correct in the suggested fix
// NOTE: this code is here just to check that the indentation is correct in the suggested fix
let a = 42;
let b = 21;
if a < b {

View file

@ -57,7 +57,7 @@ LL | async fn inh_fut() -> i32 {
help: move the body of the async block to the enclosing function
|
LL | fn inh_fut() -> impl Future<Output = i32> {
LL | // NOTE: this code is here just to check that the identation is correct in the suggested fix
LL | // NOTE: this code is here just to check that the indentation is correct in the suggested fix
LL | let a = 42;
LL | let b = 21;
LL | if a < b {

View file

@ -83,3 +83,13 @@ fn main() {
println!("{}", arr[i]);
}
}
mod issue2277 {
pub fn example(list: &[[f64; 3]]) {
let mut x: [f64; 3] = [10.; 3];
for i in 0..3 {
x[i] = list.iter().map(|item| item[i]).sum::<f64>();
}
}
}

View file

@ -166,7 +166,7 @@ pub fn test14() {
}
}
// Issue #1991: the outter loop should not warn.
// Issue #1991: the outer loop should not warn.
pub fn test15() {
'label: loop {
while false {

View file

@ -4,24 +4,32 @@
fn panic() {
let a = 2;
panic!();
panic!("message");
panic!("{} {}", "panic with", "multiple arguments");
let b = a + 2;
}
fn todo() {
let a = 2;
todo!();
todo!("message");
todo!("{} {}", "panic with", "multiple arguments");
let b = a + 2;
}
fn unimplemented() {
let a = 2;
unimplemented!();
unimplemented!("message");
unimplemented!("{} {}", "panic with", "multiple arguments");
let b = a + 2;
}
fn unreachable() {
let a = 2;
unreachable!();
unreachable!("message");
unreachable!("{} {}", "panic with", "multiple arguments");
let b = a + 2;
}

View file

@ -6,29 +6,83 @@ LL | panic!();
|
= note: `-D clippy::panic` implied by `-D warnings`
error: `panic` should not be present in production code
--> $DIR/panicking_macros.rs:7:5
|
LL | panic!("message");
| ^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: `panic` should not be present in production code
--> $DIR/panicking_macros.rs:8:5
|
LL | panic!("{} {}", "panic with", "multiple arguments");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: `todo` should not be present in production code
--> $DIR/panicking_macros.rs:12:5
--> $DIR/panicking_macros.rs:14:5
|
LL | todo!();
| ^^^^^^^^
|
= note: `-D clippy::todo` implied by `-D warnings`
error: `todo` should not be present in production code
--> $DIR/panicking_macros.rs:15:5
|
LL | todo!("message");
| ^^^^^^^^^^^^^^^^^
error: `todo` should not be present in production code
--> $DIR/panicking_macros.rs:16:5
|
LL | todo!("{} {}", "panic with", "multiple arguments");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `unimplemented` should not be present in production code
--> $DIR/panicking_macros.rs:18:5
--> $DIR/panicking_macros.rs:22:5
|
LL | unimplemented!();
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::unimplemented` implied by `-D warnings`
error: `unreachable` should not be present in production code
error: `unimplemented` should not be present in production code
--> $DIR/panicking_macros.rs:23:5
|
LL | unimplemented!("message");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `unimplemented` should not be present in production code
--> $DIR/panicking_macros.rs:24:5
|
LL | unimplemented!("{} {}", "panic with", "multiple arguments");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `unreachable` should not be present in production code
--> $DIR/panicking_macros.rs:30:5
|
LL | unreachable!();
| ^^^^^^^^^^^^^^^
|
= note: `-D clippy::unreachable` implied by `-D warnings`
error: aborting due to 4 previous errors
error: `unreachable` should not be present in production code
--> $DIR/panicking_macros.rs:31:5
|
LL | unreachable!("message");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: `unreachable` should not be present in production code
--> $DIR/panicking_macros.rs:32:5
|
LL | unreachable!("{} {}", "panic with", "multiple arguments");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 12 previous errors

View file

@ -32,7 +32,7 @@ fn main() {
let _ = -(1i32.abs());
let _ = -(1f32.abs());
// Odd functions shoud not trigger an error
// Odd functions should not trigger an error
let _ = -1f64.asin();
let _ = -1f64.asinh();
let _ = -1f64.atan();

View file

@ -32,7 +32,7 @@ fn main() {
let _ = -(1i32.abs());
let _ = -(1f32.abs());
// Odd functions shoud not trigger an error
// Odd functions should not trigger an error
let _ = -1f64.asin();
let _ = -1f64.asinh();
let _ = -1f64.atan();

View file

@ -104,7 +104,7 @@ note: previous binding is here
LL | let x = (1, x);
| ^
error: `x` is shadowed by `y`
error: `x` is being shadowed
--> $DIR/shadow.rs:34:9
|
LL | let x = y;

View file

@ -0,0 +1,36 @@
#![warn(clippy::unit_return_expecting_ord)]
#![allow(clippy::needless_return)]
#![allow(clippy::unused_unit)]
#![feature(is_sorted)]
struct Struct {
field: isize,
}
fn double(i: isize) -> isize {
i * 2
}
fn unit(_i: isize) {}
fn main() {
let mut structs = vec![Struct { field: 2 }, Struct { field: 1 }];
structs.sort_by_key(|s| {
double(s.field);
});
structs.sort_by_key(|s| double(s.field));
structs.is_sorted_by_key(|s| {
double(s.field);
});
structs.is_sorted_by_key(|s| {
if s.field > 0 {
()
} else {
return ();
}
});
structs.sort_by_key(|s| {
return double(s.field);
});
structs.sort_by_key(|s| unit(s.field));
}

View file

@ -0,0 +1,39 @@
error: this closure returns the unit type which also implements Ord
--> $DIR/unit_return_expecting_ord.rs:18:25
|
LL | structs.sort_by_key(|s| {
| ^^^
|
= note: `-D clippy::unit-return-expecting-ord` implied by `-D warnings`
help: probably caused by this trailing semicolon
--> $DIR/unit_return_expecting_ord.rs:19:24
|
LL | double(s.field);
| ^
error: this closure returns the unit type which also implements PartialOrd
--> $DIR/unit_return_expecting_ord.rs:22:30
|
LL | structs.is_sorted_by_key(|s| {
| ^^^
|
help: probably caused by this trailing semicolon
--> $DIR/unit_return_expecting_ord.rs:23:24
|
LL | double(s.field);
| ^
error: this closure returns the unit type which also implements PartialOrd
--> $DIR/unit_return_expecting_ord.rs:25:30
|
LL | structs.is_sorted_by_key(|s| {
| ^^^
error: this closure returns the unit type which also implements Ord
--> $DIR/unit_return_expecting_ord.rs:35:25
|
LL | structs.sort_by_key(|s| unit(s.field));
| ^^^
error: aborting due to 4 previous errors

View file

@ -7,7 +7,7 @@ fn main() {
// not applicable
vec![1, 2, 3, 4, 5].resize(2, 5);
// applicable here, but only implemented for integer litterals for now
// applicable here, but only implemented for integer literals for now
vec!["foo", "bar", "baz"].resize(0, "bar");
// not applicable

View file

@ -1,7 +0,0 @@
#!/bin/sh
CARGO_TARGET_DIR=$(pwd)/target/
export CARGO_TARGET_DIR
echo 'Deprecated! `util/dev` usage is deprecated, please use `cargo dev` instead.'
cd clippy_dev && cargo run -- "$@"