@@ -135,18 +135,25 @@ 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
+ // Note that we use `Node::fn_sig` instead of `Node::fn_decl` here, because the former
141
+ // excludes closures, which are allowed to have `_` in their return type.
142
+ let hir_node = self . tcx . hir_node_by_def_id ( item_def_id) ;
143
+ debug_assert ! (
144
+ !matches!( hir_node, Node :: ForeignItem ( ..) ) ,
145
+ "foreign items cannot constrain opaque types" ,
146
+ ) ;
147
+ if let Some ( hir_sig) = hir_node. fn_sig ( )
148
+ && hir_sig. decl . output . get_infer_ret_ty ( ) . is_some ( )
149
+ {
150
+ let guar = self . tcx . dcx ( ) . span_delayed_bug (
151
+ hir_sig. decl . output . span ( ) ,
152
+ "inferring return types and opaque types do not mix well" ,
153
+ ) ;
154
+ self . found =
155
+ Some ( ty:: OpaqueHiddenType { span : DUMMY_SP , ty : Ty :: new_error ( self . tcx , guar) } ) ;
156
+ return ;
150
157
}
151
158
152
159
// Calling `mir_borrowck` can lead to cycle errors through
0 commit comments