2015-08-16 15:56:09 +02:00
|
|
|
#![allow(plugin_as_library)]
|
|
|
|
#![feature(rustc_private)]
|
2015-08-14 17:14:54 +02:00
|
|
|
|
|
|
|
extern crate clippy;
|
2015-08-16 15:56:09 +02:00
|
|
|
extern crate syntax;
|
|
|
|
extern crate rustc;
|
2015-08-14 17:14:54 +02:00
|
|
|
|
2015-08-17 11:43:36 +02:00
|
|
|
use clippy::consts::{constant, ConstantVariant};
|
2015-08-16 15:56:09 +02:00
|
|
|
use clippy::consts::ConstantVariant::*;
|
2015-08-14 17:14:54 +02:00
|
|
|
use syntax::ast::*;
|
2015-08-16 15:56:09 +02:00
|
|
|
use syntax::ptr::P;
|
|
|
|
use syntax::codemap::{Spanned, COMMAND_LINE_SP};
|
|
|
|
use std::mem;
|
|
|
|
use rustc::lint::Context;
|
|
|
|
|
|
|
|
fn ctx() -> &'static Context<'static, 'static> {
|
2015-08-17 11:43:36 +02:00
|
|
|
unsafe {
|
|
|
|
let x : *const Context<'static, 'static> = std::ptr::null();
|
|
|
|
mem::transmute(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lit(l: Lit_) -> Expr {
|
|
|
|
Expr{
|
|
|
|
id: 1,
|
|
|
|
node: ExprLit(P(Spanned{
|
|
|
|
node: l,
|
|
|
|
span: COMMAND_LINE_SP,
|
|
|
|
})),
|
|
|
|
span: COMMAND_LINE_SP,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check(expect: ConstantVariant, expr: &Expr) {
|
|
|
|
assert_eq!(Some(expect), constant(ctx(), expr).map(|x| x.constant))
|
2015-08-16 15:56:09 +02:00
|
|
|
}
|
2015-08-14 17:14:54 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_lit() {
|
2015-08-17 11:43:36 +02:00
|
|
|
check(ConstantBool(true), &lit(LitBool(true)));
|
|
|
|
check(ConstantBool(false), &lit(LitBool(false)));
|
|
|
|
|
2015-08-14 17:14:54 +02:00
|
|
|
}
|