Skip to content

Commit af47257

Browse files
committed
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>
1 parent 3f413d2 commit af47257

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

compiler/rustc_error_messages/locales/en-US/typeck.ftl

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

compiler/rustc_typeck/src/astconv/generics.rs

+6-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use crate::astconv::{
33
AstConv, CreateSubstsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch,
44
GenericArgCountResult, GenericArgPosition,
55
};
6-
use crate::errors::AssocTypeBindingNotAllowed;
6+
use crate::errors::{
7+
AssocTypeBindingNotAllowed, ExplicitGenericArgsWithImplTrait,
8+
ExplicitGenericArgsWithImplTraitFeature,
9+
};
710
use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
811
use rustc_ast::ast::ParamKindOrd;
912
use rustc_errors::{struct_span_err, Applicability, Diagnostic, MultiSpan};
@@ -636,29 +639,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
636639
})
637640
.collect::<Vec<_>>();
638641

639-
let mut err = struct_span_err! {
640-
tcx.sess,
641-
spans.clone(),
642-
E0632,
643-
"cannot provide explicit generic arguments when `impl Trait` is \
644-
used in argument position"
645-
};
646-
647-
for span in spans {
648-
err.span_label(span, "explicit generic argument not allowed");
649-
}
650-
651-
err.note(
652-
"see issue #83701 <https://github.com/rust-lang/rust/issues/83701> \
653-
for more information",
654-
);
642+
let mut err = tcx.sess.create_err(ExplicitGenericArgsWithImplTrait { spans });
655643
if tcx.sess.is_nightly_build() {
656-
err.help(
657-
"add `#![feature(explicit_generic_args_with_impl_trait)]` \
658-
to the crate attributes to enable",
659-
);
644+
err.subdiagnostic(ExplicitGenericArgsWithImplTraitFeature);
660645
}
661-
662646
err.emit();
663647
}
664648

compiler/rustc_typeck/src/errors.rs

+13
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,16 @@ pub struct UnconstrainedOpaqueType {
237237
pub span: Span,
238238
pub name: Symbol,
239239
}
240+
241+
#[derive(SessionDiagnostic)]
242+
#[error(code = "E0632", slug = "typeck-explicit-generic-args-with-impl-trait")]
243+
#[note]
244+
pub struct ExplicitGenericArgsWithImplTrait {
245+
#[primary_span]
246+
#[label]
247+
pub spans: Vec<Span>,
248+
}
249+
250+
#[derive(SessionSubdiagnostic)]
251+
#[help(slug = "typeck-explicit-generic-args-with-impl-trait-feature")]
252+
pub struct ExplicitGenericArgsWithImplTraitFeature;

0 commit comments

Comments
 (0)