1
Fork 0

Emit an error when RTN is used with ty/ct params

This commit is contained in:
Michael Goulet 2023-05-01 05:15:45 +00:00
parent 408bbd0406
commit bbc536d3ac
5 changed files with 97 additions and 3 deletions

View file

@ -195,6 +195,13 @@ hir_analysis_return_type_notation_conflicting_bound =
hir_analysis_return_type_notation_equality_bound = hir_analysis_return_type_notation_equality_bound =
return type notation is not allowed to use type equality return type notation is not allowed to use type equality
hir_analysis_return_type_notation_illegal_param_const =
return type notation is not allowed for functions that have const parameters
.label = const parameter declared here
hir_analysis_return_type_notation_illegal_param_type =
return type notation is not allowed for functions that have type parameters
.label = type parameter declared here
hir_analysis_return_type_notation_missing_method = hir_analysis_return_type_notation_missing_method =
cannot find associated function `{$assoc_name}` for `{$ty_name}` cannot find associated function `{$assoc_name}` for `{$ty_name}`

View file

@ -1215,6 +1215,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} }
let projection_ty = if return_type_notation { let projection_ty = if return_type_notation {
let mut emitted_bad_param_err = false;
// If we have an method return type bound, then we need to substitute // If we have an method return type bound, then we need to substitute
// the method's early bound params with suitable late-bound params. // the method's early bound params with suitable late-bound params.
let mut num_bound_vars = candidate.bound_vars().len(); let mut num_bound_vars = candidate.bound_vars().len();
@ -1230,16 +1231,35 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}, },
) )
.into(), .into(),
GenericParamDefKind::Type { .. } => tcx GenericParamDefKind::Type { .. } => {
.mk_bound( if !emitted_bad_param_err {
tcx.sess.emit_err(
crate::errors::ReturnTypeNotationIllegalParam::Type {
span: path_span,
param_span: tcx.def_span(param.def_id),
},
);
emitted_bad_param_err = true;
}
tcx.mk_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundTy { ty::BoundTy {
var: ty::BoundVar::from_usize(num_bound_vars), var: ty::BoundVar::from_usize(num_bound_vars),
kind: ty::BoundTyKind::Param(param.def_id, param.name), kind: ty::BoundTyKind::Param(param.def_id, param.name),
}, },
) )
.into(), .into()
}
GenericParamDefKind::Const { .. } => { GenericParamDefKind::Const { .. } => {
if !emitted_bad_param_err {
tcx.sess.emit_err(
crate::errors::ReturnTypeNotationIllegalParam::Const {
span: path_span,
param_span: tcx.def_span(param.def_id),
},
);
emitted_bad_param_err = true;
}
let ty = tcx let ty = tcx
.type_of(param.def_id) .type_of(param.def_id)
.no_bound_vars() .no_bound_vars()

View file

@ -857,3 +857,21 @@ pub(crate) enum DropImplPolarity {
span: Span, span: Span,
}, },
} }
#[derive(Diagnostic)]
pub(crate) enum ReturnTypeNotationIllegalParam {
#[diag(hir_analysis_return_type_notation_illegal_param_type)]
Type {
#[primary_span]
span: Span,
#[label]
param_span: Span,
},
#[diag(hir_analysis_return_type_notation_illegal_param_const)]
Const {
#[primary_span]
span: Span,
#[label]
param_span: Span,
},
}

View file

@ -0,0 +1,20 @@
// edition: 2021
#![feature(async_fn_in_trait, return_type_notation)]
//~^ WARN the feature `return_type_notation` is incomplete
trait Foo {
async fn bar<T>() {}
async fn baz<const N: usize>() {}
}
fn test<T>()
where
T: Foo<bar(): Send, baz(): Send>,
//~^ ERROR return type notation is not allowed for functions that have const parameters
//~| ERROR return type notation is not allowed for functions that have type parameters
{
}
fn main() {}

View file

@ -0,0 +1,29 @@
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/ty-or-ct-params.rs:3:31
|
LL | #![feature(async_fn_in_trait, return_type_notation)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= note: `#[warn(incomplete_features)]` on by default
error: return type notation is not allowed for functions that have type parameters
--> $DIR/ty-or-ct-params.rs:14:12
|
LL | async fn bar<T>() {}
| - type parameter declared here
...
LL | T: Foo<bar(): Send, baz(): Send>,
| ^^^^^^^^^^^
error: return type notation is not allowed for functions that have const parameters
--> $DIR/ty-or-ct-params.rs:14:25
|
LL | async fn baz<const N: usize>() {}
| -------------- const parameter declared here
...
LL | T: Foo<bar(): Send, baz(): Send>,
| ^^^^^^^^^^^
error: aborting due to 2 previous errors; 1 warning emitted