mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-18 02:38:28 +00:00
Merge pull request #200 from Manishearth/consts
more small const improvements
This commit is contained in:
commit
7ddc402127
1 changed files with 5 additions and 11 deletions
|
@ -300,8 +300,8 @@ impl<'c, 'cc> ConstEvalContext<'c, 'cc> {
|
|||
ExprIf(ref cond, ref then, ref otherwise) =>
|
||||
self.ifthenelse(&*cond, &*then, &*otherwise),
|
||||
ExprLit(ref lit) => Some(lit_to_constant(&lit.node)),
|
||||
ExprVec(ref vec) => self.vec(&vec),
|
||||
ExprTup(ref tup) => self.tup(&tup),
|
||||
ExprVec(ref vec) => self.multi(vec).map(ConstantVec),
|
||||
ExprTup(ref tup) => self.multi(tup).map(ConstantTuple),
|
||||
ExprRepeat(ref value, ref number) =>
|
||||
self.binop_apply(value, number, |v, n|
|
||||
Some(ConstantRepeat(Box::new(v), n.as_u64() as usize))),
|
||||
|
@ -318,18 +318,12 @@ impl<'c, 'cc> ConstEvalContext<'c, 'cc> {
|
|||
}
|
||||
}
|
||||
|
||||
/// create `Some(ConstantVec(..))` of all constants, unless there is any
|
||||
/// create `Some(Vec![..])` of all constants, unless there is any
|
||||
/// non-constant part
|
||||
fn vec<E: Deref<Target=Expr> + Sized>(&mut self, vec: &[E]) -> Option<Constant> {
|
||||
fn multi<E: Deref<Target=Expr> + Sized>(&mut self, vec: &[E]) ->
|
||||
Option<Vec<Constant>> {
|
||||
vec.iter().map(|elem| self.expr(elem))
|
||||
.collect::<Option<_>>()
|
||||
.map(ConstantVec)
|
||||
}
|
||||
|
||||
fn tup<E: Deref<Target=Expr> + Sized>(&mut self, tup: &[E]) -> Option<Constant> {
|
||||
tup.iter().map(|elem| self.expr(elem))
|
||||
.collect::<Option<_>>()
|
||||
.map(ConstantTuple)
|
||||
}
|
||||
|
||||
/// lookup a possibly constant expression from a ExprPath
|
||||
|
|
Loading…
Reference in a new issue