1 use crate::structured_errors::StructuredDiagnostic;
3 pluralize, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorGuaranteed,
7 use rustc_middle::hir::map::fn_sig;
8 use rustc_middle::middle::resolve_lifetime::LifetimeScopeForPath;
9 use rustc_middle::ty::{self as ty, AssocItems, AssocKind, TyCtxt};
10 use rustc_session::Session;
11 use rustc_span::def_id::DefId;
14 use GenericArgsInfo::*;
16 /// Handles the `wrong number of type / lifetime / ... arguments` family of error messages.
17 pub struct WrongNumberOfGenericArgs<'a, 'tcx> {
18 pub(crate) tcx: TyCtxt<'tcx>,
20 pub(crate) angle_brackets: AngleBrackets,
22 pub(crate) gen_args_info: GenericArgsInfo,
24 /// Offending path segment
25 pub(crate) path_segment: &'a hir::PathSegment<'a>,
27 /// Generic parameters as expected by type or trait
28 pub(crate) gen_params: &'a ty::Generics,
30 /// Index offset into parameters. Depends on whether `Self` is included and on
31 /// number of lifetime parameters in case we're processing missing or redundant
32 /// type or constant arguments.
33 pub(crate) params_offset: usize,
35 /// Generic arguments as provided by user
36 pub(crate) gen_args: &'a hir::GenericArgs<'a>,
38 /// DefId of the generic type
39 pub(crate) def_id: DefId,
42 // Provides information about the kind of arguments that were provided for
43 // the PathSegment, for which missing generic arguments were detected
45 pub(crate) enum AngleBrackets {
46 // No angle brackets were provided, but generic arguments exist in elided form
49 // No angle brackets were provided
52 // Angle brackets are available, but missing some generic arguments
56 // Information about the kind of arguments that are either missing or are unexpected
58 pub enum GenericArgsInfo {
60 num_missing_args: usize,
63 num_redundant_args: usize,
65 MissingTypesOrConsts {
66 num_missing_args: usize,
68 // type or const generic arguments can have default values
69 num_default_params: usize,
71 // lifetime arguments precede type and const parameters, this
72 // field gives the number of generic lifetime arguments to let
73 // us infer the position of type and const generic arguments
74 // in the angle brackets
79 num_redundant_args: usize,
81 // type or const generic arguments can have default values
82 num_default_params: usize,
84 // lifetime arguments precede type and const parameters, this
85 // field gives the number of generic lifetime arguments to let
86 // us infer the position of type and const generic arguments
87 // in the angle brackets
90 // if synthetic type arguments (e.g. `impl Trait`) are specified
95 impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
98 gen_args_info: GenericArgsInfo,
99 path_segment: &'a hir::PathSegment<'_>,
100 gen_params: &'a ty::Generics,
101 params_offset: usize,
102 gen_args: &'a hir::GenericArgs<'a>,
105 let angle_brackets = if gen_args.span_ext().is_none() {
106 if gen_args.is_empty() { AngleBrackets::Missing } else { AngleBrackets::Implied }
108 AngleBrackets::Available
123 fn missing_lifetimes(&self) -> bool {
124 match self.gen_args_info {
125 MissingLifetimes { .. } | ExcessLifetimes { .. } => true,
126 MissingTypesOrConsts { .. } | ExcessTypesOrConsts { .. } => false,
130 fn kind(&self) -> String {
131 if self.missing_lifetimes() { "lifetime".to_string() } else { "generic".to_string() }
134 fn num_provided_args(&self) -> usize {
135 if self.missing_lifetimes() {
136 self.num_provided_lifetime_args()
138 self.num_provided_type_or_const_args()
142 fn num_provided_lifetime_args(&self) -> usize {
143 match self.angle_brackets {
144 AngleBrackets::Missing => 0,
145 // Only lifetime arguments can be implied
146 AngleBrackets::Implied => self.gen_args.args.len(),
147 AngleBrackets::Available => self.gen_args.num_lifetime_params(),
151 fn num_provided_type_or_const_args(&self) -> usize {
152 match self.angle_brackets {
153 AngleBrackets::Missing => 0,
154 // Only lifetime arguments can be implied
155 AngleBrackets::Implied => 0,
156 AngleBrackets::Available => self.gen_args.num_generic_params(),
160 fn num_expected_lifetime_args(&self) -> usize {
161 let num_provided_args = self.num_provided_lifetime_args();
162 match self.gen_args_info {
163 MissingLifetimes { num_missing_args } => num_provided_args + num_missing_args,
164 ExcessLifetimes { num_redundant_args } => num_provided_args - num_redundant_args,
169 fn num_expected_type_or_const_args(&self) -> usize {
170 let num_provided_args = self.num_provided_type_or_const_args();
171 match self.gen_args_info {
172 MissingTypesOrConsts { num_missing_args, .. } => num_provided_args + num_missing_args,
173 ExcessTypesOrConsts { num_redundant_args, .. } => {
174 num_provided_args - num_redundant_args
180 // Gives the number of expected arguments taking into account default arguments
181 fn num_expected_type_or_const_args_including_defaults(&self) -> usize {
182 let provided_args = self.num_provided_type_or_const_args();
183 match self.gen_args_info {
184 MissingTypesOrConsts { num_missing_args, num_default_params, .. } => {
185 provided_args + num_missing_args - num_default_params
187 ExcessTypesOrConsts { num_redundant_args, num_default_params, .. } => {
188 provided_args - num_redundant_args - num_default_params
194 fn num_missing_lifetime_args(&self) -> usize {
195 let missing_args = self.num_expected_lifetime_args() - self.num_provided_lifetime_args();
196 assert!(missing_args > 0);
200 fn num_missing_type_or_const_args(&self) -> usize {
201 let missing_args = self.num_expected_type_or_const_args_including_defaults()
202 - self.num_provided_type_or_const_args();
203 assert!(missing_args > 0);
207 fn num_excess_lifetime_args(&self) -> usize {
208 match self.gen_args_info {
209 ExcessLifetimes { num_redundant_args } => num_redundant_args,
214 fn num_excess_type_or_const_args(&self) -> usize {
215 match self.gen_args_info {
216 ExcessTypesOrConsts { num_redundant_args, .. } => num_redundant_args,
221 fn too_many_args_provided(&self) -> bool {
222 match self.gen_args_info {
223 MissingLifetimes { .. } | MissingTypesOrConsts { .. } => false,
224 ExcessLifetimes { num_redundant_args }
225 | ExcessTypesOrConsts { num_redundant_args, .. } => {
226 assert!(num_redundant_args > 0);
232 fn not_enough_args_provided(&self) -> bool {
233 match self.gen_args_info {
234 MissingLifetimes { num_missing_args }
235 | MissingTypesOrConsts { num_missing_args, .. } => {
236 assert!(num_missing_args > 0);
239 ExcessLifetimes { .. } | ExcessTypesOrConsts { .. } => false,
243 // Helper method to get the index offset in angle brackets, at which type or const arguments
245 fn get_lifetime_args_offset(&self) -> usize {
246 match self.gen_args_info {
247 MissingLifetimes { .. } | ExcessLifetimes { .. } => 0,
248 MissingTypesOrConsts { args_offset, .. } | ExcessTypesOrConsts { args_offset, .. } => {
254 fn get_num_default_params(&self) -> usize {
255 match self.gen_args_info {
256 MissingTypesOrConsts { num_default_params, .. }
257 | ExcessTypesOrConsts { num_default_params, .. } => num_default_params,
262 fn is_synth_provided(&self) -> bool {
263 match self.gen_args_info {
264 ExcessTypesOrConsts { synth_provided, .. } => synth_provided,
269 // Helper function to choose a quantifier word for the number of expected arguments
270 // and to give a bound for the number of expected arguments
271 fn get_quantifier_and_bound(&self) -> (&'static str, usize) {
272 if self.get_num_default_params() == 0 {
273 match self.gen_args_info {
274 MissingLifetimes { .. } | ExcessLifetimes { .. } => {
275 ("", self.num_expected_lifetime_args())
277 MissingTypesOrConsts { .. } | ExcessTypesOrConsts { .. } => {
278 ("", self.num_expected_type_or_const_args())
282 match self.gen_args_info {
283 MissingLifetimes { .. } => ("at least ", self.num_expected_lifetime_args()),
284 MissingTypesOrConsts { .. } => {
285 ("at least ", self.num_expected_type_or_const_args_including_defaults())
287 ExcessLifetimes { .. } => ("at most ", self.num_expected_lifetime_args()),
288 ExcessTypesOrConsts { .. } => ("at most ", self.num_expected_type_or_const_args()),
293 // Creates lifetime name suggestions from the lifetime parameter names
294 fn get_lifetime_args_suggestions_from_param_names(&self, num_params_to_take: usize) -> String {
298 .skip(self.params_offset + self.num_provided_lifetime_args())
299 .take(num_params_to_take)
300 .map(|param| param.name.to_string())
305 // Creates type or constant name suggestions from the provided parameter names
306 fn get_type_or_const_args_suggestions_from_param_names(
308 num_params_to_take: usize,
310 let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(fn_sig);
311 let is_used_in_input = |def_id| {
312 fn_sig.map_or(false, |fn_sig| {
313 fn_sig.decl.inputs.iter().any(|ty| match ty.kind {
314 hir::TyKind::Path(hir::QPath::Resolved(
316 hir::Path { res: hir::def::Res::Def(_, id), .. },
325 .skip(self.params_offset + self.num_provided_type_or_const_args())
326 .take(num_params_to_take)
327 .map(|param| match param.kind {
328 // This is being inferred from the item's inputs, no need to set it.
329 ty::GenericParamDefKind::Type { .. } if is_used_in_input(param.def_id) => {
332 _ => param.name.to_string(),
338 fn get_unbound_associated_types(&self) -> Vec<String> {
339 if self.tcx.is_trait(self.def_id) {
340 let items: &AssocItems<'_> = self.tcx.associated_items(self.def_id);
342 .in_definition_order()
343 .filter(|item| item.kind == AssocKind::Type)
345 !self.gen_args.bindings.iter().any(|binding| binding.ident.name == item.name)
347 .map(|item| item.name.to_ident_string())
354 fn create_error_message(&self) -> String {
355 let def_path = self.tcx.def_path_str(self.def_id);
356 let def_kind = self.tcx.def_kind(self.def_id).descr(self.def_id);
357 let (quantifier, bound) = self.get_quantifier_and_bound();
358 let kind = self.kind();
359 let provided_lt_args = self.num_provided_lifetime_args();
360 let provided_type_or_const_args = self.num_provided_type_or_const_args();
362 let get_verb = |num_args| if num_args == 1 { "was" } else { "were" };
364 let (provided_args_str, verb) = match self.gen_args_info {
365 MissingLifetimes { .. } | ExcessLifetimes { .. } => (
366 format!("{} lifetime argument{}", provided_lt_args, pluralize!(provided_lt_args)),
367 get_verb(provided_lt_args),
369 MissingTypesOrConsts { .. } | ExcessTypesOrConsts { .. } => (
371 "{} generic argument{}",
372 provided_type_or_const_args,
373 pluralize!(provided_type_or_const_args)
375 get_verb(provided_type_or_const_args),
379 if self.gen_args.span_ext().is_some() {
381 "this {} takes {}{} {} argument{} but {} {} supplied",
387 provided_args_str.as_str(),
391 format!("missing generics for {} `{}`", def_kind, def_path)
395 fn start_diagnostics(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
396 let span = self.path_segment.ident.span;
397 let msg = self.create_error_message();
399 self.tcx.sess.struct_span_err_with_code(span, &msg, self.code())
402 /// Builds the `expected 1 type argument / supplied 2 type arguments` message.
403 fn notify(&self, err: &mut Diagnostic) {
404 let (quantifier, bound) = self.get_quantifier_and_bound();
405 let provided_args = self.num_provided_args();
408 self.path_segment.ident.span,
410 "expected {}{} {} argument{}",
418 // When too many arguments were provided, we don't highlight each of them, because it
419 // would overlap with the suggestion to remove them:
422 // type Foo = Bar<usize, usize>;
423 // ----- ----- supplied 2 type arguments
424 // ^^^^^^^ remove this type argument
426 if self.too_many_args_provided() {
434 .skip(self.get_lifetime_args_offset())
438 for (i, arg) in args {
441 if i + 1 == provided_args {
443 "supplied {} {} argument{}",
446 pluralize!(provided_args)
455 fn suggest(&self, err: &mut Diagnostic) {
457 "suggest(self.provided {:?}, self.gen_args.span(): {:?})",
458 self.num_provided_args(),
459 self.gen_args.span(),
462 match self.angle_brackets {
463 AngleBrackets::Missing | AngleBrackets::Implied => self.suggest_adding_args(err),
464 AngleBrackets::Available => {
465 if self.not_enough_args_provided() {
466 self.suggest_adding_args(err);
467 } else if self.too_many_args_provided() {
468 self.suggest_removing_args_or_generics(err);
476 /// Suggests to add missing argument(s) when current invocation site already contains some
480 /// type Map = HashMap<String>;
482 fn suggest_adding_args(&self, err: &mut Diagnostic) {
483 if self.gen_args.parenthesized {
487 match self.gen_args_info {
488 MissingLifetimes { .. } => {
489 self.suggest_adding_lifetime_args(err);
491 MissingTypesOrConsts { .. } => {
492 self.suggest_adding_type_and_const_args(err);
498 fn suggest_adding_lifetime_args(&self, err: &mut Diagnostic) {
499 debug!("suggest_adding_lifetime_args(path_segment: {:?})", self.path_segment);
500 let num_missing_args = self.num_missing_lifetime_args();
501 let num_params_to_take = num_missing_args;
502 let msg = format!("add missing {} argument{}", self.kind(), pluralize!(num_missing_args));
504 // we first try to get lifetime name suggestions from scope or elision information. If none is
505 // available we use the parameter definitions
506 let suggested_args = if let Some(hir_id) = self.path_segment.hir_id {
507 if let Some(lifetimes_in_scope) = self.tcx.lifetime_scope(hir_id) {
508 match lifetimes_in_scope {
509 LifetimeScopeForPath::NonElided(param_names) => {
510 debug!("NonElided(param_names: {:?})", param_names);
512 if param_names.len() >= num_params_to_take {
513 // use lifetime parameters in scope for suggestions
516 .take(num_params_to_take)
521 // Not enough lifetime arguments in scope -> create suggestions from
522 // lifetime parameter names in definition. An error for the incorrect
523 // lifetime scope will be output later.
524 self.get_lifetime_args_suggestions_from_param_names(num_params_to_take)
527 LifetimeScopeForPath::Elided => {
529 // use suggestions of the form `<'_, '_>` in case lifetime can be elided
530 ["'_"].repeat(num_params_to_take).join(",")
534 self.get_lifetime_args_suggestions_from_param_names(num_params_to_take)
537 self.get_lifetime_args_suggestions_from_param_names(num_params_to_take)
540 debug!("suggested_args: {:?}", &suggested_args);
542 match self.angle_brackets {
543 AngleBrackets::Missing => {
544 let span = self.path_segment.ident.span;
546 // insert a suggestion of the form "Y<'a, 'b>"
547 let ident = self.path_segment.ident.name.to_ident_string();
548 let sugg = format!("{}<{}>", ident, suggested_args);
549 debug!("sugg: {:?}", sugg);
551 err.span_suggestion_verbose(span, &msg, sugg, Applicability::HasPlaceholders);
554 AngleBrackets::Available => {
555 let (sugg_span, is_first) = if self.num_provided_lifetime_args() == 0 {
556 (self.gen_args.span().unwrap().shrink_to_lo(), true)
558 let last_lt = &self.gen_args.args[self.num_provided_lifetime_args() - 1];
559 (last_lt.span().shrink_to_hi(), false)
561 let has_non_lt_args = self.num_provided_type_or_const_args() != 0;
562 let has_bindings = !self.gen_args.bindings.is_empty();
564 let sugg_prefix = if is_first { "" } else { ", " };
566 if is_first && (has_non_lt_args || has_bindings) { ", " } else { "" };
568 let sugg = format!("{}{}{}", sugg_prefix, suggested_args, sugg_suffix);
569 debug!("sugg: {:?}", sugg);
571 err.span_suggestion_verbose(sugg_span, &msg, sugg, Applicability::HasPlaceholders);
573 AngleBrackets::Implied => {
574 // We never encounter missing lifetimes in situations in which lifetimes are elided
580 fn suggest_adding_type_and_const_args(&self, err: &mut Diagnostic) {
581 let num_missing_args = self.num_missing_type_or_const_args();
582 let msg = format!("add missing {} argument{}", self.kind(), pluralize!(num_missing_args));
585 self.get_type_or_const_args_suggestions_from_param_names(num_missing_args);
586 debug!("suggested_args: {:?}", suggested_args);
588 match self.angle_brackets {
589 AngleBrackets::Missing | AngleBrackets::Implied => {
590 let span = self.path_segment.ident.span;
592 // insert a suggestion of the form "Y<T, U>"
593 let ident = self.path_segment.ident.name.to_ident_string();
594 let sugg = format!("{}<{}>", ident, suggested_args);
595 debug!("sugg: {:?}", sugg);
597 err.span_suggestion_verbose(span, &msg, sugg, Applicability::HasPlaceholders);
599 AngleBrackets::Available => {
600 let gen_args_span = self.gen_args.span().unwrap();
602 self.get_lifetime_args_offset() + self.num_provided_type_or_const_args();
604 let (sugg_span, is_first) = if sugg_offset == 0 {
605 (gen_args_span.shrink_to_lo(), true)
607 let arg_span = self.gen_args.args[sugg_offset - 1].span();
608 // If we came here then inferred lifetime's spans can only point
609 // to either the opening bracket or to the space right after.
610 // Both of these spans have an `hi` lower than or equal to the span
611 // of the generics excluding the brackets.
612 // This allows us to check if `arg_span` is the artificial span of
613 // an inferred lifetime, in which case the generic we're suggesting to
614 // add will be the first visible, even if it isn't the actual first generic.
615 (arg_span.shrink_to_hi(), arg_span.hi() <= gen_args_span.lo())
618 let sugg_prefix = if is_first { "" } else { ", " };
620 if is_first && !self.gen_args.bindings.is_empty() { ", " } else { "" };
622 let sugg = format!("{}{}{}", sugg_prefix, suggested_args, sugg_suffix);
623 debug!("sugg: {:?}", sugg);
625 err.span_suggestion_verbose(sugg_span, &msg, sugg, Applicability::HasPlaceholders);
630 /// Suggests to remove redundant argument(s):
633 /// type Map = HashMap<String, String, String, String>;
635 fn suggest_removing_args_or_generics(&self, err: &mut Diagnostic) {
636 let num_provided_lt_args = self.num_provided_lifetime_args();
637 let num_provided_type_const_args = self.num_provided_type_or_const_args();
638 let unbound_types = self.get_unbound_associated_types();
639 let num_provided_args = num_provided_lt_args + num_provided_type_const_args;
640 assert!(num_provided_args > 0);
642 let num_redundant_lt_args = self.num_excess_lifetime_args();
643 let num_redundant_type_or_const_args = self.num_excess_type_or_const_args();
644 let num_redundant_args = num_redundant_lt_args + num_redundant_type_or_const_args;
646 let redundant_lifetime_args = num_redundant_lt_args > 0;
647 let redundant_type_or_const_args = num_redundant_type_or_const_args > 0;
649 let remove_entire_generics = num_redundant_args >= self.gen_args.args.len();
650 let provided_args_matches_unbound_traits =
651 unbound_types.len() == num_redundant_type_or_const_args;
653 let remove_lifetime_args = |err: &mut Diagnostic| {
654 let mut lt_arg_spans = Vec::new();
655 let mut found_redundant = false;
656 for arg in self.gen_args.args {
657 if let hir::GenericArg::Lifetime(_) = arg {
658 lt_arg_spans.push(arg.span());
659 if lt_arg_spans.len() > self.num_expected_lifetime_args() {
660 found_redundant = true;
662 } else if found_redundant {
663 // Argument which is redundant and separated like this `'c`
664 // is not included to avoid including `Bar` in span.
666 // type Foo<'a, T> = &'a T;
667 // let _: Foo<'a, 'b, Bar, 'c>;
673 let span_lo_redundant_lt_args = lt_arg_spans[self.num_expected_lifetime_args()];
674 let span_hi_redundant_lt_args = lt_arg_spans[lt_arg_spans.len() - 1];
676 let span_redundant_lt_args = span_lo_redundant_lt_args.to(span_hi_redundant_lt_args);
677 debug!("span_redundant_lt_args: {:?}", span_redundant_lt_args);
679 let num_redundant_lt_args = lt_arg_spans.len() - self.num_expected_lifetime_args();
680 let msg_lifetimes = format!(
681 "remove {these} lifetime argument{s}",
682 these = pluralize!("this", num_redundant_lt_args),
683 s = pluralize!(num_redundant_lt_args),
687 span_redundant_lt_args,
690 Applicability::MaybeIncorrect,
694 let remove_type_or_const_args = |err: &mut Diagnostic| {
695 let mut gen_arg_spans = Vec::new();
696 let mut found_redundant = false;
697 for arg in self.gen_args.args {
699 hir::GenericArg::Type(_)
700 | hir::GenericArg::Const(_)
701 | hir::GenericArg::Infer(_) => {
702 gen_arg_spans.push(arg.span());
703 if gen_arg_spans.len() > self.num_expected_type_or_const_args() {
704 found_redundant = true;
707 _ if found_redundant => break,
712 let span_lo_redundant_type_or_const_args =
713 gen_arg_spans[self.num_expected_type_or_const_args()];
714 let span_hi_redundant_type_or_const_args = gen_arg_spans[gen_arg_spans.len() - 1];
716 let span_redundant_type_or_const_args =
717 span_lo_redundant_type_or_const_args.to(span_hi_redundant_type_or_const_args);
718 debug!("span_redundant_type_or_const_args: {:?}", span_redundant_type_or_const_args);
720 let num_redundant_gen_args =
721 gen_arg_spans.len() - self.num_expected_type_or_const_args();
722 let msg_types_or_consts = format!(
723 "remove {these} generic argument{s}",
724 these = pluralize!("this", num_redundant_gen_args),
725 s = pluralize!(num_redundant_gen_args),
729 span_redundant_type_or_const_args,
730 &msg_types_or_consts,
732 Applicability::MaybeIncorrect,
736 // If there is a single unbound associated type and a single excess generic param
737 // suggest replacing the generic param with the associated type bound
738 if provided_args_matches_unbound_traits && !unbound_types.is_empty() {
739 let mut suggestions = vec![];
740 let unused_generics = &self.gen_args.args[self.num_expected_type_or_const_args()..];
741 for (potential, name) in iter::zip(unused_generics, &unbound_types) {
742 if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(potential.span()) {
743 suggestions.push((potential.span(), format!("{} = {}", name, snippet)));
747 if !suggestions.is_empty() {
748 err.multipart_suggestion(
750 "replace the generic bound{s} with the associated type{s}",
751 s = pluralize!(unbound_types.len())
754 Applicability::MaybeIncorrect,
757 } else if remove_entire_generics {
764 .with_lo(self.path_segment.ident.span.hi());
767 "remove these {}generics",
768 if self.gen_args.parenthesized { "parenthetical " } else { "" },
771 err.span_suggestion(span, &msg, String::new(), Applicability::MaybeIncorrect);
772 } else if redundant_lifetime_args && redundant_type_or_const_args {
773 remove_lifetime_args(err);
774 remove_type_or_const_args(err);
775 } else if redundant_lifetime_args {
776 remove_lifetime_args(err);
778 assert!(redundant_type_or_const_args);
779 remove_type_or_const_args(err);
783 /// Builds the `type defined here` message.
784 fn show_definition(&self, err: &mut Diagnostic) {
785 let mut spans: MultiSpan = if let Some(def_span) = self.tcx.def_ident_span(self.def_id) {
786 if self.tcx.sess.source_map().span_to_snippet(def_span).is_ok() {
796 let def_kind = self.tcx.def_kind(self.def_id).descr(self.def_id);
797 let (quantifier, bound) = self.get_quantifier_and_bound();
799 let params = if bound == 0 {
806 .skip(self.params_offset)
809 let span = self.tcx.def_span(param.def_id);
810 spans.push_span_label(span, String::new());
813 .map(|param| format!("`{}`", param.name))
817 format!(": {}", params)
821 "{} defined here, with {}{} {} parameter{}{}",
831 err.span_note(spans, &msg);
834 /// Add note if `impl Trait` is explicitly specified.
835 fn note_synth_provided(&self, err: &mut Diagnostic) {
836 if !self.is_synth_provided() {
840 err.note("`impl Trait` cannot be explicitly specified as a generic argument");
844 impl<'tcx> StructuredDiagnostic<'tcx> for WrongNumberOfGenericArgs<'_, 'tcx> {
845 fn session(&self) -> &Session {
849 fn code(&self) -> DiagnosticId {
850 rustc_errors::error_code!(E0107)
853 fn diagnostic_common(&self) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
854 let mut err = self.start_diagnostics();
856 self.notify(&mut err);
857 self.suggest(&mut err);
858 self.show_definition(&mut err);
859 self.note_synth_provided(&mut err);