Skip to content

Commit 35705de

Browse files
committed
Use ExactSizeIterator + TrustedLen instead of num_cases arg for switch
1 parent 56842b2 commit 35705de

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

src/librustc_codegen_llvm/builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_codegen_ssa::mir::place::PlaceRef;
2121
use std::borrow::Cow;
2222
use std::ops::{Deref, Range};
2323
use std::ptr;
24+
use std::iter::TrustedLen;
2425

2526
// All Builders must have an llfn associated with them
2627
#[must_use]
@@ -169,11 +170,10 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
169170
&mut self,
170171
v: &'ll Value,
171172
else_llbb: &'ll BasicBlock,
172-
num_cases: usize,
173-
cases: impl Iterator<Item = (u128, &'ll BasicBlock)>,
173+
cases: impl ExactSizeIterator<Item = (u128, &'ll BasicBlock)> + TrustedLen,
174174
) {
175175
let switch = unsafe {
176-
llvm::LLVMBuildSwitch(self.llbuilder, v, else_llbb, num_cases as c_uint)
176+
llvm::LLVMBuildSwitch(self.llbuilder, v, else_llbb, cases.len() as c_uint)
177177
};
178178
for (on_val, dest) in cases {
179179
let on_val = self.const_uint_big(self.val_ty(v), on_val);

src/librustc_codegen_llvm/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(concat_idents)]
2121
#![feature(link_args)]
2222
#![feature(static_nobundle)]
23+
#![feature(trusted_len)]
2324
#![deny(rust_2018_idioms)]
2425
#![allow(explicit_outlives_requirements)]
2526

src/librustc_codegen_ssa/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![feature(try_blocks)]
1111
#![feature(in_band_lifetimes)]
1212
#![feature(nll)]
13+
#![feature(trusted_len)]
1314
#![allow(unused_attributes)]
1415
#![allow(dead_code)]
1516
#![deny(rust_2018_idioms)]

src/librustc_codegen_ssa/mir/block.rs

-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
217217
bx.switch(
218218
discr.immediate(),
219219
helper.llblock(self, *otherwise),
220-
values.len(),
221220
values.iter().zip(targets).map(|(&value, target)| {
222221
(value, helper.llblock(self, *target))
223222
})

src/librustc_codegen_ssa/traits/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::MemFlags;
1212
use rustc::ty::Ty;
1313
use rustc::ty::layout::{Align, Size};
1414
use std::ops::Range;
15+
use std::iter::TrustedLen;
1516

1617
#[derive(Copy, Clone)]
1718
pub enum OverflowOp {
@@ -49,8 +50,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
4950
&mut self,
5051
v: Self::Value,
5152
else_llbb: Self::BasicBlock,
52-
num_cases: usize,
53-
cases: impl Iterator<Item = (u128, Self::BasicBlock)>,
53+
cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)> + TrustedLen,
5454
);
5555
fn invoke(
5656
&mut self,

0 commit comments

Comments
 (0)