diff --git a/src/consts.rs b/src/consts.rs index c8d5262abab..fd6479df299 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,6 +1,4 @@ -#[cfg(test)] use rustc::lint::Context; - use rustc::middle::const_eval::lookup_const_by_id; use rustc::middle::def::PathResolution; use rustc::middle::def::Def::*; @@ -12,9 +10,6 @@ use std::ops::Deref; use self::ConstantVariant::*; use self::FloatWidth::*; -#[cfg(not(test))] -pub struct Context; - #[derive(PartialEq, Eq, Debug, Copy, Clone)] pub enum FloatWidth { Fw32, @@ -33,8 +28,8 @@ impl From for FloatWidth { #[derive(PartialEq, Eq, Debug, Clone)] pub struct Constant { - constant: ConstantVariant, - needed_resolution: bool + pub constant: ConstantVariant, + pub needed_resolution: bool } impl Constant { @@ -187,11 +182,7 @@ fn constant_tup + Sized>(cx: &Context, tup: &[E]) -> Optio }) } -#[cfg(test)] -fn fetch_path(_cx: &Context, _expr: &Expr) -> Option { None } - /// lookup a possibly constant expression from a ExprPath -#[cfg(not(test))] fn fetch_path(cx: &Context, e: &Expr) -> Option { if let Some(&PathResolution { base_def: DefConst(id), ..}) = cx.tcx.def_map.borrow().get(&e.id) { diff --git a/tests/consts.rs b/tests/consts.rs index edbbfa1e2db..db309952be4 100644 --- a/tests/consts.rs +++ b/tests/consts.rs @@ -1,11 +1,34 @@ +#![allow(plugin_as_library)] +#![feature(rustc_private)] extern crate clippy; +extern crate syntax; +extern crate rustc; -use clippy::consts; +use clippy::consts::constant; +use clippy::consts::ConstantVariant::*; use syntax::ast::*; +use syntax::ptr::P; +use syntax::codemap::{Spanned, COMMAND_LINE_SP}; +use std::mem; +use rustc::lint::Context; + +fn ctx() -> &'static Context<'static, 'static> { + unsafe { + let x : *const Context<'static, 'static> = std::ptr::null(); + mem::transmute(x) + } +} #[test] fn test_lit() { - assert_eq!(ConstantBool(true), constant(&Context, - Expr{ node_id: 1, node: ExprLit(LitBool(true)), span: default() })); + assert_eq!(Some(ConstantBool(true)), constant(ctx(), + &Expr{ + id: 1, + node: ExprLit(P(Spanned{ + node: LitBool(true), + span: COMMAND_LINE_SP, + })), + span: COMMAND_LINE_SP, + }).map(|x| x.constant)); }