diff options
| author | Michael Goulet <michael@errs.io> | 2023-05-01 05:15:45 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-06-05 19:52:04 +0000 |
| commit | bbc536d3ac83ad0e3600af2d04701faed63ecd79 (patch) | |
| tree | a9d22ca7605bed4e4955d7f0e94faccbc1a00ee6 /compiler | |
| parent | 408bbd040613f6776e0a7d05d582c81f4ddc189a (diff) | |
| download | rust-bbc536d3ac83ad0e3600af2d04701faed63ecd79.tar.gz rust-bbc536d3ac83ad0e3600af2d04701faed63ecd79.zip | |
Emit an error when RTN is used with ty/ct params
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_hir_analysis/messages.ftl | 7 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/astconv/mod.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/errors.rs | 18 |
3 files changed, 48 insertions, 3 deletions
diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index 02d1dfcd113..cd6cf36baa4 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -195,6 +195,13 @@ hir_analysis_return_type_notation_conflicting_bound = hir_analysis_return_type_notation_equality_bound = 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 = cannot find associated function `{$assoc_name}` for `{$ty_name}` diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 3d78ea9aa9b..37f17657961 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1215,6 +1215,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } 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 // the method's early bound params with suitable late-bound params. let mut num_bound_vars = candidate.bound_vars().len(); @@ -1230,16 +1231,35 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }, ) .into(), - GenericParamDefKind::Type { .. } => tcx - .mk_bound( + GenericParamDefKind::Type { .. } => { + 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::BoundTy { var: ty::BoundVar::from_usize(num_bound_vars), kind: ty::BoundTyKind::Param(param.def_id, param.name), }, ) - .into(), + .into() + } 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 .type_of(param.def_id) .no_bound_vars() diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 6e7eb4f6cdc..7dce1272f96 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -857,3 +857,21 @@ pub(crate) enum DropImplPolarity { 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, + }, +} |
