File tree 2 files changed +45
-3
lines changed
compiler/rustc_hir_analysis/src/collect/type_of
tests/ui/type-alias-impl-trait
2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -135,10 +135,16 @@ 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 ( ) {
138
+ // Function items with `_` in their return type already emit an error, skip any
139
+ // "non-defining use" errors for them.
140
+ match self . tcx . hir_node_by_def_id ( item_def_id) {
141
+ Node :: TraitItem ( TraitItem { kind : hir:: TraitItemKind :: Fn ( fn_sig, _) , .. } )
142
+ | Node :: ImplItem ( ImplItem { kind : hir:: ImplItemKind :: Fn ( fn_sig, _) , .. } )
143
+ | Node :: Item ( Item { kind : hir:: ItemKind :: Fn ( fn_sig, _, _) , .. } )
144
+ if fn_sig. decl . output . get_infer_ret_ty ( ) . is_some ( ) =>
145
+ {
140
146
let guar = self . tcx . dcx ( ) . span_delayed_bug (
141
- hir_sig . output . span ( ) ,
147
+ fn_sig . decl . output . span ( ) ,
142
148
"inferring return types and opaque types do not mix well" ,
143
149
) ;
144
150
self . found = Some ( ty:: OpaqueHiddenType {
@@ -147,6 +153,7 @@ impl TaitConstraintLocator<'_> {
147
153
} ) ;
148
154
return ;
149
155
}
156
+ _ => { }
150
157
}
151
158
152
159
// 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