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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)