Skip to content

Commit 3fccae4

Browse files
author
Lukas Markeffsky
committed
Don't ICE if TAIT-defining fn contains a closure with _ in return type
1 parent 665d2c6 commit 3fccae4

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,18 @@ impl TaitConstraintLocator<'_> {
135135
return;
136136
}
137137

138-
if let Some(hir_sig) = self.tcx.hir_node_by_def_id(item_def_id).fn_decl() {
139-
if hir_sig.output.get_infer_ret_ty().is_some() {
140-
let guar = self.tcx.dcx().span_delayed_bug(
141-
hir_sig.output.span(),
142-
"inferring return types and opaque types do not mix well",
143-
);
144-
self.found = Some(ty::OpaqueHiddenType {
145-
span: DUMMY_SP,
146-
ty: Ty::new_error(self.tcx, guar),
147-
});
148-
return;
149-
}
138+
// Function items with `_` in their return type already emit an error, skip any
139+
// "non-defining use" errors for them.
140+
if let Some(hir_sig) = self.tcx.hir_node_by_def_id(item_def_id).fn_sig()
141+
&& hir_sig.decl.output.get_infer_ret_ty().is_some()
142+
{
143+
let guar = self.tcx.dcx().span_delayed_bug(
144+
hir_sig.decl.output.span(),
145+
"inferring return types and opaque types do not mix well",
146+
);
147+
self.found =
148+
Some(ty::OpaqueHiddenType { span: DUMMY_SP, ty: Ty::new_error(self.tcx, guar) });
149+
return;
150150
}
151151

152152
// Calling `mir_borrowck` can lead to cycle errors through
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// check-pass
2+
3+
// Regression test for an ICE: https://github.com/rust-lang/rust/issues/119916
4+
5+
#![feature(impl_trait_in_assoc_type)]
6+
#![feature(type_alias_impl_trait)]
7+
8+
// `impl_trait_in_assoc_type` example from the bug report.
9+
pub trait StreamConsumer {
10+
type BarrierStream;
11+
fn execute() -> Self::BarrierStream;
12+
}
13+
14+
pub struct DispatchExecutor;
15+
16+
impl StreamConsumer for DispatchExecutor {
17+
type BarrierStream = impl Sized;
18+
fn execute() -> Self::BarrierStream {
19+
|| -> _ {}
20+
}
21+
}
22+
23+
// Functions that constrain TAITs can contain closures with an `_` in the return type.
24+
type Foo = impl Sized;
25+
fn foo() -> Foo {
26+
|| -> _ {}
27+
}
28+
29+
// The `_` in the closure return type can also be the TAIT itself.
30+
type Bar = impl Sized;
31+
fn bar() -> impl FnOnce() -> Bar {
32+
|| -> _ {}
33+
}
34+
35+
fn main() {}

0 commit comments

Comments
 (0)