File tree 5 files changed +97
-3
lines changed
compiler/rustc_hir_analysis
tests/ui/async-await/return-type-notation
5 files changed +97
-3
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,13 @@ hir_analysis_return_type_notation_conflicting_bound =
195
195
hir_analysis_return_type_notation_equality_bound =
196
196
return type notation is not allowed to use type equality
197
197
198
+ hir_analysis_return_type_notation_illegal_param_const =
199
+ return type notation is not allowed for functions that have const parameters
200
+ .label = const parameter declared here
201
+ hir_analysis_return_type_notation_illegal_param_type =
202
+ return type notation is not allowed for functions that have type parameters
203
+ .label = type parameter declared here
204
+
198
205
hir_analysis_return_type_notation_missing_method =
199
206
cannot find associated function `{ $assoc_name } ` for `{ $ty_name } `
200
207
Original file line number Diff line number Diff line change @@ -1215,6 +1215,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1215
1215
}
1216
1216
1217
1217
let projection_ty = if return_type_notation {
1218
+ let mut emitted_bad_param_err = false ;
1218
1219
// If we have an method return type bound, then we need to substitute
1219
1220
// the method's early bound params with suitable late-bound params.
1220
1221
let mut num_bound_vars = candidate. bound_vars ( ) . len ( ) ;
@@ -1230,16 +1231,35 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1230
1231
} ,
1231
1232
)
1232
1233
. into ( ) ,
1233
- GenericParamDefKind :: Type { .. } => tcx
1234
- . mk_bound (
1234
+ GenericParamDefKind :: Type { .. } => {
1235
+ if !emitted_bad_param_err {
1236
+ tcx. sess . emit_err (
1237
+ crate :: errors:: ReturnTypeNotationIllegalParam :: Type {
1238
+ span : path_span,
1239
+ param_span : tcx. def_span ( param. def_id ) ,
1240
+ } ,
1241
+ ) ;
1242
+ emitted_bad_param_err = true ;
1243
+ }
1244
+ tcx. mk_bound (
1235
1245
ty:: INNERMOST ,
1236
1246
ty:: BoundTy {
1237
1247
var : ty:: BoundVar :: from_usize ( num_bound_vars) ,
1238
1248
kind : ty:: BoundTyKind :: Param ( param. def_id , param. name ) ,
1239
1249
} ,
1240
1250
)
1241
- . into ( ) ,
1251
+ . into ( )
1252
+ }
1242
1253
GenericParamDefKind :: Const { .. } => {
1254
+ if !emitted_bad_param_err {
1255
+ tcx. sess . emit_err (
1256
+ crate :: errors:: ReturnTypeNotationIllegalParam :: Const {
1257
+ span : path_span,
1258
+ param_span : tcx. def_span ( param. def_id ) ,
1259
+ } ,
1260
+ ) ;
1261
+ emitted_bad_param_err = true ;
1262
+ }
1243
1263
let ty = tcx
1244
1264
. type_of ( param. def_id )
1245
1265
. no_bound_vars ( )
Original file line number Diff line number Diff line change @@ -857,3 +857,21 @@ pub(crate) enum DropImplPolarity {
857
857
span : Span ,
858
858
} ,
859
859
}
860
+
861
+ #[ derive( Diagnostic ) ]
862
+ pub ( crate ) enum ReturnTypeNotationIllegalParam {
863
+ #[ diag( hir_analysis_return_type_notation_illegal_param_type) ]
864
+ Type {
865
+ #[ primary_span]
866
+ span : Span ,
867
+ #[ label]
868
+ param_span : Span ,
869
+ } ,
870
+ #[ diag( hir_analysis_return_type_notation_illegal_param_const) ]
871
+ Const {
872
+ #[ primary_span]
873
+ span : Span ,
874
+ #[ label]
875
+ param_span : Span ,
876
+ } ,
877
+ }
Original file line number Diff line number Diff line change
1
+ // edition: 2021
2
+
3
+ #![ feature( async_fn_in_trait, return_type_notation) ]
4
+ //~^ WARN the feature `return_type_notation` is incomplete
5
+
6
+ trait Foo {
7
+ async fn bar < T > ( ) { }
8
+
9
+ async fn baz < const N : usize > ( ) { }
10
+ }
11
+
12
+ fn test < T > ( )
13
+ where
14
+ T : Foo < bar ( ) : Send , baz ( ) : Send > ,
15
+ //~^ ERROR return type notation is not allowed for functions that have const parameters
16
+ //~| ERROR return type notation is not allowed for functions that have type parameters
17
+ {
18
+ }
19
+
20
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2
+ --> $DIR/ty-or-ct-params.rs:3:31
3
+ |
4
+ LL | #![feature(async_fn_in_trait, return_type_notation)]
5
+ | ^^^^^^^^^^^^^^^^^^^^
6
+ |
7
+ = note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8
+ = note: `#[warn(incomplete_features)]` on by default
9
+
10
+ error: return type notation is not allowed for functions that have type parameters
11
+ --> $DIR/ty-or-ct-params.rs:14:12
12
+ |
13
+ LL | async fn bar<T>() {}
14
+ | - type parameter declared here
15
+ ...
16
+ LL | T: Foo<bar(): Send, baz(): Send>,
17
+ | ^^^^^^^^^^^
18
+
19
+ error: return type notation is not allowed for functions that have const parameters
20
+ --> $DIR/ty-or-ct-params.rs:14:25
21
+ |
22
+ LL | async fn baz<const N: usize>() {}
23
+ | -------------- const parameter declared here
24
+ ...
25
+ LL | T: Foo<bar(): Send, baz(): Send>,
26
+ | ^^^^^^^^^^^
27
+
28
+ error: aborting due to 2 previous errors; 1 warning emitted
29
+
You can’t perform that action at this time.
0 commit comments