File tree 2 files changed +47
-12
lines changed
compiler/rustc_hir_analysis/src/collect/type_of
tests/ui/type-alias-impl-trait
2 files changed +47
-12
lines changed Original file line number Diff line number Diff line change @@ -135,18 +135,18 @@ impl TaitConstraintLocator<'_> {
135
135
return ;
136
136
}
137
137
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 ;
150
150
}
151
151
152
152
// Calling `mir_borrowck` can lead to cycle errors through
Original file line number Diff line number Diff line change
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 ( ) { }
You can’t perform that action at this time.
0 commit comments