-
Notifications
You must be signed in to change notification settings - Fork 13k
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
UX improvements around const usage and error lints #72660
Comments
Ping @estebank, I'm going to try and tackle this! |
Note: found about these error messages originally here: #51999 I think that improving these will also enhance the "panicking in const" experience. |
More notes: found some info about |
Basically all the points in the original post seem to stay relevant, but the last one (improving the note about lint level) changes to the question whether we should just get rid of it. |
Note that improving this will be hard until we resolve #71800. Since Cc @rust-lang/wg-const-eval |
Every attribute in Rust is per-item/expression/whatever-it-is-attached-to. If you want to set What do you think a better message would look like? Notice that your code is equivalent to something like const TEST_2: bool = TEST;
// 1000 lines of code.
#[warn(const_err)]
const TEST: bool = [true][1]; So it seems to me like the fact that an unrelated item has |
So, it seems that I had a misunderstanding what the error below was trying to tell:
I thought it was that the use of So, here's a rethought example of what I consider better errors, with this code: (note, removed the
Here's what it currently produces:
Here's what I find better errors, updated to reflect my new understanding:
|
Note: The unused lint warns separately for each unused item even for items that have been used inside another unused item. The linting for consts is in line with that, so it's not relevant to this issue, and shouldn't be unclear if the error message itself is improved. |
In my eyes the ideal output here would be:
Making the definition of Hiding the lint level note is in my eyes a regression, because it hides information from the user. We present it in the first place so that people know that this is 1) a lint and 2) how to disable it if they wish. Hiding the "cannot define |
@estebank I'm currently reading and tinkering with the error handling code in the const eval system + miri to see how it works, trying to eventually get only single error instead of two. About hiding the lint level: on the other thread ( #71800 ) there seemed to be significant momentum towards deprecating that lint. Because of backwards compatibility, we can't get rid of it, but I think that if it's deprecated, hiding it makes sense. |
@estebank There is another error around const panicking that wasn't talked about in this issue yet, but I'm eager to hear your opinion about it: Here, the error looks like this:
What do you think about the However, here, with |
It would be nice if we could have some kind of annotation similar to |
Another problem is that constants that depend on type parameters don’t report the value of those type parameters when they error. For an example, see https://users.rust-lang.org/t/how-to-get-context-for-associated-const-errors/44478 When an error occurs in one monomorphization but not others, it’s important to be able to tell where the error occurred. |
This code produces errors and warnings that I consider suboptimal:
(Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=20e9f735947348f61b83d9331c36f538 )
The errors and warnings are:
What could be better about this error message?
const_err
lint towarn
, it shows error message "warning: any use of this value will cause an error". Indeed, it errors whenTEST
is used in the definition ofTEST_2
. However, it also warns thatTEST
isn't used; so it has a conflicting definition of what counts as "use".#[deny(const_err)]
on by default" is confusing: yes, the default setting forconst_err
isdeny
, but it isn't actuallydeny
here. Is the default setting what you wanted to tell about? How is it relevant, especially as it would be better conveyed in the earlier "note: the lint level is defined here" warning?#[deny(const_err)]
on by default" message.#[deny(const_err)]
is a per-item attribute, so it notes that it's on by default... on this item. The message could be better.Meta
Reproduces on Rust version: 1.43.1 && latest nightly 2020-05-26.
The text was updated successfully, but these errors were encountered: