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

Weird span for #[bench] method error #52411

Open
estebank opened this issue Jul 16, 2018 · 1 comment
Open

Weird span for #[bench] method error #52411

estebank opened this issue Jul 16, 2018 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Given

#[bench]
fn bar(x: isize) { }

The current output is suboptimal:

error[E0308]: mismatched types
  --> $DIR/issue-12997-2.rs:16:1
   |
LL | fn bar(x: isize) { }
   | ^^^^^^^^^^^^^^^^^^^^ expected isize, found mutable reference
   |
   = note: expected type `isize`
found type `&mut __test::test::Bencher`
@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 16, 2018
@euclio
Copy link
Contributor

euclio commented Oct 4, 2018

Unfortunately, I'm not sure that it's possible to get a better error message without making #[bench] a full-blown compiler plugin. Since #[bench] expansion happens before resolution, we can only check that the argument list has the expected number of arguments. We can't check the name of the argument either, because it could be aliased.

// NB: inadequate check, but we're running
// well before resolve, can't get too deep.
decl.inputs.len() == 1

So, we get this error after the macro has been expanded and the types fail to match. The reason #[test] can get better diagnostics here is because it can just assert that there are no args. You'll get a similarly confusing message if you write a test with a signature like fn test() -> String.

@crlf0710 crlf0710 added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants