Skip to content

Commit 814280a

Browse files
committed
improve error message span
1 parent f4e7dc2 commit 814280a

File tree

8 files changed

+14
-15
lines changed

8 files changed

+14
-15
lines changed

derive/src/codegen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::parser::{ParseData, ParseDataField, TypeOrInline};
22
use proc_macro2::TokenStream;
3-
use quote::quote;
4-
use syn::LitStr;
3+
use quote::{quote, quote_spanned};
4+
use syn::{spanned::Spanned, LitStr};
55

66
pub(super) fn gen_doc_option(doc: &[String]) -> TokenStream {
77
let doc = doc.join("\n");
@@ -38,7 +38,7 @@ fn gen_struct(name: Option<&LitStr>, fields: &[ParseDataField]) -> TokenStream {
3838
let doc = gen_doc_option(&f.doc);
3939
let schema = match &f.ty {
4040
TypeOrInline::Type(ty) => {
41-
quote!(<#ty as ::openapi_type::OpenapiType>::schema())
41+
quote_spanned!(ty.span() => <#ty as ::openapi_type::OpenapiType>::schema())
4242
},
4343
TypeOrInline::Inline(data) => data.gen_schema()
4444
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: #[derive(OpenapiType)] does not support enums with no variants
2-
--> $DIR/enum_with_no_variants.rs:4:10
2+
--> tests/fail/enum_with_no_variants.rs:4:10
33
|
44
4 | enum Foo {}
55
| ^^

tests/fail/not_openapitype.stderr

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
error[E0277]: the trait bound `Bar: OpenapiType` is not satisfied
2-
--> $DIR/not_openapitype.rs:3:10
2+
--> tests/fail/not_openapitype.rs:5:7
33
|
4-
3 | #[derive(OpenapiType)]
5-
| ^^^^^^^^^^^ the trait `OpenapiType` is not implemented for `Bar`
4+
5 | bar: Bar
5+
| ^^^ the trait `OpenapiType` is not implemented for `Bar`
66
|
77
note: required by `schema`
8-
--> $DIR/lib.rs:146:2
8+
--> src/lib.rs
99
|
10-
146 | fn schema() -> OpenapiSchema;
10+
| fn schema() -> OpenapiSchema;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= note: this error originates in the derive macro `OpenapiType` (in Nightly builds, run with -Z macro-backtrace for more info)

tests/fail/not_openapitype_generics.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0599]: the function or associated item `schema` exists for struct `Foo<Bar>`, but its trait bounds were not satisfied
2-
--> $DIR/not_openapitype_generics.rs:11:14
2+
--> tests/fail/not_openapitype_generics.rs:11:14
33
|
44
4 | struct Foo<T> {
55
| -------------

tests/fail/tuple_struct.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: #[derive(OpenapiType)] does not support tuple structs
2-
--> $DIR/tuple_struct.rs:4:11
2+
--> tests/fail/tuple_struct.rs:4:11
33
|
44
4 | struct Foo(i64, i64);
55
| ^^^^^^^^^^

tests/fail/tuple_variant.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: #[derive(OpenapiType)] does not support tuple variants
2-
--> $DIR/tuple_variant.rs:5:6
2+
--> tests/fail/tuple_variant.rs:5:6
33
|
44
5 | Pair(i64, i64)
55
| ^^^^^^^^^^

tests/fail/union.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: #[derive(OpenapiType)] cannot be used on unions
2-
--> $DIR/union.rs:4:1
2+
--> tests/fail/union.rs:4:1
33
|
44
4 | union Foo {
55
| ^^^^^
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: Unexpected token
2-
--> $DIR/unknown_attribute.rs:4:11
2+
--> tests/fail/unknown_attribute.rs:4:11
33
|
44
4 | #[openapi(pizza)]
55
| ^^^^^

0 commit comments

Comments
 (0)