Skip to content

Commit 4653c93

Browse files
committed
Auto merge of #105892 - Dylan-DPC:rollup-eozolx4, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #105682 (Use `expose_addr()` in `fmt::Pointer`) - #105839 (Suggest a `T: Send` bound for `&mut T` upvars in `Send` generators) - #105864 (clippy::complexity fixes) - #105882 (Don't ICE in closure arg borrow suggestion) - #105889 (Fix `uninlined_format_args` in libtest) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1072337 + 2a57493 commit 4653c93

File tree

28 files changed

+181
-102
lines changed

28 files changed

+181
-102
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
600600
self.impl_trait_defs = current_impl_trait_defs;
601601
self.impl_trait_bounds = current_impl_trait_bounds;
602602

603-
debug_assert!(self.children.iter().find(|(id, _)| id == &def_id).is_none());
603+
debug_assert!(!self.children.iter().any(|(id, _)| id == &def_id));
604604
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
605605
}
606606

compiler/rustc_borrowck/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -2059,12 +2059,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20592059
) -> Option<InitIndex> {
20602060
let mpi = self.move_data.rev_lookup.find_local(local);
20612061
let ii = &self.move_data.init_path_map[mpi];
2062-
for &index in ii {
2063-
if flow_state.ever_inits.contains(index) {
2064-
return Some(index);
2065-
}
2066-
}
2067-
None
2062+
ii.into_iter().find(|&&index| flow_state.ever_inits.contains(index)).copied()
20682063
}
20692064

20702065
/// Adds the place into the used mutable variables set

compiler/rustc_codegen_llvm/src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
233233
// Set KCFI operand bundle
234234
let is_indirect_call = unsafe { llvm::LLVMIsAFunction(llfn).is_none() };
235235
let kcfi_bundle =
236-
if self.tcx.sess.is_sanitizer_kcfi_enabled() && fn_abi.is_some() && is_indirect_call {
237-
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi.unwrap());
236+
if self.tcx.sess.is_sanitizer_kcfi_enabled() && let Some(fn_abi) = fn_abi && is_indirect_call {
237+
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi);
238238
Some(llvm::OperandBundleDef::new("kcfi", &[self.const_u32(kcfi_typeid)]))
239239
} else {
240240
None

compiler/rustc_codegen_ssa/src/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn try_filter_fat_archs<'a>(
123123
) -> io::Result<Option<(&'a [u8], u64)>> {
124124
let archs = archs.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
125125

126-
let desired = match archs.iter().filter(|a| a.architecture() == target_arch).next() {
126+
let desired = match archs.iter().find(|a| a.architecture() == target_arch) {
127127
Some(a) => a,
128128
None => return Ok(None),
129129
};

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11241124
}
11251125

11261126
let hir = self.tcx.hir();
1127-
let cond_parent = hir.parent_iter(expr.hir_id).skip_while(|(_, node)| {
1128-
matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And)
1129-
}).next();
1127+
let cond_parent = hir.parent_iter(expr.hir_id).find(|(_, node)| {
1128+
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(op, _, _), .. }) if op.node == hir::BinOpKind::And)
1129+
});
11301130
// Don't suggest:
11311131
// `let Some(_) = a.is_some() && b`
11321132
// ++++++++++

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
488488
// If this empty region is from a universe that can
489489
// name the placeholder, then the placeholder is
490490
// larger; otherwise, the only ancestor is `'static`.
491-
if a_ui.can_name(placeholder.universe) { true } else { false }
491+
return a_ui.can_name(placeholder.universe);
492492
}
493493
}
494494
}

compiler/rustc_infer/src/infer/undo_log.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,12 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
8787

8888
/// The combined undo log for all the various unification tables. For each change to the storage
8989
/// for any kind of inference variable, we record an UndoLog entry in the vector here.
90-
#[derive(Clone)]
90+
#[derive(Clone, Default)]
9191
pub(crate) struct InferCtxtUndoLogs<'tcx> {
9292
logs: Vec<UndoLog<'tcx>>,
9393
num_open_snapshots: usize,
9494
}
9595

96-
impl Default for InferCtxtUndoLogs<'_> {
97-
fn default() -> Self {
98-
Self { logs: Default::default(), num_open_snapshots: Default::default() }
99-
}
100-
}
101-
10296
/// The UndoLogs trait defines how we undo a particular kind of action (of type T). We can undo any
10397
/// action that is convertible into an UndoLog (per the From impls above).
10498
impl<'tcx, T> UndoLogs<T> for InferCtxtUndoLogs<'tcx>

