mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
Use ExactSizeIterator + TrustedLen instead of num_cases arg for switch
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
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]
|
||||
@@ -169,11 +170,10 @@ fn switch(
|
||||
&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);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#![feature(concat_idents)]
|
||||
#![feature(link_args)]
|
||||
#![feature(static_nobundle)]
|
||||
#![feature(trusted_len)]
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![allow(explicit_outlives_requirements)]
|
||||
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -217,7 +217,6 @@ fn codegen_switchint_terminator<'b>(
|
||||
bx.switch(
|
||||
discr.immediate(),
|
||||
helper.llblock(self, *otherwise),
|
||||
values.len(),
|
||||
values.iter().zip(targets).map(|(&value, target)| {
|
||||
(value, helper.llblock(self, *target))
|
||||
})
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
use rustc::ty::Ty;
|
||||
use rustc::ty::layout::{Align, Size};
|
||||
use std::ops::Range;
|
||||
use std::iter::TrustedLen;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum OverflowOp {
|
||||
@@ -49,8 +50,7 @@ fn switch(
|
||||
&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,
|
||||
|
||||
Reference in New Issue
Block a user