mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
and a few more from other dirs
This commit is contained in:
parent
cb6d1267c4
commit
59d0e8caba
10 changed files with 46 additions and 50 deletions
|
@ -41,7 +41,7 @@ fn main() {
|
|||
matches.contains_id("msrv"),
|
||||
) {
|
||||
Ok(_) => update_lints::update(update_lints::UpdateMode::Change),
|
||||
Err(e) => eprintln!("Unable to create lint: {}", e),
|
||||
Err(e) => eprintln!("Unable to create lint: {e}"),
|
||||
}
|
||||
},
|
||||
Some(("setup", sub_command)) => match sub_command.subcommand() {
|
||||
|
|
|
@ -131,12 +131,12 @@ pub fn get_unique_inner_attr(sess: &Session, attrs: &[ast::Attribute], name: &'s
|
|||
match attr.style {
|
||||
ast::AttrStyle::Inner if unique_attr.is_none() => unique_attr = Some(attr.clone()),
|
||||
ast::AttrStyle::Inner => {
|
||||
sess.struct_span_err(attr.span, &format!("`{}` is defined multiple times", name))
|
||||
sess.struct_span_err(attr.span, &format!("`{name}` is defined multiple times"))
|
||||
.span_note(unique_attr.as_ref().unwrap().span, "first definition found here")
|
||||
.emit();
|
||||
},
|
||||
ast::AttrStyle::Outer => {
|
||||
sess.span_err(attr.span, &format!("`{}` cannot be an outer attribute", name));
|
||||
sess.span_err(attr.span, &format!("`{name}` cannot be an outer attribute"));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,11 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
|
|||
if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() {
|
||||
if let Some(lint) = lint.name_lower().strip_prefix("clippy::") {
|
||||
diag.help(&format!(
|
||||
"for further information visit https://rust-lang.github.io/rust-clippy/{}/index.html#{}",
|
||||
"for further information visit https://rust-lang.github.io/rust-clippy/{}/index.html#{lint}",
|
||||
&option_env!("RUST_RELEASE_NUM").map_or("master".to_string(), |n| {
|
||||
// extract just major + minor version and ignore patch versions
|
||||
format!("rust-{}", n.rsplit_once('.').unwrap().1)
|
||||
}),
|
||||
lint
|
||||
})
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ pub fn parse_msrv(msrv: &str, sess: Option<&Session>, span: Option<Span>) -> Opt
|
|||
return Some(version);
|
||||
} else if let Some(sess) = sess {
|
||||
if let Some(span) = span {
|
||||
sess.span_err(span, &format!("`{}` is not a valid Rust version", msrv));
|
||||
sess.span_err(span, &format!("`{msrv}` is not a valid Rust version"));
|
||||
}
|
||||
}
|
||||
None
|
||||
|
|
|
@ -392,7 +392,7 @@ impl FormatString {
|
|||
unescape_literal(inner, mode, &mut |_, ch| match ch {
|
||||
Ok(ch) => unescaped.push(ch),
|
||||
Err(e) if !e.is_fatal() => (),
|
||||
Err(e) => panic!("{:?}", e),
|
||||
Err(e) => panic!("{e:?}"),
|
||||
});
|
||||
|
||||
let mut parts = Vec::new();
|
||||
|
|
|
@ -33,10 +33,10 @@ pub fn is_min_const_fn<'a, 'tcx>(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, msrv:
|
|||
| ty::PredicateKind::ConstEquate(..)
|
||||
| ty::PredicateKind::Trait(..)
|
||||
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
|
||||
ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {:#?}", predicate),
|
||||
ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {:#?}", predicate),
|
||||
ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {:#?}", predicate),
|
||||
ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {:#?}", predicate),
|
||||
ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"),
|
||||
ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"),
|
||||
ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {predicate:#?}"),
|
||||
ty::PredicateKind::Coerce(_) => panic!("coerce predicate on function: {predicate:#?}"),
|
||||
}
|
||||
}
|
||||
match predicates.parent {
|
||||
|
@ -315,8 +315,7 @@ fn check_terminator<'a, 'tcx>(
|
|||
span,
|
||||
format!(
|
||||
"can only call other `const fn` within a `const fn`, \
|
||||
but `{:?}` is not stable as `const fn`",
|
||||
func,
|
||||
but `{func:?}` is not stable as `const fn`",
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
|
|
|
@ -25,11 +25,11 @@ pub fn expr_block<'a, T: LintContext>(
|
|||
if expr.span.from_expansion() {
|
||||
Cow::Owned(format!("{{ {} }}", snippet_with_macro_callsite(cx, expr.span, default)))
|
||||
} else if let ExprKind::Block(_, _) = expr.kind {
|
||||
Cow::Owned(format!("{}{}", code, string))
|
||||
Cow::Owned(format!("{code}{string}"))
|
||||
} else if string.is_empty() {
|
||||
Cow::Owned(format!("{{ {} }}", code))
|
||||
Cow::Owned(format!("{{ {code} }}"))
|
||||
} else {
|
||||
Cow::Owned(format!("{{\n{};\n{}\n}}", code, string))
|
||||
Cow::Owned(format!("{{\n{code};\n{string}\n}}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -466,7 +466,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_without_block_comments_lines_without_block_comments() {
|
||||
let result = without_block_comments(vec!["/*", "", "*/"]);
|
||||
println!("result: {:?}", result);
|
||||
println!("result: {result:?}");
|
||||
assert!(result.is_empty());
|
||||
|
||||
let result = without_block_comments(vec!["", "/*", "", "*/", "#[crate_type = \"lib\"]", "/*", "", "*/", ""]);
|
||||
|
|
|
@ -310,19 +310,19 @@ impl<'a> Sugg<'a> {
|
|||
|
||||
/// Convenience method to transform suggestion into a return call
|
||||
pub fn make_return(self) -> Sugg<'static> {
|
||||
Sugg::NonParen(Cow::Owned(format!("return {}", self)))
|
||||
Sugg::NonParen(Cow::Owned(format!("return {self}")))
|
||||
}
|
||||
|
||||
/// Convenience method to transform suggestion into a block
|
||||
/// where the suggestion is a trailing expression
|
||||
pub fn blockify(self) -> Sugg<'static> {
|
||||
Sugg::NonParen(Cow::Owned(format!("{{ {} }}", self)))
|
||||
Sugg::NonParen(Cow::Owned(format!("{{ {self} }}")))
|
||||
}
|
||||
|
||||
/// Convenience method to prefix the expression with the `async` keyword.
|
||||
/// Can be used after `blockify` to create an async block.
|
||||
pub fn asyncify(self) -> Sugg<'static> {
|
||||
Sugg::NonParen(Cow::Owned(format!("async {}", self)))
|
||||
Sugg::NonParen(Cow::Owned(format!("async {self}")))
|
||||
}
|
||||
|
||||
/// Convenience method to create the `<lhs>..<rhs>` or `<lhs>...<rhs>`
|
||||
|
@ -346,12 +346,12 @@ impl<'a> Sugg<'a> {
|
|||
if has_enclosing_paren(&sugg) {
|
||||
Sugg::MaybeParen(sugg)
|
||||
} else {
|
||||
Sugg::NonParen(format!("({})", sugg).into())
|
||||
Sugg::NonParen(format!("({sugg})").into())
|
||||
}
|
||||
},
|
||||
Sugg::BinOp(op, lhs, rhs) => {
|
||||
let sugg = binop_to_string(op, &lhs, &rhs);
|
||||
Sugg::NonParen(format!("({})", sugg).into())
|
||||
Sugg::NonParen(format!("({sugg})").into())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -379,20 +379,18 @@ fn binop_to_string(op: AssocOp, lhs: &str, rhs: &str) -> String {
|
|||
| AssocOp::Greater
|
||||
| AssocOp::GreaterEqual => {
|
||||
format!(
|
||||
"{} {} {}",
|
||||
lhs,
|
||||
op.to_ast_binop().expect("Those are AST ops").to_string(),
|
||||
rhs
|
||||
"{lhs} {} {rhs}",
|
||||
op.to_ast_binop().expect("Those are AST ops").to_string()
|
||||
)
|
||||
},
|
||||
AssocOp::Assign => format!("{} = {}", lhs, rhs),
|
||||
AssocOp::Assign => format!("{lhs} = {rhs}"),
|
||||
AssocOp::AssignOp(op) => {
|
||||
format!("{} {}= {}", lhs, token_kind_to_string(&token::BinOp(op)), rhs)
|
||||
format!("{lhs} {}= {rhs}", token_kind_to_string(&token::BinOp(op)))
|
||||
},
|
||||
AssocOp::As => format!("{} as {}", lhs, rhs),
|
||||
AssocOp::DotDot => format!("{}..{}", lhs, rhs),
|
||||
AssocOp::DotDotEq => format!("{}..={}", lhs, rhs),
|
||||
AssocOp::Colon => format!("{}: {}", lhs, rhs),
|
||||
AssocOp::As => format!("{lhs} as {rhs}"),
|
||||
AssocOp::DotDot => format!("{lhs}..{rhs}"),
|
||||
AssocOp::DotDotEq => format!("{lhs}..={rhs}"),
|
||||
AssocOp::Colon => format!("{lhs}: {rhs}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -523,7 +521,7 @@ impl<T: Display> Display for ParenHelper<T> {
|
|||
/// operators have the same
|
||||
/// precedence.
|
||||
pub fn make_unop(op: &str, expr: Sugg<'_>) -> Sugg<'static> {
|
||||
Sugg::MaybeParen(format!("{}{}", op, expr.maybe_par()).into())
|
||||
Sugg::MaybeParen(format!("{op}{}", expr.maybe_par()).into())
|
||||
}
|
||||
|
||||
/// Builds the string for `<lhs> <op> <rhs>` adding parenthesis when necessary.
|
||||
|
@ -744,7 +742,7 @@ impl<T: LintContext> DiagnosticExt<T> for rustc_errors::Diagnostic {
|
|||
if let Some(indent) = indentation(cx, item) {
|
||||
let span = item.with_hi(item.lo());
|
||||
|
||||
self.span_suggestion(span, msg, format!("{}\n{}", attr, indent), applicability);
|
||||
self.span_suggestion(span, msg, format!("{attr}\n{indent}"), applicability);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -758,14 +756,14 @@ impl<T: LintContext> DiagnosticExt<T> for rustc_errors::Diagnostic {
|
|||
.map(|l| {
|
||||
if first {
|
||||
first = false;
|
||||
format!("{}\n", l)
|
||||
format!("{l}\n")
|
||||
} else {
|
||||
format!("{}{}\n", indent, l)
|
||||
format!("{indent}{l}\n")
|
||||
}
|
||||
})
|
||||
.collect::<String>();
|
||||
|
||||
self.span_suggestion(span, msg, format!("{}\n{}", new_item, indent), applicability);
|
||||
self.span_suggestion(span, msg, format!("{new_item}\n{indent}"), applicability);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -863,7 +861,7 @@ impl<'tcx> DerefDelegate<'_, 'tcx> {
|
|||
pub fn finish(&mut self) -> String {
|
||||
let end_span = Span::new(self.next_pos, self.closure_span.hi(), self.closure_span.ctxt(), None);
|
||||
let end_snip = snippet_with_applicability(self.cx, end_span, "..", &mut self.applicability);
|
||||
let sugg = format!("{}{}", self.suggestion_start, end_snip);
|
||||
let sugg = format!("{}{end_snip}", self.suggestion_start);
|
||||
if self.closure_arg_is_type_annotated_double_ref {
|
||||
sugg.replacen('&', "", 1)
|
||||
} else {
|
||||
|
@ -925,7 +923,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
|
|||
if cmt.place.projections.is_empty() {
|
||||
// handle item without any projection, that needs an explicit borrowing
|
||||
// i.e.: suggest `&x` instead of `x`
|
||||
let _ = write!(self.suggestion_start, "{}&{}", start_snip, ident_str);
|
||||
let _ = write!(self.suggestion_start, "{start_snip}&{ident_str}");
|
||||
} else {
|
||||
// cases where a parent `Call` or `MethodCall` is using the item
|
||||
// i.e.: suggest `.contains(&x)` for `.find(|x| [1, 2, 3].contains(x)).is_none()`
|
||||
|
@ -940,7 +938,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
|
|||
// given expression is the self argument and will be handled completely by the compiler
|
||||
// i.e.: `|x| x.is_something()`
|
||||
ExprKind::MethodCall(_, self_expr, ..) if self_expr.hir_id == cmt.hir_id => {
|
||||
let _ = write!(self.suggestion_start, "{}{}", start_snip, ident_str_with_proj);
|
||||
let _ = write!(self.suggestion_start, "{start_snip}{ident_str_with_proj}");
|
||||
self.next_pos = span.hi();
|
||||
return;
|
||||
},
|
||||
|
@ -973,9 +971,9 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
|
|||
} else {
|
||||
ident_str
|
||||
};
|
||||
format!("{}{}", start_snip, ident)
|
||||
format!("{start_snip}{ident}")
|
||||
} else {
|
||||
format!("{}&{}", start_snip, ident_str)
|
||||
format!("{start_snip}&{ident_str}")
|
||||
};
|
||||
self.suggestion_start.push_str(&ident_sugg);
|
||||
self.next_pos = span.hi();
|
||||
|
@ -1042,13 +1040,13 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
|
|||
|
||||
for item in projections {
|
||||
if item.kind == ProjectionKind::Deref {
|
||||
replacement_str = format!("*{}", replacement_str);
|
||||
replacement_str = format!("*{replacement_str}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _ = write!(self.suggestion_start, "{}{}", start_snip, replacement_str);
|
||||
let _ = write!(self.suggestion_start, "{start_snip}{replacement_str}");
|
||||
}
|
||||
self.next_pos = span.hi();
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ impl std::fmt::Display for VersionInfo {
|
|||
if (hash_trimmed.len() + date_trimmed.len()) > 0 {
|
||||
write!(
|
||||
f,
|
||||
"{} {}.{}.{} ({} {})",
|
||||
self.crate_name, self.major, self.minor, self.patch, hash_trimmed, date_trimmed,
|
||||
"{} {}.{}.{} ({hash_trimmed} {date_trimmed})",
|
||||
self.crate_name, self.major, self.minor, self.patch,
|
||||
)?;
|
||||
} else {
|
||||
write!(f, "{} {}.{}.{}", self.crate_name, self.major, self.minor, self.patch)?;
|
||||
|
@ -153,7 +153,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_debug_local() {
|
||||
let vi = get_version_info!();
|
||||
let s = format!("{:?}", vi);
|
||||
let s = format!("{vi:?}");
|
||||
assert_eq!(
|
||||
s,
|
||||
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 2, patch: 0 }"
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::process::Command;
|
|||
#[cfg_attr(feature = "integration", test)]
|
||||
fn integration_test() {
|
||||
let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set");
|
||||
let repo_url = format!("https://github.com/{}", repo_name);
|
||||
let repo_url = format!("https://github.com/{repo_name}");
|
||||
let crate_name = repo_name
|
||||
.split('/')
|
||||
.nth(1)
|
||||
|
@ -83,7 +83,7 @@ fn integration_test() {
|
|||
|
||||
match output.status.code() {
|
||||
Some(0) => println!("Compilation successful"),
|
||||
Some(code) => eprintln!("Compilation failed. Exit code: {}", code),
|
||||
Some(code) => eprintln!("Compilation failed. Exit code: {code}"),
|
||||
None => panic!("Process terminated by signal"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue