Fix bad placeholder type error on certain consts and statics#77431
Fix bad placeholder type error on certain consts and statics#77431varkor wants to merge 1 commit intorust-lang:masterfrom
Conversation
|
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
|
r? @estebank |
| fn foo() -> _ { 5 } //~ ERROR E0121 | ||
|
|
||
| static BAR: _ = "test"; //~ ERROR E0121 | ||
| //~^ ERROR E0121 |
There was a problem hiding this comment.
There's a duplicate error now, but as this is a pre-existing issue (#77428), and this fixes an ICE that could reasonably be encountered by users, I thought a quick fix was best.
There was a problem hiding this comment.
Actually, this triggers quite a few more additional error messages in other places; it'd be nicer to fix this now.
There was a problem hiding this comment.
@estebank: I thought we deduplicated diagnostics? Do you know the reason it's failing in this case?
There was a problem hiding this comment.
We don't deduplicate automatically at the error level, we do it on a case by case basis ahead of time. For _ E0121 errors it was a bit ad-hoc (introduced in #69148).
I remember having to tweak the logic a bit to have correct coverage (the self.tcx().sess.delay_span_bug(span, "bad placeholder type"); in one of the ty_infer impls had triggered a couple of times due to it). I would imagine that we'll need to do something along the lines of #70294 because two different codepaths that evaluate statics end up calling placeholder_type_error.
Edit: Oh! I see, this only happens for const/static for trait types. This is exactly the same type of duplicated problem I was seeing. I think you can get away by looking at the type we're evaluating...
There was a problem hiding this comment.
I think you can get away by looking at the type we're evaluating...
What do you mean by this?
| if matches!(it.kind, hir::ItemKind::Static(..) | hir::ItemKind::Const(..)) { | ||
| let mut visitor = PlaceholderHirTyCollector::default(); | ||
| visitor.visit_item(it); | ||
| placeholder_type_error(tcx, None, &[], visitor.0, false); |
There was a problem hiding this comment.
Wait... what happens if you remove this call? I'm pretty sure that using PlaceholderHirTyCollector it will make the call when encountering the _ as expected.
There was a problem hiding this comment.
Unfortunately, it has no effect, and the test continues to ICE.
|
back to author to fix broken test |
|
(I will try to get back to this, but there are higher priority issues for now.) |
|
I'm not going to be able to get back to this soon, so closing for now. |
Fixes #75889.