File tree Expand file tree Collapse file tree 3 files changed +17
-26
lines changed
compiler/rustc_hir_analysis/src/collect/type_of
tests/ui/type-alias-impl-trait Expand file tree Collapse file tree 3 files changed +17
-26
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,21 @@ impl TaitConstraintLocator<'_> {
134134 debug ! ( "no constraint: no typeck results" ) ;
135135 return ;
136136 }
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+ }
150+ }
151+
137152 // Calling `mir_borrowck` can lead to cycle errors through
138153 // const-checking, avoid calling it if we don't have to.
139154 // ```rust
Original file line number Diff line number Diff line change @@ -6,9 +6,7 @@ type Pointer<T> = impl std::ops::Deref<Target = T>;
66
77fn test ( ) -> Pointer < _ > {
88 //~^ ERROR: the placeholder `_` is not allowed within types
9- //~| ERROR: non-defining opaque type use in defining scope
109 Box :: new ( 1 )
11- //~^ ERROR expected generic type parameter, found `i32`
1210}
1311
1412fn main ( ) {
Original file line number Diff line number Diff line change @@ -7,28 +7,6 @@ LL | fn test() -> Pointer<_> {
77 | | not allowed in type signatures
88 | help: replace with the correct return type: `Pointer<i32>`
99
10- error[E0792]: non-defining opaque type use in defining scope
11- --> $DIR/issue-77179.rs:7:14
12- |
13- LL | fn test() -> Pointer<_> {
14- | ^^^^^^^^^^ argument `i32` is not a generic parameter
15- |
16- note: for this opaque type
17- --> $DIR/issue-77179.rs:5:19
18- |
19- LL | type Pointer<T> = impl std::ops::Deref<Target = T>;
20- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
22- error[E0792]: expected generic type parameter, found `i32`
23- --> $DIR/issue-77179.rs:10:5
24- |
25- LL | type Pointer<T> = impl std::ops::Deref<Target = T>;
26- | - this generic parameter must be used with a generic type parameter
27- ...
28- LL | Box::new(1)
29- | ^^^^^^^^^^^
30-
31- error: aborting due to 3 previous errors
10+ error: aborting due to 1 previous error
3211
33- Some errors have detailed explanations: E0121, E0792.
34- For more information about an error, try `rustc --explain E0121`.
12+ For more information about this error, try `rustc --explain E0121`.
You can’t perform that action at this time.
0 commit comments