Improve missing argument compile-time error.

This commit is contained in:
Sergio Benitez 2017-08-22 01:01:57 -07:00
parent 89443bcdf0
commit c5890934c0
3 changed files with 20 additions and 20 deletions

View File

@ -41,10 +41,10 @@ fn media_type_to_expr(ecx: &ExtCtxt, ct: Option<MediaType>) -> Option<P<Expr>> {
impl RouteParams {
fn missing_declared_err<T: Display>(&self, ecx: &ExtCtxt, arg: &Spanned<T>) {
let fn_span = self.annotated_fn.span();
let msg = format!("'{}' is declared as an argument...", arg.node);
ecx.span_err(arg.span, &msg);
ecx.span_err(fn_span, "...but isn't in the function signature.");
let (fn_span, fn_name) = (self.annotated_fn.span(), self.annotated_fn.ident());
ecx.struct_span_err(arg.span, &format!("unused dynamic parameter: `{}`", arg.node))
.span_note(fn_span, &format!("expected argument named `{}` in `{}`", arg.node, fn_name))
.emit();
}
fn gen_form(&self,

View File

@ -1,16 +1,16 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
#[get("/<name>")] //~ ERROR 'name' is declared
fn get(other: usize) -> &'static str { "hi" } //~ ERROR isn't in the function
#[get("/<name>")] //~ ERROR unused dynamic parameter: `name`
fn get(other: usize) -> &'static str { "hi" } //~ NOTE expected
#[get("/a?<r>")] //~ ERROR 'r' is declared
fn get1() -> &'static str { "hi" } //~ ERROR isn't in the function
#[get("/a?<r>")] //~ ERROR unused dynamic parameter: `r`
fn get1() -> &'static str { "hi" } //~ NOTE expected
#[post("/a", data = "<test>")] //~ ERROR 'test' is declared
fn post() -> &'static str { "hi" } //~ ERROR isn't in the function
#[post("/a", data = "<test>")] //~ ERROR unused dynamic parameter: `test`
fn post() -> &'static str { "hi" } //~ NOTE expected
#[get("/<_r>")] //~ ERROR '_r' is declared
fn get2(r: usize) -> &'static str { "hi" } //~ ERROR isn't in the function
#[get("/<_r>")] //~ ERROR unused dynamic parameter: `_r`
fn get2(r: usize) -> &'static str { "hi" } //~ NOTE expected
fn main() { }

View File

@ -1,17 +1,17 @@
#![feature(plugin)]
#![plugin(rocket_codegen)]
#[get("/<param>")] //~ ERROR declared
fn get() { } //~ ERROR isn't in the function signature
#[get("/<param>")] //~ ERROR unused dynamic parameter: `param`
fn get() { } //~ NOTE expected
#[get("/<a>")] //~ ERROR declared
fn get2() { } //~ ERROR isn't in the function signature
#[get("/<a>")] //~ ERROR unused dynamic parameter: `a`
fn get2() { } //~ NOTE expected
#[get("/a/b/c/<a>/<b>")]
//~^ ERROR 'a' is declared
//~^^ ERROR 'b' is declared
//~^ ERROR unused dynamic parameter: `a`
//~^^ ERROR unused dynamic parameter: `b`
fn get32() { }
//~^ ERROR isn't in the function signature
//~^^ ERROR isn't in the function signature
//~^ NOTE expected
//~^^ NOTE expected
fn main() { }