File tree 3 files changed +17
-26
lines changed
compiler/rustc_hir_analysis/src/collect/type_of
tests/ui/type-alias-impl-trait
3 files changed +17
-26
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,21 @@ impl TaitConstraintLocator<'_> {
134
134
debug ! ( "no constraint: no typeck results" ) ;
135
135
return ;
136
136
}
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
+
137
152
// Calling `mir_borrowck` can lead to cycle errors through
138
153
// const-checking, avoid calling it if we don't have to.
139
154
// ```rust
Original file line number Diff line number Diff line change @@ -6,9 +6,7 @@ type Pointer<T> = impl std::ops::Deref<Target = T>;
6
6
7
7
fn test ( ) -> Pointer < _ > {
8
8
//~^ ERROR: the placeholder `_` is not allowed within types
9
- //~| ERROR: non-defining opaque type use in defining scope
10
9
Box :: new ( 1 )
11
- //~^ ERROR expected generic type parameter, found `i32`
12
10
}
13
11
14
12
fn main ( ) {
Original file line number Diff line number Diff line change @@ -7,28 +7,6 @@ LL | fn test() -> Pointer<_> {
7
7
| | not allowed in type signatures
8
8
| help: replace with the correct return type: `Pointer<i32>`
9
9
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
32
11
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