Skip to content

Commit bf7e7a5

Browse files
committed
Always pass a &PathSegment in astconv.
1 parent 7ad5f31 commit bf7e7a5

File tree

2 files changed

+18
-48
lines changed

2 files changed

+18
-48
lines changed

compiler/rustc_hir_analysis/src/astconv/generics.rs

+7-20
Original file line numberDiff line numberDiff line change
@@ -382,25 +382,13 @@ pub fn check_generic_arg_count_for_call(
382382
seg: &hir::PathSegment<'_>,
383383
is_method_call: IsMethodCall,
384384
) -> GenericArgCountResult {
385-
let empty_args = hir::GenericArgs::none();
386-
let gen_args = seg.args.unwrap_or(&empty_args);
387385
let gen_pos = match is_method_call {
388386
IsMethodCall::Yes => GenericArgPosition::MethodCall,
389387
IsMethodCall::No => GenericArgPosition::Value,
390388
};
391389
let has_self = generics.parent.is_none() && generics.has_self;
392390

393-
check_generic_arg_count(
394-
tcx,
395-
span,
396-
def_id,
397-
seg,
398-
generics,
399-
gen_args,
400-
gen_pos,
401-
has_self,
402-
seg.infer_args,
403-
)
391+
check_generic_arg_count(tcx, span, def_id, seg, generics, gen_pos, has_self)
404392
}
405393

