You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The proper way to fix this is to move the errors/warnings into the query, instead of having to do this at all places where the query is made. This is both the right fix for #52849 and avoids duplicate errors.
So the const_eval query would be renamed to const_eval_raw and only used internally. There would be three new queries eval_const, eval_static, eval_promoted with different behavior wrt. showing an error or a warning, and whether to do validation of the final value.
The lint would just trigger all these queries. Thanks to caching, a warning triggered by a query is only ever shown once.
Yea, there's enough things testing this. The only concern I see now is that if you allow(const_err) you have no idea anymore what's going on with the constant, rustc just tells you
error[E0080]: could not evaluate constant
--> src/main.rs:10:13
|
10 | let f = BAD;
| ^^^ referenced constant has errors
error: any use of this value will cause an error
--> src/main.rs:8:1
|
8 | const BAD: usize = unsafe { Foo { a: &1 }.b * 2};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------------^^
| |
| "pointer arithmetic or comparison" needs an rfc before being allowed inside constants
|
= note: #[deny(const_err)] on by default
Activity
RalfJung commentedon Jul 31, 2018
It gets even better when having
warn(const_err): Then we get if 4 times.RalfJung commentedon Aug 1, 2018
From conversation with @oli-obk:
The proper way to fix this is to move the errors/warnings into the query, instead of having to do this at all places where the query is made. This is both the right fix for #52849 and avoids duplicate errors.
So the
const_evalquery would be renamed toconst_eval_rawand only used internally. There would be three new querieseval_const,eval_static,eval_promotedwith different behavior wrt. showing an error or a warning, and whether to do validation of the final value.The lint would just trigger all these queries. Thanks to caching, a warning triggered by a query is only ever shown once.
RalfJung commentedon Nov 9, 2018
Thanks to @oli-obk's const-query-error PR, this is now fixed.
@oli-obk should this get a dedicated regression test? My impression is that we already have tons of tests like this.
oli-obk commentedon Nov 9, 2018
Yea, there's enough things testing this. The only concern I see now is that if you
allow(const_err)you have no idea anymore what's going on with the constant, rustc just tells youwithout any further info.
estebank commentedon Jan 8, 2019
Closing as per #53821: