Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use ExactSizeIterator + TrustedLen instead of num_cases arg for switch
  • Loading branch information
bjorn3 committed Mar 29, 2019
commit 35705dee7eb10783280e0be92aedfc187e019dd2
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use rustc_codegen_ssa::mir::place::PlaceRef;
use std::borrow::Cow;
use std::ops::{Deref, Range};
use std::ptr;
use std::iter::TrustedLen;

// All Builders must have an llfn associated with them
#[must_use]
Expand Down Expand Up @@ -169,11 +170,10 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
&mut self,
v: &'ll Value,
else_llbb: &'ll BasicBlock,
num_cases: usize,
cases: impl Iterator<Item = (u128, &'ll BasicBlock)>,
cases: impl ExactSizeIterator<Item = (u128, &'ll BasicBlock)> + TrustedLen,
) {
let switch = unsafe {
llvm::LLVMBuildSwitch(self.llbuilder, v, else_llbb, num_cases as c_uint)
llvm::LLVMBuildSwitch(self.llbuilder, v, else_llbb, cases.len() as c_uint)
};
for (on_val, dest) in cases {
let on_val = self.const_uint_big(self.val_ty(v), on_val);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#![feature(concat_idents)]
#![feature(link_args)]
#![feature(static_nobundle)]
#![feature(trusted_len)]
#![deny(rust_2018_idioms)]
#![allow(explicit_outlives_requirements)]

Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![feature(try_blocks)]
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![feature(trusted_len)]
#![allow(unused_attributes)]
#![allow(dead_code)]
#![deny(rust_2018_idioms)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.switch(
discr.immediate(),
helper.llblock(self, *otherwise),
values.len(),
values.iter().zip(targets).map(|(&value, target)| {
(value, helper.llblock(self, *target))
})
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/traits/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::MemFlags;
use rustc::ty::Ty;
use rustc::ty::layout::{Align, Size};
use std::ops::Range;
use std::iter::TrustedLen;

#[derive(Copy, Clone)]
pub enum OverflowOp {
Expand Down Expand Up @@ -49,8 +50,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
&mut self,
v: Self::Value,
else_llbb: Self::BasicBlock,
num_cases: usize,
cases: impl Iterator<Item = (u128, Self::BasicBlock)>,
cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)> + TrustedLen,
);
fn invoke(
&mut self,
Expand Down