typeck: port "explicit generic args w/ impl trait"

Port the "explicit generic arguments with impl trait" diagnostic to
using the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-05-06 03:46:12 +01:00
parent 3f413d2abb
commit af47257c0d
3 changed files with 27 additions and 22 deletions

View File

@ -93,3 +93,11 @@ typeck-expected-return-type = expected `{$expected}` because of return type
typeck-unconstrained-opaque-type = unconstrained opaque type
.note = `{$name}` must be used in combination with a concrete type within the same module
typeck-explicit-generic-args-with-impl-trait =
cannot provide explicit generic arguments when `impl Trait` is used in argument position
.label = explicit generic argument not allowed
.note = see issue #83701 <https://github.com/rust-lang/rust/issues/83701> for more information
typeck-explicit-generic-args-with-impl-trait-feature =
add `#![feature(explicit_generic_args_with_impl_trait)]` to the crate attributes to enable

View File

@ -3,7 +3,10 @@ use crate::astconv::{
AstConv, CreateSubstsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch,
GenericArgCountResult, GenericArgPosition,
};
use crate::errors::AssocTypeBindingNotAllowed;
use crate::errors::{
AssocTypeBindingNotAllowed, ExplicitGenericArgsWithImplTrait,
ExplicitGenericArgsWithImplTraitFeature,
};
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
use rustc_ast::ast::ParamKindOrd;
use rustc_errors::{struct_span_err, Applicability, Diagnostic, MultiSpan};
@ -636,29 +639,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
})
.collect::<Vec<_>>();
let mut err = struct_span_err! {
tcx.sess,
spans.clone(),
E0632,
"cannot provide explicit generic arguments when `impl Trait` is \
used in argument position"
};
for span in spans {
err.span_label(span, "explicit generic argument not allowed");
}
err.note(
"see issue #83701 <https://github.com/rust-lang/rust/issues/83701> \
for more information",
);
let mut err = tcx.sess.create_err(ExplicitGenericArgsWithImplTrait { spans });
if tcx.sess.is_nightly_build() {
err.help(
"add `#![feature(explicit_generic_args_with_impl_trait)]` \
to the crate attributes to enable",
);
err.subdiagnostic(ExplicitGenericArgsWithImplTraitFeature);
}
err.emit();
}

View File

@ -237,3 +237,16 @@ pub struct UnconstrainedOpaqueType {
pub span: Span,
pub name: Symbol,
}
#[derive(SessionDiagnostic)]
#[error(code = "E0632", slug = "typeck-explicit-generic-args-with-impl-trait")]
#[note]
pub struct ExplicitGenericArgsWithImplTrait {
#[primary_span]
#[label]
pub spans: Vec<Span>,
}
#[derive(SessionSubdiagnostic)]
#[help(slug = "typeck-explicit-generic-args-with-impl-trait-feature")]
pub struct ExplicitGenericArgsWithImplTraitFeature;