Skip to content

Commit 46b8e74

Browse files
committed
Auto merge of #90668 - matthiaskrgr:clippy_nov7, r=jyn514
more clippy fixes
2 parents 68568dc + 5c45455 commit 46b8e74

File tree

27 files changed

+138
-182
lines changed

27 files changed

+138
-182
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -539,15 +539,13 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
539539
ast::ExprKind::TryBlock(_) => {
540540
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
541541
}
542-
ast::ExprKind::Block(_, opt_label) => {
543-
if let Some(label) = opt_label {
544-
gate_feature_post!(
545-
&self,
546-
label_break_value,
547-
label.ident.span,
548-
"labels on blocks are unstable"
549-
);
550-
}
542+
ast::ExprKind::Block(_, Some(label)) => {
543+
gate_feature_post!(
544+
&self,
545+
label_break_value,
546+
label.ident.span,
547+
"labels on blocks are unstable"
548+
);
551549
}
552550
_ => {}
553551
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,7 @@ impl<'a> State<'a> {
14381438
}
14391439
}
14401440

1441-
crate fn print_record_struct_body(
1442-
&mut self,
1443-
fields: &Vec<ast::FieldDef>,
1444-
span: rustc_span::Span,
1445-
) {
1441+
crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
14461442
self.nbsp();
14471443
self.bopen();
14481444
self.hardbreak_if_not_bol();

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
655655
// If the region is live at at least one location in the promoted MIR,
656656
// then add a liveness constraint to the main MIR for this region
657657
// at the location provided as an argument to this method
658-
if let Some(_) = liveness_constraints.get_elements(region).next() {
658+
if liveness_constraints.get_elements(region).next().is_some() {
659659
self.cx
660660
.borrowck_context
661661
.constraints

compiler/rustc_builtin_macros/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
547547
if let Some(snippet) = &template_snippet {
548548
if let Some(pos) = snippet.find(needle) {
549549
let end = pos
550-
+ &snippet[pos..]
550+
+ snippet[pos..]
551551
.find(|c| matches!(c, '\n' | ';' | '\\' | '"'))
552552
.unwrap_or(snippet[pos..].len() - 1);
553553
let inner = InnerSpan::new(pos, end);

compiler/rustc_codegen_ssa/src/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1095,10 +1095,10 @@ fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut d
10951095
}
10961096

10971097
fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
1098-
fn find_sanitizer_runtime(sess: &Session, filename: &String) -> PathBuf {
1098+
fn find_sanitizer_runtime(sess: &Session, filename: &str) -> PathBuf {
10991099
let session_tlib =
11001100
filesearch::make_target_lib_path(&sess.sysroot, sess.opts.target_triple.triple());
1101-
let path = session_tlib.join(&filename);
1101+
let path = session_tlib.join(filename);
11021102
if path.exists() {
11031103
return session_tlib;
11041104
} else {

compiler/rustc_data_structures/src/steal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<T> Steal<T> {
3434
#[track_caller]
3535
pub fn borrow(&self) -> MappedReadGuard<'_, T> {
3636
let borrow = self.value.borrow();
37-
if let None = &*borrow {
37+
if borrow.is_none() {
3838
panic!("attempted to read from stolen value: {}", std::any::type_name::<T>());
3939
}
4040
ReadGuard::map(borrow, |opt| opt.as_ref().unwrap())

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14661466
let mut returned_async_output_error = false;
14671467
for &sp in values {
14681468
if sp.is_desugaring(DesugaringKind::Async) && !returned_async_output_error {
1469-
if &[sp] != err.span.primary_spans() {
1469+
if [sp] != err.span.primary_spans() {
14701470
let mut span: MultiSpan = sp.into();
14711471
span.push_span_label(
14721472
sp,

compiler/rustc_interface/src/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use std::ffi::OsString;
4747
use std::io::{self, BufWriter, Write};
4848
use std::lazy::SyncLazy;
4949
use std::marker::PhantomPinned;
50-
use std::path::PathBuf;
50+
use std::path::{Path, PathBuf};
5151
use std::pin::Pin;
5252
use std::rc::Rc;
5353
use std::{env, fs, iter};
@@ -536,7 +536,7 @@ where
536536
None
537537
}
538538

539-
fn output_contains_path(output_paths: &[PathBuf], input_path: &PathBuf) -> bool {
539+
fn output_contains_path(output_paths: &[PathBuf], input_path: &Path) -> bool {
540540
let input_path = input_path.canonicalize().ok();
541541
if input_path.is_none() {
542542
return false;
@@ -552,7 +552,7 @@ fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> {
552552
check_output(output_paths, check)
553553
}
554554

555-
fn escape_dep_filename(filename: &String) -> String {
555+
fn escape_dep_filename(filename: &str) -> String {
556556
// Apparently clang and gcc *only* escape spaces:
557557
// https://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
558558
filename.replace(" ", "\\ ")

compiler/rustc_lint/src/builtin.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -3130,18 +3130,13 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
31303130
false
31313131
}
31323132

3133-
if let rustc_hir::ExprKind::Unary(ref un_op, ref expr_deref) = expr.kind {
3134-
if let rustc_hir::UnOp::Deref = un_op {
3135-
if is_null_ptr(cx, expr_deref) {
3136-
cx.struct_span_lint(DEREF_NULLPTR, expr.span, |lint| {
3137-
let mut err = lint.build("dereferencing a null pointer");
3138-
err.span_label(
3139-
expr.span,
3140-
"this code causes undefined behavior when executed",
3141-
);
3142-
err.emit();
3143-
});
3144-
}
3133+
if let rustc_hir::ExprKind::Unary(rustc_hir::UnOp::Deref, expr_deref) = expr.kind {
3134+
if is_null_ptr(cx, expr_deref) {
3135+
cx.struct_span_lint(DEREF_NULLPTR, expr.span, |lint| {
3136+
let mut err = lint.build("dereferencing a null pointer");
3137+
err.span_label(expr.span, "this code causes undefined behavior when executed");
3138+
err.emit();
3139+
});
31453140
}
31463141
}
31473142
}
@@ -3196,7 +3191,7 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
31963191
let snippet = template_snippet.as_str();
31973192
if let Some(pos) = snippet.find(needle) {
31983193
let end = pos
3199-
+ &snippet[pos..]
3194+
+ snippet[pos..]
32003195
.find(|c| c == ':')
32013196
.unwrap_or(snippet[pos..].len() - 1);
32023197
let inner = InnerSpan::new(pos, end);

compiler/rustc_lint/src/internal.rs

+45-54
Original file line numberDiff line numberDiff line change
@@ -101,33 +101,31 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
101101

102102
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx Ty<'tcx>) {
103103
match &ty.kind {
104-
TyKind::Path(qpath) => {
105-
if let QPath::Resolved(_, path) = qpath {
106-
if let Some(last) = path.segments.iter().last() {
107-
if lint_ty_kind_usage(cx, last) {
108-
cx.struct_span_lint(USAGE_OF_TY_TYKIND, path.span, |lint| {
109-
lint.build("usage of `ty::TyKind`")
110-
.help("try using `Ty` instead")
111-
.emit();
112-
})
113-
} else {
114-
if ty.span.from_expansion() {
115-
return;
116-
}
117-
if let Some(t) = is_ty_or_ty_ctxt(cx, ty) {
118-
if path.segments.len() > 1 {
119-
cx.struct_span_lint(USAGE_OF_QUALIFIED_TY, path.span, |lint| {
120-
lint.build(&format!("usage of qualified `ty::{}`", t))
121-
.span_suggestion(
122-
path.span,
123-
"try using it unqualified",
124-
t,
125-
// The import probably needs to be changed
126-
Applicability::MaybeIncorrect,
127-
)
128-
.emit();
129-
})
130-
}
104+
TyKind::Path(QPath::Resolved(_, path)) => {
105+
if let Some(last) = path.segments.iter().last() {
106+
if lint_ty_kind_usage(cx, last) {
107+
cx.struct_span_lint(USAGE_OF_TY_TYKIND, path.span, |lint| {
108+
lint.build("usage of `ty::TyKind`")
109+
.help("try using `Ty` instead")
110+
.emit();
111+
})
112+
} else {
113+
if ty.span.from_expansion() {
114+
return;
115+
}
116+
if let Some(t) = is_ty_or_ty_ctxt(cx, ty) {
117+
if path.segments.len() > 1 {
118+
cx.struct_span_lint(USAGE_OF_QUALIFIED_TY, path.span, |lint| {
119+
lint.build(&format!("usage of qualified `ty::{}`", t))
120+
.span_suggestion(
121+
path.span,
122+
"try using it unqualified",
123+
t,
124+
// The import probably needs to be changed
125+
Applicability::MaybeIncorrect,
126+
)
127+
.emit();
128+
})
131129
}
132130
}
133131
}
@@ -169,37 +167,30 @@ fn lint_ty_kind_usage(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> bool {
169167
}
170168

171169
fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, ty: &Ty<'_>) -> Option<String> {
172-
if let TyKind::Path(qpath) = &ty.kind {
173-
if let QPath::Resolved(_, path) = qpath {
174-
match path.res {
175-
Res::Def(_, def_id) => {
176-
if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(def_id)
177-
{
178-
return Some(format!(
179-
"{}{}",
180-
name,
181-
gen_args(path.segments.last().unwrap())
182-
));
183-
}
170+
if let TyKind::Path(QPath::Resolved(_, path)) = &ty.kind {
171+
match path.res {
172+
Res::Def(_, def_id) => {
173+
if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(def_id) {
174+
return Some(format!("{}{}", name, gen_args(path.segments.last().unwrap())));
184175
}
185-
// Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
186-
Res::SelfTy(None, Some((did, _))) => {
187-
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
188-
if let Some(name @ (sym::Ty | sym::TyCtxt)) =
189-
cx.tcx.get_diagnostic_name(adt.did)
190-
{
191-
// NOTE: This path is currently unreachable as `Ty<'tcx>` is
192-
// defined as a type alias meaning that `impl<'tcx> Ty<'tcx>`
193-
// is not actually allowed.
194-
//
195-
// I(@lcnr) still kept this branch in so we don't miss this
196-
// if we ever change it in the future.
197-
return Some(format!("{}<{}>", name, substs[0]));
198-
}
176+
}
177+
// Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
178+
Res::SelfTy(None, Some((did, _))) => {
179+
if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
180+
if let Some(name @ (sym::Ty | sym::TyCtxt)) =
181+
cx.tcx.get_diagnostic_name(adt.did)
182+
{
183+
// NOTE: This path is currently unreachable as `Ty<'tcx>` is
184+
// defined as a type alias meaning that `impl<'tcx> Ty<'tcx>`
185+
// is not actually allowed.
186+
//
187+
// I(@lcnr) still kept this branch in so we don't miss this
188+
// if we ever change it in the future.
189+
return Some(format!("{}<{}>", name, substs[0]));
199190
}
200191
}
201-
_ => (),
202192
}
193+
_ => (),
203194
}
204195
}
205196

compiler/rustc_macros/src/hash_stable.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ fn parse_attributes(field: &syn::Field) -> Attributes {
2424
}
2525
if meta.path().is_ident("project") {
2626
if let Meta::List(list) = meta {
27-
if let Some(nested) = list.nested.iter().next() {
28-
if let NestedMeta::Meta(meta) = nested {
29-
attrs.project = meta.path().get_ident().cloned();
30-
any_attr = true;
31-
}
27+
if let Some(NestedMeta::Meta(meta)) = list.nested.iter().next() {
28+
attrs.project = meta.path().get_ident().cloned();
29+
any_attr = true;
3230
}
3331
}
3432
}

compiler/rustc_metadata/src/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl Collector<'tcx> {
309309
.libs
310310
.iter()
311311
.filter_map(|lib| lib.name.as_ref())
312-
.any(|n| &n.as_str() == &lib.name);
312+
.any(|n| n.as_str() == lib.name);
313313
if new_name.is_empty() {
314314
self.tcx.sess.err(&format!(
315315
"an empty renaming target was specified for library `{}`",

compiler/rustc_passes/src/check_const.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ impl<'tcx> CheckConstVisitor<'tcx> {
210210
required_gates.iter().copied().filter(|&g| !features.enabled(g)).collect();
211211

212212
match missing_gates.as_slice() {
213-
&[] => struct_span_err!(tcx.sess, span, E0744, "{}", msg).emit(),
213+
[] => struct_span_err!(tcx.sess, span, E0744, "{}", msg).emit(),
214214

215-
&[missing_primary, ref missing_secondary @ ..] => {
216-
let mut err = feature_err(&tcx.sess.parse_sess, missing_primary, span, &msg);
215+
[missing_primary, ref missing_secondary @ ..] => {
216+
let mut err = feature_err(&tcx.sess.parse_sess, *missing_primary, span, &msg);
217217

218218
// If multiple feature gates would be required to enable this expression, include
219219
// them as help messages. Don't emit a separate error for each missing feature gate.

compiler/rustc_resolve/src/late/diagnostics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1344,12 +1344,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
13441344
} else {
13451345
// Search in module.
13461346
let mod_path = &path[..path.len() - 1];
1347-
if let PathResult::Module(module) =
1347+
if let PathResult::Module(ModuleOrUniformRoot::Module(module)) =
13481348
self.resolve_path(mod_path, Some(TypeNS), false, span, CrateLint::No)
13491349
{
1350-
if let ModuleOrUniformRoot::Module(module) = module {
1351-
self.r.add_module_candidates(module, &mut names, &filter_fn);
1352-
}
1350+
self.r.add_module_candidates(module, &mut names, &filter_fn);
13531351
}
13541352
}
13551353

compiler/rustc_resolve/src/late/lifetimes.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -1931,20 +1931,18 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
19311931
break;
19321932
}
19331933
}
1934-
hir::TyKind::Path(ref qpath) => {
1935-
if let QPath::Resolved(_, path) = qpath {
1936-
let last_segment = &path.segments[path.segments.len() - 1];
1937-
let generics = last_segment.args();
1938-
for arg in generics.args.iter() {
1939-
if let GenericArg::Lifetime(lt) = arg {
1940-
if lt.name.ident() == name {
1941-
elide_use = Some(lt.span);
1942-
break;
1943-
}
1934+
hir::TyKind::Path(QPath::Resolved(_, path)) => {
1935+
let last_segment = &path.segments[path.segments.len() - 1];
1936+
let generics = last_segment.args();
1937+
for arg in generics.args.iter() {
1938+
if let GenericArg::Lifetime(lt) = arg {
1939+
if lt.name.ident() == name {
1940+
elide_use = Some(lt.span);
1941+
break;
19441942
}
19451943
}
1946-
break;
19471944
}
1945+
break;
19481946
}
19491947
_ => {}
19501948
}

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateCo
914914
pub(super) fn build_target_config(
915915
opts: &Options,
916916
target_override: Option<Target>,
917-
sysroot: &PathBuf,
917+
sysroot: &Path,
918918
) -> Target {
919919
let target_result = target_override.map_or_else(
920920
|| Target::search(&opts.target_triple, sysroot),

compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ mod parse {
881881
match v {
882882
Some(s) => {
883883
if !slot.is_empty() {
884-
slot.push_str(",");
884+
slot.push(',');
885885
}
886886
slot.push_str(s);
887887
true

compiler/rustc_span/src/lib.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,8 @@ impl<S: Encoder> Encodable<S> for RealFileName {
194194
encoder.emit_enum(|encoder| match *self {
195195
RealFileName::LocalPath(ref local_path) => {
196196
encoder.emit_enum_variant("LocalPath", 0, 1, |encoder| {
197-
Ok({
198-
encoder
199-
.emit_enum_variant_arg(true, |encoder| local_path.encode(encoder))?;
200-
})
197+
encoder.emit_enum_variant_arg(true, |encoder| local_path.encode(encoder))?;
198+
Ok(())
201199
})
202200
}
203201

@@ -206,12 +204,9 @@ impl<S: Encoder> Encodable<S> for RealFileName {
206204
// For privacy and build reproducibility, we must not embed host-dependant path in artifacts
207205
// if they have been remapped by --remap-path-prefix
208206
assert!(local_path.is_none());
209-
Ok({
210-
encoder
211-
.emit_enum_variant_arg(true, |encoder| local_path.encode(encoder))?;
212-
encoder
213-
.emit_enum_variant_arg(false, |encoder| virtual_name.encode(encoder))?;
214-
})
207+
encoder.emit_enum_variant_arg(true, |encoder| local_path.encode(encoder))?;
208+
encoder.emit_enum_variant_arg(false, |encoder| virtual_name.encode(encoder))?;
209+
Ok(())
215210
}),
216211
})
217212
}

0 commit comments

Comments
 (0)