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

#[test] function signature verification improvements #112366

Merged
merged 3 commits into from
Jun 19, 2023

Conversation

lukas-code
Copy link
Member

@lukas-code lukas-code commented Jun 6, 2023

This PR contains two improvements to the expansion of the #[test] macro.

The first one fixes #112360 by correctly recovering item statements if the signature verification fails.

The second one forbids non-lifetime generics on #[test] functions. These were previously allowed if the function returned (), but always caused an inference error:

before:

error[E0282]: type annotations needed
 --> src/lib.rs:2:1
  |
1 | #[test]
  | ------- in this procedural macro expansion
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^ cannot infer type

after:

error: functions used as tests can not have any non-lifetime generic parameters
 --> src/lib.rs:2:1
  |
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^

Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.

Lukas Markeffsky added 3 commits June 6, 2023 23:28
Previously, these were allowed if the function returned `()`, but always led to an ambiguity error.
@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2023

r? @eholk

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 6, 2023
}
(false, _) => true,
if has_should_panic_attr && has_output {
sd.span_err(i.span, "functions using `#[should_panic]` must return `()`");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(false, _) => true,
if has_should_panic_attr && has_output {
sd.span_err(i.span, "functions using `#[should_panic]` must return `()`");
return false;
Copy link
Member

@Noratrieb Noratrieb Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function should probably return Result<(), ErrorGuaranteed> in a follow-up PR if you want

Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable
r? Nilstrieb

@rustbot rustbot assigned Noratrieb and unassigned eholk Jun 19, 2023
@Noratrieb
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 19, 2023

📌 Commit 5049743 has been approved by Nilstrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2023
jyn514 added a commit to jyn514/rust that referenced this pull request Jun 19, 2023
`#[test]` function signature verification improvements

This PR contains two improvements to the expansion of the `#[test]` macro.

The first one fixes rust-lang#112360 by correctly recovering item statements if the signature verification fails.

The second one forbids non-lifetime generics on `#[test]` functions. These were previously allowed if the function returned `()`, but always caused an inference error:

before:
```text
error[E0282]: type annotations needed
 --> src/lib.rs:2:1
  |
1 | #[test]
  | ------- in this procedural macro expansion
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^ cannot infer type
```

after:
```text
error: functions used as tests can not have any non-lifetime generic parameters
 --> src/lib.rs:2:1
  |
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^
```

Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.
@bors
Copy link
Contributor

bors commented Jun 19, 2023

⌛ Testing commit 5049743 with merge 6895110...

@bors
Copy link
Contributor

bors commented Jun 19, 2023

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing 6895110 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 19, 2023
@bors bors merged commit 6895110 into rust-lang:master Jun 19, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 19, 2023
@lukas-code lukas-code deleted the test branch June 19, 2023 16:48
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6895110): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.8% [-2.8%, -2.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.8% [-2.8%, -2.8%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 658.179s -> 656.783s (-0.21%)

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 24, 2023
use ErrorGuaranteed instead of booleans in rustc_builtin_macros

implements rust-lang#112366 (comment)

No functional changes.

Best reviewed with whitespace diff disabled.

r? `@Nilstrieb`
oli-obk pushed a commit to oli-obk/miri that referenced this pull request Jun 28, 2023
use ErrorGuaranteed instead of booleans in rustc_builtin_macros

implements rust-lang/rust#112366 (comment)

No functional changes.

Best reviewed with whitespace diff disabled.

r? `@Nilstrieb`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE expected statement --test
6 participants