mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-29 05:42:35 +00:00
78e2f8a3c9
This commit completely revamps the way that codegen handles route URI "parameters". The changes are largely internal. In summary, codegen code is better organized, better written, and less subject to error. There are three breaking changes: * `path` is now `uri` in `route` attribute: `#[route(GET, path = "..")]` becomes `#[route(GET, uri = "..")]`. * the order of execution for path and query guards relative to each-other is now unspecified * URI normalization now normalizes the query part as well. Several error messages were improved. A couple of bugs were fixed: * Prior to this commit, Rocket would optimistically try to parse every segment of a URI as an ident, in case one was needed in the future. A bug in rustc results in codegen "panicking" if the segment couldn't _lex_ as an ident. This panic didn't manifest until far after expansion, unfortunately. This wasn't a problem before as we only allowed ident-like segments (ASCII), but now that we allow any UTF-8, the bug surfaced. This was fixed by never attempting to parse non-idents as idents. * Prior to this commit, it was impossible to generate typed URIs for paths that ignored path parameters via the recently added syntax `<_>`: the macro would panic. This was fixed by, well, handling these ignored parameters. Some minor additions: * Added `RawStr::find()`, expanding its `Pattern`-based API. * Added an internal mechanism to dynamically determine if a `UriPart` is `Path` or `Query`.
243 lines
5.6 KiB
Plaintext
243 lines
5.6 KiB
Plaintext
error: invalid route URI: expected token '/' but found 'a' at index 0
|
|
--> $DIR/route-path-bad-syntax.rs:5:8
|
|
|
|
|
5 | #[get("a")]
|
|
| ^
|
|
|
|
|
= help: expected URI in origin form: "/path/<param>"
|
|
|
|
error: invalid route URI: unexpected EOF: expected token '/' at index 0
|
|
--> $DIR/route-path-bad-syntax.rs:8:8
|
|
|
|
|
8 | #[get("")]
|
|
| ^
|
|
|
|
|
= help: expected URI in origin form: "/path/<param>"
|
|
|
|
error: invalid route URI: expected token '/' but found 'a' at index 0
|
|
--> $DIR/route-path-bad-syntax.rs:11:8
|
|
|
|
|
11 | #[get("a/b/c")]
|
|
| ^
|
|
|
|
|
= help: expected URI in origin form: "/path/<param>"
|
|
|
|
error: route URIs cannot contain empty segments
|
|
--> $DIR/route-path-bad-syntax.rs:14:10
|
|
|
|
|
14 | #[get("/a///b")]
|
|
| ^^
|
|
|
|
|
= note: expected "/a/b", found "/a///b"
|
|
|
|
error: route URIs cannot contain empty segments
|
|
--> $DIR/route-path-bad-syntax.rs:17:13
|
|
|
|
|
17 | #[get("/?bat&&")]
|
|
| ^^
|
|
|
|
|
= note: expected "/?bat", found "/?bat&&"
|
|
|
|
error: route URIs cannot contain empty segments
|
|
--> $DIR/route-path-bad-syntax.rs:20:13
|
|
|
|
|
20 | #[get("/?bat&&")]
|
|
| ^^
|
|
|
|
|
= note: expected "/?bat", found "/?bat&&"
|
|
|
|
error: route URIs cannot contain empty segments
|
|
--> $DIR/route-path-bad-syntax.rs:23:12
|
|
|
|
|
23 | #[get("/a/b//")]
|
|
| ^^
|
|
|
|
|
= note: expected "/a/b", found "/a/b//"
|
|
|
|
error: unused parameter
|
|
--> $DIR/route-path-bad-syntax.rs:42:10
|
|
|
|
|
42 | #[get("/<name>")]
|
|
| ^^^^
|
|
|
|
|
note: expected argument named `name` here
|
|
--> $DIR/route-path-bad-syntax.rs:43:6
|
|
|
|
|
43 | fn h0(_name: usize) {}
|
|
| ^^^^^^^^^^^^^^
|
|
|
|
error: unused parameter
|
|
--> $DIR/route-path-bad-syntax.rs:45:12
|
|
|
|
|
45 | #[get("/a?<r>")]
|
|
| ^
|
|
|
|
|
note: expected argument named `r` here
|
|
--> $DIR/route-path-bad-syntax.rs:46:6
|
|
|
|
|
46 | fn h1() {}
|
|
| ^^
|
|
|
|
error: unused parameter
|
|
--> $DIR/route-path-bad-syntax.rs:48:23
|
|
|
|
|
48 | #[post("/a", data = "<test>")]
|
|
| ^^^^
|
|
|
|
|
note: expected argument named `test` here
|
|
--> $DIR/route-path-bad-syntax.rs:49:6
|
|
|
|
|
49 | fn h2() {}
|
|
| ^^
|
|
|
|
error: unused parameter
|
|
--> $DIR/route-path-bad-syntax.rs:51:10
|
|
|
|
|
51 | #[get("/<_r>")]
|
|
| ^^
|
|
|
|
|
note: expected argument named `_r` here
|
|
--> $DIR/route-path-bad-syntax.rs:52:6
|
|
|
|
|
52 | fn h3() {}
|
|
| ^^
|
|
|
|
error: unused parameter
|
|
--> $DIR/route-path-bad-syntax.rs:54:10
|
|
|
|
|
54 | #[get("/<_r>/<b>")]
|
|
| ^^
|
|
|
|
|
note: expected argument named `_r` here
|
|
--> $DIR/route-path-bad-syntax.rs:55:6
|
|
|
|
|
55 | fn h4() {}
|
|
| ^^
|
|
|
|
error: unused parameter
|
|
--> $DIR/route-path-bad-syntax.rs:54:15
|
|
|
|
|
54 | #[get("/<_r>/<b>")]
|
|
| ^
|
|
|
|
|
note: expected argument named `b` here
|
|
--> $DIR/route-path-bad-syntax.rs:55:6
|
|
|
|
|
55 | fn h4() {}
|
|
| ^^
|
|
|
|
error: invalid identifier: `foo_.`
|
|
--> $DIR/route-path-bad-syntax.rs:60:10
|
|
|
|
|
60 | #[get("/<foo_.>")]
|
|
| ^^^^^
|
|
|
|
|
= help: dynamic parameters must be valid identifiers
|
|
= help: did you mean `<foo_>`?
|
|
|
|
error: invalid identifier: `foo*`
|
|
--> $DIR/route-path-bad-syntax.rs:63:10
|
|
|
|
|
63 | #[get("/<foo*>")]
|
|
| ^^^^
|
|
|
|
|
= help: dynamic parameters must be valid identifiers
|
|
= help: did you mean `<foo>`?
|
|
|
|
error: invalid identifier: `!`
|
|
--> $DIR/route-path-bad-syntax.rs:66:10
|
|
|
|
|
66 | #[get("/<!>")]
|
|
| ^
|
|
|
|
|
= help: dynamic parameters must be valid identifiers
|
|
= help: did you mean `<param>`?
|
|
|
|
error: invalid identifier: `name>:<id`
|
|
--> $DIR/route-path-bad-syntax.rs:69:10
|
|
|
|
|
69 | #[get("/<name>:<id>")]
|
|
| ^^^^^^^^^
|
|
|
|
|
= help: dynamic parameters must be valid identifiers
|
|
= help: did you mean `<nameid>`?
|
|
|
|
error: unexpected static parameter
|
|
--> $DIR/route-path-bad-syntax.rs:74:20
|
|
|
|
|
74 | #[get("/", data = "foo")]
|
|
| ^^^
|
|
|
|
|
= help: parameter must be dynamic: `<foo>`
|
|
|
|
error: parameter cannot be trailing
|
|
--> $DIR/route-path-bad-syntax.rs:77:20
|
|
|
|
|
77 | #[get("/", data = "<foo..>")]
|
|
| ^^^^^^^
|
|
|
|
|
= help: did you mean `<foo>`?
|
|
|
|
warning: `segment` starts with `<` but does not end with `>`
|
|
--> $DIR/route-path-bad-syntax.rs:80:20
|
|
|
|
|
80 | #[get("/", data = "<foo")]
|
|
| ^^^^
|
|
|
|
|
= help: perhaps you meant the dynamic parameter `<foo>`?
|
|
|
|
error: unexpected static parameter
|
|
--> $DIR/route-path-bad-syntax.rs:80:20
|
|
|
|
|
80 | #[get("/", data = "<foo")]
|
|
| ^^^^
|
|
|
|
|
= help: parameter must be dynamic: `<foo>`
|
|
|
|
error: invalid identifier: `test `
|
|
--> $DIR/route-path-bad-syntax.rs:83:21
|
|
|
|
|
83 | #[get("/", data = "<test >")]
|
|
| ^^^^^
|
|
|
|
|
= help: dynamic parameters must be valid identifiers
|
|
= help: did you mean `<test>`?
|
|
|
|
error: handler arguments cannot be ignored
|
|
--> $DIR/route-path-bad-syntax.rs:89:7
|
|
|
|
|
89 | fn k0(_: usize) {}
|
|
| ^^^^^^^^
|
|
|
|
|
= note: handler arguments must be of the form: `ident: Type`
|
|
|
|
error: parameters cannot be empty
|
|
--> $DIR/route-path-bad-syntax.rs:93:9
|
|
|
|
|
93 | #[get("/<>")]
|
|
| ^^
|
|
|
|
warning: `segment` starts with `<` but does not end with `>`
|
|
--> $DIR/route-path-bad-syntax.rs:96:9
|
|
|
|
|
96 | #[get("/<id><")]
|
|
| ^^^^^
|
|
|
|
|
= help: perhaps you meant the dynamic parameter `<id>`?
|
|
|
|
warning: `segment` starts with `<` but does not end with `>`
|
|
--> $DIR/route-path-bad-syntax.rs:99:9
|
|
|
|
|
99 | #[get("/<<<<id><")]
|
|
| ^^^^^^^^
|
|
|
|
|
= help: perhaps you meant the dynamic parameter `<id>`?
|
|
|
|
warning: `segment` starts with `<` but does not end with `>`
|
|
--> $DIR/route-path-bad-syntax.rs:102:9
|
|
|
|
|
102 | #[get("/<>name><")]
|
|
| ^^^^^^^^
|
|
|
|
|
= help: perhaps you meant the dynamic parameter `<name>`?
|