-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail to compile with invalid attribute parameters (#385)
* Use syn::Error when parsing attributes, error message constants * Add compiletests for attribute parse errors * Compile errors for invalid attribute parameters * Replace anon fn args in compilefail examples with underscore * Fix spaces and blank line * Revert accidental change to macros auto_args * Revert accidental macros changes * Revert accidental change to pubsuc macros tests * Fix build on rust 1.33-beta: remove Rpc impls * Clone after filter * Remove redundant static lifetime on constants * Remove redundant braces
- Loading branch information
Showing
31 changed files
with
404 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
extern crate serde; | ||
extern crate jsonrpc_core; | ||
#[macro_use] | ||
extern crate jsonrpc_derive; | ||
|
||
use jsonrpc_core::Result; | ||
|
||
#[rpc] | ||
pub trait Rpc { | ||
/// Returns a protocol version | ||
#[rpc(name = "protocolVersion", Xalias("alias"))] | ||
fn protocol_version(&self) -> Result<String>; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: Invalid attribute parameter(s): 'Xalias'. Expected 'alias' | ||
--> $DIR/attr-invalid-meta-list-names.rs:10:2 | ||
| | ||
10 | /// Returns a protocol version | ||
| _____^ | ||
11 | | #[rpc(name = "protocolVersion", Xalias("alias"))] | ||
12 | | fn protocol_version(&self) -> Result<String>; | ||
| |_________________________________________________^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
extern crate serde; | ||
extern crate jsonrpc_core; | ||
#[macro_use] | ||
extern crate jsonrpc_derive; | ||
|
||
use jsonrpc_core::Result; | ||
|
||
#[rpc] | ||
pub trait Rpc { | ||
/// Returns a protocol version | ||
#[rpc(name = "protocolVersion", Xmeta)] | ||
fn protocol_version(&self) -> Result<String>; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: Invalid attribute parameter(s): 'Xmeta'. Expected 'meta' | ||
--> $DIR/attr-invalid-meta-words.rs:10:2 | ||
| | ||
10 | /// Returns a protocol version | ||
| _____^ | ||
11 | | #[rpc(name = "protocolVersion", Xmeta)] | ||
12 | | fn protocol_version(&self) -> Result<String>; | ||
| |_________________________________________________^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
extern crate serde; | ||
extern crate jsonrpc_core; | ||
#[macro_use] | ||
extern crate jsonrpc_derive; | ||
|
||
use jsonrpc_core::Result; | ||
|
||
#[rpc] | ||
pub trait Rpc { | ||
/// Returns a protocol version | ||
#[rpc(Xname = "protocolVersion")] | ||
fn protocol_version(&self) -> Result<String>; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: Invalid attribute parameter(s): 'Xname'. Expected 'name' | ||
--> $DIR/attr-invalid-name-values.rs:10:2 | ||
| | ||
10 | /// Returns a protocol version | ||
| _____^ | ||
11 | | #[rpc(Xname = "protocolVersion")] | ||
12 | | fn protocol_version(&self) -> Result<String>; | ||
| |_________________________________________________^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
extern crate serde; | ||
extern crate jsonrpc_core; | ||
#[macro_use] | ||
extern crate jsonrpc_derive; | ||
|
||
use jsonrpc_core::Result; | ||
|
||
#[rpc] | ||
pub trait Rpc { | ||
/// Returns a protocol version | ||
#[rpc] | ||
fn protocol_version(&self) -> Result<String>; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: rpc attribute should have a name e.g. `name = "method_name"` | ||
--> $DIR/attr-missing-rpc-name.rs:10:2 | ||
| | ||
10 | /// Returns a protocol version | ||
| _____^ | ||
11 | | #[rpc] | ||
12 | | fn protocol_version(&self) -> Result<String>; | ||
| |_________________________________________________^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extern crate serde; | ||
extern crate jsonrpc_core; | ||
#[macro_use] | ||
extern crate jsonrpc_derive; | ||
|
||
use jsonrpc_core::Result; | ||
|
||
#[rpc] | ||
pub trait Rpc { | ||
/// Returns a protocol version | ||
#[rpc(name = "protocolVersion")] | ||
#[rpc(name = "protocolVersionAgain")] | ||
fn protocol_version(&self) -> Result<String>; | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error: Expected only a single rpc attribute per method | ||
--> $DIR/multiple-rpc-attributes.rs:10:2 | ||
| | ||
10 | /// Returns a protocol version | ||
| _____^ | ||
11 | | #[rpc(name = "protocolVersion")] | ||
12 | | #[rpc(name = "protocolVersionAgain")] | ||
13 | | fn protocol_version(&self) -> Result<String>; | ||
| |_________________________________________________^ | ||
|
||
error: aborting due to previous error | ||
|
19 changes: 19 additions & 0 deletions
19
derive/tests/ui/pubsub/attr-both-subscribe-and-unsubscribe.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[macro_use] | ||
extern crate jsonrpc_derive; | ||
extern crate jsonrpc_core; | ||
extern crate jsonrpc_pubsub; | ||
|
||
#[rpc] | ||
pub trait Rpc { | ||
type Metadata; | ||
|
||
/// Hello subscription | ||
#[pubsub(subscription = "hello", subscribe, unsubscribe, name = "hello_subscribe", alias("hello_sub"))] | ||
fn subscribe(&self, _: Self::Metadata, _: typed::Subscriber<String>, _: u64); | ||
|
||
/// Unsubscribe from hello subscription. | ||
#[pubsub(subscription = "hello", unsubscribe, name = "hello_unsubscribe")] | ||
fn unsubscribe(&self, _: Option<Self::Metadata>, _: SubscriptionId) -> Result<bool>; | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
derive/tests/ui/pubsub/attr-both-subscribe-and-unsubscribe.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: pubsub attribute annotated with both subscribe and unsubscribe | ||
--> $DIR/attr-both-subscribe-and-unsubscribe.rs:10:2 | ||
| | ||
10 | /// Hello subscription | ||
| _____^ | ||
11 | | #[pubsub(subscription = "hello", subscribe, unsubscribe, name = "hello_subscribe", alias("hello_sub"))] | ||
12 | | fn subscribe(&self, _: Self::Metadata, _: typed::Subscriber<String>, _: u64); | ||
| |_________________________________________________________________________________^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[macro_use] | ||
extern crate jsonrpc_derive; | ||
extern crate jsonrpc_core; | ||
extern crate jsonrpc_pubsub; | ||
|
||
#[rpc] | ||
pub trait Rpc { | ||
type Metadata; | ||
|
||
/// Hello subscription | ||
#[pubsub(subscription = "hello", subscribe, name = "hello_subscribe", Xalias("hello_sub"))] | ||
fn subscribe(&self, _: Self::Metadata, _: typed::Subscriber<String>, _: u64); | ||
|
||
/// Unsubscribe from hello subscription. | ||
#[pubsub(subscription = "hello", unsubscribe, name = "hello_unsubscribe")] | ||
fn unsubscribe(&self, _: Option<Self::Metadata>, _: SubscriptionId) -> Result<bool>; | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
derive/tests/ui/pubsub/attr-invalid-meta-list-names.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: Invalid attribute parameter(s): 'Xalias'. Expected 'alias' | ||
--> $DIR/attr-invalid-meta-list-names.rs:10:2 | ||
| | ||
10 | /// Hello subscription | ||
| _____^ | ||
11 | | #[pubsub(subscription = "hello", subscribe, name = "hello_subscribe", Xalias("hello_sub"))] | ||
12 | | fn subscribe(&self, _: Self::Metadata, _: typed::Subscriber<String>, _: u64); | ||
| |_________________________________________________________________________________^ | ||
|
||
error: aborting due to previous error | ||
|
Oops, something went wrong.