Skip to content

Commit 1eb2835

Browse files
committed
Add info about allowed attributes to error
1 parent 7241ddc commit 1eb2835

14 files changed

Lines changed: 49 additions & 17 deletions

diesel_compile_tests/tests/fail/derive/bad_belongs_to.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ error: expected `=`
4040
71 | #[diesel(belongs_to(Bar, foreign_key(bar_id)))]
4141
| ^^^^^^^^
4242

43-
error: unknown attribute
43+
error: unknown attribute, expected `foreign_key`
4444
--> $DIR/bad_belongs_to.rs:78:26
4545
|
4646
78 | #[diesel(belongs_to(Bar, what))]

diesel_compile_tests/tests/fail/derive/bad_mysql_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ error: expected string literal
3434
26 | #[diesel(mysql_type(name = Foo))]
3535
| ^^^
3636

37-
error: unknown attribute
37+
error: unknown attribute, expected `name`
3838
--> $DIR/bad_mysql_type.rs:30:21
3939
|
4040
30 | #[diesel(mysql_type(what))]

diesel_compile_tests/tests/fail/derive/bad_postgres_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ error: expected `name` to be also present
7373
50 | #[diesel(postgres_type(schema = "foo"))]
7474
| ^^^^^
7575

76-
error: unknown attribute
76+
error: unknown attribute, expected one of `oid`, `array_oid`, `name`, `schema`
7777
--> $DIR/bad_postgres_type.rs:54:24
7878
|
7979
54 | #[diesel(postgres_type(what))]

diesel_compile_tests/tests/fail/derive/bad_sqlite_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ error: expected string literal
3434
26 | #[diesel(sqlite_type(name = Foo))]
3535
| ^^^
3636

37-
error: unknown attribute
37+
error: unknown attribute, expected `name`
3838
--> $DIR/bad_sqlite_type.rs:30:22
3939
|
4040
30 | #[diesel(sqlite_type(what))]

diesel_compile_tests/tests/fail/derive/belongs_to_second_parent.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unknown attribute
1+
error: unknown attribute, expected `foreign_key`
22
--> $DIR/belongs_to_second_parent.rs:29:26
33
|
44
29 | #[diesel(belongs_to(Bar, Baz))]

diesel_compile_tests/tests/fail/derive/unknown_attribute.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: unknown attribute
1+
error: unknown attribute, expected one of `aggregate`, `not_sized`, `foreign_derive`, `table_name`, `sql_type`, `treat_none_as_default_value`, `treat_none_as_null`, `belongs_to`, `mysql_type`, `sqlite_type`, `postgres_type`, `primary_key`
22
--> $DIR/unknown_attribute.rs:5:10
33
|
44
5 | #[diesel(what = true)]
55
| ^^^^
66

7-
error: unknown attribute
7+
error: unknown attribute, expected one of `embed`, `column_name`, `sql_type`, `serialize_as`, `deserialize_as`
88
--> $DIR/unknown_attribute.rs:12:14
99
|
1010
12 | #[diesel(what = true)]

diesel_compile_tests/tests/fail/derive_deprecated/deprecated_postgres_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ error: expected string literal
6767
warning: #[postgres] attribute form is deprecated
6868
= help: use `#[diesel(postgres_type(oid = 1, array_oid = 1))]` instead
6969

70-
error: unknown attribute
70+
error: unknown attribute, expected one of `oid`, `array_oid`, `type_name`
7171
--> $DIR/deprecated_postgres_type.rs:54:12
7272
|
7373
54 | #[postgres(what)]

diesel_derives/src/attrs.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,16 @@ impl Parse for FieldAttr {
9191
"serialize_as" => Ok(FieldAttr::SerializeAs(name, parse_eq(input)?)),
9292
"deserialize_as" => Ok(FieldAttr::DeserializeAs(name, parse_eq(input)?)),
9393

94-
_ => unknown_attribute(&name),
94+
_ => unknown_attribute(
95+
&name,
96+
&[
97+
"embed",
98+
"column_name",
99+
"sql_type",
100+
"serialize_as",
101+
"deserialize_as",
102+
],
103+
),
95104
}
96105
}
97106
}
@@ -141,7 +150,23 @@ impl Parse for StructAttr {
141150
content.parse_terminated(Ident::parse)?
142151
})),
143152

144-
_ => unknown_attribute(&name),
153+
_ => unknown_attribute(
154+
&name,
155+
&[
156+
"aggregate",
157+
"not_sized",
158+
"foreign_derive",
159+
"table_name",
160+
"sql_type",
161+
"treat_none_as_default_value",
162+
"treat_none_as_null",
163+
"belongs_to",
164+
"mysql_type",
165+
"sqlite_type",
166+
"postgres_type",
167+
"primary_key",
168+
],
169+
),
145170
}
146171
}
147172
}

diesel_derives/src/deprecated/postgres_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Parse for Attr {
3232
parse_eq_and_lit_str(name, input)?,
3333
)),
3434

35-
_ => unknown_attribute(&name),
35+
_ => unknown_attribute(&name, &["oid", "array_oid", "type_name"]),
3636
}
3737
}
3838
}

diesel_derives/src/parsers/belongs_to.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Parse for Attr {
1717
match &*name_str {
1818
"foreign_key" => Ok(Attr::ForeignKey(name, parse_eq(input)?)),
1919

20-
_ => unknown_attribute(&name),
20+
_ => unknown_attribute(&name, &["foreign_key"]),
2121
}
2222
}
2323
}

0 commit comments

Comments
 (0)