Skip to content

Commit 3f9bddc

Browse files
committed
Auto merge of #69570 - Dylan-DPC:rollup-d6boczt, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #69477 (docs: add mention of async blocks in move keyword docs) - #69504 (Use assert_ne in hash tests) - #69546 (use to_vec() instead of .iter().cloned().collect() to convert slices to vecs.) - #69551 (use is_empty() instead of len() == x to determine if structs are empty.) - #69563 (Fix no_std detection for target triples) - #69567 (use .to_string() instead of format!() macro to create strings) Failed merges: r? @ghost
2 parents 04e7f96 + bbfec7c commit 3f9bddc

File tree

70 files changed

+152
-141
lines changed

Some content is hidden

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

70 files changed

+152
-141
lines changed

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub struct Target {
180180
impl Target {
181181
pub fn from_triple(triple: &str) -> Self {
182182
let mut target: Self = Default::default();
183-
if triple.contains("-none-") || triple.contains("nvptx") {
183+
if triple.contains("-none") || triple.contains("nvptx") {
184184
target.no_std = true;
185185
}
186186
target

src/libcore/slice/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3823,7 +3823,7 @@ where
38233823
// The last index of self.v is already checked and found to match
38243824
// by the last iteration, so we start searching a new match
38253825
// one index to the left.
3826-
let remainder = if self.v.len() == 0 { &[] } else { &self.v[..(self.v.len() - 1)] };
3826+
let remainder = if self.v.is_empty() { &[] } else { &self.v[..(self.v.len() - 1)] };
38273827
let idx = remainder.iter().rposition(|x| (self.pred)(x)).map(|idx| idx + 1).unwrap_or(0);
38283828
if idx == 0 {
38293829
self.finished = true;
@@ -4033,7 +4033,7 @@ where
40334033
return None;
40344034
}
40354035

4036-
let idx_opt = if self.v.len() == 0 {
4036+
let idx_opt = if self.v.is_empty() {
40374037
None
40384038
} else {
40394039
// work around borrowck limitations

src/libcore/tests/hash/sip.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn test_siphash_2_4() {
238238
#[cfg(target_pointer_width = "32")]
239239
fn test_hash_usize() {
240240
let val = 0xdeadbeef_deadbeef_u64;
241-
assert!(hash(&(val as u64)) != hash(&(val as usize)));
241+
assert_ne!(hash(&(val as u64)), hash(&(val as usize)));
242242
assert_eq!(hash(&(val as u32)), hash(&(val as usize)));
243243
}
244244

@@ -247,7 +247,7 @@ fn test_hash_usize() {
247247
fn test_hash_usize() {
248248
let val = 0xdeadbeef_deadbeef_u64;
249249
assert_eq!(hash(&(val as u64)), hash(&(val as usize)));
250-
assert!(hash(&(val as u32)) != hash(&(val as usize)));
250+
assert_ne!(hash(&(val as u32)), hash(&(val as usize)));
251251
}
252252

253253
#[test]
@@ -262,14 +262,14 @@ fn test_hash_idempotent() {
262262
fn test_hash_no_bytes_dropped_64() {
263263
let val = 0xdeadbeef_deadbeef_u64;
264264

265-
assert!(hash(&val) != hash(&zero_byte(val, 0)));
266-
assert!(hash(&val) != hash(&zero_byte(val, 1)));
267-
assert!(hash(&val) != hash(&zero_byte(val, 2)));
268-
assert!(hash(&val) != hash(&zero_byte(val, 3)));
269-
assert!(hash(&val) != hash(&zero_byte(val, 4)));
270-
assert!(hash(&val) != hash(&zero_byte(val, 5)));
271-
assert!(hash(&val) != hash(&zero_byte(val, 6)));
272-
assert!(hash(&val) != hash(&zero_byte(val, 7)));
265+
assert_ne!(hash(&val), hash(&zero_byte(val, 0)));
266+
assert_ne!(hash(&val), hash(&zero_byte(val, 1)));
267+
assert_ne!(hash(&val), hash(&zero_byte(val, 2)));
268+
assert_ne!(hash(&val), hash(&zero_byte(val, 3)));
269+
assert_ne!(hash(&val), hash(&zero_byte(val, 4)));
270+
assert_ne!(hash(&val), hash(&zero_byte(val, 5)));
271+
assert_ne!(hash(&val), hash(&zero_byte(val, 6)));
272+
assert_ne!(hash(&val), hash(&zero_byte(val, 7)));
273273

274274
fn zero_byte(val: u64, byte: usize) -> u64 {
275275
assert!(byte < 8);
@@ -281,10 +281,10 @@ fn test_hash_no_bytes_dropped_64() {
281281
fn test_hash_no_bytes_dropped_32() {
282282
let val = 0xdeadbeef_u32;
283283

284-
assert!(hash(&val) != hash(&zero_byte(val, 0)));
285-
assert!(hash(&val) != hash(&zero_byte(val, 1)));
286-
assert!(hash(&val) != hash(&zero_byte(val, 2)));
287-
assert!(hash(&val) != hash(&zero_byte(val, 3)));
284+
assert_ne!(hash(&val), hash(&zero_byte(val, 0)));
285+
assert_ne!(hash(&val), hash(&zero_byte(val, 1)));
286+
assert_ne!(hash(&val), hash(&zero_byte(val, 2)));
287+
assert_ne!(hash(&val), hash(&zero_byte(val, 3)));
288288

289289
fn zero_byte(val: u32, byte: usize) -> u32 {
290290
assert!(byte < 4);
@@ -299,14 +299,17 @@ fn test_hash_no_concat_alias() {
299299
let u = ("a", "abb");
300300

301301
assert!(s != t && t != u);
302-
assert!(hash(&s) != hash(&t) && hash(&s) != hash(&u));
302+
assert_ne!(s, t);
303+
assert_ne!(t, u);
304+
assert_ne!(hash(&s), hash(&t));
305+
assert_ne!(hash(&s), hash(&u));
303306

304307
let u = [1, 0, 0, 0];
305308
let v = (&u[..1], &u[1..3], &u[3..]);
306309
let w = (&u[..], &u[4..4], &u[4..4]);
307310

308-
assert!(v != w);
309-
assert!(hash(&v) != hash(&w));
311+
assert_ne!(v, w);
312+
assert_ne!(hash(&v), hash(&w));
310313
}
311314

312315
#[test]

src/librustc/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl<'tcx> Arena<'tcx> {
250250

251251
#[inline]
252252
pub fn alloc_slice<T: Copy>(&self, value: &[T]) -> &mut [T] {
253-
if value.len() == 0 {
253+
if value.is_empty() {
254254
return &mut [];
255255
}
256256
self.dropless.alloc_slice(value)

src/librustc/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ impl DepGraph {
809809
dep_node
810810
);
811811

812-
if unlikely!(diagnostics.len() > 0) {
812+
if unlikely!(!diagnostics.is_empty()) {
813813
self.emit_diagnostics(tcx, data, dep_node_index, prev_dep_node_index, diagnostics);
814814
}
815815

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use smallvec::SmallVec;
1919
use std::cmp::Ord;
2020

2121
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
22-
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
22+
debug_assert!(!ich::IGNORED_ATTRIBUTES.is_empty());
2323
ich::IGNORED_ATTRIBUTES.iter().map(|&s| s).collect()
2424
}
2525

src/librustc/ich/impls_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'ctx> rustc_target::HashStableContext for StableHashingContext<'ctx> {}
1414

1515
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
1616
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
17-
if self.len() == 0 {
17+
if self.is_empty() {
1818
self.len().hash_stable(hcx, hasher);
1919
return;
2020
}

src/librustc/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'tcx> ConstEvalErr<'tcx> {
171171
// Skip the last, which is just the environment of the constant. The stacktrace
172172
// is sometimes empty because we create "fake" eval contexts in CTFE to do work
173173
// on constant values.
174-
if self.stacktrace.len() > 0 {
174+
if !self.stacktrace.is_empty() {
175175
for frame_info in &self.stacktrace[..self.stacktrace.len() - 1] {
176176
err.span_label(frame_info.call_site, frame_info.to_string());
177177
}

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
22192219
});
22202220
let region = if print_region {
22212221
let mut region = region.to_string();
2222-
if region.len() > 0 {
2222+
if !region.is_empty() {
22232223
region.push(' ');
22242224
}
22252225
region

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::borrow::Cow;
1818

1919
fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
2020
if def_id.is_top_level_module() {
21-
format!("top-level module")
21+
"top-level module".to_string()
2222
} else {
2323
format!("module `{}`", tcx.def_path_str(def_id))
2424
}

src/librustc/ty/context.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ impl<'tcx> TyCtxt<'tcx> {
24732473
// FIXME consider asking the input slice to be sorted to avoid
24742474
// re-interning permutations, in which case that would be asserted
24752475
// here.
2476-
if preds.len() == 0 {
2476+
if preds.is_empty() {
24772477
// The macro-generated method below asserts we don't intern an empty slice.
24782478
List::empty()
24792479
} else {
@@ -2482,31 +2482,31 @@ impl<'tcx> TyCtxt<'tcx> {
24822482
}
24832483

24842484
pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List<Ty<'tcx>> {
2485-
if ts.len() == 0 { List::empty() } else { self._intern_type_list(ts) }
2485+
if ts.is_empty() { List::empty() } else { self._intern_type_list(ts) }
24862486
}
24872487

24882488
pub fn intern_substs(self, ts: &[GenericArg<'tcx>]) -> &'tcx List<GenericArg<'tcx>> {
2489-
if ts.len() == 0 { List::empty() } else { self._intern_substs(ts) }
2489+
if ts.is_empty() { List::empty() } else { self._intern_substs(ts) }
24902490
}
24912491

24922492
pub fn intern_projs(self, ps: &[ProjectionKind]) -> &'tcx List<ProjectionKind> {
2493-
if ps.len() == 0 { List::empty() } else { self._intern_projs(ps) }
2493+
if ps.is_empty() { List::empty() } else { self._intern_projs(ps) }
24942494
}
24952495

24962496
pub fn intern_place_elems(self, ts: &[PlaceElem<'tcx>]) -> &'tcx List<PlaceElem<'tcx>> {
2497-
if ts.len() == 0 { List::empty() } else { self._intern_place_elems(ts) }
2497+
if ts.is_empty() { List::empty() } else { self._intern_place_elems(ts) }
24982498
}
24992499

25002500
pub fn intern_canonical_var_infos(self, ts: &[CanonicalVarInfo]) -> CanonicalVarInfos<'tcx> {
2501-
if ts.len() == 0 { List::empty() } else { self._intern_canonical_var_infos(ts) }
2501+
if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) }
25022502
}
25032503

25042504
pub fn intern_clauses(self, ts: &[Clause<'tcx>]) -> Clauses<'tcx> {
2505-
if ts.len() == 0 { List::empty() } else { self._intern_clauses(ts) }
2505+
if ts.is_empty() { List::empty() } else { self._intern_clauses(ts) }
25062506
}
25072507

25082508
pub fn intern_goals(self, ts: &[Goal<'tcx>]) -> Goals<'tcx> {
2509-
if ts.len() == 0 { List::empty() } else { self._intern_goals(ts) }
2509+
if ts.is_empty() { List::empty() } else { self._intern_goals(ts) }
25102510
}
25112511

25122512
pub fn mk_fn_sig<I>(

src/librustc/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<'tcx> Instance<'tcx> {
314314
) -> Option<Instance<'tcx>> {
315315
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
316316
let fn_sig = tcx.fn_sig(def_id);
317-
let is_vtable_shim = fn_sig.inputs().skip_binder().len() > 0
317+
let is_vtable_shim = !fn_sig.inputs().skip_binder().is_empty()
318318
&& fn_sig.input(0).skip_binder().is_param(0)
319319
&& tcx.generics_of(def_id).has_self;
320320
if is_vtable_shim {

src/librustc/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
798798
// (Typechecking will reject discriminant-sizing attrs.)
799799

800800
let v = present_first.unwrap();
801-
let kind = if def.is_enum() || variants[v].len() == 0 {
801+
let kind = if def.is_enum() || variants[v].is_empty() {
802802
StructKind::AlwaysSized
803803
} else {
804804
let param_env = tcx.param_env(def.did);

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl<T: Copy> List<T> {
698698
fn from_arena<'tcx>(arena: &'tcx Arena<'tcx>, slice: &[T]) -> &'tcx List<T> {
699699
assert!(!mem::needs_drop::<T>());
700700
assert!(mem::size_of::<T>() != 0);
701-
assert!(slice.len() != 0);
701+
assert!(!slice.is_empty());
702702

703703
// Align up the size of the len (usize) field
704704
let align = mem::align_of::<T>();

src/librustc_ast_lowering/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
229229
err.span_label(data.span, "only `Fn` traits may use parentheses");
230230
if let Ok(snippet) = self.sess.source_map().span_to_snippet(data.span) {
231231
// Do not suggest going from `Trait()` to `Trait<>`
232-
if data.inputs.len() > 0 {
232+
if !data.inputs.is_empty() {
233233
if let Some(split) = snippet.find('(') {
234234
let trait_name = &snippet[0..split];
235235
let args = &snippet[split + 1..snippet.len() - 1];

src/librustc_ast_pretty/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ impl<'a> PrintState<'a> for State<'a> {
791791
s.print_generic_arg(generic_arg)
792792
});
793793

794-
let mut comma = data.args.len() != 0;
794+
let mut comma = !data.args.is_empty();
795795

796796
for constraint in data.constraints.iter() {
797797
if comma {

src/librustc_attr/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
5353
err.span_suggestion(
5454
span,
5555
"consider removing the prefix",
56-
format!("{}", &lint_str[1..]),
56+
lint_str[1..].to_string(),
5757
Applicability::MaybeIncorrect,
5858
);
5959
}

src/librustc_builtin_macros/concat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn expand_concat(
4949
}
5050
}
5151
}
52-
if missing_literal.len() > 0 {
52+
if !missing_literal.is_empty() {
5353
let mut err = cx.struct_span_err(missing_literal, "expected a literal");
5454
err.note("only literals (like `\"foo\"`, `42` and `3.14`) can be passed to `concat!()`");
5555
err.emit();

src/librustc_builtin_macros/deriving/generic/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,14 @@ impl<'a> TraitDef<'a> {
588588
span: self.span,
589589
bound_generic_params: wb.bound_generic_params.clone(),
590590
bounded_ty: wb.bounded_ty.clone(),
591-
bounds: wb.bounds.iter().cloned().collect(),
591+
bounds: wb.bounds.to_vec(),
592592
})
593593
}
594594
ast::WherePredicate::RegionPredicate(ref rb) => {
595595
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
596596
span: self.span,
597597
lifetime: rb.lifetime,
598-
bounds: rb.bounds.iter().cloned().collect(),
598+
bounds: rb.bounds.to_vec(),
599599
})
600600
}
601601
ast::WherePredicate::EqPredicate(ref we) => {

src/librustc_builtin_macros/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ pub fn expand_preparsed_format_args(
10961096
cx.str_pieces.push(s);
10971097
}
10981098

1099-
if cx.invalid_refs.len() >= 1 {
1099+
if !cx.invalid_refs.is_empty() {
11001100
cx.report_invalid_references(numbered_position_args);
11011101
}
11021102

src/librustc_codegen_llvm/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ fn fat_lto(
237237
let module: ModuleCodegen<ModuleLlvm> = match costliest_module {
238238
Some((_cost, i)) => in_memory.remove(i),
239239
None => {
240-
assert!(serialized_modules.len() > 0, "must have at least one serialized module");
240+
assert!(!serialized_modules.is_empty(), "must have at least one serialized module");
241241
let (buffer, name) = serialized_modules.remove(0);
242242
info!("no in-memory regular modules to choose from, parsing {:?}", name);
243243
ModuleCodegen {

src/librustc_codegen_llvm/llvm_util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ unsafe fn configure_llvm(sess: &Session) {
6161
let sess_args = cg_opts.chain(tg_opts);
6262

6363
let user_specified_args: FxHashSet<_> =
64-
sess_args.clone().map(|s| llvm_arg_to_arg_name(s)).filter(|s| s.len() > 0).collect();
64+
sess_args.clone().map(|s| llvm_arg_to_arg_name(s)).filter(|s| !s.is_empty()).collect();
6565

6666
{
6767
// This adds the given argument to LLVM. Unless `force` is true

src/librustc_codegen_ssa/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1524,12 +1524,12 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
15241524
for &(cnum, _) in deps.iter().rev() {
15251525
if let Some(missing) = info.missing_lang_items.get(&cnum) {
15261526
end_with.extend(missing.iter().cloned());
1527-
if end_with.len() > 0 && group_end.is_none() {
1527+
if !end_with.is_empty() && group_end.is_none() {
15281528
group_end = Some(cnum);
15291529
}
15301530
}
15311531
end_with.retain(|item| info.lang_item_to_crate.get(item) != Some(&cnum));
1532-
if end_with.len() == 0 && group_end.is_some() {
1532+
if end_with.is_empty() && group_end.is_some() {
15331533
group_start = Some(cnum);
15341534
break;
15351535
}

src/librustc_codegen_ssa/back/write.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1244,11 +1244,11 @@ fn start_executing_work<B: ExtraBackendMethods>(
12441244
while !codegen_done
12451245
|| running > 0
12461246
|| (!codegen_aborted
1247-
&& (work_items.len() > 0
1248-
|| needs_fat_lto.len() > 0
1249-
|| needs_thin_lto.len() > 0
1250-
|| lto_import_only_modules.len() > 0
1251-
|| main_thread_worker_state != MainThreadWorkerState::Idle))
1247+
&& !(work_items.is_empty()
1248+
&& needs_fat_lto.is_empty()
1249+
&& needs_thin_lto.is_empty()
1250+
&& lto_import_only_modules.is_empty()
1251+
&& main_thread_worker_state == MainThreadWorkerState::Idle))
12521252
{
12531253
// While there are still CGUs to be codegened, the coordinator has
12541254
// to decide how to utilize the compiler processes implicit Token:
@@ -1289,7 +1289,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
12891289
// Perform the serial work here of figuring out what we're
12901290
// going to LTO and then push a bunch of work items onto our
12911291
// queue to do LTO
1292-
if work_items.len() == 0
1292+
if work_items.is_empty()
12931293
&& running == 0
12941294
&& main_thread_worker_state == MainThreadWorkerState::Idle
12951295
{
@@ -1354,7 +1354,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
13541354

13551355
// Spin up what work we can, only doing this while we've got available
13561356
// parallelism slots and work left to spawn.
1357-
while !codegen_aborted && work_items.len() > 0 && running < tokens.len() {
1357+
while !codegen_aborted && !work_items.is_empty() && running < tokens.len() {
13581358
let (item, _) = work_items.pop().unwrap();
13591359

13601360
maybe_start_llvm_timer(prof, cgcx.config(item.module_kind()), &mut llvm_start_time);

src/librustc_data_structures/profiling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl SelfProfiler {
425425
}
426426

427427
// Warn about any unknown event names
428-
if unknown_events.len() > 0 {
428+
if !unknown_events.is_empty() {
429429
unknown_events.sort();
430430
unknown_events.dedup();
431431

0 commit comments

Comments
 (0)