Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions diesel_compile_tests/tests/compile-fail/associations_errors.rs

This file was deleted.

34 changes: 34 additions & 0 deletions diesel_compile_tests/tests/ui/belongs_to_invalid_option_syntax.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#[macro_use]
extern crate diesel;

table! {
foo {
id -> Integer,
}
}

#[derive(Identifiable)]
#[table_name = "foo"]
struct Bar {
id: i32,
}

#[derive(Identifiable)]
#[table_name = "foo"]
struct Baz {
id: i32,
}

#[derive(Associations)]
#[belongs_to]
#[belongs_to = "Bar"]
#[belongs_to()]
#[belongs_to(foreign_key = "bar_id")]
#[belongs_to(Bar, foreign_key)]
#[belongs_to(Bar, foreign_key(bar_id))]
#[belongs_to(Baz, foreign_key = "bar_id", random_option)]
struct Foo {
bar_id: i32,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
error: `belongs_to` must be in the form `belongs_to(...)`
--> <macro expansion>:1:1
|
1 | #[belongs_to]
| ^

error: `belongs_to` must be in the form `belongs_to(...)`
--> <macro expansion>:1:1
|
1 | #[belongs_to = "Bar"]
| ^

error: Expected a struct name
--> <macro expansion>:1:1
|
1 | #[belongs_to()]
| ^
|
= help: e.g. `#[belongs_to(User)]`

error: Expected a struct name
--> <macro expansion>:1:1
|
1 | #[belongs_to(foreign_key = "bar_id")]
| ^
|
= help: e.g. `#[belongs_to(User)]`

error: `foreign_key` must be in the form `foreign_key = "value"`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar, foreign_key)]
| ^

warning: The form `foreign_key(value)` is deprecated. Use `foreign_key = "value"` instead
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar, foreign_key(bar_id))]
| ^

warning: Unrecognized option random_option
--> <macro expansion>:1:1
|
1 | #[belongs_to(Baz, foreign_key = "bar_id", random_option)]
| ^

error: aborting due to 5 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#[macro_use]
extern crate diesel;

struct Bar;

table! {
foo {
id -> Integer,
}
}

#[derive(Associations)]
#[belongs_to(Bar)]
#[table_name = "foo"]
struct Foo1 {
bar_id: i32,
}

#[derive(Associations)]
#[belongs_to(Bar, foreign_key = "bar_id")]
#[table_name = "foo"]
struct Foo2 {
bar_id: i32,
}

#[derive(Associations)]
#[belongs_to(Bar)]
#[table_name = "foo"]
struct Foo3 {
#[column_name = "bar_id"]
baz_id: i32,
}

#[derive(Associations)]
#[belongs_to(Bar, foreign_key = "bar_id")]
#[table_name = "foo"]
struct Foo4 {
#[column_name = "bar_id"]
baz_id: i32,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
error[E0412]: cannot find type `bar_id` in module `foo`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar)]
| ^ not found in `foo`

error[E0425]: cannot find value `bar_id` in module `foo`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar)]
| ^ not found in `foo`

error[E0412]: cannot find type `bar_id` in module `foo`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar, foreign_key = "bar_id")]
| ^ not found in `foo`

error[E0425]: cannot find value `bar_id` in module `foo`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar, foreign_key = "bar_id")]
| ^ not found in `foo`

error[E0412]: cannot find type `bar_id` in module `foo`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar)]
| ^ not found in `foo`

error[E0425]: cannot find value `bar_id` in module `foo`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar)]
| ^ not found in `foo`

error[E0412]: cannot find type `bar_id` in module `foo`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar, foreign_key = "bar_id")]
| ^ not found in `foo`

error[E0425]: cannot find value `bar_id` in module `foo`
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar, foreign_key = "bar_id")]
| ^ not found in `foo`

error: aborting due to 8 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[macro_use]
extern crate diesel;

struct Bar;

#[derive(Associations)]
#[belongs_to(Bar)]
#[belongs_to(Bar, foreign_key = "bar_id")]
struct Foo {}

#[derive(Associations)]
#[belongs_to(Bar)]
#[belongs_to(Bar, foreign_key = "bar_id")]
struct Baz {
#[column_name = "baz_id"]
bar_id: i32,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: No field with column name bar_id
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar)]
| ^

error: No field with column name bar_id
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar, foreign_key = "bar_id")]
| ^

error: No field with column name bar_id
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar)]
| ^

error: No field with column name bar_id
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar, foreign_key = "bar_id")]
| ^

error: aborting due to 4 previous errors

17 changes: 17 additions & 0 deletions diesel_compile_tests/tests/ui/belongs_to_missing_parent_import.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[macro_use]
extern crate diesel;

table! {
foos {
id -> Integer,
bar_id -> Integer,
}
}

#[derive(Associations)]
#[belongs_to(Bar)]
struct Foo {
bar_id: i32,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error[E0412]: cannot find type `Bar` in this scope
--> <macro expansion>:1:1
|
1 | #[belongs_to(Bar)]
| ^ not found in this scope

error: aborting due to previous error

Loading