-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3/n] [daft-derive] attempt to better annotate semantic errors
Add some span info to try and annotate semantic errors better (such as highlighting the name of the field that's not diffable). This isn't perfect for now because we still produce some call-site errors, but at least we produce one error that's attributed directly to the field name so rust-analyzer should be happy. I tried adding more bounds but ran into rust-lang/rust#48214. Reviewers: andrewjstone Reviewed By: andrewjstone Pull Request: #60
- Loading branch information
1 parent
f4fc719
commit 7cb7e7a
Showing
8 changed files
with
197 additions
and
14 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
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
39 changes: 39 additions & 0 deletions
39
daft-derive/tests/fixtures/invalid/output/struct-field-not-diffable.output.rs
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,39 @@ | ||
struct MyStructDiff<'__daft> { | ||
a: <i32 as ::daft::Diffable>::Diff<'__daft>, | ||
b: <NonDiffable as ::daft::Diffable>::Diff<'__daft>, | ||
} | ||
impl<'__daft> ::std::fmt::Debug for MyStructDiff<'__daft> | ||
where | ||
<i32 as ::daft::Diffable>::Diff<'__daft>: ::std::fmt::Debug, | ||
<NonDiffable as ::daft::Diffable>::Diff<'__daft>: ::std::fmt::Debug, | ||
{ | ||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { | ||
f.debug_struct(stringify!(MyStructDiff)) | ||
.field(stringify!(a), &self.a) | ||
.field(stringify!(b), &self.b) | ||
.finish() | ||
} | ||
} | ||
impl<'__daft> ::std::cmp::PartialEq for MyStructDiff<'__daft> | ||
where | ||
<i32 as ::daft::Diffable>::Diff<'__daft>: ::std::cmp::PartialEq, | ||
<NonDiffable as ::daft::Diffable>::Diff<'__daft>: ::std::cmp::PartialEq, | ||
{ | ||
fn eq(&self, other: &Self) -> bool { | ||
self.a == other.a && self.b == other.b | ||
} | ||
} | ||
impl<'__daft> ::std::cmp::Eq for MyStructDiff<'__daft> | ||
where | ||
<i32 as ::daft::Diffable>::Diff<'__daft>: ::std::cmp::Eq, | ||
<NonDiffable as ::daft::Diffable>::Diff<'__daft>: ::std::cmp::Eq, | ||
{} | ||
impl ::daft::Diffable for MyStruct { | ||
type Diff<'__daft> = MyStructDiff<'__daft> where Self: '__daft; | ||
fn diff<'__daft>(&'__daft self, other: &'__daft Self) -> MyStructDiff<'__daft> { | ||
Self::Diff { | ||
a: ::daft::Diffable::diff(&self.a, &other.a), | ||
b: ::daft::Diffable::diff(&self.b, &other.b), | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
daft-derive/tests/fixtures/invalid/struct-field-not-diffable.rs
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,14 @@ | ||
use daft::Diffable; | ||
|
||
struct NonDiffable {} | ||
|
||
#[derive(Diffable)] | ||
struct MyStruct { | ||
a: i32, | ||
b: NonDiffable, | ||
} | ||
|
||
fn main() { | ||
// MyStruct should still exist, even though the Diffable impl has errors. | ||
let _ = MyStruct { a: 0, b: NonDiffable {} }; | ||
} |
88 changes: 88 additions & 0 deletions
88
daft-derive/tests/fixtures/invalid/struct-field-not-diffable.stderr
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,88 @@ | ||
error[E0277]: the trait bound `NonDiffable: Diffable` is not satisfied | ||
--> tests/fixtures/invalid/struct-field-not-diffable.rs:8:5 | ||
| | ||
8 | b: NonDiffable, | ||
| ^ the trait `Diffable` is not implemented for `NonDiffable` | ||
| | ||
= help: the following other types implement trait `Diffable`: | ||
&'a T | ||
() | ||
(A, B) | ||
(A, B, C) | ||
(A, B, C, D) | ||
(A, B, C, D, E) | ||
(A, B, C, D, E, F) | ||
(A, B, C, D, E, F, G) | ||
and $N others | ||
|
||
error[E0277]: the trait bound `NonDiffable: Diffable` is not satisfied | ||
--> tests/fixtures/invalid/struct-field-not-diffable.rs:5:10 | ||
| | ||
5 | #[derive(Diffable)] | ||
| ^^^^^^^^ the trait `Diffable` is not implemented for `NonDiffable` | ||
| | ||
= help: the following other types implement trait `Diffable`: | ||
&'a T | ||
() | ||
(A, B) | ||
(A, B, C) | ||
(A, B, C, D) | ||
(A, B, C, D, E) | ||
(A, B, C, D, E, F) | ||
(A, B, C, D, E, F, G) | ||
and $N others | ||
= note: this error originates in the derive macro `Diffable` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `NonDiffable: Diffable` is not satisfied in `MyStructDiff<'__daft>` | ||
--> tests/fixtures/invalid/struct-field-not-diffable.rs:5:10 | ||
| | ||
5 | #[derive(Diffable)] | ||
| ^^^^^^^^ within `MyStructDiff<'__daft>`, the trait `Diffable` is not implemented for `NonDiffable` | ||
| | ||
= help: the following other types implement trait `Diffable`: | ||
&'a T | ||
() | ||
(A, B) | ||
(A, B, C) | ||
(A, B, C, D) | ||
(A, B, C, D, E) | ||
(A, B, C, D, E, F) | ||
(A, B, C, D, E, F, G) | ||
and $N others | ||
note: required because it appears within the type `MyStructDiff<'__daft>` | ||
--> tests/fixtures/invalid/struct-field-not-diffable.rs:5:10 | ||
| | ||
5 | #[derive(Diffable)] | ||
| ^^^^^^^^ | ||
note: required by a bound in `daft::Diffable::Diff` | ||
--> $WORKSPACE/daft/src/diffable.rs | ||
| | ||
| / type Diff<'daft> | ||
| | where | ||
| | Self: 'daft; | ||
| |____________________^ required by this bound in `Diffable::Diff` | ||
= note: this error originates in the derive macro `Diffable` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `NonDiffable: Diffable` is not satisfied in `MyStructDiff<'__daft>` | ||
--> tests/fixtures/invalid/struct-field-not-diffable.rs:5:10 | ||
| | ||
5 | #[derive(Diffable)] | ||
| ^^^^^^^^ within `MyStructDiff<'__daft>`, the trait `Diffable` is not implemented for `NonDiffable` | ||
| | ||
= help: the following other types implement trait `Diffable`: | ||
&'a T | ||
() | ||
(A, B) | ||
(A, B, C) | ||
(A, B, C, D) | ||
(A, B, C, D, E) | ||
(A, B, C, D, E, F) | ||
(A, B, C, D, E, F, G) | ||
and $N others | ||
note: required because it appears within the type `MyStructDiff<'__daft>` | ||
--> tests/fixtures/invalid/struct-field-not-diffable.rs:5:10 | ||
| | ||
5 | #[derive(Diffable)] | ||
| ^^^^^^^^ | ||
= note: the return type of a function must have a statically known size | ||
= note: this error originates in the derive macro `Diffable` (in Nightly builds, run with -Z macro-backtrace for more info) |
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,8 @@ | ||
# We use a specific toolchain revision to ensure our tests - which | ||
# occasionally depend on specific compiler output - remain stable | ||
# for all developers until the toolchain is explicitly advanced. | ||
# The intent is to keep this updated as new stable versions are relased. | ||
|
||
[toolchain] | ||
channel = "1.85.0" | ||
profile = "default" |