Skip to content

Commit

Permalink
typeck: port "explicit generic args w/ impl trait"
Browse files Browse the repository at this point in the history
Port the "explicit generic arguments with impl trait" diagnostic to
using the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
  • Loading branch information
davidtwco committed May 6, 2022
1 parent 3f413d2 commit af47257
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
8 changes: 8 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/typeck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 6 additions & 22 deletions compiler/rustc_typeck/src/astconv/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
}

Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit af47257

Please sign in to comment.