rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.14k stars 12.69k forks source link

Consider changing the way unevaluated constants are printed #61581

Open oli-obk opened 5 years ago

oli-obk commented 5 years ago

cc https://github.com/rust-lang/rust/pull/60742#discussion_r288742080

Right now when we encounter a ConstValue::Unevaluated during pretty printing, we fall back to printing the constant's source code or _ if that also fails. Alternative options are:

varkor commented 5 years ago

I think it would be ideal if we could print the unevaluated expression itself. (Though we might have to point out specifically that it's unevaluated in diagnostics if this proves confusing.)

oli-obk commented 5 years ago

that's what we are doing right now, but you end up with errors like expected 3 got 3usize. If we eagerly evaluated we'd even get expected 3usize got 3usize

These errors may just disappear if we manage to normalize before doing whatever causes the error.

varkor commented 5 years ago

Ah, I was specifically referring to the case when _ is printed at the moment, which has been encountered quite frequently with const generics.

I agree the cases when it does print the expression, and they look the same as what's expected is confusing, but these seem more indicative of existing issues, like normalisation, than printing. Maybe the diagnostics, rather than the pretty printing, could be adjusted for now to address this.