-
Notifications
You must be signed in to change notification settings - Fork 804
Add fake return to improve span on type error in tracing::instrument
#2270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
baae90b
Add fake return to improve span on type error in tracing::instrument
compiler-errors 9aea0e5
Add trybuild test for instrumented async fn type mismatch
compiler-errors 33354fd
Suppress clippy divergence warning
compiler-errors 6ce6714
Improve error for async fn implicitly returning unit
compiler-errors 4d833c6
Suppress more clippy
compiler-errors 1e64ae0
Pin trybuild test to stable instead
compiler-errors b2ee65d
Merge branch 'master' into return-span
davidbarsky fe23492
Merge branch 'master' into return-span
hawkw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
// Only test on nightly, since UI tests are bound to change over time | ||
#[rustversion::nightly] | ||
#[test] | ||
fn async_instrument() { | ||
let t = trybuild::TestCases::new(); | ||
t.compile_fail("tests/ui/async_instrument.rs"); | ||
} |
This file contains hidden or 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,46 @@ | ||
#![allow(unreachable_code)] | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#[tracing::instrument] | ||
async fn unit() { | ||
"" | ||
} | ||
|
||
#[tracing::instrument] | ||
async fn simple_mismatch() -> String { | ||
"" | ||
} | ||
|
||
// FIXME: this span is still pretty poor | ||
#[tracing::instrument] | ||
async fn opaque_unsatisfied() -> impl std::fmt::Display { | ||
("",) | ||
} | ||
|
||
struct Wrapper<T>(T); | ||
|
||
#[tracing::instrument] | ||
async fn mismatch_with_opaque() -> Wrapper<impl std::fmt::Display> { | ||
"" | ||
} | ||
|
||
#[tracing::instrument] | ||
async fn early_return_unit() { | ||
if true { | ||
return ""; | ||
} | ||
} | ||
|
||
#[tracing::instrument] | ||
async fn early_return() -> String { | ||
if true { | ||
return ""; | ||
} | ||
String::new() | ||
} | ||
|
||
#[tracing::instrument] | ||
async fn extra_semicolon() -> i32 { | ||
1; | ||
} | ||
|
||
fn main() {} |
This file contains hidden or 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,98 @@ | ||
error[E0308]: mismatched types | ||
--> tests/ui/async_instrument.rs:5:5 | ||
| | ||
5 | "" | ||
| ^^ expected `()`, found `&str` | ||
| | ||
note: return type inferred to be `()` here | ||
--> tests/ui/async_instrument.rs:4:10 | ||
| | ||
4 | async fn unit() { | ||
| ^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> tests/ui/async_instrument.rs:10:5 | ||
| | ||
10 | "" | ||
| ^^- help: try using a conversion method: `.to_string()` | ||
| | | ||
| expected struct `String`, found `&str` | ||
| | ||
note: return type inferred to be `String` here | ||
--> tests/ui/async_instrument.rs:9:31 | ||
| | ||
9 | async fn simple_mismatch() -> String { | ||
| ^^^^^^ | ||
|
||
error[E0277]: `(&str,)` doesn't implement `std::fmt::Display` | ||
--> tests/ui/async_instrument.rs:14:1 | ||
| | ||
14 | #[tracing::instrument] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ `(&str,)` cannot be formatted with the default formatter | ||
| | ||
= help: the trait `std::fmt::Display` is not implemented for `(&str,)` | ||
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead | ||
= note: this error originates in the attribute macro `tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: `(&str,)` doesn't implement `std::fmt::Display` | ||
--> tests/ui/async_instrument.rs:15:34 | ||
| | ||
15 | async fn opaque_unsatisfied() -> impl std::fmt::Display { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ `(&str,)` cannot be formatted with the default formatter | ||
| | ||
= help: the trait `std::fmt::Display` is not implemented for `(&str,)` | ||
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead | ||
|
||
error[E0308]: mismatched types | ||
--> tests/ui/async_instrument.rs:23:5 | ||
| | ||
23 | "" | ||
| ^^ expected struct `Wrapper`, found `&str` | ||
| | ||
= note: expected struct `Wrapper<_>` | ||
found reference `&'static str` | ||
note: return type inferred to be `Wrapper<_>` here | ||
--> tests/ui/async_instrument.rs:22:36 | ||
| | ||
22 | async fn mismatch_with_opaque() -> Wrapper<impl std::fmt::Display> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: try wrapping the expression in `Wrapper` | ||
| | ||
23 | Wrapper("") | ||
| ++++++++ + | ||
|
||
error[E0308]: mismatched types | ||
--> tests/ui/async_instrument.rs:29:16 | ||
| | ||
29 | return ""; | ||
| ^^ expected `()`, found `&str` | ||
| | ||
note: return type inferred to be `()` here | ||
--> tests/ui/async_instrument.rs:27:10 | ||
| | ||
27 | async fn early_return_unit() { | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> tests/ui/async_instrument.rs:36:16 | ||
| | ||
36 | return ""; | ||
| ^^- help: try using a conversion method: `.to_string()` | ||
| | | ||
| expected struct `String`, found `&str` | ||
| | ||
note: return type inferred to be `String` here | ||
--> tests/ui/async_instrument.rs:34:28 | ||
| | ||
34 | async fn early_return() -> String { | ||
| ^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> tests/ui/async_instrument.rs:42:35 | ||
| | ||
42 | async fn extra_semicolon() -> i32 { | ||
| ___________________________________^ | ||
43 | | 1; | ||
| | - help: remove this semicolon | ||
44 | | } | ||
| |_^ expected `i32`, found `()` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.