Skip to content

Commit c8db7dc

Browse files
authored
Rollup merge of #69551 - matthiaskrgr:len_zero, r=Mark-Simulacrum
use is_empty() instead of len() == x to determine if structs are empty.
2 parents ba2df27 + 1622b6e commit c8db7dc

File tree

54 files changed

+76
-76
lines changed

Some content is hidden

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

54 files changed

+76
-76
lines changed

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/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/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_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/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

src/librustc_errors/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ pub trait Emitter {
231231
].contains(&sugg.style)
232232
{
233233
let substitution = &sugg.substitutions[0].parts[0].snippet.trim();
234-
let msg = if substitution.len() == 0 || sugg.style.hide_inline() {
234+
let msg = if substitution.is_empty() || sugg.style.hide_inline() {
235235
// This substitution is only removal OR we explicitly don't want to show the
236236
// code inline (`hide_inline`). Therefore, we don't show the substitution.
237237
format!("help: {}", sugg.msg)

src/librustc_errors/snippet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl Annotation {
152152
// |
153153
//
154154
// Note that this would be the complete output users would see.
155-
label.len() > 0
155+
!label.is_empty()
156156
} else {
157157
false
158158
}

src/librustc_infer/infer/canonical/query_response.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
421421
for _ in num_universes_in_query..num_universes_in_response {
422422
universe_map.push(self.create_next_universe());
423423
}
424-
assert!(universe_map.len() >= 1); // always have the root universe
424+
assert!(!universe_map.is_empty()); // always have the root universe
425425
assert_eq!(universe_map[ty::UniverseIndex::ROOT.as_usize()], ty::UniverseIndex::ROOT);
426426

427427
// Every canonical query result includes values for each of

src/librustc_infer/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
587587

588588
// skip no-op cases known to be satisfied
589589
if let VerifyBound::AllBounds(ref bs) = verify.bound {
590-
if bs.len() == 0 {
590+
if bs.is_empty() {
591591
return;
592592
}
593593
}

src/librustc_infer/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
440440
/// going to help).
441441
pub fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> ! {
442442
let cycle = self.resolve_vars_if_possible(&cycle.to_owned());
443-
assert!(cycle.len() > 0);
443+
assert!(!cycle.is_empty());
444444

445445
debug!("report_overflow_error_cycle: cycle={:?}", cycle);
446446

src/librustc_infer/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2157,7 +2157,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21572157
debug!("builtin_bound: nested={:?}", nested);
21582158
candidates
21592159
.vec
2160-
.push(BuiltinCandidate { has_nested: nested.skip_binder().len() > 0 });
2160+
.push(BuiltinCandidate { has_nested: !nested.skip_binder().is_empty() });
21612161
}
21622162
BuiltinImplConditions::None => {}
21632163
BuiltinImplConditions::Ambiguous => {

src/librustc_lint/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl<'s> LintLevelsBuilder<'s> {
375375
}
376376

377377
let prev = self.cur;
378-
if specs.len() > 0 {
378+
if !specs.is_empty() {
379379
self.cur = self.sets.list.len() as u32;
380380
self.sets.list.push(LintSet::Node { specs: specs, parent: prev });
381381
}

src/librustc_metadata/dependency_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ fn activate_injected_dep(
339339
// there's only going to be one allocator in the output.
340340
fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) {
341341
let sess = &tcx.sess;
342-
if list.len() == 0 {
342+
if list.is_empty() {
343343
return;
344344
}
345345
let mut panic_runtime = None;

src/librustc_mir/interpret/eval_context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
264264

265265
#[inline(always)]
266266
pub fn cur_frame(&self) -> usize {
267-
assert!(self.stack.len() > 0);
267+
assert!(!self.stack.is_empty());
268268
self.stack.len() - 1
269269
}
270270

@@ -505,7 +505,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
505505
return_place: Option<PlaceTy<'tcx, M::PointerTag>>,
506506
return_to_block: StackPopCleanup,
507507
) -> InterpResult<'tcx> {
508-
if self.stack.len() > 0 {
508+
if !self.stack.is_empty() {
509509
info!("PAUSING({}) {}", self.cur_frame(), self.frame().instance);
510510
}
511511
::log_settings::settings().indentation += 1;
@@ -698,7 +698,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
698698
}
699699
}
700700

701-
if self.stack.len() > 0 {
701+
if !self.stack.is_empty() {
702702
info!(
703703
"CONTINUING({}) {} (unwinding = {})",
704704
self.cur_frame(),

src/librustc_mir/transform/uninhabited_enum_branching.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn get_switched_on_type<'tcx>(
2828

2929
// Only bother checking blocks which terminate by switching on a local.
3030
if let Some(local) = get_discriminant_local(&terminator.kind) {
31-
let stmt_before_term = (block_data.statements.len() > 0)
31+
let stmt_before_term = (!block_data.statements.is_empty())
3232
.then(|| &block_data.statements[block_data.statements.len() - 1].kind);
3333

3434
if let Some(StatementKind::Assign(box (l, Rvalue::Discriminant(place)))) = stmt_before_term

src/librustc_mir/util/elaborate_drops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ where
369369

370370
fn open_drop_for_adt(&mut self, adt: &'tcx ty::AdtDef, substs: SubstsRef<'tcx>) -> BasicBlock {
371371
debug!("open_drop_for_adt({:?}, {:?}, {:?})", self, adt, substs);
372-
if adt.variants.len() == 0 {
372+
if adt.variants.is_empty() {
373373
return self.elaborator.patch().new_block(BasicBlockData {
374374
statements: vec![],
375375
terminator: Some(Terminator {

src/librustc_mir/util/patch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> MirPatch<'tcx> {
3737
let mut resume_stmt_block = None;
3838
for (bb, block) in body.basic_blocks().iter_enumerated() {
3939
if let TerminatorKind::Resume = block.terminator().kind {
40-
if block.statements.len() > 0 {
40+
if !block.statements.is_empty() {
4141
assert!(resume_stmt_block.is_none());
4242
resume_stmt_block = Some(bb);
4343
} else {

src/librustc_mir_build/build/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14381438
let target_blocks: Vec<_> = target_candidates
14391439
.into_iter()
14401440
.map(|mut candidates| {
1441-
if candidates.len() != 0 {
1441+
if !candidates.is_empty() {
14421442
let candidate_start = this.cfg.start_new_block();
14431443
this.match_candidates(
14441444
span,

0 commit comments

Comments
 (0)