Skip to content
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

macros: Improve IDE support #6968

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions tests-build/tests/fail/macros_dead_code.stderr

This file was deleted.

28 changes: 23 additions & 5 deletions tests-build/tests/fail/macros_invalid_input.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,28 @@ error: second test attribute is supplied, consider removing or changing the orde
64 | #[std::prelude::rust_2021::test]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: second test attribute is supplied, consider removing or changing the order of your test attributes
--> tests/fail/macros_invalid_input.rs:67:1
error: duplicated attribute
--> tests/fail/macros_invalid_input.rs:48:1
|
48 | #[test]
| ^^^^^^^
|
67 | #[tokio::test]
| ^^^^^^^^^^^^^^
note: the lint level is defined here
--> tests/fail/macros_invalid_input.rs:1:9
|
= note: this error originates in the attribute macro `tokio::test` (in Nightly builds, run with -Z macro-backtrace for more info)
1 | #![deny(duplicate_macro_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: `()` is not a future
--> tests/fail/macros_invalid_input.rs:5:1
|
5 | #[tokio::main]
| ^^^^^^^^^^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`
note: required by a bound in `Runtime::block_on`
--> $WORKSPACE/tokio/src/runtime/runtime.rs
|
| pub fn block_on<F: Future>(&self, future: F) -> F::Output {
| ^^^^^^ required by this bound in `Runtime::block_on`
= note: this error originates in the attribute macro `tokio::main` (in Nightly builds, run with -Z macro-backtrace for more info)
8 changes: 0 additions & 8 deletions tests-build/tests/fail/macros_type_mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ async fn missing_return_type() {

#[tokio::main]
async fn extra_semicolon() -> Result<(), ()> {
/* TODO(taiki-e): help message still wrong
help: try using a variant of the expected enum
|
23 | Ok(Ok(());)
|
23 | Err(Ok(());)
|
*/
Ok(());
}

Expand Down
105 changes: 26 additions & 79 deletions tests-build/tests/fail/macros_type_mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,111 +6,58 @@ error[E0308]: mismatched types
|
= note: expected unit type `()`
found enum `Result<(), _>`
help: a return type might be missing here
|
4 | async fn missing_semicolon_or_return_type() -> _ {
| ++++
help: consider using `Result::expect` to unwrap the `Result<(), _>` value, panicking if the value is a `Result::Err`
|
5 | Ok(()).expect("REASON")
| +++++++++++++++++

error[E0308]: mismatched types
--> tests/fail/macros_type_mismatch.rs:10:5
--> tests/fail/macros_type_mismatch.rs:10:12
|
10 | return Ok(());
| ^^^^^^^^^^^^^^ expected `()`, found `Result<(), _>`
| ^^^^^^ expected `()`, found `Result<(), _>`
|
= note: expected unit type `()`
found enum `Result<(), _>`
help: a return type might be missing here
|
9 | async fn missing_return_type() -> _ {
| ++++
help: consider using `Result::expect` to unwrap the `Result<(), _>` value, panicking if the value is a `Result::Err`
|
10 | return Ok(());.expect("REASON")
| +++++++++++++++++

error[E0308]: mismatched types
--> tests/fail/macros_type_mismatch.rs:23:5
--> tests/fail/macros_type_mismatch.rs:14:46
|
14 | async fn extra_semicolon() -> Result<(), ()> {
| -------------- expected `Result<(), ()>` because of return type
...
23 | Ok(());
| ^^^^^^^ expected `Result<(), ()>`, found `()`
14 | async fn extra_semicolon() -> Result<(), ()> {
| ______________________________________________^
15 | | Ok(());
| | - help: remove this semicolon to return this value
16 | | }
| |_^ expected `Result<(), ()>`, found `()`
|
= note: expected enum `Result<(), ()>`
found unit type `()`
help: try adding an expression at the end of the block
|
23 ~ Ok(());;
24 + Ok(())
|

error[E0277]: the `?` operator can only be used in an async block that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> tests/fail/macros_type_mismatch.rs:40:9
|
38 | #[tokio::main]
| -------------- this function should return `Result` or `Option` to accept `?`
39 | async fn question_mark_operator_with_invalid_option() -> Option<()> {
40 | None?;
| ^ cannot use the `?` operator in an async block that returns `()`
|
= help: the trait `FromResidual<Option<Infallible>>` is not implemented for `()`

error[E0308]: mismatched types
--> tests/fail/macros_type_mismatch.rs:40:5
--> tests/fail/macros_type_mismatch.rs:31:69
|
39 | async fn question_mark_operator_with_invalid_option() -> Option<()> {
| ---------- expected `Option<()>` because of return type
40 | None?;
| ^^^^^^ expected `Option<()>`, found `()`
31 | async fn question_mark_operator_with_invalid_option() -> Option<()> {
| _____________________________________________________________________^
32 | | None?;
| | - help: remove this semicolon to return this value
33 | | }
| |_^ expected `Option<()>`, found `()`
|
= note: expected enum `Option<()>`
found unit type `()`
help: try adding an expression at the end of the block
|
40 ~ None?;;
41 + None
|
40 ~ None?;;
41 + Some(())
|

error[E0277]: the `?` operator can only be used in an async block that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> tests/fail/macros_type_mismatch.rs:57:11
|
55 | #[tokio::main]
| -------------- this function should return `Result` or `Option` to accept `?`
56 | async fn question_mark_operator_with_invalid_result() -> Result<(), ()> {
57 | Ok(())?;
| ^ cannot use the `?` operator in an async block that returns `()`
|
= help: the trait `FromResidual<Result<Infallible, _>>` is not implemented for `()`

error[E0308]: mismatched types
--> tests/fail/macros_type_mismatch.rs:57:5
--> tests/fail/macros_type_mismatch.rs:48:73
|
56 | async fn question_mark_operator_with_invalid_result() -> Result<(), ()> {
| -------------- expected `Result<(), ()>` because of return type
57 | Ok(())?;
| ^^^^^^^^ expected `Result<(), ()>`, found `()`
48 | async fn question_mark_operator_with_invalid_result() -> Result<(), ()> {
| _________________________________________________________________________^
49 | | Ok(())?;
50 | | }
| |_^ expected `Result<(), ()>`, found `()`
|
= note: expected enum `Result<(), ()>`
found unit type `()`
help: try adding an expression at the end of the block
|
57 ~ Ok(())?;;
58 + Ok(())
|

error[E0308]: mismatched types
--> tests/fail/macros_type_mismatch.rs:66:5
--> tests/fail/macros_type_mismatch.rs:57:12
|
64 | async fn issue_4635() {
56 | async fn issue_4635() {
| - help: try adding a return type: `-> i32`
65 | return 1;
66 | ;
| ^ expected `()`, found integer
57 | return 1;
| ^ expected `()`, found integer
4 changes: 2 additions & 2 deletions tests-build/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ fn compile_fail_full() {
t.pass("tests/pass/macros_main_loop.rs");

#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_invalid_input.rs");
t.pass("tests/pass/macros_dead_code.rs");

#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_dead_code.rs");
t.compile_fail("tests/fail/macros_invalid_input.rs");

#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_type_mismatch.rs");
Expand Down
7 changes: 0 additions & 7 deletions tests-build/tests/macros_clippy.rs

This file was deleted.

Loading
Loading