Fix false positives in unmounted_routes lint due to 'launch'.

This commit is contained in:
Sergio Benitez 2017-02-05 02:11:32 -08:00
parent 0b69a5d8f7
commit 92f22ca63b
3 changed files with 49 additions and 4 deletions

View File

@ -180,10 +180,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RocketLint {
}
}
if let Some((recvr, _)) = rocket_method_call("launch", cx, expr) {
let instance = recvr.and_then(|r| instance_for(self, r));
self.instances.entry(instance)
.or_insert_with(|| InstanceInfo::default());
// This captures a corner case where neither `manage` nor `mount` is
// called on an instance.
if let Some((Some(recvr_expr), _)) = rocket_method_call("launch", cx, expr) {
if let Some(instance) = instance_for(self, recvr_expr) {
self.instances.entry(Some(instance))
.or_insert_with(|| InstanceInfo::default());
}
}
}

View File

@ -0,0 +1,14 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
#![allow(dead_code)]
#![deny(unmounted_route)]
extern crate rocket;
#[get("/")]
fn index() { }
//~^ ERROR is not mounted
fn main() {
rocket::ignite().launch();
}

View File

@ -0,0 +1,28 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
#![allow(dead_code, unused_variables)]
#![deny(unmounted_routes, unmanaged_state)]
extern crate rocket;
use rocket::{Rocket, State};
#[get("/")]
fn index(state: State<u32>) { }
fn rocket() -> Rocket {
rocket::ignite()
.mount("/", routes![index])
.manage(100u32)
}
fn main() {
if false {
rocket().launch();
}
let instance = rocket();
if false {
instance.launch();
}
}