diff options
Diffstat (limited to 'third_party/rust/inherent/tests')
10 files changed, 120 insertions, 0 deletions
diff --git a/third_party/rust/inherent/tests/compiletest.rs b/third_party/rust/inherent/tests/compiletest.rs new file mode 100644 index 0000000000..f9aea23b51 --- /dev/null +++ b/third_party/rust/inherent/tests/compiletest.rs @@ -0,0 +1,6 @@ +#[rustversion::attr(not(nightly), ignore)] +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); +} diff --git a/third_party/rust/inherent/tests/test.rs b/third_party/rust/inherent/tests/test.rs new file mode 100644 index 0000000000..3e271d85c9 --- /dev/null +++ b/third_party/rust/inherent/tests/test.rs @@ -0,0 +1,27 @@ +mod types { + use inherent::inherent; + + trait Trait { + fn f<T: ?Sized>(self); + // A default method + fn g(&self) {} + } + + pub struct Struct; + + #[inherent(pub)] + impl Trait for Struct { + fn f<T: ?Sized>(self) {} + default! { + fn g(&self); + } + } +} + +#[test] +fn test() { + // types::Trait is not in scope. + let s = types::Struct; + s.g(); + s.f::<str>(); +} diff --git a/third_party/rust/inherent/tests/ui/default-with-body.rs b/third_party/rust/inherent/tests/ui/default-with-body.rs new file mode 100644 index 0000000000..df2f67ee66 --- /dev/null +++ b/third_party/rust/inherent/tests/ui/default-with-body.rs @@ -0,0 +1,18 @@ +use inherent::inherent; + +trait A { + fn a(&self) {} +} + +struct X; + +#[inherent] +impl A for X { + default! { + fn a(&self) { + println!("Default with a body >:-P"); + } + } +} + +fn main() {} diff --git a/third_party/rust/inherent/tests/ui/default-with-body.stderr b/third_party/rust/inherent/tests/ui/default-with-body.stderr new file mode 100644 index 0000000000..82dee8dd14 --- /dev/null +++ b/third_party/rust/inherent/tests/ui/default-with-body.stderr @@ -0,0 +1,8 @@ +error: Default method can't have a body + --> $DIR/default-with-body.rs:12:21 + | +12 | fn a(&self) { + | _____________________^ +13 | | println!("Default with a body >:-P"); +14 | | } + | |_________^ diff --git a/third_party/rust/inherent/tests/ui/nonsense-in-default.rs b/third_party/rust/inherent/tests/ui/nonsense-in-default.rs new file mode 100644 index 0000000000..907f6bdd81 --- /dev/null +++ b/third_party/rust/inherent/tests/ui/nonsense-in-default.rs @@ -0,0 +1,16 @@ +use inherent::inherent; + +trait A { + fn a(&self) {} +} + +struct X; + +#[inherent] +impl A for X { + default! { + const NONSENSE: usize = 1; + } +} + +fn main() {} diff --git a/third_party/rust/inherent/tests/ui/nonsense-in-default.stderr b/third_party/rust/inherent/tests/ui/nonsense-in-default.stderr new file mode 100644 index 0000000000..af6ce91e3a --- /dev/null +++ b/third_party/rust/inherent/tests/ui/nonsense-in-default.stderr @@ -0,0 +1,5 @@ +error: expected `fn` + --> $DIR/nonsense-in-default.rs:12:15 + | +12 | const NONSENSE: usize = 1; + | ^^^^^^^^ diff --git a/third_party/rust/inherent/tests/ui/not-trait-impl.rs b/third_party/rust/inherent/tests/ui/not-trait-impl.rs new file mode 100644 index 0000000000..a9a6a11628 --- /dev/null +++ b/third_party/rust/inherent/tests/ui/not-trait-impl.rs @@ -0,0 +1,10 @@ +use inherent::inherent; + +struct Struct; + +#[inherent] +impl Struct { + fn f() {} +} + +fn main() {} diff --git a/third_party/rust/inherent/tests/ui/not-trait-impl.stderr b/third_party/rust/inherent/tests/ui/not-trait-impl.stderr new file mode 100644 index 0000000000..afd9689a44 --- /dev/null +++ b/third_party/rust/inherent/tests/ui/not-trait-impl.stderr @@ -0,0 +1,7 @@ +error: must be placed on a trait impl + --> $DIR/not-trait-impl.rs:5:1 + | +5 | #[inherent] + | ^^^^^^^^^^^ + | + = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/inherent/tests/ui/not-visible.rs b/third_party/rust/inherent/tests/ui/not-visible.rs new file mode 100644 index 0000000000..faccf90ff4 --- /dev/null +++ b/third_party/rust/inherent/tests/ui/not-visible.rs @@ -0,0 +1,18 @@ +mod types { + use inherent::inherent; + + trait Trait { + fn f(); + } + + pub struct Struct; + + #[inherent] + impl Trait for Struct { + fn f() {} + } +} + +fn main() { + types::Struct::f(); +} diff --git a/third_party/rust/inherent/tests/ui/not-visible.stderr b/third_party/rust/inherent/tests/ui/not-visible.stderr new file mode 100644 index 0000000000..1adde54555 --- /dev/null +++ b/third_party/rust/inherent/tests/ui/not-visible.stderr @@ -0,0 +1,5 @@ +error[E0624]: associated function `f` is private + --> $DIR/not-visible.rs:17:20 + | +17 | types::Struct::f(); + | ^ private associated function |