This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +97
-3
lines changed
compiler/rustc_hir_analysis
tests/ui/async-await/return-type-notation Expand file tree Collapse file tree 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 =
195195hir_analysis_return_type_notation_equality_bound =
196196 return type notation is not allowed to use type equality
197197
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+
198205hir_analysis_return_type_notation_missing_method =
199206 cannot find associated function `{ $assoc_name } ` for `{ $ty_name } `
200207
Original file line number Diff line number Diff line change @@ -1215,6 +1215,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12151215 }
12161216
12171217 let projection_ty = if return_type_notation {
1218+ let mut emitted_bad_param_err = false ;
12181219 // If we have an method return type bound, then we need to substitute
12191220 // the method's early bound params with suitable late-bound params.
12201221 let mut num_bound_vars = candidate. bound_vars ( ) . len ( ) ;
@@ -1230,16 +1231,35 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12301231 } ,
12311232 )
12321233 . 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 (
12351245 ty:: INNERMOST ,
12361246 ty:: BoundTy {
12371247 var : ty:: BoundVar :: from_usize ( num_bound_vars) ,
12381248 kind : ty:: BoundTyKind :: Param ( param. def_id , param. name ) ,
12391249 } ,
12401250 )
1241- . into ( ) ,
1251+ . into ( )
1252+ }
12421253 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+ }
12431263 let ty = tcx
12441264 . type_of ( param. def_id )
12451265 . no_bound_vars ( )
Original file line number Diff line number Diff line change @@ -857,3 +857,21 @@ pub(crate) enum DropImplPolarity {
857857 span : Span ,
858858 } ,
859859}
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