Auto merge of #9323 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none
This commit is contained in:
bors 2022-08-11 17:28:47 +00:00
commit 2b2190cb56
36 changed files with 108 additions and 95 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.64"
version = "0.1.65"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"

View file

@ -438,7 +438,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
let mut lint_context = None;
let mut iter = rustc_lexer::tokenize(&file_contents).map(|t| {
let range = offset..offset + t.len;
let range = offset..offset + t.len as usize;
offset = range.end;
LintDeclSearchResult {

View file

@ -836,7 +836,7 @@ pub(crate) struct LintDeclSearchResult<'a> {
fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
let mut offset = 0usize;
let mut iter = tokenize(contents).map(|t| {
let range = offset..offset + t.len;
let range = offset..offset + t.len as usize;
offset = range.end;
LintDeclSearchResult {
@ -899,7 +899,7 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
fn parse_deprecated_contents(contents: &str, lints: &mut Vec<DeprecatedLint>) {
let mut offset = 0usize;
let mut iter = tokenize(contents).map(|t| {
let range = offset..offset + t.len;
let range = offset..offset + t.len as usize;
offset = range.end;
LintDeclSearchResult {
@ -946,7 +946,7 @@ fn parse_renamed_contents(contents: &str, lints: &mut Vec<RenamedLint>) {
for line in contents.lines() {
let mut offset = 0usize;
let mut iter = tokenize(line).map(|t| {
let range = offset..offset + t.len;
let range = offset..offset + t.len as usize;
offset = range.end;
LintDeclSearchResult {

View file

@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
version = "0.1.64"
version = "0.1.65"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"

View file

@ -110,14 +110,14 @@ fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option<Span> {
fn is_crate_keyword(tt: &TokenTree) -> Option<Span> {
if_chain! {
if let TokenTree::Token(Token { kind: TokenKind::Ident(symbol, _), span }) = tt;
if let TokenTree::Token(Token { kind: TokenKind::Ident(symbol, _), span }, _) = tt;
if symbol.as_str() == "crate";
then { Some(*span) } else { None }
}
}
fn is_token(tt: &TokenTree, kind: &TokenKind) -> bool {
if let TokenTree::Token(Token { kind: other, .. }) = tt {
if let TokenTree::Token(Token { kind: other, .. }, _) = tt {
kind == other
} else {
false

View file

@ -220,9 +220,11 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tc
}
fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: DefId) -> String {
match cx.tcx.associated_item(method_def_id).container {
ty::TraitContainer(def_id) => cx.tcx.def_path_str(def_id),
ty::ImplContainer(def_id) => {
let assoc_item = cx.tcx.associated_item(method_def_id);
let def_id = assoc_item.container_id(cx.tcx);
match assoc_item.container {
ty::TraitContainer => cx.tcx.def_path_str(def_id),
ty::ImplContainer => {
let ty = cx.tcx.type_of(def_id);
match ty.kind() {
ty::Adt(adt, _) => cx.tcx.def_path_str(adt.did()),

View file

@ -9,7 +9,7 @@ use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{sym, Span};
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
use rustc_trait_selection::traits::{self, FulfillmentError, TraitEngine};
use rustc_trait_selection::traits::{self, FulfillmentError};
declare_clippy_lint! {
/// ### What it does
@ -80,9 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
let span = decl.output.span();
let send_errors = cx.tcx.infer_ctxt().enter(|infcx| {
let cause = traits::ObligationCause::misc(span, hir_id);
let mut fulfillment_cx = traits::FulfillmentContext::new();
fulfillment_cx.register_bound(&infcx, cx.param_env, ret_ty, send_trait, cause);
fulfillment_cx.select_all_or_error(&infcx)
traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait)
});
if !send_errors.is_empty() {
span_lint_and_then(

View file

@ -1112,7 +1112,7 @@ fn span_contains_cfg(cx: &LateContext<'_>, s: Span) -> bool {
let mut pos = 0usize;
let mut iter = tokenize(&snip).map(|t| {
let start = pos;
pos += t.len;
pos += t.len as usize;
(t.kind, start..pos)
});

View file

@ -12,7 +12,8 @@ pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, count_recv: &hi
if_chain! {
if is_trait_method(cx, count_recv, sym::Iterator);
let closure = expr_or_init(cx, map_arg);
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(closure.hir_id);
if let Some(def_id) = cx.tcx.hir().opt_local_def_id(closure.hir_id);
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(def_id);
let closure_body = cx.tcx.hir().body(body_id);
if !cx.typeck_results().expr_ty(&closure_body.value).is_unit();
then {

View file

@ -12,7 +12,7 @@ use if_chain::if_chain;
use rustc_ast::ast::{self, MetaItem, MetaItemKind};
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::{self, DefIdTree};
use rustc_middle::ty::DefIdTree;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::source_map::Span;
@ -175,13 +175,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::ImplItem<'_>) {
// If the method is an impl for a trait, don't doc.
match cx.tcx.associated_item(impl_item.def_id).container {
ty::TraitContainer(_) => return,
ty::ImplContainer(cid) => {
if cx.tcx.impl_trait_ref(cid).is_some() {
return;
}
},
if let Some(cid) = cx.tcx.associated_item(impl_item.def_id).impl_container(cx.tcx) {
if cx.tcx.impl_trait_ref(cid).is_some() {
return;
}
} else {
return;
}
let (article, desc) = cx.tcx.article_and_description(impl_item.def_id.to_def_id());

View file

@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
match tit_.kind {
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
hir::TraitItemKind::Fn(..) => {
if tit.defaultness.has_value() {
if cx.tcx.impl_defaultness(tit.id.def_id).has_value() {
// trait method with default body needs inline in case
// an impl is not provided
let desc = "a default trait method";
@ -151,9 +151,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::TyAlias(_) => return,
};
let trait_def_id = match cx.tcx.associated_item(impl_item.def_id).container {
TraitContainer(cid) => Some(cid),
ImplContainer(cid) => cx.tcx.impl_trait_ref(cid).map(|t| t.def_id),
let assoc_item = cx.tcx.associated_item(impl_item.def_id);
let container_id = assoc_item.container_id(cx.tcx);
let trait_def_id = match assoc_item.container {
TraitContainer => Some(container_id),
ImplContainer => cx.tcx.impl_trait_ref(container_id).map(|t| t.def_id),
};
if let Some(trait_def_id) = trait_def_id {

View file

@ -345,7 +345,7 @@ fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) ->
if line.starts_with("/*") {
let src = src[line_start..line_starts.last().unwrap().to_usize() - offset].trim_start();
let mut tokens = tokenize(src);
return src[..tokens.next().unwrap().len]
return src[..tokens.next().unwrap().len as usize]
.to_ascii_uppercase()
.contains("SAFETY:")
&& tokens.all(|t| t.kind == TokenKind::Whitespace);

View file

@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
fn check_item(cx: &LateContext<'_>, hir_id: HirId) {
let hir = cx.tcx.hir();
if let Some(body_id) = hir.maybe_body_owned_by(hir_id) {
if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner()) {
check_node(cx, hir_id, |v| {
v.expr(&v.bind("expr", &hir.body(body_id).value));
});

View file

@ -496,12 +496,14 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
cx,
};
let body_id = cx.tcx.hir().body_owned_by(
impl_item_refs
.iter()
.find(|iiref| iiref.ident.as_str() == "get_lints")
.expect("LintPass needs to implement get_lints")
.id
.hir_id(),
cx.tcx.hir().local_def_id(
impl_item_refs
.iter()
.find(|iiref| iiref.ident.as_str() == "get_lints")
.expect("LintPass needs to implement get_lints")
.id
.hir_id(),
),
);
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
}

View file

@ -462,7 +462,7 @@ impl SimpleFormatArgs {
}
}
},
ArgumentNamed(n, _) => {
ArgumentNamed(n) => {
let n = Symbol::intern(n);
if let Some(x) = self.named.iter_mut().find(|x| x.0 == n) {
match x.1.as_slice() {

View file

@ -1,6 +1,6 @@
[package]
name = "clippy_utils"
version = "0.1.64"
version = "0.1.65"
edition = "2021"
publish = false

View file

@ -141,7 +141,7 @@ impl HirEqInterExpr<'_, '_, '_> {
let mut left_pos = 0;
let left = tokenize(&left)
.map(|t| {
let end = left_pos + t.len;
let end = left_pos + t.len as usize;
let s = &left[left_pos..end];
left_pos = end;
(t, s)
@ -156,7 +156,7 @@ impl HirEqInterExpr<'_, '_, '_> {
let mut right_pos = 0;
let right = tokenize(&right)
.map(|t| {
let end = right_pos + t.len;
let end = right_pos + t.len as usize;
let s = &right[right_pos..end];
right_pos = end;
(t, s)

View file

@ -969,7 +969,7 @@ pub fn can_move_expr_to_closure<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'
}
},
ExprKind::Closure { .. } => {
let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id).to_def_id();
let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id);
for capture in self.cx.typeck_results().closure_min_captures_flattened(closure_id) {
let local_id = match capture.place.base {
PlaceBase::Local(id) => id,
@ -1354,7 +1354,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
if is_integer_literal(e, value) {
return true;
}
let enclosing_body = cx.tcx.hir().local_def_id(cx.tcx.hir().enclosing_body_owner(e.hir_id));
let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id);
if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) {
return value == v;
}

View file

@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2022-07-28"
channel = "nightly-2022-08-11"
components = ["cargo", "llvm-tools-preview", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]

View file

@ -2,6 +2,7 @@
// As the most common case is the `http` crate, it replicates `http::HeadewrName`'s structure.
#![allow(clippy::declare_interior_mutable_const)]
#![allow(unused_tuple_struct_fields)]
use std::sync::atomic::AtomicUsize;

View file

@ -1,6 +1,7 @@
// run-rustfix
#![allow(
unused_tuple_struct_fields,
clippy::print_literal,
clippy::redundant_clone,
clippy::to_string_in_format_args,

View file

@ -1,6 +1,7 @@
// run-rustfix
#![allow(
unused_tuple_struct_fields,
clippy::print_literal,
clippy::redundant_clone,
clippy::to_string_in_format_args,

View file

@ -1,5 +1,5 @@
error: useless use of `format!`
--> $DIR/format.rs:18:5
--> $DIR/format.rs:19:5
|
LL | format!("foo");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
@ -7,19 +7,19 @@ LL | format!("foo");
= note: `-D clippy::useless-format` implied by `-D warnings`
error: useless use of `format!`
--> $DIR/format.rs:19:5
--> $DIR/format.rs:20:5
|
LL | format!("{{}}");
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{}".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:20:5
--> $DIR/format.rs:21:5
|
LL | format!("{{}} abc {{}}");
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"{} abc {}".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:21:5
--> $DIR/format.rs:22:5
|
LL | / format!(
LL | | r##"foo {{}}
@ -34,91 +34,91 @@ LL ~ " bar"##.to_string();
|
error: useless use of `format!`
--> $DIR/format.rs:26:13
--> $DIR/format.rs:27:13
|
LL | let _ = format!("");
| ^^^^^^^^^^^ help: consider using `String::new()`: `String::new()`
error: useless use of `format!`
--> $DIR/format.rs:28:5
--> $DIR/format.rs:29:5
|
LL | format!("{}", "foo");
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:32:5
--> $DIR/format.rs:33:5
|
LL | format!("{:+}", "foo"); // Warn when the format makes no difference.
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:33:5
--> $DIR/format.rs:34:5
|
LL | format!("{:<}", "foo"); // Warn when the format makes no difference.
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"foo".to_string()`
error: useless use of `format!`
--> $DIR/format.rs:38:5
--> $DIR/format.rs:39:5
|
LL | format!("{}", arg);
| ^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:42:5
--> $DIR/format.rs:43:5
|
LL | format!("{:+}", arg); // Warn when the format makes no difference.
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:43:5
--> $DIR/format.rs:44:5
|
LL | format!("{:<}", arg); // Warn when the format makes no difference.
| ^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `arg.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:70:5
--> $DIR/format.rs:71:5
|
LL | format!("{}", 42.to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `42.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:72:5
--> $DIR/format.rs:73:5
|
LL | format!("{}", x.display().to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.display().to_string()`
error: useless use of `format!`
--> $DIR/format.rs:76:18
--> $DIR/format.rs:77:18
|
LL | let _ = Some(format!("{}", a + "bar"));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `a + "bar"`
error: useless use of `format!`
--> $DIR/format.rs:80:22
--> $DIR/format.rs:81:22
|
LL | let _s: String = format!("{}", &*v.join("/n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()`
error: useless use of `format!`
--> $DIR/format.rs:86:13
--> $DIR/format.rs:87:13
|
LL | let _ = format!("{x}");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:88:13
--> $DIR/format.rs:89:13
|
LL | let _ = format!("{y}", y = x);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:92:13
--> $DIR/format.rs:93:13
|
LL | let _ = format!("{abc}");
| ^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `abc.to_string()`
error: useless use of `format!`
--> $DIR/format.rs:94:13
--> $DIR/format.rs:95:13
|
LL | let _ = format!("{xx}");
| ^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `xx.to_string()`

View file

@ -1,7 +1,7 @@
// run-rustfix
#![warn(clippy::from_iter_instead_of_collect)]
#![allow(unused_imports)]
#![allow(unused_imports, unused_tuple_struct_fields)]
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};

View file

@ -1,7 +1,7 @@
// run-rustfix
#![warn(clippy::from_iter_instead_of_collect)]
#![allow(unused_imports)]
#![allow(unused_imports, unused_tuple_struct_fields)]
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};

View file

@ -1,6 +1,6 @@
// run-rustfix
#![feature(never_type)]
#![allow(unused_mut, clippy::redundant_allocation)]
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};

View file

@ -1,6 +1,6 @@
// run-rustfix
#![feature(never_type)]
#![allow(unused_mut, clippy::redundant_allocation)]
#![allow(unused_mut, unused_tuple_struct_fields, clippy::redundant_allocation)]
#![warn(clippy::must_use_candidate)]
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};

View file

@ -1,5 +1,6 @@
//run-rustfix
#![warn(clippy::init_numbered_fields)]
#![allow(unused_tuple_struct_fields)]
#[derive(Default)]
struct TupleStruct(u32, u32, u8);

View file

@ -1,5 +1,6 @@
//run-rustfix
#![warn(clippy::init_numbered_fields)]
#![allow(unused_tuple_struct_fields)]
#[derive(Default)]
struct TupleStruct(u32, u32, u8);

View file

@ -1,5 +1,5 @@
error: used a field initializer for a tuple struct
--> $DIR/numbered_fields.rs:18:13
--> $DIR/numbered_fields.rs:19:13
|
LL | let _ = TupleStruct {
| _____________^
@ -12,7 +12,7 @@ LL | | };
= note: `-D clippy::init-numbered-fields` implied by `-D warnings`
error: used a field initializer for a tuple struct
--> $DIR/numbered_fields.rs:25:13
--> $DIR/numbered_fields.rs:26:13
|
LL | let _ = TupleStruct {
| _____________^

View file

@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::option_if_let_else)]
#![allow(
unused_tuple_struct_fields,
clippy::redundant_closure,
clippy::ref_option_ref,
clippy::equatable_if_let,

View file

@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::option_if_let_else)]
#![allow(
unused_tuple_struct_fields,
clippy::redundant_closure,
clippy::ref_option_ref,
clippy::equatable_if_let,

View file

@ -1,5 +1,5 @@
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:11:5
--> $DIR/option_if_let_else.rs:12:5
|
LL | / if let Some(x) = string {
LL | | (true, x)
@ -11,19 +11,19 @@ LL | | }
= note: `-D clippy::option-if-let-else` implied by `-D warnings`
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:29:13
--> $DIR/option_if_let_else.rs:30:13
|
LL | let _ = if let Some(s) = *string { s.len() } else { 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.map_or(0, |s| s.len())`
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:30:13
--> $DIR/option_if_let_else.rs:31:13
|
LL | let _ = if let Some(s) = &num { s } else { &0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:31:13
--> $DIR/option_if_let_else.rs:32:13
|
LL | let _ = if let Some(s) = &mut num {
| _____________^
@ -43,13 +43,13 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:37:13
--> $DIR/option_if_let_else.rs:38:13
|
LL | let _ = if let Some(ref s) = num { s } else { &0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `num.as_ref().map_or(&0, |s| s)`
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:38:13
--> $DIR/option_if_let_else.rs:39:13
|
LL | let _ = if let Some(mut s) = num {
| _____________^
@ -69,7 +69,7 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:44:13
--> $DIR/option_if_let_else.rs:45:13
|
LL | let _ = if let Some(ref mut s) = num {
| _____________^
@ -89,7 +89,7 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:53:5
--> $DIR/option_if_let_else.rs:54:5
|
LL | / if let Some(x) = arg {
LL | | let y = x * x;
@ -108,7 +108,7 @@ LL + })
|
error: use Option::map_or_else instead of an if let/else
--> $DIR/option_if_let_else.rs:66:13
--> $DIR/option_if_let_else.rs:67:13
|
LL | let _ = if let Some(x) = arg {
| _____________^
@ -120,7 +120,7 @@ LL | | };
| |_____^ help: try: `arg.map_or_else(|| side_effect(), |x| x)`
error: use Option::map_or_else instead of an if let/else
--> $DIR/option_if_let_else.rs:75:13
--> $DIR/option_if_let_else.rs:76:13
|
LL | let _ = if let Some(x) = arg {
| _____________^
@ -143,7 +143,7 @@ LL ~ }, |x| x * x * x * x);
|
error: use Option::map_or_else instead of an if let/else
--> $DIR/option_if_let_else.rs:108:13
--> $DIR/option_if_let_else.rs:109:13
|
LL | / if let Some(idx) = s.find('.') {
LL | | vec![s[..idx].to_string(), s[idx..].to_string()]
@ -153,13 +153,13 @@ LL | | }
| |_____________^ help: try: `s.find('.').map_or_else(|| vec![s.to_string()], |idx| vec![s[..idx].to_string(), s[idx..].to_string()])`
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:132:13
--> $DIR/option_if_let_else.rs:133:13
|
LL | let _ = if let Some(x) = optional { x + 2 } else { 5 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `optional.map_or(5, |x| x + 2)`
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:141:13
--> $DIR/option_if_let_else.rs:142:13
|
LL | let _ = if let Some(x) = Some(0) {
| _____________^
@ -181,13 +181,13 @@ LL ~ });
|
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:169:13
--> $DIR/option_if_let_else.rs:170:13
|
LL | let _ = if let Some(x) = Some(0) { s.len() + x } else { s.len() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Some(0).map_or(s.len(), |x| s.len() + x)`
error: use Option::map_or instead of an if let/else
--> $DIR/option_if_let_else.rs:173:13
--> $DIR/option_if_let_else.rs:174:13
|
LL | let _ = if let Some(x) = Some(0) {
| _____________^

View file

@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::unreadable_literal)]
#![allow(unused_tuple_struct_fields)]
struct Foo(u64);

View file

@ -1,6 +1,7 @@
// run-rustfix
#![warn(clippy::unreadable_literal)]
#![allow(unused_tuple_struct_fields)]
struct Foo(u64);

View file

@ -1,5 +1,5 @@
error: digits of hex or binary literal not grouped by four
--> $DIR/unreadable_literal.rs:25:9
--> $DIR/unreadable_literal.rs:26:9
|
LL | 0x1_234_567,
| ^^^^^^^^^^^ help: consider: `0x0123_4567`
@ -7,7 +7,7 @@ LL | 0x1_234_567,
= note: `-D clippy::unusual-byte-groupings` implied by `-D warnings`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:33:17
--> $DIR/unreadable_literal.rs:34:17
|
LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
| ^^^^^^^^^^^^ help: consider: `0b11_0110_i64`
@ -15,55 +15,55 @@ LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:33:31
--> $DIR/unreadable_literal.rs:34:31
|
LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
| ^^^^^^^^^^^^^^^^ help: consider: `0x1234_5678_usize`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:33:49
--> $DIR/unreadable_literal.rs:34:49
|
LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
| ^^^^^^^^^^ help: consider: `123_456_f32`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:33:61
--> $DIR/unreadable_literal.rs:34:61
|
LL | let _bad = (0b110110_i64, 0x12345678_usize, 123456_f32, 1.234567_f32);
| ^^^^^^^^^^^^ help: consider: `1.234_567_f32`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:35:20
--> $DIR/unreadable_literal.rs:36:20
|
LL | let _bad_sci = 1.123456e1;
| ^^^^^^^^^^ help: consider: `1.123_456e1`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:37:18
--> $DIR/unreadable_literal.rs:38:18
|
LL | let _fail1 = 0xabcdef;
| ^^^^^^^^ help: consider: `0x00ab_cdef`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:38:23
--> $DIR/unreadable_literal.rs:39:23
|
LL | let _fail2: u32 = 0xBAFEBAFE;
| ^^^^^^^^^^ help: consider: `0xBAFE_BAFE`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:39:18
--> $DIR/unreadable_literal.rs:40:18
|
LL | let _fail3 = 0xabcdeff;
| ^^^^^^^^^ help: consider: `0x0abc_deff`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:40:24
--> $DIR/unreadable_literal.rs:41:24
|
LL | let _fail4: i128 = 0xabcabcabcabcabcabc;
| ^^^^^^^^^^^^^^^^^^^^ help: consider: `0x00ab_cabc_abca_bcab_cabc`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:41:18
--> $DIR/unreadable_literal.rs:42:18
|
LL | let _fail5 = 1.100300400;
| ^^^^^^^^^^^ help: consider: `1.100_300_400`