]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_hir_analysis/src/astconv/generics.rs
New upstream version 1.69.0+dfsg1
[rustc.git] / compiler / rustc_hir_analysis / src / astconv / generics.rs
CommitLineData
5869c6ff 1use super::IsMethodCall;
3dfed10e 2use crate::astconv::{
9c376795 3 CreateSubstsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch,
fc512014 4 GenericArgCountResult, GenericArgPosition,
3dfed10e 5};
923072b8 6use crate::errors::AssocTypeBindingNotAllowed;
17df50a5 7use crate::structured_errors::{GenericArgsInfo, StructuredDiagnostic, WrongNumberOfGenericArgs};
3dfed10e 8use rustc_ast::ast::ParamKindOrd;
9ffffee4 9use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorGuaranteed, MultiSpan};
3dfed10e 10use rustc_hir as hir;
6a06907d 11use rustc_hir::def::{DefKind, Res};
3dfed10e 12use rustc_hir::def_id::DefId;
fc512014 13use rustc_hir::GenericArg;
3dfed10e 14use rustc_middle::ty::{
923072b8 15 self, subst, subst::SubstsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty, TyCtxt,
3dfed10e 16};
5869c6ff 17use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
04454e1e 18use rustc_span::{symbol::kw, Span};
3dfed10e
XL
19use smallvec::SmallVec;
20
9c376795
FG
21/// Report an error that a generic argument did not match the generic parameter that was
22/// expected.
23fn generic_arg_mismatch_err(
24 tcx: TyCtxt<'_>,
25 arg: &GenericArg<'_>,
26 param: &GenericParamDef,
27 possible_ordering_error: bool,
28 help: Option<&str>,
9ffffee4 29) -> ErrorGuaranteed {
9c376795
FG
30 let sess = tcx.sess;
31 let mut err = struct_span_err!(
32 sess,
33 arg.span(),
34 E0747,
35 "{} provided when a {} was expected",
36 arg.descr(),
37 param.kind.descr(),
38 );
39
40 if let GenericParamDefKind::Const { .. } = param.kind {
41 if matches!(arg, GenericArg::Type(hir::Ty { kind: hir::TyKind::Infer, .. })) {
42 err.help("const arguments cannot yet be inferred with `_`");
43 if sess.is_nightly_build() {
44 err.help("add `#![feature(generic_arg_infer)]` to the crate attributes to enable");
fc512014
XL
45 }
46 }
9c376795 47 }
fc512014 48
9c376795
FG
49 let add_braces_suggestion = |arg: &GenericArg<'_>, err: &mut Diagnostic| {
50 let suggestions = vec![
51 (arg.span().shrink_to_lo(), String::from("{ ")),
52 (arg.span().shrink_to_hi(), String::from(" }")),
53 ];
54 err.multipart_suggestion(
55 "if this generic argument was intended as a const parameter, \
6a06907d 56 surround it with braces",
9c376795
FG
57 suggestions,
58 Applicability::MaybeIncorrect,
59 );
60 };
61
62 // Specific suggestion set for diagnostics
63 match (arg, &param.kind) {
64 (
65 GenericArg::Type(hir::Ty {
66 kind: hir::TyKind::Path(rustc_hir::QPath::Resolved(_, path)),
67 ..
68 }),
69 GenericParamDefKind::Const { .. },
70 ) => match path.res {
71 Res::Err => {
72 add_braces_suggestion(arg, &mut err);
9ffffee4
FG
73 return err
74 .set_primary_message("unresolved item provided when a constant was expected")
6a06907d 75 .emit();
9c376795
FG
76 }
77 Res::Def(DefKind::TyParam, src_def_id) => {
78 if let Some(param_local_id) = param.def_id.as_local() {
79 let param_name = tcx.hir().ty_param_name(param_local_id);
9ffffee4 80 let param_type = tcx.type_of(param.def_id).subst_identity();
9c376795
FG
81 if param_type.is_suggestable(tcx, false) {
82 err.span_suggestion(
83 tcx.def_span(src_def_id),
9ffffee4 84 "consider changing this type parameter to a const parameter",
9c376795
FG
85 format!("const {}: {}", param_name, param_type),
86 Applicability::MaybeIncorrect,
87 );
88 };
5869c6ff
XL
89 }
90 }
9c376795
FG
91 _ => add_braces_suggestion(arg, &mut err),
92 },
93 (
94 GenericArg::Type(hir::Ty { kind: hir::TyKind::Path(_), .. }),
95 GenericParamDefKind::Const { .. },
96 ) => add_braces_suggestion(arg, &mut err),
97 (
98 GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
99 GenericParamDefKind::Const { .. },
9ffffee4 100 ) if tcx.type_of(param.def_id).skip_binder() == tcx.types.usize => {
9c376795
FG
101 let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id()));
102 if let Ok(snippet) = snippet {
103 err.span_suggestion(
104 arg.span(),
105 "array type provided where a `usize` was expected, try",
106 format!("{{ {} }}", snippet),
107 Applicability::MaybeIncorrect,
108 );
109 }
110 }
111 (GenericArg::Const(cnst), GenericParamDefKind::Type { .. }) => {
112 let body = tcx.hir().body(cnst.value.body);
113 if let rustc_hir::ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) = body.value.kind
114 {
115 if let Res::Def(DefKind::Fn { .. }, id) = path.res {
116 err.help(&format!("`{}` is a function item, not a type", tcx.item_name(id)));
117 err.help("function item types cannot be named directly");
cdc7bbd5
XL
118 }
119 }
fc512014 120 }
9c376795
FG
121 _ => {}
122 }
fc512014 123
9c376795
FG
124 let kind_ord = param.kind.to_ord();
125 let arg_ord = arg.to_ord();
5869c6ff 126
9c376795
FG
127 // This note is only true when generic parameters are strictly ordered by their kind.
128 if possible_ordering_error && kind_ord.cmp(&arg_ord) != core::cmp::Ordering::Equal {
129 let (first, last) = if kind_ord < arg_ord {
130 (param.kind.descr(), arg.descr())
131 } else {
132 (arg.descr(), param.kind.descr())
133 };
134 err.note(&format!("{} arguments must be provided before {} arguments", first, last));
135 if let Some(help) = help {
136 err.help(help);
3dfed10e 137 }
9c376795
FG
138 }
139
9ffffee4 140 err.emit()
9c376795 141}
3dfed10e 142
9c376795
FG
143/// Creates the relevant generic argument substitutions
144/// corresponding to a set of generic parameters. This is a
145/// rather complex function. Let us try to explain the role
146/// of each of its parameters:
147///
148/// To start, we are given the `def_id` of the thing we are
149/// creating the substitutions for, and a partial set of
150/// substitutions `parent_substs`. In general, the substitutions
151/// for an item begin with substitutions for all the "parents" of
152/// that item -- e.g., for a method it might include the
153/// parameters from the impl.
154///
155/// Therefore, the method begins by walking down these parents,
156/// starting with the outermost parent and proceed inwards until
157/// it reaches `def_id`. For each parent `P`, it will check `parent_substs`
158/// first to see if the parent's substitutions are listed in there. If so,
159/// we can append those and move on. Otherwise, it invokes the
160/// three callback functions:
161///
162/// - `args_for_def_id`: given the `DefId` `P`, supplies back the
163/// generic arguments that were given to that parent from within
164/// the path; so e.g., if you have `<T as Foo>::Bar`, the `DefId`
165/// might refer to the trait `Foo`, and the arguments might be
166/// `[T]`. The boolean value indicates whether to infer values
167/// for arguments whose values were not explicitly provided.
168/// - `provided_kind`: given the generic parameter and the value from `args_for_def_id`,
169/// instantiate a `GenericArg`.
170/// - `inferred_kind`: if no parameter was provided, and inference is enabled, then
171/// creates a suitable inference variable.
172pub fn create_substs_for_generic_args<'tcx, 'a>(
173 tcx: TyCtxt<'tcx>,
174 def_id: DefId,
175 parent_substs: &[subst::GenericArg<'tcx>],
176 has_self: bool,
177 self_ty: Option<Ty<'tcx>>,
178 arg_count: &GenericArgCountResult,
179 ctx: &mut impl CreateSubstsForGenericArgsCtxt<'a, 'tcx>,
180) -> SubstsRef<'tcx> {
181 // Collect the segments of the path; we need to substitute arguments
182 // for parameters throughout the entire path (wherever there are
183 // generic parameters).
184 let mut parent_defs = tcx.generics_of(def_id);
185 let count = parent_defs.count();
186 let mut stack = vec![(def_id, parent_defs)];
187 while let Some(def_id) = parent_defs.parent {
188 parent_defs = tcx.generics_of(def_id);
189 stack.push((def_id, parent_defs));
3dfed10e
XL
190 }
191
9c376795
FG
192 // We manually build up the substitution, rather than using convenience
193 // methods in `subst.rs`, so that we can iterate over the arguments and
194 // parameters in lock-step linearly, instead of trying to match each pair.
195 let mut substs: SmallVec<[subst::GenericArg<'tcx>; 8]> = SmallVec::with_capacity(count);
196 // Iterate over each segment of the path.
197 while let Some((def_id, defs)) = stack.pop() {
198 let mut params = defs.params.iter().peekable();
199
200 // If we have already computed substitutions for parents, we can use those directly.
201 while let Some(&param) = params.peek() {
202 if let Some(&kind) = parent_substs.get(param.index as usize) {
203 substs.push(kind);
204 params.next();
205 } else {
206 break;
207 }
3dfed10e
XL
208 }
209
9c376795
FG
210 // `Self` is handled first, unless it's been handled in `parent_substs`.
211 if has_self {
212 if let Some(&param) = params.peek() {
213 if param.index == 0 {
214 if let GenericParamDefKind::Type { .. } = param.kind {
215 substs.push(
216 self_ty
217 .map(|ty| ty.into())
218 .unwrap_or_else(|| ctx.inferred_kind(None, param, true)),
219 );
220 params.next();
221 }
3dfed10e
XL
222 }
223 }
9c376795 224 }
3dfed10e 225
9c376795
FG
226 // Check whether this segment takes generic arguments and the user has provided any.
227 let (generic_args, infer_args) = ctx.args_for_def_id(def_id);
228
229 let args_iter = generic_args.iter().flat_map(|generic_args| generic_args.args.iter());
230 let mut args = args_iter.clone().peekable();
231
232 // If we encounter a type or const when we expect a lifetime, we infer the lifetimes.
233 // If we later encounter a lifetime, we know that the arguments were provided in the
234 // wrong order. `force_infer_lt` records the type or const that forced lifetimes to be
235 // inferred, so we can use it for diagnostics later.
236 let mut force_infer_lt = None;
237
238 loop {
239 // We're going to iterate through the generic arguments that the user
240 // provided, matching them with the generic parameters we expect.
241 // Mismatches can occur as a result of elided lifetimes, or for malformed
242 // input. We try to handle both sensibly.
243 match (args.peek(), params.peek()) {
244 (Some(&arg), Some(&param)) => {
245 match (arg, &param.kind, arg_count.explicit_late_bound) {
246 (GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _)
247 | (
248 GenericArg::Type(_) | GenericArg::Infer(_),
249 GenericParamDefKind::Type { .. },
250 _,
251 )
252 | (
253 GenericArg::Const(_) | GenericArg::Infer(_),
254 GenericParamDefKind::Const { .. },
255 _,
256 ) => {
257 substs.push(ctx.provided_kind(param, arg));
258 args.next();
3dfed10e
XL
259 params.next();
260 }
9c376795
FG
261 (
262 GenericArg::Infer(_) | GenericArg::Type(_) | GenericArg::Const(_),
263 GenericParamDefKind::Lifetime,
264 _,
265 ) => {
266 // We expected a lifetime argument, but got a type or const
267 // argument. That means we're inferring the lifetimes.
268 substs.push(ctx.inferred_kind(None, param, infer_args));
269 force_infer_lt = Some((arg, param));
270 params.next();
3dfed10e 271 }
9c376795
FG
272 (GenericArg::Lifetime(_), _, ExplicitLateBound::Yes) => {
273 // We've come across a lifetime when we expected something else in
274 // the presence of explicit late bounds. This is most likely
275 // due to the presence of the explicit bound so we're just going to
276 // ignore it.
277 args.next();
3dfed10e 278 }
9c376795
FG
279 (_, _, _) => {
280 // We expected one kind of parameter, but the user provided
281 // another. This is an error. However, if we already know that
282 // the arguments don't match up with the parameters, we won't issue
283 // an additional error, as the user already knows what's wrong.
284 if arg_count.correct.is_ok() {
285 // We're going to iterate over the parameters to sort them out, and
286 // show that order to the user as a possible order for the parameters
287 let mut param_types_present = defs
288 .params
289 .iter()
290 .map(|param| (param.kind.to_ord(), param.clone()))
291 .collect::<Vec<(ParamKindOrd, GenericParamDef)>>();
292 param_types_present.sort_by_key(|(ord, _)| *ord);
293 let (mut param_types_present, ordered_params): (
294 Vec<ParamKindOrd>,
295 Vec<GenericParamDef>,
296 ) = param_types_present.into_iter().unzip();
297 param_types_present.dedup();
298
299 generic_arg_mismatch_err(
300 tcx,
301 arg,
302 param,
303 !args_iter.clone().is_sorted_by_key(|arg| arg.to_ord()),
304 Some(&format!(
305 "reorder the arguments: {}: `<{}>`",
306 param_types_present
307 .into_iter()
308 .map(|ord| format!("{}s", ord))
309 .collect::<Vec<String>>()
310 .join(", then "),
311 ordered_params
312 .into_iter()
313 .filter_map(|param| {
314 if param.name == kw::SelfUpper {
315 None
316 } else {
317 Some(param.name.to_string())
318 }
319 })
320 .collect::<Vec<String>>()
321 .join(", ")
322 )),
323 );
324 }
3dfed10e 325
9c376795
FG
326 // We've reported the error, but we want to make sure that this
327 // problem doesn't bubble down and create additional, irrelevant
328 // errors. In this case, we're simply going to ignore the argument
329 // and any following arguments. The rest of the parameters will be
330 // inferred.
331 while args.next().is_some() {}
332 }
3dfed10e 333 }
9c376795 334 }
3dfed10e 335
9c376795
FG
336 (Some(&arg), None) => {
337 // We should never be able to reach this point with well-formed input.
338 // There are three situations in which we can encounter this issue.
339 //
340 // 1. The number of arguments is incorrect. In this case, an error
341 // will already have been emitted, and we can ignore it.
342 // 2. There are late-bound lifetime parameters present, yet the
343 // lifetime arguments have also been explicitly specified by the
344 // user.
345 // 3. We've inferred some lifetimes, which have been provided later (i.e.
346 // after a type or const). We want to throw an error in this case.
347
348 if arg_count.correct.is_ok()
349 && arg_count.explicit_late_bound == ExplicitLateBound::No
350 {
351 let kind = arg.descr();
352 assert_eq!(kind, "lifetime");
353 let (provided_arg, param) =
354 force_infer_lt.expect("lifetimes ought to have been inferred");
355 generic_arg_mismatch_err(tcx, provided_arg, param, false, None);
3dfed10e
XL
356 }
357
9c376795
FG
358 break;
359 }
360
361 (None, Some(&param)) => {
362 // If there are fewer arguments than parameters, it means
363 // we're inferring the remaining arguments.
364 substs.push(ctx.inferred_kind(Some(&substs), param, infer_args));
365 params.next();
3dfed10e 366 }
9c376795
FG
367
368 (None, None) => break,
3dfed10e
XL
369 }
370 }
3dfed10e
XL
371 }
372
9ffffee4 373 tcx.mk_substs(&substs)
9c376795
FG
374}
375
376/// Checks that the correct number of generic arguments have been provided.
377/// Used specifically for function calls.
378pub fn check_generic_arg_count_for_call(
379 tcx: TyCtxt<'_>,
380 span: Span,
381 def_id: DefId,
382 generics: &ty::Generics,
383 seg: &hir::PathSegment<'_>,
384 is_method_call: IsMethodCall,
385) -> GenericArgCountResult {
386 let empty_args = hir::GenericArgs::none();
387 let gen_args = seg.args.unwrap_or(&empty_args);
9ffffee4
FG
388 let gen_pos = match is_method_call {
389 IsMethodCall::Yes => GenericArgPosition::MethodCall,
390 IsMethodCall::No => GenericArgPosition::Value,
9c376795
FG
391 };
392 let has_self = generics.parent.is_none() && generics.has_self;
393
394 check_generic_arg_count(
395 tcx,
396 span,
397 def_id,
398 seg,
399 generics,
400 gen_args,
401 gen_pos,
402 has_self,
403 seg.infer_args,
404 )
405}
406
407/// Checks that the correct number of generic arguments have been provided.
408/// This is used both for datatypes and function calls.
409#[instrument(skip(tcx, gen_pos), level = "debug")]
410pub(crate) fn check_generic_arg_count(
411 tcx: TyCtxt<'_>,
412 span: Span,
413 def_id: DefId,
414 seg: &hir::PathSegment<'_>,
415 gen_params: &ty::Generics,
416 gen_args: &hir::GenericArgs<'_>,
417 gen_pos: GenericArgPosition,
418 has_self: bool,
419 infer_args: bool,
420) -> GenericArgCountResult {
421 let default_counts = gen_params.own_defaults();
422 let param_counts = gen_params.own_counts();
423
424 // Subtracting from param count to ensure type params synthesized from `impl Trait`
425 // cannot be explicitly specified.
426 let synth_type_param_count = gen_params
427 .params
428 .iter()
429 .filter(|param| matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. }))
430 .count();
431 let named_type_param_count = param_counts.types - has_self as usize - synth_type_param_count;
432 let infer_lifetimes =
433 (gen_pos != GenericArgPosition::Type || infer_args) && !gen_args.has_lifetime_params();
434
435 if gen_pos != GenericArgPosition::Type && let Some(b) = gen_args.bindings.first() {
436 prohibit_assoc_ty_binding(tcx, b.span);
437 }
438
439 let explicit_late_bound =
440 prohibit_explicit_late_bound_lifetimes(tcx, gen_params, gen_args, gen_pos);
441
442 let mut invalid_args = vec![];
443
444 let mut check_lifetime_args = |min_expected_args: usize,
445 max_expected_args: usize,
446 provided_args: usize,
447 late_bounds_ignore: bool| {
448 if (min_expected_args..=max_expected_args).contains(&provided_args) {
449 return Ok(());
450 }
451
452 if late_bounds_ignore {
453 return Ok(());
454 }
455
456 if provided_args > max_expected_args {
457 invalid_args.extend(
458 gen_args.args[max_expected_args..provided_args].iter().map(|arg| arg.span()),
459 );
460 };
461
462 let gen_args_info = if provided_args > min_expected_args {
463 invalid_args.extend(
464 gen_args.args[min_expected_args..provided_args].iter().map(|arg| arg.span()),
465 );
466 let num_redundant_args = provided_args - min_expected_args;
467 GenericArgsInfo::ExcessLifetimes { num_redundant_args }
5869c6ff 468 } else {
9c376795
FG
469 let num_missing_args = min_expected_args - provided_args;
470 GenericArgsInfo::MissingLifetimes { num_missing_args }
5869c6ff 471 };
5869c6ff 472
9c376795 473 let reported = WrongNumberOfGenericArgs::new(
923072b8 474 tcx,
9c376795 475 gen_args_info,
923072b8 476 seg,
9c376795
FG
477 gen_params,
478 has_self as usize,
923072b8 479 gen_args,
9c376795 480 def_id,
3dfed10e 481 )
9c376795
FG
482 .diagnostic()
483 .emit();
484
485 Err(reported)
486 };
487
488 let min_expected_lifetime_args = if infer_lifetimes { 0 } else { param_counts.lifetimes };
489 let max_expected_lifetime_args = param_counts.lifetimes;
490 let num_provided_lifetime_args = gen_args.num_lifetime_params();
491
492 let lifetimes_correct = check_lifetime_args(
493 min_expected_lifetime_args,
494 max_expected_lifetime_args,
495 num_provided_lifetime_args,
496 explicit_late_bound == ExplicitLateBound::Yes,
497 );
498
499 let mut check_types_and_consts = |expected_min,
500 expected_max,
501 expected_max_with_synth,
502 provided,
503 params_offset,
504 args_offset| {
505 debug!(
506 ?expected_min,
507 ?expected_max,
508 ?provided,
509 ?params_offset,
510 ?args_offset,
511 "check_types_and_consts"
512 );
513 if (expected_min..=expected_max).contains(&provided) {
514 return Ok(());
3dfed10e
XL
515 }
516
9c376795 517 let num_default_params = expected_max - expected_min;
3dfed10e 518
9c376795
FG
519 let gen_args_info = if provided > expected_max {
520 invalid_args.extend(
521 gen_args.args[args_offset + expected_max..args_offset + provided]
522 .iter()
523 .map(|arg| arg.span()),
524 );
525 let num_redundant_args = provided - expected_max;
17df50a5 526
9c376795
FG
527 // Provide extra note if synthetic arguments like `impl Trait` are specified.
528 let synth_provided = provided <= expected_max_with_synth;
17df50a5 529
9c376795
FG
530 GenericArgsInfo::ExcessTypesOrConsts {
531 num_redundant_args,
532 num_default_params,
533 args_offset,
534 synth_provided,
5e7ed085 535 }
9c376795
FG
536 } else {
537 let num_missing_args = expected_max - provided;
3dfed10e 538
9c376795
FG
539 GenericArgsInfo::MissingTypesOrConsts {
540 num_missing_args,
541 num_default_params,
542 args_offset,
543 }
544 };
17df50a5 545
9c376795 546 debug!(?gen_args_info);
17df50a5 547
9c376795
FG
548 let reported = WrongNumberOfGenericArgs::new(
549 tcx,
550 gen_args_info,
551 seg,
552 gen_params,
553 params_offset,
554 gen_args,
555 def_id,
556 )
557 .diagnostic()
558 .emit_unless(gen_args.has_err());
5869c6ff 559
9c376795
FG
560 Err(reported)
561 };
3dfed10e 562
9c376795
FG
563 let args_correct = {
564 let expected_min = if infer_args {
565 0
566 } else {
567 param_counts.consts + named_type_param_count
568 - default_counts.types
569 - default_counts.consts
5869c6ff 570 };
9c376795
FG
571 debug!(?expected_min);
572 debug!(arg_counts.lifetimes=?gen_args.num_lifetime_params());
573
574 check_types_and_consts(
575 expected_min,
576 param_counts.consts + named_type_param_count,
577 param_counts.consts + named_type_param_count + synth_type_param_count,
578 gen_args.num_generic_params(),
579 param_counts.lifetimes + has_self as usize,
580 gen_args.num_lifetime_params(),
581 )
582 };
1b1a35ee 583
9c376795
FG
584 GenericArgCountResult {
585 explicit_late_bound,
586 correct: lifetimes_correct
587 .and(args_correct)
588 .map_err(|reported| GenericArgCountMismatch { reported: Some(reported), invalid_args }),
3dfed10e 589 }
9c376795 590}
3dfed10e 591
9c376795
FG
592/// Emits an error regarding forbidden type binding associations
593pub fn prohibit_assoc_ty_binding(tcx: TyCtxt<'_>, span: Span) {
594 tcx.sess.emit_err(AssocTypeBindingNotAllowed { span });
595}
3dfed10e 596
9c376795
FG
597/// Prohibits explicit lifetime arguments if late-bound lifetime parameters
598/// are present. This is used both for datatypes and function calls.
599pub(crate) fn prohibit_explicit_late_bound_lifetimes(
600 tcx: TyCtxt<'_>,
601 def: &ty::Generics,
602 args: &hir::GenericArgs<'_>,
603 position: GenericArgPosition,
604) -> ExplicitLateBound {
605 let param_counts = def.own_counts();
606 let infer_lifetimes = position != GenericArgPosition::Type && !args.has_lifetime_params();
607
608 if infer_lifetimes {
609 return ExplicitLateBound::No;
610 }
5869c6ff 611
9c376795
FG
612 if let Some(span_late) = def.has_late_bound_regions {
613 let msg = "cannot specify lifetime arguments explicitly \
3dfed10e 614 if late bound lifetime parameters are present";
9c376795
FG
615 let note = "the late bound lifetime parameter is introduced here";
616 let span = args.args[0].span();
617
618 if position == GenericArgPosition::Value
619 && args.num_lifetime_params() != param_counts.lifetimes
620 {
621 let mut err = tcx.sess.struct_span_err(span, msg);
622 err.span_note(span_late, note);
623 err.emit();
3dfed10e 624 } else {
9c376795
FG
625 let mut multispan = MultiSpan::from_span(span);
626 multispan.push_span_label(span_late, note);
627 tcx.struct_span_lint_hir(
628 LATE_BOUND_LIFETIME_ARGUMENTS,
629 args.args[0].hir_id(),
630 multispan,
631 msg,
632 |lint| lint,
633 );
3dfed10e 634 }
9c376795
FG
635
636 ExplicitLateBound::Yes
637 } else {
638 ExplicitLateBound::No
3dfed10e
XL
639 }
640}