Support legacy '#[error]' and 'errors!' macros.

Their use now emits a deprecation warning.

Fixes #419.
This commit is contained in:
Philip Jenvey 2018-06-28 15:27:14 -07:00 committed by Sergio Benitez
parent 48b1491f8f
commit 9ac9cd462d
4 changed files with 47 additions and 0 deletions

View File

@ -98,3 +98,17 @@ pub fn catch_decorator(
output
}
pub fn error_decorator(
ecx: &mut ExtCtxt,
sp: Span,
meta_item: &MetaItem,
annotated: Annotatable
) -> Vec<Annotatable> {
ecx.struct_span_warn(sp, "use of deprecated Rocket attribute `error` \
(deprecated since v0.3.15)")
.help("the `error` attribute was replaced by the `catch` attribute: \
`#[catch(..)]`")
.emit();
catch_decorator(ecx, sp, meta_item, annotated)
}

View File

@ -199,6 +199,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
}
reg.register_macro("routes", macros::routes);
reg.register_macro("errors", macros::errors);
reg.register_macro("catchers", macros::catchers);
register_derives!(reg,
@ -206,6 +207,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
);
register_decorators!(reg,
"error" => error_decorator,
"catch" => catch_decorator,
"route" => route_decorator,
"get" => get_decorator,

View File

@ -60,3 +60,14 @@ pub fn catchers(ecx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
quote_expr!(ecx, rocket::Catcher::from(&$path))
}, ecx, sp, args)
}
#[rustfmt_skip]
pub fn errors(ecx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
-> Box<MacResult + 'static> {
ecx.struct_span_warn(sp, "use of deprecated Rocket macro `errors` \
(deprecated since v0.3.15)")
.help("the `errors` macro was replaced by the `catchers` macro: \
`catchers![..]`")
.emit();
catchers(ecx, sp, args)
}

View File

@ -0,0 +1,20 @@
// must-compile-successfully
#![feature(plugin)]
#![plugin(rocket_codegen)]
extern crate rocket;
use rocket::response::content;
#[error(404)]
//~^ WARNING use of deprecated Rocket attribute `error` (deprecated since v0.3.15)
fn not_found(req: &rocket::Request) -> content::Html<String> {
content::Html(format!("<p>whappen?</p>"))
}
fn main() {
let e = rocket::ignite()
.catch(errors![not_found])
//~^ WARNING use of deprecated Rocket macro `errors` (deprecated since v0.3.15)
.launch();
}