Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 46b8e74

Browse files
committedNov 7, 2021
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

Lines changed: 7 additions & 9 deletions
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 8 additions & 13 deletions
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

Lines changed: 45 additions & 54 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 9 additions & 11 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 10 deletions
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
}

‎compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,7 +2071,7 @@ impl Target {
20712071
/// JSON decoding.
20722072
pub fn search(
20732073
target_triple: &TargetTriple,
2074-
sysroot: &PathBuf,
2074+
sysroot: &Path,
20752075
) -> Result<(Target, TargetWarnings), String> {
20762076
use rustc_serialize::json;
20772077
use std::env;

‎compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,19 +2000,14 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
20002000
let sized_trait = self.tcx.lang_items().sized_trait();
20012001
debug!("maybe_suggest_unsized_generics: generics.params={:?}", generics.params);
20022002
debug!("maybe_suggest_unsized_generics: generics.where_clause={:?}", generics.where_clause);
2003-
let param = generics
2004-
.params
2005-
.iter()
2006-
.filter(|param| param.span == span)
2007-
.filter(|param| {
2008-
// Check that none of the explicit trait bounds is `Sized`. Assume that an explicit
2009-
// `Sized` bound is there intentionally and we don't need to suggest relaxing it.
2010-
param
2011-
.bounds
2012-
.iter()
2013-
.all(|bound| bound.trait_ref().and_then(|tr| tr.trait_def_id()) != sized_trait)
2014-
})
2015-
.next();
2003+
let param = generics.params.iter().filter(|param| param.span == span).find(|param| {
2004+
// Check that none of the explicit trait bounds is `Sized`. Assume that an explicit
2005+
// `Sized` bound is there intentionally and we don't need to suggest relaxing it.
2006+
param
2007+
.bounds
2008+
.iter()
2009+
.all(|bound| bound.trait_ref().and_then(|tr| tr.trait_def_id()) != sized_trait)
2010+
});
20162011
let param = match param {
20172012
Some(param) => param,
20182013
_ => return,

‎compiler/rustc_typeck/src/check/demand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
446446
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
447447
if let hir::ExprKind::Lit(_) = expr.kind {
448448
if let Ok(src) = sm.span_to_snippet(sp) {
449-
if let Some(_) = replace_prefix(&src, "b\"", "\"") {
449+
if replace_prefix(&src, "b\"", "\"").is_some() {
450450
let pos = sp.lo() + BytePos(1);
451451
return Some((
452452
sp.with_hi(pos),
@@ -462,7 +462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
462462
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
463463
if let hir::ExprKind::Lit(_) = expr.kind {
464464
if let Ok(src) = sm.span_to_snippet(sp) {
465-
if let Some(_) = replace_prefix(&src, "\"", "b\"") {
465+
if replace_prefix(&src, "\"", "b\"").is_some() {
466466
return Some((
467467
sp.shrink_to_lo(),
468468
"consider adding a leading `b`",

‎compiler/rustc_typeck/src/check/expr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,8 +2058,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20582058
) -> Option<(&Vec<ty::FieldDef>, SubstsRef<'tcx>)> {
20592059
debug!("get_field_candidates(span: {:?}, base_t: {:?}", span, base_t);
20602060

2061-
let mut autoderef = self.autoderef(span, base_t);
2062-
while let Some((base_t, _)) = autoderef.next() {
2061+
for (base_t, _) in self.autoderef(span, base_t) {
20632062
match base_t.kind() {
20642063
ty::Adt(base_def, substs) if !base_def.is_enum() => {
20652064
let fields = &base_def.non_enum_variant().fields;

‎compiler/rustc_typeck/src/check/fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
176176
.type_var_origin(ty)
177177
.map(|origin| origin.span)
178178
.unwrap_or(rustc_span::DUMMY_SP);
179-
let oty = self.inner.borrow().opaque_types_vars.get(ty).map(|v| *v);
179+
let oty = self.inner.borrow().opaque_types_vars.get(ty).copied();
180180
if let Some(opaque_ty) = oty {
181181
debug!(
182182
"fallback_opaque_type_vars(ty={:?}): falling back to opaque type {:?}",

‎compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,34 +1045,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10451045
call_expr: &'tcx hir::Expr<'tcx>,
10461046
) {
10471047
if let hir::ExprKind::Call(path, _) = &call_expr.kind {
1048-
if let hir::ExprKind::Path(qpath) = &path.kind {
1049-
if let hir::QPath::Resolved(_, path) = &qpath {
1050-
for error in errors {
1051-
if let ty::PredicateKind::Trait(predicate) =
1052-
error.obligation.predicate.kind().skip_binder()
1048+
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = &path.kind {
1049+
for error in errors {
1050+
if let ty::PredicateKind::Trait(predicate) =
1051+
error.obligation.predicate.kind().skip_binder()
1052+
{
1053+
// If any of the type arguments in this path segment caused the
1054+
// `FulfillmentError`, point at its span (#61860).
1055+
for arg in path
1056+
.segments
1057+
.iter()
1058+
.filter_map(|seg| seg.args.as_ref())
1059+
.flat_map(|a| a.args.iter())
10531060
{
1054-
// If any of the type arguments in this path segment caused the
1055-
// `FulfillmentError`, point at its span (#61860).
1056-
for arg in path
1057-
.segments
1058-
.iter()
1059-
.filter_map(|seg| seg.args.as_ref())
1060-
.flat_map(|a| a.args.iter())
1061-
{
1062-
if let hir::GenericArg::Type(hir_ty) = &arg {
1063-
if let hir::TyKind::Path(hir::QPath::TypeRelative(..)) =
1064-
&hir_ty.kind
1065-
{
1066-
// Avoid ICE with associated types. As this is best
1067-
// effort only, it's ok to ignore the case. It
1068-
// would trigger in `is_send::<T::AssocType>();`
1069-
// from `typeck-default-trait-impl-assoc-type.rs`.
1070-
} else {
1071-
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, hir_ty);
1072-
let ty = self.resolve_vars_if_possible(ty);
1073-
if ty == predicate.self_ty() {
1074-
error.obligation.cause.make_mut().span = hir_ty.span;
1075-
}
1061+
if let hir::GenericArg::Type(hir_ty) = &arg {
1062+
if let hir::TyKind::Path(hir::QPath::TypeRelative(..)) =
1063+
&hir_ty.kind
1064+
{
1065+
// Avoid ICE with associated types. As this is best
1066+
// effort only, it's ok to ignore the case. It
1067+
// would trigger in `is_send::<T::AssocType>();`
1068+
// from `typeck-default-trait-impl-assoc-type.rs`.
1069+
} else {
1070+
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, hir_ty);
1071+
let ty = self.resolve_vars_if_possible(ty);
1072+
if ty == predicate.self_ty() {
1073+
error.obligation.cause.make_mut().span = hir_ty.span;
10761074
}
10771075
}
10781076
}

‎compiler/rustc_typeck/src/check/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12081208
let edition_fix = candidates
12091209
.iter()
12101210
.find(|did| self.tcx.is_diagnostic_item(sym::TryInto, **did))
1211-
.map(|&d| d);
1211+
.copied();
12121212

12131213
err.help("items from traits can only be used if the trait is in scope");
12141214
let msg = format!(

‎compiler/rustc_typeck/src/check/op.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
399399
}
400400
};
401401
if let Ref(_, rty, _) = lhs_ty.kind() {
402-
if {
403-
self.infcx.type_is_copy_modulo_regions(self.param_env, rty, lhs_expr.span)
404-
&& self
405-
.lookup_op_method(rty, &[rhs_ty], Op::Binary(op, is_assign))
406-
.is_ok()
407-
} {
402+
if self.infcx.type_is_copy_modulo_regions(self.param_env, rty, lhs_expr.span)
403+
&& self.lookup_op_method(rty, &[rhs_ty], Op::Binary(op, is_assign)).is_ok()
404+
{
408405
if let Ok(lstring) = source_map.span_to_snippet(lhs_expr.span) {
409406
let msg = &format!(
410407
"`{}{}` can be used on `{}`, you can dereference `{}`",

‎compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,7 @@ fn check_gat_where_clauses(
435435
let written_predicates: ty::GenericPredicates<'_> =
436436
tcx.explicit_predicates_of(trait_item.def_id);
437437
let mut clauses: Vec<_> = clauses
438-
.drain_filter(|clause| {
439-
written_predicates.predicates.iter().find(|p| &p.0 == clause).is_none()
440-
})
438+
.drain_filter(|clause| !written_predicates.predicates.iter().any(|p| &p.0 == clause))
441439
.map(|clause| format!("{}", clause))
442440
.collect();
443441
// We sort so that order is predictable

0 commit comments

Comments
 (0)
Please sign in to comment.