@@ -409,6 +409,8 @@ pub(crate) fn check_generic_arg_count(
409409 has_self : bool ,
410410) -> GenericArgCountResult {
411411 let gen_args = seg. args ( ) ;
412+ let tcx = cx. tcx ( ) ;
413+ let kind = tcx. def_kind ( def_id) ;
412414 let default_counts = gen_params. own_defaults ( ) ;
413415 let param_counts = gen_params. own_counts ( ) ;
414416
@@ -430,14 +432,28 @@ pub(crate) fn check_generic_arg_count(
430432 prohibit_assoc_item_constraint ( cx, c, None ) ;
431433 }
432434
433- let tcx = cx. tcx ( ) ;
435+ // this works!
436+ // let hidden_early_bound = 0;
437+ let hidden_early_bound = if matches ! ( gen_pos, GenericArgPosition :: Value ( _) ) {
438+ gen_params. own_params . iter ( ) . filter ( |x| x. is_anonymous_lifetime ( ) ) . count ( )
439+ } else {
440+ 0
441+ } ;
442+
443+ let hidden_lifetimes = if matches ! ( gen_pos, GenericArgPosition :: Value ( _) ) {
444+ gen_params. own_all_params . iter ( ) . filter ( |x| x. is_anonymous_lifetime ( ) ) . count ( )
445+ } else {
446+ 0
447+ } ;
448+
449+ let late_bound_lt_count = gen_params. own_late_bound_regions . len ( ) ;
434450
435- let kind = tcx. def_kind ( def_id) ;
436451 if kind. is_fn_like ( ) {
437452 tracing:: info!( "we are using fn-like {:?} ({gen_pos:?})" , tcx. item_name( def_id) ) ;
438453 }
439- tracing:: info!( ?gen_args) ;
440- tracing:: info!( ?gen_params) ;
454+ tracing:: info!( ?late_bound_lt_count) ;
455+ tracing:: info!( "# gen_args = {}" , gen_args. args. len( ) ) ;
456+ tracing:: info!( "ALL gen_params={:?}" , gen_params. own_all_params) ;
441457
442458 // Suppress this warning for delegations as it is compiler generated and lifetimes are
443459 // propagated while late-bound lifetimes may be present.
@@ -448,56 +464,44 @@ pub(crate) fn check_generic_arg_count(
448464
449465 let mut invalid_args = vec ! [ ] ;
450466
451- let mut check_lifetime_args = |min_expected_args : usize ,
452- max_expected_args : usize ,
453- provided_args : usize ,
454- late_bounds_ignore : bool | {
455- if ( min_expected_args..=max_expected_args) . contains ( & provided_args) {
456- return Ok ( ( ) ) ;
457- }
458-
459- if late_bounds_ignore {
460- return Ok ( ( ) ) ;
461- }
467+ let mut check_lifetime_args =
468+ |min_expected_args : usize , max_expected_args : usize , provided_args : usize | {
469+ if ( min_expected_args..=max_expected_args) . contains ( & provided_args) {
470+ return Ok ( ( ) ) ;
471+ }
462472
463- invalid_args. extend ( min_expected_args..provided_args) ;
473+ invalid_args. extend ( min_expected_args..provided_args) ;
464474
465- let gen_args_info = if provided_args > min_expected_args {
466- let num_redundant_args = provided_args - min_expected_args;
467- GenericArgsInfo :: ExcessLifetimes { num_redundant_args }
468- } else {
469- let num_missing_args = min_expected_args - provided_args;
470- GenericArgsInfo :: MissingLifetimes { num_missing_args }
475+ let gen_args_info = if provided_args > min_expected_args {
476+ let num_redundant_args = provided_args - min_expected_args;
477+ GenericArgsInfo :: ExcessLifetimes { num_redundant_args }
478+ } else {
479+ let num_missing_args = min_expected_args - provided_args;
480+ GenericArgsInfo :: MissingLifetimes { num_missing_args }
481+ } ;
482+
483+ let reported = cx. dcx ( ) . emit_err ( WrongNumberOfGenericArgs :: new (
484+ tcx,
485+ gen_args_info,
486+ seg,
487+ gen_params,
488+ has_self as usize ,
489+ gen_args,
490+ def_id,
491+ ) ) ;
492+
493+ Err ( reported)
471494 } ;
472495
473- let reported = cx. dcx ( ) . emit_err ( WrongNumberOfGenericArgs :: new (
474- tcx,
475- gen_args_info,
476- seg,
477- gen_params,
478- has_self as usize ,
479- gen_args,
480- def_id,
481- ) ) ;
482-
483- Err ( reported)
484- } ;
485-
486- // this works!
487- let hidden_early_bound = 0 ;
488- // let hidden_early_bound = if matches!(gen_pos, GenericArgPosition::Value(_)) {
489- // gen_params.own_params.iter().filter(|x| x.is_anonymous_lifetime()).count()
490- // } else {
491- // 0
492- // };
493-
494496 let min_expected_lifetime_args =
495497 if infer_lifetimes { 0 } else { param_counts. lifetimes - hidden_early_bound } ;
496- let max_expected_lifetime_args = param_counts. lifetimes - hidden_early_bound;
498+ let max_expected_lifetime_args =
499+ param_counts. lifetimes - hidden_lifetimes + late_bound_lt_count;
497500 let num_provided_lifetime_args = gen_args. num_lifetime_args ( ) ;
498501
499502 tracing:: info!(
500503 ?hidden_early_bound,
504+ ?hidden_lifetimes,
501505 ?min_expected_lifetime_args,
502506 ?max_expected_lifetime_args,
503507 ?num_provided_lifetime_args,
@@ -507,7 +511,7 @@ pub(crate) fn check_generic_arg_count(
507511 min_expected_lifetime_args,
508512 max_expected_lifetime_args,
509513 num_provided_lifetime_args,
510- explicit_late_bound == ExplicitLateBound :: Yes ,
514+ // explicit_late_bound == ExplicitLateBound::Yes,
511515 ) ;
512516
513517 let mut check_types_and_consts = |expected_min,
@@ -668,11 +672,12 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
668672
669673 let param_counts = def. own_counts ( ) ;
670674
671- if let Some ( span_late) = def. has_late_bound_regions
675+ // FIXME(addiesh): just turning off the diagnostic is probably not enough to solve the problem. see:
676+ // https://rust-lang.zulipchat.com/#narrow/channel/600108-t-types.2Fearly-late-cleanup/topic/turbofishing.20elided.20lifetimes/near/607748866
677+ if cx. tcx ( ) . features ( ) . late_bound_turbofishing ( ) {
678+ ExplicitLateBound :: Yes
679+ } else if let Some ( span_late) = def. own_late_bound_regions . first ( ) . copied ( )
672680 && args. has_lifetime_args ( )
673- // FIXME(addiesh): just turning off the diagnostic is probably not enough to solve the problem. see:
674- // https://rust-lang.zulipchat.com/#narrow/channel/600108-t-types.2Fearly-late-cleanup/topic/turbofishing.20elided.20lifetimes/near/607748866
675- && !cx. tcx ( ) . features ( ) . late_bound_turbofishing ( )
676681 {
677682 let gone_turbofishing = "this may change in the future; see issue #156581 <https://github.com/rust-lang/rust/issues/156581> for more information" ;
678683
0 commit comments