mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-05 01:02:42 +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`.
214 lines
5.5 KiB
Plaintext
214 lines
5.5 KiB
Plaintext
error: missing expected parameter: `uri`
|
|
--> $DIR/route-attribute-general-syntax.rs:4:1
|
|
|
|
|
4 | #[get()]
|
|
| ^^^^^^^^
|
|
|
|
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
|
|
error: expected `fn`
|
|
--> $DIR/route-attribute-general-syntax.rs:9:1
|
|
|
|
|
9 | struct S;
|
|
| ^^^^^^
|
|
|
|
|
= help: #[get] can only be used on functions
|
|
|
|
error: expected `fn`
|
|
--> $DIR/route-attribute-general-syntax.rs:12:1
|
|
|
|
|
12 | enum A { }
|
|
| ^^^^
|
|
|
|
|
= help: #[get] can only be used on functions
|
|
|
|
error: expected `fn`
|
|
--> $DIR/route-attribute-general-syntax.rs:15:1
|
|
|
|
|
15 | trait Foo { }
|
|
| ^^^^^
|
|
|
|
|
= help: #[get] can only be used on functions
|
|
|
|
error: expected `fn`
|
|
--> $DIR/route-attribute-general-syntax.rs:18:1
|
|
|
|
|
18 | impl S { }
|
|
| ^^^^
|
|
|
|
|
= help: #[get] can only be used on functions
|
|
|
|
error: expected key/value `key = value`
|
|
--> $DIR/route-attribute-general-syntax.rs:21:12
|
|
|
|
|
21 | #[get("/", 123)]
|
|
| ^^^
|
|
|
|
error: expected key/value `key = value`
|
|
--> $DIR/route-attribute-general-syntax.rs:24:12
|
|
|
|
|
24 | #[get("/", "/")]
|
|
| ^^^
|
|
|
|
error: unexpected keyed parameter: expected literal or identifier
|
|
--> $DIR/route-attribute-general-syntax.rs:27:7
|
|
|
|
|
27 | #[get(data = "<foo>", "/")]
|
|
| ^^^^^^^^^^^^^^
|
|
|
|
error: unexpected attribute parameter: `unknown`
|
|
--> $DIR/route-attribute-general-syntax.rs:30:12
|
|
|
|
|
30 | #[get("/", unknown = "foo")]
|
|
| ^^^^^^^^^^^^^^^
|
|
|
|
error: expected key/value `key = value`
|
|
--> $DIR/route-attribute-general-syntax.rs:33:12
|
|
|
|
|
33 | #[get("/", ...)]
|
|
| ^^^
|
|
|
|
error: handler arguments cannot be ignored
|
|
--> $DIR/route-attribute-general-syntax.rs:39:7
|
|
|
|
|
39 | fn c1(_: usize) {}
|
|
| ^^^^^^^^
|
|
|
|
|
= note: handler arguments must be of the form: `ident: Type`
|
|
|
|
error: invalid value: expected string literal
|
|
--> $DIR/route-attribute-general-syntax.rs:43:7
|
|
|
|
|
43 | #[get(100)]
|
|
| ^^^
|
|
|
|
error: invalid value: expected string literal
|
|
--> $DIR/route-attribute-general-syntax.rs:46:7
|
|
|
|
|
46 | #[get('/')]
|
|
| ^^^
|
|
|
|
error: invalid value: expected integer literal
|
|
--> $DIR/route-attribute-general-syntax.rs:49:19
|
|
|
|
|
49 | #[get("/", rank = "1")]
|
|
| ^^^
|
|
|
|
error: invalid value: expected integer literal
|
|
--> $DIR/route-attribute-general-syntax.rs:52:19
|
|
|
|
|
52 | #[get("/", rank = '1')]
|
|
| ^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:57:21
|
|
|
|
|
57 | #[get("/", format = "applicationx-custom")]
|
|
| ^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:60:21
|
|
|
|
|
60 | #[get("/", format = "")]
|
|
| ^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:63:21
|
|
|
|
|
63 | #[get("/", format = "//")]
|
|
| ^^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:66:21
|
|
|
|
|
66 | #[get("/", format = "/")]
|
|
| ^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:69:21
|
|
|
|
|
69 | #[get("/", format = "a/")]
|
|
| ^^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:72:21
|
|
|
|
|
72 | #[get("/", format = "/a")]
|
|
| ^^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:75:21
|
|
|
|
|
75 | #[get("/", format = "/a/")]
|
|
| ^^^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:78:21
|
|
|
|
|
78 | #[get("/", format = "a/b/")]
|
|
| ^^^^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:81:21
|
|
|
|
|
81 | #[get("/", format = "unknown")]
|
|
| ^^^^^^^^^
|
|
|
|
error: invalid value: expected string literal
|
|
--> $DIR/route-attribute-general-syntax.rs:84:21
|
|
|
|
|
84 | #[get("/", format = 12)]
|
|
| ^^
|
|
|
|
error: invalid value: expected string literal
|
|
--> $DIR/route-attribute-general-syntax.rs:87:21
|
|
|
|
|
87 | #[get("/", format = 'j')]
|
|
| ^^^
|
|
|
|
error: invalid or unknown media type
|
|
--> $DIR/route-attribute-general-syntax.rs:90:21
|
|
|
|
|
90 | #[get("/", format = "text//foo")]
|
|
| ^^^^^^^^^^^
|
|
|
|
error: invalid HTTP method for route handlers
|
|
--> $DIR/route-attribute-general-syntax.rs:95:9
|
|
|
|
|
95 | #[route(CONNECT, "/")]
|
|
| ^^^^^^^
|
|
|
|
|
= help: method must be one of: `GET`, `PUT`, `POST`, `DELETE`, `HEAD`, `PATCH`, `OPTIONS`
|
|
|
|
error: invalid HTTP method
|
|
--> $DIR/route-attribute-general-syntax.rs:98:9
|
|
|
|
|
98 | #[route(FIX, "/")]
|
|
| ^^^
|
|
|
|
|
= help: method must be one of: `GET`, `PUT`, `POST`, `DELETE`, `HEAD`, `PATCH`, `OPTIONS`
|
|
|
|
error: expected identifier, found string literal
|
|
--> $DIR/route-attribute-general-syntax.rs:101:9
|
|
|
|
|
101 | #[route("hi", "/")]
|
|
| ^^^^
|
|
|
|
|
= help: method must be one of: `GET`, `PUT`, `POST`, `DELETE`, `HEAD`, `PATCH`, `OPTIONS`
|
|
|
|
error: expected identifier, found string literal
|
|
--> $DIR/route-attribute-general-syntax.rs:104:9
|
|
|
|
|
104 | #[route("GET", "/")]
|
|
| ^^^^^
|
|
|
|
|
= help: method must be one of: `GET`, `PUT`, `POST`, `DELETE`, `HEAD`, `PATCH`, `OPTIONS`
|
|
|
|
error: expected identifier, found integer literal
|
|
--> $DIR/route-attribute-general-syntax.rs:107:9
|
|
|
|
|
107 | #[route(120, "/")]
|
|
| ^^^
|
|
|
|
|
= help: method must be one of: `GET`, `PUT`, `POST`, `DELETE`, `HEAD`, `PATCH`, `OPTIONS`
|