compiler/rustc_middle/src/middle/privacy.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ impl EffectiveVisibilities {
103103

104104
pub fn public_at_level(&self, id: LocalDefId) -> Option<Level> {
105105
self.effective_vis(id).and_then(|effective_vis| {
106-
for level in Level::all_levels() {
107-
if effective_vis.is_public_at_level(level) {
108-
return Some(level);
109-
}
110-
}
111-
None
106+
Level::all_levels().into_iter().find(|&level| effective_vis.is_public_at_level(level))
112107
})
113108
}
114109

compiler/rustc_mir_transform/src/sroa.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn replace_flattened_locals<'tcx>(
182182
let mut fragments = IndexVec::new();
183183
for (k, v) in &replacements.fields {
184184
fragments.ensure_contains_elem(k.local, || Vec::new());
185-
fragments[k.local].push((&k.projection[..], *v));
185+
fragments[k.local].push((k.projection, *v));
186186
}
187187
debug!(?fragments);
188188

compiler/rustc_monomorphize/src/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ fn check_recursion_limit<'tcx>(
595595
let def_path_str = tcx.def_path_str(def_id);
596596
let (shrunk, written_to_path) = shrunk_instance_name(tcx, &instance);
597597
let mut path = PathBuf::new();
598-
let was_written = if written_to_path.is_some() {
599-
path = written_to_path.unwrap();
598+
let was_written = if let Some(written_to_path) = written_to_path {
599+
path = written_to_path;
600600
Some(())
601601
} else {
602602
None

compiler/rustc_parse/src/parser/path.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ impl<'a> Parser<'a> {
277277
if let Some(arg) = args
278278
.iter()
279279
.rev()
280-
.skip_while(|arg| matches!(arg, AngleBracketedArg::Constraint(_)))
281-
.next()
280+
.find(|arg| !matches!(arg, AngleBracketedArg::Constraint(_)))
282281
{
283282
err.span_suggestion_verbose(
284283
arg.span().shrink_to_hi(),

compiler/rustc_passes/src/dead.rs

-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ impl<'tcx> DeadVisitor<'tcx> {
787787
let mut dead_codes = dead_codes
788788
.iter()
789789
.filter(|v| !v.name.as_str().starts_with('_'))
790-
.map(|v| v)
791790
.collect::<Vec<&DeadVariant>>();
792791
if dead_codes.is_empty() {
793792
return;

compiler/rustc_session/src/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
122122
let target = crate::config::host_triple();
123123
let mut sysroot_candidates: SmallVec<[PathBuf; 2]> =
124124
smallvec![get_or_default_sysroot().expect("Failed finding sysroot")];
125-
let path = current_dll_path().and_then(|s| Ok(s.canonicalize().map_err(|e| e.to_string())?));
125+
let path = current_dll_path().and_then(|s| s.canonicalize().map_err(|e| e.to_string()));
126126
if let Ok(dll) = path {
127127
// use `parent` twice to chop off the file name and then also the
128128
// directory containing the dll which should be either `lib` or `bin`.
@@ -165,7 +165,7 @@ pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
165165
}
166166

167167
fn default_from_rustc_driver_dll() -> Result<PathBuf, String> {
168-
let dll = current_dll_path().and_then(|s| Ok(canonicalize(s)))?;
168+
let dll = current_dll_path().map(|s| canonicalize(s))?;
169169

170170
// `dll` will be in one of the following two:
171171
// - compiler's libdir: $sysroot/lib/*.dll

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,8 @@ fn is_c_void_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
9999
ty::Adt(adt_def, ..) => {
100100
let def_id = adt_def.0.did;
101101
let crate_name = tcx.crate_name(def_id.krate);
102-
if tcx.item_name(def_id).as_str() == "c_void"
102+
tcx.item_name(def_id).as_str() == "c_void"
103103
&& (crate_name == sym::core || crate_name == sym::std || crate_name == sym::libc)
104-
{
105-
true
106-
} else {
107-
false
108-
}
109104
}
110105
_ => false,
111106
}
@@ -267,8 +262,7 @@ fn encode_predicates<'tcx>(
267262
) -> String {
268263
// <predicate1[..predicateN]>E as part of vendor extended type
269264
let mut s = String::new();
270-
let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> =
271-
predicates.iter().map(|predicate| predicate).collect();
265+
let predicates: Vec<ty::PolyExistentialPredicate<'tcx>> = predicates.iter().collect();
272266
for predicate in predicates {
273267
s.push_str(&encode_predicate(tcx, predicate, dict, options));
274268
}
@@ -322,7 +316,7 @@ fn encode_substs<'tcx>(
322316
) -> String {
323317
// [I<subst1..substN>E] as part of vendor extended type
324318
let mut s = String::new();
325-
let substs: Vec<GenericArg<'_>> = substs.iter().map(|subst| subst).collect();
319+
let substs: Vec<GenericArg<'_>> = substs.iter().collect();
326320
if !substs.is_empty() {
327321
s.push('I');
328322
for subst in substs {
@@ -703,11 +697,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
703697
tcx.layout_of(param_env.and(ty)).map_or(false, |layout| layout.is_zst());
704698
!is_zst
705699
});
706-
if field.is_none() {
707-
// Transform repr(transparent) types without non-ZST field into ()
708-
ty = tcx.mk_unit();
709-
} else {
710-
let ty0 = tcx.type_of(field.unwrap().did);
700+
if let Some(field) = field {
701+
let ty0 = tcx.type_of(field.did);
711702
// Generalize any repr(transparent) user-defined type that is either a pointer
712703
// or reference, and either references itself or any other type that contains or
713704
// references itself, to avoid a reference cycle.
@@ -720,6 +711,9 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
720711
} else {
721712
ty = transform_ty(tcx, ty0, options);
722713
}
714+
} else {
715+
// Transform repr(transparent) types without non-ZST field into ()
716+
ty = tcx.mk_unit();
723717
}
724718
} else {
725719
ty = tcx.mk_adt(*adt_def, transform_substs(tcx, substs, options));

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
17891789
self.note_conflicting_closure_bounds(cause, &mut err);
17901790

17911791
if let Some(found_node) = found_node {
1792-
hint_missing_borrow(span, found_span, found, expected, found_node, &mut err);
1792+
hint_missing_borrow(span, found, expected, found_node, &mut err);
17931793
}
17941794

17951795
err
@@ -2344,28 +2344,33 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23442344
}
23452345
}
23462346
GeneratorInteriorOrUpvar::Upvar(upvar_span) => {
2347-
// `Some(ref_ty)` if `target_ty` is `&T` and `T` fails to impl `Sync`
2348-
let refers_to_non_sync = match target_ty.kind() {
2349-
ty::Ref(_, ref_ty, _) => match self.evaluate_obligation(&obligation) {
2350-
Ok(eval) if !eval.may_apply() => Some(ref_ty),
2347+
// `Some((ref_ty, is_mut))` if `target_ty` is `&T` or `&mut T` and fails to impl `Send`
2348+
let non_send = match target_ty.kind() {
2349+
ty::Ref(_, ref_ty, mutability) => match self.evaluate_obligation(&obligation) {
2350+
Ok(eval) if !eval.may_apply() => Some((ref_ty, mutability.is_mut())),
23512351
_ => None,
23522352
},
23532353
_ => None,
23542354
};
23552355

2356-
let (span_label, span_note) = match refers_to_non_sync {
2357-
// if `target_ty` is `&T` and `T` fails to impl `Sync`,
2358-
// include suggestions to make `T: Sync` so that `&T: Send`
2359-
Some(ref_ty) => (
2360-
format!(
2361-
"has type `{}` which {}, because `{}` is not `Sync`",
2362-
target_ty, trait_explanation, ref_ty
2363-
),
2364-
format!(
2365-
"captured value {} because `&` references cannot be sent unless their referent is `Sync`",
2366-
trait_explanation
2367-
),
2368-
),
2356+
let (span_label, span_note) = match non_send {
2357+
// if `target_ty` is `&T` or `&mut T` and fails to impl `Send`,
2358+
// include suggestions to make `T: Sync` so that `&T: Send`,
2359+
// or to make `T: Send` so that `&mut T: Send`
2360+
Some((ref_ty, is_mut)) => {
2361+
let ref_ty_trait = if is_mut { "Send" } else { "Sync" };
2362+
let ref_kind = if is_mut { "&mut" } else { "&" };
2363+
(
2364+
format!(
2365+
"has type `{}` which {}, because `{}` is not `{}`",
2366+
target_ty, trait_explanation, ref_ty, ref_ty_trait
2367+
),
2368+
format!(
2369+
"captured value {} because `{}` references cannot be sent unless their referent is `{}`",
2370+
trait_explanation, ref_kind, ref_ty_trait
2371+
),
2372+
)
2373+
}
23692374
None => (
23702375
format!("has type `{}` which {}", target_ty, trait_explanation),
23712376
format!("captured value {}", trait_explanation),
@@ -3455,7 +3460,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
34553460
/// Add a hint to add a missing borrow or remove an unnecessary one.
34563461
fn hint_missing_borrow<'tcx>(
34573462
span: Span,
3458-
found_span: Span,
34593463
found: Ty<'tcx>,
34603464
expected: Ty<'tcx>,
34613465
found_node: Node<'_>,
@@ -3474,9 +3478,8 @@ fn hint_missing_borrow<'tcx>(
34743478
}
34753479
};
34763480

3477-
let fn_decl = found_node
3478-
.fn_decl()
3479-
.unwrap_or_else(|| span_bug!(found_span, "found node must be a function"));
3481+
// This could be a variant constructor, for example.
3482+
let Some(fn_decl) = found_node.fn_decl() else { return; };
34803483

34813484
let arg_spans = fn_decl.inputs.iter().map(|ty| ty.span);
34823485

compiler/rustc_transmute/src/maybe_transmutable/query_context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ mod rustc {
7676
}
7777
};
7878

79-
let ret = if self.visibility(def_id).is_accessible_from(parent, *self) {
80-
true
81-
} else {
82-
false
83-
};
79+
let ret: bool = self.visibility(def_id).is_accessible_from(parent, *self);
8480

8581
trace!(?ret, "ret");
8682
ret

library/core/src/fmt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2471,8 +2471,8 @@ impl Display for char {
24712471
#[stable(feature = "rust1", since = "1.0.0")]
24722472
impl<T: ?Sized> Pointer for *const T {
24732473
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
2474-
// Cast is needed here because `.addr()` requires `T: Sized`.
2475-
pointer_fmt_inner((*self as *const ()).addr(), f)
2474+
// Cast is needed here because `.expose_addr()` requires `T: Sized`.
2475+
pointer_fmt_inner((*self as *const ()).expose_addr(), f)
24762476
}
24772477
}
24782478

library/test/src/cli.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ fn get_shuffle_seed(matches: &getopts::Matches, allow_unstable: bool) -> OptPart
354354
Err(e) => {
355355
return Err(format!(
356356
"argument for --shuffle-seed must be a number \
357-
(error: {})",
358-
e
357+
(error: {e})"
359358
));
360359
}
361360
},
@@ -383,8 +382,7 @@ fn get_test_threads(matches: &getopts::Matches) -> OptPartRes<Option<usize>> {
383382
Err(e) => {
384383
return Err(format!(
385384
"argument for --test-threads must be a number > 0 \
386-
(error: {})",
387-
e
385+
(error: {e})"
388386
));
389387
}
390388
},
@@ -418,8 +416,7 @@ fn get_format(
418416
Some(v) => {
419417
return Err(format!(
420418
"argument for --format must be pretty, terse, json or junit (was \
421-
{})",
422-
v
419+
{v})"
423420
));
424421
}
425422
};
@@ -436,8 +433,7 @@ fn get_color_config(matches: &getopts::Matches) -> OptPartRes<ColorConfig> {
436433
Some(v) => {
437434
return Err(format!(
438435
"argument for --color must be auto, always, or never (was \
439-
{})",
440-
v
436+
{v})"
441437
));
442438
}
443439
};

library/test/src/formatters/json.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<T: Write> JsonFormatter<T> {
5353
self.write_message(&*format!(r#", "stdout": "{}""#, EscapedString(stdout)))?;
5454
}
5555
if let Some(extra) = extra {
56-
self.write_message(&*format!(r#", {}"#, extra))?;
56+
self.write_message(&*format!(r#", {extra}"#))?;
5757
}
5858
self.writeln_message(" }")
5959
}
@@ -62,13 +62,12 @@ impl<T: Write> JsonFormatter<T> {
6262
impl<T: Write> OutputFormatter for JsonFormatter<T> {
6363
fn write_run_start(&mut self, test_count: usize, shuffle_seed: Option<u64>) -> io::Result<()> {
6464
let shuffle_seed_json = if let Some(shuffle_seed) = shuffle_seed {
65-
format!(r#", "shuffle_seed": {}"#, shuffle_seed)
65+
format!(r#", "shuffle_seed": {shuffle_seed}"#)
6666
} else {
6767
String::new()
6868
};
6969
self.writeln_message(&*format!(
70-
r#"{{ "type": "suite", "event": "started", "test_count": {}{} }}"#,
71-
test_count, shuffle_seed_json
70+
r#"{{ "type": "suite", "event": "started", "test_count": {test_count}{shuffle_seed_json} }}"#
7271
))
7372
}
7473

library/test/src/formatters/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ pub(crate) fn write_stderr_delimiter(test_output: &mut Vec<u8>, test_name: &Test
3838
Some(_) => test_output.push(b'\n'),
3939
None => (),
4040
}
41-
writeln!(test_output, "---- {} stderr ----", test_name).unwrap();
41+
writeln!(test_output, "---- {test_name} stderr ----").unwrap();
4242
}

library/test/src/formatters/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T: Write> PrettyFormatter<T> {
4747

4848
pub fn write_ignored(&mut self, message: Option<&'static str>) -> io::Result<()> {
4949
if let Some(message) = message {
50-
self.write_short_result(&format!("ignored, {}", message), term::color::YELLOW)
50+
self.write_short_result(&format!("ignored, {message}"), term::color::YELLOW)
5151
} else {
5252
self.write_short_result("ignored", term::color::YELLOW)
5353
}

0 commit comments

Comments
 (0)