Skip to content

Commit 45ff5d1

Browse files
committed
fixed style issues and incorrect implementation
1 parent 67492b9 commit 45ff5d1

File tree

452 files changed

+1758
-1505
lines changed

Some content is hidden

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

452 files changed

+1758
-1505
lines changed

compiler/rustc_expand/src/mbe/macro_parser.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -678,13 +678,14 @@ impl TtParser {
678678
// edition-specific matching behavior for non-terminals.
679679
let nt = match parser.to_mut().parse_nonterminal(kind) {
680680
Err(err) => {
681-
let guarantee = err.with_span_label(
682-
span,
683-
format!(
681+
let guarantee = err
682+
.with_span_label(
683+
span,
684+
format!(
684685
"while parsing argument for this `{kind}` macro fragment"
685686
),
686-
)
687-
.emit();
687+
)
688+
.emit();
688689
return ErrorReported(guarantee);
689690
}
690691
Ok(nt) => nt,

compiler/rustc_index_macros/src/newtype.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl Parse for Newtype {
122122
#gate_rustc_only
123123
impl ::std::iter::Step for #name {
124124
#[inline]
125-
fn steps_between(start: &Self, end: &Self) -> (usize,Option<usize>) {
125+
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
126126
<usize as ::std::iter::Step>::steps_between(
127127
&Self::index(*start),
128128
&Self::index(*end),

compiler/rustc_middle/src/ty/normalize_erasing_regions.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,12 @@ impl<'tcx> NormalizeAfterErasingRegionsFolder<'tcx> {
166166
) -> ty::GenericArg<'tcx> {
167167
let arg = self.param_env.and(arg);
168168

169-
self.tcx.try_normalize_generic_arg_after_erasing_regions(arg).unwrap_or_else(|_| bug!(
169+
self.tcx.try_normalize_generic_arg_after_erasing_regions(arg).unwrap_or_else(|_| {
170+
bug!(
170171
"Failed to normalize {:?}, maybe try to call `try_normalize_erasing_regions` instead",
171172
arg.value
172-
))
173+
)
174+
})
173175
}
174176
}
175177

compiler/rustc_mir_build/src/check_unsafety.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
117117
let suggestion = suggestion
118118
.and_then(|suggestion| {
119119
sm.indentation_before(span).map(|indent| {
120-
format!("{}// TODO: Audit that {}.\n", indent, suggestion) // ignore-tidy-todo
120+
format!("{}// TODO: Audit that {}.\n", indent, suggestion)
121+
// ignore-tidy-todo
121122
})
122123
})
123124
.unwrap_or_default();

compiler/rustc_parse/src/lexer/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
519519
.with_code(E0766)
520520
.emit()
521521
}
522-
self.cook_unicode(token::ByteStr, Mode::ByteStr, start, end, 2, 1) // b" "
522+
self.cook_unicode(token::ByteStr, Mode::ByteStr, start, end, 2, 1)
523+
// b" "
523524
}
524525
rustc_lexer::LiteralKind::CStr { terminated } => {
525526
if !terminated {
@@ -537,7 +538,8 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
537538
if let Some(n_hashes) = n_hashes {
538539
let n = u32::from(n_hashes);
539540
let kind = token::StrRaw(n_hashes);
540-
self.cook_unicode(kind, Mode::RawStr, start, end, 2 + n, 1 + n) // r##" "##
541+
self.cook_unicode(kind, Mode::RawStr, start, end, 2 + n, 1 + n)
542+
// r##" "##
541543
} else {
542544
self.report_raw_str_error(start, 1);
543545
}
@@ -546,7 +548,8 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
546548
if let Some(n_hashes) = n_hashes {
547549
let n = u32::from(n_hashes);
548550
let kind = token::ByteStrRaw(n_hashes);
549-
self.cook_unicode(kind, Mode::RawByteStr, start, end, 3 + n, 1 + n) // br##" "##
551+
self.cook_unicode(kind, Mode::RawByteStr, start, end, 3 + n, 1 + n)
552+
// br##" "##
550553
} else {
551554
self.report_raw_str_error(start, 2);
552555
}
@@ -555,7 +558,8 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
555558
if let Some(n_hashes) = n_hashes {
556559
let n = u32::from(n_hashes);
557560
let kind = token::CStrRaw(n_hashes);
558-
self.cook_unicode(kind, Mode::RawCStr, start, end, 3 + n, 1 + n) // cr##" "##
561+
self.cook_unicode(kind, Mode::RawCStr, start, end, 3 + n, 1 + n)
562+
// cr##" "##
559563
} else {
560564
self.report_raw_str_error(start, 2);
561565
}

compiler/rustc_resolve/src/diagnostics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17421742
)) = binding.kind
17431743
{
17441744
let def_id = self.tcx.parent(ctor_def_id);
1745-
return self.field_idents(def_id)?.iter().map(|&f| f.span).reduce(Span::to); // None for `struct Foo()`
1745+
return self.field_idents(def_id)?.iter().map(|&f| f.span).reduce(Span::to);
1746+
// None for `struct Foo()`
17461747
}
17471748
None
17481749
}

library/core/src/iter/range.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,13 @@ macro_rules! step_integer_impls {
259259
step_unsigned_methods!();
260260

261261
#[inline]
262-
fn steps_between(start: &Self, end: &Self) -> (usize,Option<usize>) {
262+
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
263263
if *start <= *end {
264264
// This relies on $u_narrower <= usize
265-
((*end-*start) as usize, Some((*end - *start) as usize))
265+
let steps = (*end - *start) as usize
266+
(steps, Some(steps))
266267
} else {
267-
(0,None)
268+
(0, None)
268269
}
269270
}
270271

@@ -299,7 +300,8 @@ macro_rules! step_integer_impls {
299300
// Casting to isize extends the width but preserves the sign.
300301
// Use wrapping_sub in isize space and cast to usize to compute
301302
// the difference that might not fit inside the range of isize.
302-
((*end as isize).wrapping_sub(*start as isize) as usize,Some((*end as isize).wrapping_sub(*start as isize) as usize))
303+
let steps = (*end as isize).wrapping_sub(*start as isize) as usize;
304+
(steps, Some(steps))
303305
} else {
304306
(0,None)
305307
}
@@ -707,7 +709,7 @@ impl<A: Step> RangeIteratorImpl for ops::Range<A> {
707709
#[inline]
708710
default fn spec_advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
709711
let steps = Step::steps_between(&self.start, &self.end);
710-
let available = if let Some(steps) = steps.1 { steps } else { steps.0 };
712+
let available = steps.1.unwrap_or(steps.0);
711713

712714
let taken = available.min(n);
713715

@@ -745,7 +747,7 @@ impl<A: Step> RangeIteratorImpl for ops::Range<A> {
745747
#[inline]
746748
default fn spec_advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
747749
let steps = Step::steps_between(&self.start, &self.end);
748-
let available = if let Some(steps) = steps.1 { steps } else { steps.0 };
750+
let available = steps.1.unwrap_or(steps.0);
749751

750752
let taken = available.min(n);
751753

@@ -786,7 +788,7 @@ impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
786788
#[inline]
787789
fn spec_advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
788790
let steps = Step::steps_between(&self.start, &self.end);
789-
let available = if let Some(steps) = steps.1 { steps } else { steps.0 };
791+
let available = steps.1.unwrap_or(step.0);
790792

791793
let taken = available.min(n);
792794

@@ -827,7 +829,7 @@ impl<T: TrustedStep> RangeIteratorImpl for ops::Range<T> {
827829
#[inline]
828830
fn spec_advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
829831
let steps = Step::steps_between(&self.start, &self.end);
830-
let available = if let Some(steps) = steps.1 { steps } else { steps.0 };
832+
let available = steps.1.unwrap_or(steps.0);
831833

832834
let taken = available.min(n);
833835

@@ -849,11 +851,7 @@ impl<A: Step> Iterator for ops::Range<A> {
849851

850852
#[inline]
851853
fn size_hint(&self) -> (usize, Option<usize>) {
852-
if self.start < self.end {
853-
(0, Some(0))
854-
} else {
855-
Step::steps_between(&self.start, &self.end)
856-
}
854+
Step::steps_between(&self.start, &self.end)
857855
}
858856

859857
#[inline]

src/tools/clippy/clippy_config/src/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::ClippyConfiguration;
21
use crate::msrvs::Msrv;
32
use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename};
3+
use crate::ClippyConfiguration;
44
use rustc_errors::Applicability;
55
use rustc_session::Session;
66
use rustc_span::edit_distance::edit_distance;

src/tools/clippy/clippy_config/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ mod metadata;
2626
pub mod msrvs;
2727
pub mod types;
2828

29-
pub use conf::{Conf, get_configuration_metadata, lookup_conf_file, sanitize_explanation};
29+
pub use conf::{get_configuration_metadata, lookup_conf_file, sanitize_explanation, Conf};
3030
pub use metadata::ClippyConfiguration;

src/tools/clippy/clippy_config/src/msrvs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::Attribute;
22
use rustc_attr::parse_version;
33
use rustc_session::{RustcVersion, Session};
4-
use rustc_span::{Symbol, sym};
4+
use rustc_span::{sym, Symbol};
55
use serde::Deserialize;
66
use std::fmt;
77

src/tools/clippy/clippy_config/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use serde::de::{self, Deserializer, Visitor};
2-
use serde::{Deserialize, Serialize, ser};
2+
use serde::{ser, Deserialize, Serialize};
33
use std::fmt;
44

55
#[derive(Debug, Deserialize)]

src/tools/clippy/clippy_dev/src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::clippy_project_root;
22
use itertools::Itertools;
3-
use rustc_lexer::{TokenKind, tokenize};
3+
use rustc_lexer::{tokenize, TokenKind};
44
use shell_escape::escape;
55
use std::ffi::{OsStr, OsString};
66
use std::ops::ControlFlow;

src/tools/clippy/clippy_dev/src/new_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
441441

442442
#[allow(clippy::too_many_lines)]
443443
fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str> {
444-
use super::update_lints::{LintDeclSearchResult, match_tokens};
444+
use super::update_lints::{match_tokens, LintDeclSearchResult};
445445
use rustc_lexer::TokenKind;
446446

447447
let lint_name_upper = lint.name.to_uppercase();

src/tools/clippy/clippy_dev/src/update_lints.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::clippy_project_root;
22
use aho_corasick::AhoCorasickBuilder;
33
use itertools::Itertools;
4-
use rustc_lexer::{LiteralKind, TokenKind, tokenize, unescape};
4+
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
55
use std::collections::{HashMap, HashSet};
66
use std::ffi::OsStr;
77
use std::fmt::{self, Write};
@@ -1048,17 +1048,23 @@ mod tests {
10481048
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
10491049
];
10501050
let mut expected: HashMap<String, Vec<Lint>> = HashMap::new();
1051-
expected.insert("group1".to_string(), vec![
1052-
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
1053-
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
1054-
]);
1055-
expected.insert("group2".to_string(), vec![Lint::new(
1056-
"should_assert_eq2",
1057-
"group2",
1058-
"\"abc\"",
1059-
"module_name",
1060-
Range::default(),
1061-
)]);
1051+
expected.insert(
1052+
"group1".to_string(),
1053+
vec![
1054+
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
1055+
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
1056+
],
1057+
);
1058+
expected.insert(
1059+
"group2".to_string(),
1060+
vec![Lint::new(
1061+
"should_assert_eq2",
1062+
"group2",
1063+
"\"abc\"",
1064+
"module_name",
1065+
Range::default(),
1066+
)],
1067+
);
10621068
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
10631069
}
10641070
}

src/tools/clippy/clippy_lints/src/absolute_paths.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use clippy_utils::diagnostics::span_lint;
33
use clippy_utils::is_from_proc_macro;
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_hir::def::{DefKind, Res};
6-
use rustc_hir::def_id::{CRATE_DEF_INDEX, DefId};
6+
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
77
use rustc_hir::{HirId, ItemKind, Node, Path};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_session::impl_lint_pass;
10-
use rustc_span::Symbol;
1110
use rustc_span::symbol::kw;
11+
use rustc_span::Symbol;
1212

1313
declare_clippy_lint! {
1414
/// ### What it does

src/tools/clippy/clippy_lints/src/almost_complete_range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use clippy_config::Conf;
21
use clippy_config::msrvs::{self, Msrv};
2+
use clippy_config::Conf;
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::source::{trim_span, walk_span_to_context};
55
use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits};

src/tools/clippy/clippy_lints/src/approx_const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use clippy_config::Conf;
21
use clippy_config::msrvs::{self, Msrv};
2+
use clippy_config::Conf;
33
use clippy_utils::diagnostics::span_lint_and_help;
44
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_session::{RustcVersion, impl_lint_pass};
7+
use rustc_session::{impl_lint_pass, RustcVersion};
88
use rustc_span::symbol;
99
use std::f64::consts as f64;
1010

src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
44
use rustc_hir::{Expr, ExprKind, QPath};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::ty;
7-
use rustc_middle::ty::GenericArgKind;
87
use rustc_middle::ty::print::with_forced_trimmed_paths;
8+
use rustc_middle::ty::GenericArgKind;
99
use rustc_session::declare_lint_pass;
1010
use rustc_span::symbol::sym;
1111

src/tools/clippy/clippy_lints/src/assertions_on_constants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::consts::{ConstEvalCtxt, Constant};
22
use clippy_utils::diagnostics::span_lint_and_help;
33
use clippy_utils::is_inside_always_const_context;
4-
use clippy_utils::macros::{PanicExpn, find_assert_args, root_macro_call_first_node};
4+
use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn};
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::declare_lint_pass;

src/tools/clippy/clippy_lints/src/assertions_on_result_states.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::macros::{PanicExpn, find_assert_args, root_macro_call_first_node};
2+
use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn};
33
use clippy_utils::source::snippet_with_context;
44
use clippy_utils::ty::{has_debug_impl, is_copy, is_type_diagnostic_item};
55
use clippy_utils::usage::local_used_after_expr;

src/tools/clippy/clippy_lints/src/assigning_clones.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use clippy_config::Conf;
21
use clippy_config::msrvs::{self, Msrv};
2+
use clippy_config::Conf;
33
use clippy_utils::diagnostics::span_lint_and_then;
4-
use clippy_utils::mir::{PossibleBorrowerMap, enclosing_mir};
4+
use clippy_utils::mir::{enclosing_mir, PossibleBorrowerMap};
55
use clippy_utils::sugg::Sugg;
66
use clippy_utils::{is_diag_trait_item, is_in_test, last_path_segment, local_is_initialized, path_to_local};
77
use rustc_errors::Applicability;

src/tools/clippy/clippy_lints/src/attrs/allow_attributes_without_reason.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{ALLOW_ATTRIBUTES_WITHOUT_REASON, Attribute};
1+
use super::{Attribute, ALLOW_ATTRIBUTES_WITHOUT_REASON};
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::is_from_proc_macro;
44
use rustc_ast::{MetaItemInner, MetaItemKind};

src/tools/clippy/clippy_lints/src/attrs/blanket_clippy_restriction_lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
21
use super::utils::extract_clippy_lint;
2+
use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
33
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
44
use rustc_ast::MetaItemInner;
55
use rustc_lint::{EarlyContext, Level, LintContext};
66
use rustc_span::symbol::Symbol;
7-
use rustc_span::{DUMMY_SP, sym};
7+
use rustc_span::{sym, DUMMY_SP};
88

99
pub(super) fn check(cx: &EarlyContext<'_>, name: Symbol, items: &[MetaItemInner]) {
1010
for lint in items {

src/tools/clippy/clippy_lints/src/attrs/deprecated_cfg_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR, unnecessary_clippy_cfg};
1+
use super::{unnecessary_clippy_cfg, Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR};
22
use clippy_config::msrvs::{self, Msrv};
33
use clippy_utils::diagnostics::span_lint_and_sugg;
44
use rustc_ast::AttrStyle;

src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
33
use rustc_ast::{Attribute, MetaItem};
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_lint::EarlyContext;
6-
use rustc_span::{Span, sym};
6+
use rustc_span::{sym, Span};
77
use std::collections::hash_map::Entry;
88

99
fn emit_if_duplicated(

src/tools/clippy/clippy_lints/src/attrs/inline_always.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use super::INLINE_ALWAYS;
21
use super::utils::is_word;
2+
use super::INLINE_ALWAYS;
33
use clippy_utils::diagnostics::span_lint;
44
use rustc_ast::Attribute;
55
use rustc_lint::LateContext;
66
use rustc_span::symbol::Symbol;
7-
use rustc_span::{Span, sym};
7+
use rustc_span::{sym, Span};
88

99
pub(super) fn check(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribute]) {
1010
if span.from_expansion() {

0 commit comments

Comments
 (0)