-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
Previously, these were allowed if the function returned `()`, but always led to an ambiguity error.
r? @eholk (rustbot has picked a reviewer for you, use r? to override) |
} | ||
(false, _) => true, | ||
if has_should_panic_attr && has_output { | ||
sd.span_err(i.span, "functions using `#[should_panic]` must return `()`"); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this 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
@bors r+ |
`#[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.
☀️ Test successful - checks-actions |
Finished benchmarking commit (6895110): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 658.179s -> 656.783s (-0.21%) |
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`
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`
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:
after:
Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.