Handle 'TypeRelative' qualified paths in lints.

Fixes #367.
This commit is contained in:
Sergio Benitez 2017-08-02 02:40:37 -07:00
parent 84fe23a9fb
commit 72bed509b9
2 changed files with 22 additions and 2 deletions

View File

@ -37,13 +37,15 @@ struct InstanceInfo {
enum Receiver { enum Receiver {
Instance(DefId, Span), Instance(DefId, Span),
Call(NodeId, Span), Call(NodeId, Span),
Relative(Span),
} }
impl Receiver { impl Receiver {
/// Returns the span associated with the receiver. /// Returns the span associated with the receiver.
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
use self::Receiver::*;
match *self { match *self {
Receiver::Instance(_, sp) | Receiver::Call(_, sp) => sp Instance(_, sp) | Call(_, sp) | Relative(sp) => sp
} }
} }
} }
@ -152,8 +154,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RocketLint {
.and_then(|id| lint.instance_vars.get(&id)) .and_then(|id| lint.instance_vars.get(&id))
.map(|recvr| recvr.clone()) .map(|recvr| recvr.clone())
} }
ExprPath(QPath::TypeRelative(_, _)) => {
Some(Receiver::Relative(rexpr.span))
}
ExprCall(ref c, ..) => Some(Receiver::Call(c.id, rexpr.span)), ExprCall(ref c, ..) => Some(Receiver::Call(c.id, rexpr.span)),
_ => unreachable!() _ => panic!("Unexpected node: {:?}", rexpr.node)
} }
}; };

View File

@ -67,4 +67,19 @@ fn main() {
.manage(MyType) .manage(MyType)
.manage(100i32) .manage(100i32)
.manage(100u32); .manage(100u32);
let config = rocket::Config::development().unwrap();
// Ensure unresolved paths are handled properly by lint.
rocket::Rocket::custom(config, false)
.mount("/", routes![managed, unmanaged, external::unmanaged])
.mount("/", routes![managed_two, ignored, mounted_only_once])
.mount("/", routes![external::managed, external::unmanaged_unmounted])
.mount("/", routes![unmounted_doesnt_error, managed_two])
.manage(MyType)
.manage(MySecondType)
.manage(100i32)
.manage(100u32)
.manage(1u8)
.manage(1i8);
} }