406394
/// Checks that the correct number of generic arguments have been provided.
@@ -412,13 +400,12 @@ pub(crate) fn check_generic_arg_count(
412400
def_id: DefId,
413401
seg: &hir::PathSegment<'_>,
414402
gen_params: &ty::Generics,
415-
gen_args: &hir::GenericArgs<'_>,
416403
gen_pos: GenericArgPosition,
417404
has_self: bool,
418-
infer_args: bool,
419405
) -> GenericArgCountResult {
420406
let default_counts = gen_params.own_defaults();
421407
let param_counts = gen_params.own_counts();
408+
let gen_args = seg.args();
422409

423410
// Subtracting from param count to ensure type params synthesized from `impl Trait`
424411
// cannot be explicitly specified.
@@ -429,14 +416,13 @@ pub(crate) fn check_generic_arg_count(
429416
.count();
430417
let named_type_param_count = param_counts.types - has_self as usize - synth_type_param_count;
431418
let infer_lifetimes =
432-
(gen_pos != GenericArgPosition::Type || infer_args) && !gen_args.has_lifetime_params();
419+
(gen_pos != GenericArgPosition::Type || seg.infer_args) && !gen_args.has_lifetime_params();
433420

434421
if gen_pos != GenericArgPosition::Type && let Some(b) = gen_args.bindings.first() {
435422
prohibit_assoc_ty_binding(tcx, b.span);
436423
}
437424

438-
let explicit_late_bound =
439-
prohibit_explicit_late_bound_lifetimes(tcx, gen_params, gen_args, gen_pos);
425+
let explicit_late_bound = prohibit_explicit_late_bound_lifetimes(tcx, gen_params, seg, gen_pos);
440426

441427
let mut invalid_args = vec![];
442428

@@ -560,7 +546,7 @@ pub(crate) fn check_generic_arg_count(
560546
};
561547

562548
let args_correct = {
563-
let expected_min = if infer_args {
549+
let expected_min = if seg.infer_args {
564550
0
565551
} else {
566552
param_counts.consts + named_type_param_count
@@ -598,9 +584,10 @@ pub fn prohibit_assoc_ty_binding(tcx: TyCtxt<'_>, span: Span) {
598584
pub(crate) fn prohibit_explicit_late_bound_lifetimes(
599585
tcx: TyCtxt<'_>,
600586
def: &ty::Generics,
601-
args: &hir::GenericArgs<'_>,
587+
seg: &hir::PathSegment<'_>,
602588
position: GenericArgPosition,
603589
) -> ExplicitLateBound {
590+
let args = seg.args();
604591
let infer_lifetimes = position != GenericArgPosition::Type && !args.has_lifetime_params();
605592

606593
if infer_lifetimes {

compiler/rustc_hir_analysis/src/astconv/mod.rs

+11-28
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
288288
def_id,
289289
&[],
290290
item_segment,
291-
item_segment.args(),
292-
item_segment.infer_args,
293291
None,
294292
ty::BoundConstness::NotConst,
295293
);
@@ -332,14 +330,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
332330
/// type itself: `['a]`. The returned `SubstsRef` concatenates these two
333331
/// lists: `[Vec<u8>, u8, 'a]`.
334332
#[instrument(level = "debug", skip(self, span), ret)]
335-
fn create_substs_for_ast_path<'a>(
333+
fn create_substs_for_ast_path(
336334
&self,
337335
span: Span,
338336
def_id: DefId,
339337
parent_substs: &[subst::GenericArg<'tcx>],
340338
seg: &hir::PathSegment<'_>,
341-
generic_args: &'a hir::GenericArgs<'_>,
342-
infer_args: bool,
343339
self_ty: Option<Ty<'tcx>>,
344340
constness: ty::BoundConstness,
345341
) -> (SubstsRef<'tcx>, GenericArgCountResult) {
@@ -370,10 +366,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
370366
def_id,
371367
seg,
372368
generics,
373-
generic_args,
374369
GenericArgPosition::Type,
375370
self_ty.is_some(),
376-
infer_args,
377371
);
378372

379373
// Skip processing if type has no generic parameters.
@@ -540,9 +534,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
540534
astconv: self,
541535
def_id,
542536
span,
543-
generic_args,
537+
generic_args: seg.args(),
544538
inferred_params: vec![],
545-
infer_args,
539+
infer_args: seg.infer_args,
546540
};
547541
let substs = create_substs_for_generic_args(
548542
tcx,
@@ -623,8 +617,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
623617
item_def_id,
624618
parent_substs,
625619
item_segment,
626-
item_segment.args(),
627-
item_segment.infer_args,
628620
None,
629621
ty::BoundConstness::NotConst,
630622
);
@@ -671,17 +663,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
671663
trait_ref_span: Span,
672664
trait_def_id: DefId,
673665
trait_segment: &hir::PathSegment<'_>,
674-
args: &GenericArgs<'_>,
675-
infer_args: bool,
676666
self_ty: Ty<'tcx>,
677667
) -> GenericArgCountResult {
678668
let (substs, arg_count) = self.create_substs_for_ast_path(
679669
trait_ref_span,
680670
trait_def_id,
681671
&[],
682672
trait_segment,
683-
args,
684-
infer_args,
685673
Some(self_ty),
686674
constness,
687675
);
@@ -690,7 +678,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
690678
let bound_vars = tcx.late_bound_vars(hir_id);
691679
debug!(?bound_vars);
692680

693-
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
681+
let assoc_bindings = self.create_assoc_bindings_for_generic_args(trait_segment.args());
694682

695683
let poly_trait_ref =
696684
ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars);
@@ -751,8 +739,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
751739
let trait_ref_span = trait_ref.path.span;
752740
let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
753741
let trait_segment = trait_ref.path.segments.last().unwrap();
754-
let args = trait_segment.args();
755-
let infer_args = trait_segment.infer_args;
756742

757743
self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter(), |_| {});
758744
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, false);
@@ -767,8 +753,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
767753
trait_ref_span,
768754
trait_def_id,
769755
trait_segment,
770-
args,
771-
infer_args,
772756
self_ty,
773757
)
774758
}
@@ -787,8 +771,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
787771
let speculative = false;
788772
let trait_ref_span = span;
789773
let trait_def_id = self.tcx().require_lang_item(lang_item, Some(span));
790-
let trait_segment = &hir::PathSegment::invalid();
791-
let infer_args = false;
774+
let trait_segment = &hir::PathSegment {
775+
ident: Ident::empty(),
776+
hir_id: hir::HirId::INVALID,
777+
res: Res::Err,
778+
args: Some(args),
779+
infer_args: false,
780+
};
792781

793782
self.instantiate_poly_trait_ref_inner(
794783
hir_id,
@@ -800,8 +789,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
800789
trait_ref_span,
801790
trait_def_id,
802791
trait_segment,
803-
args,
804-
infer_args,
805792
self_ty,
806793
);
807794
}
@@ -846,8 +833,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
846833
trait_def_id,
847834
&[],
848835
trait_segment,
849-
trait_segment.args(),
850-
trait_segment.infer_args,
851836
Some(self_ty),
852837
constness,
853838
)
@@ -3074,8 +3059,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
30743059
def_id,
30753060
&[],
30763061
&hir::PathSegment::invalid(),
3077-
&GenericArgs::none(),
3078-
true,
30793062
None,
30803063
ty::BoundConstness::NotConst,
30813064
);

0 commit comments

Comments
 (0)