-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use core::fmt::{self, Display}; | ||
use core::ops::Add; | ||
|
||
use super::prelude::*; | ||
use crate::no_std::prelude::*; | ||
|
||
#[derive(Any, Debug, PartialEq)] | ||
#[rune_derive(ADD, STRING_DEBUG, STRING_DISPLAY)] | ||
#[rune_functions(Self::new)] | ||
struct Struct(usize); | ||
|
||
impl Struct { | ||
#[rune::function(path = Self::new)] | ||
fn new(it: usize) -> Self { | ||
Self(it) | ||
} | ||
} | ||
|
||
impl Add for Struct { | ||
type Output = Self; | ||
|
||
fn add(mut self, other: Self) -> Self { | ||
self.0 += other.0; | ||
self | ||
} | ||
} | ||
|
||
impl Display for Struct { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result { | ||
self.0.fmt(f) | ||
} | ||
} | ||
|
||
#[test] | ||
fn rune_derive() -> Result<()> { | ||
let mut m = Module::new(); | ||
m.ty::<Struct>()?; | ||
assert_eq!( | ||
rune_n! { | ||
&m, | ||
(), | ||
Struct => pub fn main() {Struct::new(1) + Struct::new(2)} | ||
}, | ||
Struct(3) | ||
); | ||
|
||
assert_eq!( | ||
rune_n! { | ||
&m, | ||
(), | ||
String => pub fn main() {format!("{}", Struct::new(1))} | ||
}, | ||
"1" | ||
); | ||
|
||
assert_eq!( | ||
rune_n! { | ||
&m, | ||
(), | ||
String => pub fn main() {format!("{:?}", Struct::new(1))} | ||
}, | ||
"Struct(1)" | ||
); | ||
Ok(()) | ||
} |
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,13 @@ | ||
use rune::Any; | ||
|
||
// Generates a warning that the path should no longer be using a string literal. | ||
#[derive(Any)] | ||
#[rune_derive(ADD, STRING_DISPLAY, STRING_DEBUG)] | ||
struct UnimplementedTraits; | ||
|
||
#[derive(Any)] | ||
#[rune_derive(NON_EXISTENT)] | ||
struct NonExistingProtocol; | ||
|
||
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,57 @@ | ||
error: Rune protocol `NON_EXISTENT` cannot be derived | ||
--> tests/ui/rune_derive.rs:9:15 | ||
| | ||
9 | #[rune_derive(NON_EXISTENT)] | ||
| ^^^^^^^^^^^^ | ||
|
||
error[E0369]: cannot add `UnimplementedTraits` to `UnimplementedTraits` | ||
--> tests/ui/rune_derive.rs:5:15 | ||
| | ||
5 | #[rune_derive(ADD, STRING_DISPLAY, STRING_DEBUG)] | ||
| ^^^ | ||
| | ||
note: an implementation of `std::ops::Add` might be missing for `UnimplementedTraits` | ||
--> tests/ui/rune_derive.rs:6:1 | ||
| | ||
6 | struct UnimplementedTraits; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ must implement `std::ops::Add` | ||
note: the trait `std::ops::Add` must be implemented | ||
--> $RUST/core/src/ops/arith.rs | ||
| | ||
| pub trait Add<Rhs = Self> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: `UnimplementedTraits` doesn't implement `std::fmt::Display` | ||
--> tests/ui/rune_derive.rs:5:20 | ||
| | ||
5 | #[rune_derive(ADD, STRING_DISPLAY, STRING_DEBUG)] | ||
| ^^^^^^^^^^^^^^ `UnimplementedTraits` cannot be formatted with the default formatter | ||
| | ||
::: $RUST/core/src/macros/mod.rs | ||
| | ||
| $dst.write_fmt($crate::format_args!($($arg)*)) | ||
| ------------------------------ in this macro invocation | ||
| | ||
= help: the trait `std::fmt::Display` is not implemented for `UnimplementedTraits` | ||
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead | ||
= note: this error originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: `UnimplementedTraits` doesn't implement `std::fmt::Debug` | ||
--> tests/ui/rune_derive.rs:5:36 | ||
| | ||
5 | #[rune_derive(ADD, STRING_DISPLAY, STRING_DEBUG)] | ||
| ^^^^^^^^^^^^ `UnimplementedTraits` cannot be formatted using `{:?}` | ||
| | ||
::: $RUST/core/src/macros/mod.rs | ||
| | ||
| $dst.write_fmt($crate::format_args!($($arg)*)) | ||
| ------------------------------ in this macro invocation | ||
| | ||
= help: the trait `std::fmt::Debug` is not implemented for `UnimplementedTraits` | ||
= note: add `#[derive(Debug)]` to `UnimplementedTraits` or manually `impl std::fmt::Debug for UnimplementedTraits` | ||
= note: this error originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: consider annotating `UnimplementedTraits` with `#[derive(Debug)]` | ||
| | ||
6 + #[derive(Debug)] | ||
7 | struct UnimplementedTraits; | ||
| |