Skip to content

Commit 4efdb8b

Browse files
committed
Merge pull request #260 from nikomatsakis/master
Fix region errors uncovered by rust-lang/rust#27641
2 parents 3fd622f + ef248df commit 4efdb8b

File tree

8 files changed

+39
-33
lines changed

8 files changed

+39
-33
lines changed

src/favicon_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct FaviconHandler {
1919
}
2020

2121
impl Middleware for FaviconHandler {
22-
fn invoke<'a, 'b>(&'a self, req: &mut Request<'b, 'a, 'b>, res: Response<'a, net::Fresh>)
22+
fn invoke<'a, 'server>(&'a self, req: &mut Request<'a, 'server>, res: Response<'a, net::Fresh>)
2323
-> MiddlewareResult<'a> {
2424
if FaviconHandler::is_favicon_request(req) {
2525
self.handle_request(req, res)
@@ -78,7 +78,7 @@ impl FaviconHandler {
7878
}
7979
}
8080

81-
pub fn send_favicon<'a, 'b>(&self, req: &Request, mut res: Response<'a>) -> MiddlewareResult<'a> {
81+
pub fn send_favicon<'a, 'server>(&self, req: &Request, mut res: Response<'a>) -> MiddlewareResult<'a> {
8282
debug!("{:?} {:?}", req.origin.method, self.icon_path.display());
8383
res.set(MediaType::Ico);
8484
res.send(&*self.icon)

src/json_body_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::io::{Read, ErrorKind};
88
// Plugin boilerplate
99
struct JsonBodyParser;
1010
impl Key for JsonBodyParser { type Value = String; }
11-
impl<'a, 'b, 'k> Plugin<Request<'a, 'b, 'k>> for JsonBodyParser {
11+
impl<'mw, 'conn> Plugin<Request<'mw, 'conn>> for JsonBodyParser {
1212
type Error = io::Error;
1313

1414
fn eval(req: &mut Request) -> Result<String, io::Error> {
@@ -22,7 +22,7 @@ pub trait JsonBody {
2222
fn json_as<T: Decodable>(&mut self) -> Result<T, io::Error>;
2323
}
2424

25-
impl<'a, 'b, 'k> JsonBody for Request<'a, 'b, 'k> {
25+
impl<'mw, 'conn> JsonBody for Request<'mw, 'conn> {
2626
fn json_as<T: Decodable>(&mut self) -> Result<T, io::Error> {
2727
self.get_ref::<JsonBodyParser>().and_then(|parsed|
2828
json::decode::<T>(&*parsed).map_err(|err|

src/macros/middleware.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ macro_rules! _middleware_inner {
3838
use $crate::{MiddlewareResult,Responder, Response, Request};
3939

4040
#[inline(always)]
41-
fn restrict<'a, R: Responder>(r: R, res: Response<'a>)
42-
-> MiddlewareResult<'a> {
41+
fn restrict<'mw, R: Responder>(r: R, res: Response<'mw>)
42+
-> MiddlewareResult<'mw> {
4343
res.send(r)
4444
}
4545

4646
// Inference fails due to thinking it's a (&Request, Response) with
4747
// different mutability requirements
4848
#[inline(always)]
4949
fn restrict_closure<F>(f: F) -> F
50-
where F: for<'r, 'b, 'a>
51-
Fn(&'r mut Request<'b, 'a, 'b>, Response<'a>)
52-
-> MiddlewareResult<'a> + Send + Sync { f }
50+
where F: for<'r, 'mw, 'conn>
51+
Fn(&'r mut Request<'mw, 'conn>, Response<'mw>)
52+
-> MiddlewareResult<'mw> + Send + Sync { f }
5353

5454
restrict_closure(move |as_pat!($req), $res_binding| {
5555
restrict(as_block!({$($b)+}), $res)

src/middleware.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use hyper::net;
55

66
pub use self::Action::{Continue, Halt};
77

8-
pub type MiddlewareResult<'a> = Result<Action<Response<'a, net::Fresh>,
9-
Response<'a, net::Streaming>>,
10-
NickelError<'a>>;
8+
pub type MiddlewareResult<'mw> = Result<Action<Response<'mw, net::Fresh>,
9+
Response<'mw, net::Streaming>>,
10+
NickelError<'mw>>;
1111

1212
pub enum Action<T=(), U=()> {
1313
Continue(T),
@@ -17,13 +17,13 @@ pub enum Action<T=(), U=()> {
1717
// the usage of + Send is weird here because what we really want is + Static
1818
// but that's not possible as of today. We have to use + Send for now.
1919
pub trait Middleware: Send + 'static + Sync {
20-
fn invoke<'a, 'b>(&'a self, _req: &mut Request<'b, 'a, 'b>, res: Response<'a, net::Fresh>) -> MiddlewareResult<'a> {
20+
fn invoke<'mw, 'conn>(&'mw self, _req: &mut Request<'mw, 'conn>, res: Response<'mw, net::Fresh>) -> MiddlewareResult<'mw> {
2121
Ok(Continue(res))
2222
}
2323
}
2424

25-
impl<T> Middleware for T where T: for<'r, 'b, 'a> Fn(&'r mut Request<'b, 'a, 'b>, Response<'a>) -> MiddlewareResult<'a> + Send + Sync + 'static {
26-
fn invoke<'a, 'b>(&'a self, req: &mut Request<'b, 'a, 'b>, res: Response<'a>) -> MiddlewareResult<'a> {
25+
impl<T> Middleware for T where T: for<'r, 'mw, 'conn> Fn(&'r mut Request<'mw, 'conn>, Response<'mw>) -> MiddlewareResult<'mw> + Send + Sync + 'static {
26+
fn invoke<'mw, 'conn>(&'mw self, req: &mut Request<'mw, 'conn>, res: Response<'mw>) -> MiddlewareResult<'mw> {
2727
(*self)(req, res)
2828
}
2929
}
@@ -52,7 +52,7 @@ impl MiddlewareStack {
5252
self.error_handlers.push(Box::new(handler));
5353
}
5454

55-
pub fn invoke<'a, 'b>(&'a self, mut req: Request<'a, 'a, 'b>, mut res: Response<'a>) {
55+
pub fn invoke<'mw, 'conn>(&'mw self, mut req: Request<'mw, 'conn>, mut res: Response<'mw>) {
5656
for handler in self.handlers.iter() {
5757
match handler.invoke(&mut req, res) {
5858
Ok(Halt(res)) => {

src/query_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Query {
3333
struct QueryStringParser;
3434
impl Key for QueryStringParser { type Value = Query; }
3535

36-
impl<'a, 'b, 'k> Plugin<Request<'a, 'b, 'k>> for QueryStringParser {
36+
impl<'mw, 'conn> Plugin<Request<'mw, 'conn>> for QueryStringParser {
3737
type Error = ();
3838

3939
fn eval(req: &mut Request) -> Result<Query, ()> {
@@ -46,7 +46,7 @@ pub trait QueryString {
4646
fn query(&mut self) -> &Query;
4747
}
4848

49-
impl<'a, 'b, 'k> QueryString for Request<'a, 'b, 'k> {
49+
impl<'mw, 'conn> QueryString for Request<'mw, 'conn> {
5050
fn query(&mut self) -> &Query {
5151
self.get_ref::<QueryStringParser>()
5252
.ok()

src/request.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ use typemap::TypeMap;
44
use hyper::server::Request as HyperRequest;
55
use hyper::uri::RequestUri::AbsolutePath;
66

7-
///A container for all the request data
8-
pub struct Request<'a, 'b: 'k, 'k: 'a> {
7+
/// A container for all the request data.
8+
///
9+
/// The lifetime `'mw` represents the lifetime of various bits of
10+
/// middleware state within nickel. It can vary and get shorter.
11+
///
12+
/// The lifetime `'server` represents the lifetime of data internal to
13+
/// the server. It is fixed and longer than `'mw`.
14+
pub struct Request<'mw, 'server: 'mw> {
915
///the original `hyper::server::Request`
10-
pub origin: HyperRequest<'a, 'k>,
16+
pub origin: HyperRequest<'mw, 'server>,
1117
///a `HashMap<String, String>` holding all params with names and values
12-
pub route_result: Option<RouteResult<'b>>,
18+
pub route_result: Option<RouteResult<'mw>>,
1319

1420
map: TypeMap
1521
}
1622

17-
impl<'a, 'b, 'k> Request<'a, 'b, 'k> {
18-
pub fn from_internal(req: HyperRequest<'a, 'k>) -> Request<'a, 'b, 'k> {
23+
impl<'mw, 'server> Request<'mw, 'server> {
24+
pub fn from_internal(req: HyperRequest<'mw, 'server>) -> Request<'mw, 'server> {
1925
Request {
2026
origin: req,
2127
route_result: None,
@@ -35,7 +41,7 @@ impl<'a, 'b, 'k> Request<'a, 'b, 'k> {
3541
}
3642
}
3743

38-
impl<'a, 'b, 'k> Extensible for Request<'a, 'b, 'k> {
44+
impl<'mw, 'server> Extensible for Request<'mw, 'server> {
3945
fn extensions(&self) -> &TypeMap {
4046
&self.map
4147
}
@@ -45,4 +51,4 @@ impl<'a, 'b, 'k> Extensible for Request<'a, 'b, 'k> {
4551
}
4652
}
4753

48-
impl<'a, 'b, 'k> Pluggable for Request<'a, 'b, 'k> {}
54+
impl<'mw, 'server> Pluggable for Request<'mw, 'server> {}

src/router/router.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ pub struct Route {
2020
/// It contains the matched `route` and also a `params` property holding
2121
/// a HashMap with the keys being the variable names and the value being the
2222
/// evaluated string
23-
pub struct RouteResult<'a> {
24-
pub route: &'a Route,
23+
pub struct RouteResult<'mw> {
24+
pub route: &'mw Route,
2525
params: Vec<(String, String)>
2626
}
2727

28-
impl<'a> RouteResult<'a> {
28+
impl<'mw> RouteResult<'mw> {
2929
pub fn param(&self, key: &str) -> Option<&str> {
3030
for &(ref k, ref v) in &self.params {
3131
if k == &key {
@@ -56,7 +56,7 @@ impl Router {
5656
}
5757
}
5858

59-
pub fn match_route<'a>(&'a self, method: &Method, path: &str) -> Option<RouteResult<'a>> {
59+
pub fn match_route<'mw>(&'mw self, method: &Method, path: &str) -> Option<RouteResult<'mw>> {
6060
self.routes
6161
.iter()
6262
.find(|item| item.method == *method && item.matcher.is_match(path))
@@ -95,8 +95,8 @@ impl HttpRouter for Router {
9595
}
9696

9797
impl Middleware for Router {
98-
fn invoke<'a, 'b>(&'a self, req: &mut Request<'b, 'a, 'b>, mut res: Response<'a>)
99-
-> MiddlewareResult<'a> {
98+
fn invoke<'mw, 'conn>(&'mw self, req: &mut Request<'mw, 'conn>, mut res: Response<'mw>)
99+
-> MiddlewareResult<'mw> {
100100
debug!("Router::invoke for '{:?}'", req.origin.uri);
101101

102102
// Strip off the querystring when matching a route

src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ struct ArcServer(Arc<Server>);
1919

2020
impl Handler for ArcServer {
2121
fn handle<'a, 'k>(&'a self, req: Request<'a, 'k>, res: Response<'a>) {
22+
let req: Request<'a, 'k> = req;
2223
let nickel_req = request::Request::from_internal(req);
2324
let nickel_res = response::Response::from_internal(res, &self.0.templates);
24-
2525
self.0.middleware_stack.invoke(nickel_req, nickel_res);
2626
}
2727
}

0 commit comments

Comments
 (0)