-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report error locus within instrumented code (#170)
* Add report locus test * Give Function a higher precedence than Impl when parsing * Let rust parse impl automatically Letting Rust parse the impl block allows us to keep the same TokenStream as input in the autometrics macro code, even when async_trait is involved. Keeping the original TokenStream keeps the Span information in method/function bodies so error reporting in instrumented code is not absorbed in "#[autometrics]" span. This also simplifies the parsing code a little bit.
- Loading branch information
Showing
18 changed files
with
56 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! Tests relying on macros or compiler diagnostics | ||
|
||
#[test] | ||
fn harness() { | ||
let t = trybuild::TestCases::new(); | ||
|
||
// Test the ResultLabels macro | ||
t.pass("tests/compilation/result_labels/pass/*.rs"); | ||
t.compile_fail("tests/compilation/result_labels/fail/*.rs"); | ||
|
||
// Test that compiler reports errors in the correct location | ||
t.compile_fail("tests/compilation/error_locus/fail/*.rs"); | ||
} |
15 changes: 15 additions & 0 deletions
15
autometrics/tests/compilation/error_locus/fail/report_original_line.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,15 @@ | ||
// This test ensures that when an instrumented function has a compilation error, | ||
// then the error is reported at the correct line in the original code. | ||
use autometrics::autometrics; | ||
|
||
#[autometrics] | ||
fn bad_function() { | ||
// This vec is not mut | ||
let contents: Vec<u32> = Vec::new(); | ||
|
||
contents.push(2); | ||
} | ||
|
||
fn main() { | ||
bad_function(); | ||
} |
10 changes: 10 additions & 0 deletions
10
autometrics/tests/compilation/error_locus/fail/report_original_line.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,10 @@ | ||
error[E0596]: cannot borrow `contents` as mutable, as it is not declared as mutable | ||
--> tests/compilation/error_locus/fail/report_original_line.rs:10:5 | ||
| | ||
10 | contents.push(2); | ||
| ^^^^^^^^ cannot borrow as mutable | ||
| | ||
help: consider changing this to be mutable | ||
| | ||
8 | let mut contents: Vec<u32> = Vec::new(); | ||
| +++ |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...result_labels/fail/wrong_attribute.stderr → ...result_labels/fail/wrong_attribute.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: Only `label(result = "RES")` (RES can be "ok" or "error") is supported | ||
--> tests/result_labels/fail/wrong_attribute.rs:11:7 | ||
--> tests/compilation/result_labels/fail/wrong_attribute.rs:11:7 | ||
| | ||
11 | #[label] | ||
| ^^^^^ |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ult_labels/fail/wrong_kv_attribute.stderr → ...ult_labels/fail/wrong_kv_attribute.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: Only `label(result = "RES")` (RES can be "ok" or "error") is supported | ||
--> tests/result_labels/fail/wrong_kv_attribute.rs:11:7 | ||
--> tests/compilation/result_labels/fail/wrong_kv_attribute.rs:11:7 | ||
| | ||
11 | #[label = "error"] | ||
| ^^^^^^^^^^^^^^^ |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...sult_labels/fail/wrong_result_name.stderr → ...sult_labels/fail/wrong_result_name.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: Only `result = "RES"` (RES can be "ok" or "error") is supported | ||
--> tests/result_labels/fail/wrong_result_name.rs:11:13 | ||
--> tests/compilation/result_labels/fail/wrong_result_name.rs:11:13 | ||
| | ||
11 | #[label(unknown = "ok")] | ||
| ^^^^^^^ |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...s/result_labels/fail/wrong_variant.stderr → ...n/result_labels/fail/wrong_variant.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: Only "ok" or "error" are accepted as result values | ||
--> tests/result_labels/fail/wrong_variant.rs:12:22 | ||
--> tests/compilation/result_labels/fail/wrong_variant.rs:12:22 | ||
| | ||
12 | #[label(result = "not ok")] | ||
| ^^^^^^^^ |
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
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.