Skip to content

Commit 3e89753

Browse files
committed
Rename PathParameter(s) to GenericArg(s)
1 parent e05ad4f commit 3e89753

File tree

24 files changed

+194
-203
lines changed

24 files changed

+194
-203
lines changed

src/librustc/hir/intravisit.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,10 @@ pub trait Visitor<'v> : Sized {
344344
fn visit_label(&mut self, label: &'v Label) {
345345
walk_label(self, label)
346346
}
347-
fn visit_path_param(&mut self, path_param: &'v PathParam) {
348-
match path_param {
349-
PathParam::Lifetime(lt) => self.visit_lifetime(lt),
350-
PathParam::Type(ty) => self.visit_ty(ty),
347+
fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg) {
348+
match generic_arg {
349+
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
350+
GenericArg::Type(ty) => self.visit_ty(ty),
351351
}
352352
}
353353
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
@@ -362,8 +362,8 @@ pub trait Visitor<'v> : Sized {
362362
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
363363
walk_path_segment(self, path_span, path_segment)
364364
}
365-
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'v PathParameters) {
366-
walk_path_parameters(self, path_span, path_parameters)
365+
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs) {
366+
walk_generic_args(self, path_span, generic_args)
367367
}
368368
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) {
369369
walk_assoc_type_binding(self, type_binding)
@@ -649,15 +649,15 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
649649
segment: &'v PathSegment) {
650650
visitor.visit_name(path_span, segment.name);
651651
if let Some(ref parameters) = segment.parameters {
652-
visitor.visit_path_parameters(path_span, parameters);
652+
visitor.visit_generic_args(path_span, parameters);
653653
}
654654
}
655655

656-
pub fn walk_path_parameters<'v, V: Visitor<'v>>(visitor: &mut V,
656+
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V,
657657
_path_span: Span,
658-
path_parameters: &'v PathParameters) {
659-
walk_list!(visitor, visit_path_param, &path_parameters.parameters);
660-
walk_list!(visitor, visit_assoc_type_binding, &path_parameters.bindings);
658+
generic_args: &'v GenericArgs) {
659+
walk_list!(visitor, visit_generic_arg, &generic_args.parameters);
660+
walk_list!(visitor, visit_assoc_type_binding, &generic_args.bindings);
661661
}
662662

663663
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,

src/librustc/hir/lowering.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use hir::HirVec;
4646
use hir::map::{DefKey, DefPathData, Definitions};
4747
use hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
4848
use hir::def::{Def, PathResolution, PerNS};
49-
use hir::PathParam;
49+
use hir::GenericArg;
5050
use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES};
5151
use middle::cstore::CrateStore;
5252
use rustc_data_structures::indexed_vec::IndexVec;
@@ -1038,16 +1038,16 @@ impl<'a> LoweringContext<'a> {
10381038
}
10391039
}
10401040

1041-
fn lower_path_param(&mut self,
1041+
fn lower_generic_arg(&mut self,
10421042
p: &AngleBracketedParam,
10431043
itctx: ImplTraitContext)
1044-
-> PathParam {
1044+
-> GenericArg {
10451045
match p {
10461046
AngleBracketedParam::Lifetime(lt) => {
1047-
PathParam::Lifetime(self.lower_lifetime(&lt))
1047+
GenericArg::Lifetime(self.lower_lifetime(&lt))
10481048
}
10491049
AngleBracketedParam::Type(ty) => {
1050-
PathParam::Type(self.lower_ty(&ty, itctx))
1050+
GenericArg::Type(self.lower_ty(&ty, itctx))
10511051
}
10521052
}
10531053
}
@@ -1322,15 +1322,15 @@ impl<'a> LoweringContext<'a> {
13221322
hir::intravisit::NestedVisitorMap::None
13231323
}
13241324

1325-
fn visit_path_parameters(&mut self, span: Span, parameters: &'v hir::PathParameters) {
1325+
fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs) {
13261326
// Don't collect elided lifetimes used inside of `Fn()` syntax.
13271327
if parameters.parenthesized {
13281328
let old_collect_elided_lifetimes = self.collect_elided_lifetimes;
13291329
self.collect_elided_lifetimes = false;
1330-
hir::intravisit::walk_path_parameters(self, span, parameters);
1330+
hir::intravisit::walk_generic_args(self, span, parameters);
13311331
self.collect_elided_lifetimes = old_collect_elided_lifetimes;
13321332
} else {
1333-
hir::intravisit::walk_path_parameters(self, span, parameters);
1333+
hir::intravisit::walk_generic_args(self, span, parameters);
13341334
}
13351335
}
13361336

@@ -1567,7 +1567,7 @@ impl<'a> LoweringContext<'a> {
15671567
assert!(!def_id.is_local());
15681568
let item_generics =
15691569
self.cstore.item_generics_cloned_untracked(def_id, self.sess);
1570-
let n = item_generics.own_counts().lifetimes();
1570+
let n = item_generics.own_counts().lifetimes;
15711571
self.type_def_lifetime_params.insert(def_id, n);
15721572
n
15731573
});
@@ -1684,13 +1684,14 @@ impl<'a> LoweringContext<'a> {
16841684
parenthesized_generic_args: ParenthesizedGenericArgs,
16851685
itctx: ImplTraitContext,
16861686
) -> hir::PathSegment {
1687-
let (mut parameters, infer_types) = if let Some(ref parameters) = segment.parameters {
1687+
let (mut generic_args, infer_types) =
1688+
if let Some(ref generic_args) = segment.parameters {
16881689
let msg = "parenthesized parameters may only be used with a trait";
1689-
match **path_params {
1690-
PathParameters::AngleBracketed(ref data) => {
1690+
match **generic_args {
1691+
GenericArgs::AngleBracketed(ref data) => {
16911692
self.lower_angle_bracketed_parameter_data(data, param_mode, itctx)
16921693
}
1693-
PathParameters::Parenthesized(ref data) => match parenthesized_generic_args {
1694+
GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args {
16941695
ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data),
16951696
ParenthesizedGenericArgs::Warn => {
16961697
self.sess.buffer_lint(
@@ -1699,30 +1700,30 @@ impl<'a> LoweringContext<'a> {
16991700
data.span,
17001701
msg.into(),
17011702
);
1702-
(hir::PathParameters::none(), true)
1703+
(hir::GenericArgs::none(), true)
17031704
}
17041705
ParenthesizedGenericArgs::Err => {
17051706
struct_span_err!(self.sess, data.span, E0214, "{}", msg)
17061707
.span_label(data.span, "only traits may use parentheses")
17071708
.emit();
1708-
(hir::PathParameters::none(), true)
1709+
(hir::GenericArgs::none(), true)
17091710
}
17101711
},
17111712
}
17121713
} else {
17131714
self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx)
17141715
};
17151716

1716-
if !parameters.parenthesized && parameters.lifetimes.is_empty() {
1717-
path_params.parameters = (0..expected_lifetimes).map(|_| {
1718-
PathParam::Lifetime(self.elided_lifetime(path_span))
1719-
}).chain(path_params.parameters.into_iter()).collect();
1717+
if !generic_args.parenthesized && generic_args.lifetimes().count() == 0 {
1718+
generic_args.parameters = (0..expected_lifetimes).map(|_| {
1719+
GenericArg::Lifetime(self.elided_lifetime(path_span))
1720+
}).chain(generic_args.parameters.into_iter()).collect();
17201721
}
17211722

17221723
hir::PathSegment::new(
1723-
self.lower_ident(segment.ident),
1724-
path_params,
1725-
infer_types,
1724+
self.lower_ident(segment.identifier),
1725+
generic_args,
1726+
infer_types
17261727
)
17271728
}
17281729

@@ -1731,14 +1732,14 @@ impl<'a> LoweringContext<'a> {
17311732
data: &AngleBracketedParameterData,
17321733
param_mode: ParamMode,
17331734
itctx: ImplTraitContext,
1734-
) -> (hir::PathParameters, bool) {
1735+
) -> (hir::GenericArgs, bool) {
17351736
let &AngleBracketedParameterData { ref parameters, ref bindings, .. } = data;
1736-
(hir::PathParameters {
1737-
parameters: parameters.iter().map(|p| self.lower_path_param(p, itctx)).collect(),
1737+
(hir::GenericArgs {
1738+
parameters: parameters.iter().map(|p| self.lower_generic_arg(p, itctx)).collect(),
17381739
bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(),
17391740
parenthesized: false,
17401741
},
1741-
types.is_empty() && param_mode == ParamMode::Optional)
1742+
data.types().count() == 0 && param_mode == ParamMode::Optional)
17421743
}
17431744

17441745
fn lower_parenthesized_parameter_data(
@@ -1774,8 +1775,8 @@ impl<'a> LoweringContext<'a> {
17741775
};
17751776

17761777
(
1777-
hir::PathParameters {
1778-
parameters: hir_vec![PathParam::Type(mk_tup(this, inputs, span))],
1778+
hir::GenericArgs {
1779+
parameters: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))],
17791780
bindings: hir_vec![
17801781
hir::TypeBinding {
17811782
id: this.next_id().node_id,

src/librustc/hir/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ pub struct PathSegment {
327327
/// this is more than just simple syntactic sugar; the use of
328328
/// parens affects the region binding rules, so we preserve the
329329
/// distinction.
330-
pub parameters: Option<P<PathParameters>>,
330+
pub parameters: Option<P<GenericArgs>>,
331331

332332
/// Whether to infer remaining type parameters, if any.
333333
/// This only applies to expression and pattern paths, and
@@ -346,7 +346,7 @@ impl PathSegment {
346346
}
347347
}
348348

349-
pub fn new(name: Name, parameters: PathParameters, infer_types: bool) -> Self {
349+
pub fn new(name: Name, parameters: GenericArgs, infer_types: bool) -> Self {
350350
PathSegment {
351351
name,
352352
infer_types,
@@ -359,11 +359,11 @@ impl PathSegment {
359359
}
360360

361361
// FIXME: hack required because you can't create a static
362-
// PathParameters, so you can't just return a &PathParameters.
362+
// GenericArgs, so you can't just return a &GenericArgs.
363363
pub fn with_parameters<F, R>(&self, f: F) -> R
364-
where F: FnOnce(&PathParameters) -> R
364+
where F: FnOnce(&GenericArgs) -> R
365365
{
366-
let dummy = PathParameters::none();
366+
let dummy = GenericArgs::none();
367367
f(if let Some(ref params) = self.parameters {
368368
&params
369369
} else {
@@ -373,15 +373,15 @@ impl PathSegment {
373373
}
374374

375375
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
376-
pub enum PathParam {
376+
pub enum GenericArg {
377377
Lifetime(Lifetime),
378378
Type(P<Ty>),
379379
}
380380

381381
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
382-
pub struct PathParameters {
382+
pub struct GenericArgs {
383383
/// The generic parameters for this path segment.
384-
pub parameters: HirVec<PathParam>,
384+
pub parameters: HirVec<GenericArg>,
385385
/// Bindings (equality constraints) on associated types, if present.
386386
/// E.g., `Foo<A=Bar>`.
387387
pub bindings: HirVec<TypeBinding>,
@@ -391,7 +391,7 @@ pub struct PathParameters {
391391
pub parenthesized: bool,
392392
}
393393

394-
impl PathParameters {
394+
impl GenericArgs {
395395
pub fn none() -> Self {
396396
Self {
397397
parameters: HirVec::new(),
@@ -406,33 +406,33 @@ impl PathParameters {
406406

407407
pub fn inputs(&self) -> &[P<Ty>] {
408408
if self.parenthesized {
409-
if let Some(ref ty) = self.types().get(0) {
409+
if let Some(ref ty) = self.types().next() {
410410
if let TyTup(ref tys) = ty.node {
411411
return tys;
412412
}
413413
}
414414
}
415-
bug!("PathParameters::inputs: not a `Fn(T) -> U`");
415+
bug!("GenericArgs::inputs: not a `Fn(T) -> U`");
416416
}
417417

418-
pub fn lifetimes(&self) -> Vec<&Lifetime> {
418+
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> {
419419
self.parameters.iter().filter_map(|p| {
420-
if let PathParam::Lifetime(lt) = p {
420+
if let GenericArg::Lifetime(lt) = p {
421421
Some(lt)
422422
} else {
423423
None
424424
}
425-
}).collect()
425+
})
426426
}
427427

428-
pub fn types(&self) -> Vec<&P<Ty>> {
428+
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> {
429429
self.parameters.iter().filter_map(|p| {
430-
if let PathParam::Type(ty) = p {
430+
if let GenericArg::Type(ty) = p {
431431
Some(ty)
432432
} else {
433433
None
434434
}
435-
}).collect()
435+
})
436436
}
437437
}
438438

@@ -562,11 +562,11 @@ impl Generics {
562562
self.params.iter().any(|param| param.is_type_param())
563563
}
564564

565-
pub fn lifetimes<'a>(&'a self) -> impl Iterator<Item = &'a LifetimeDef> {
565+
pub fn lifetimes<'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a LifetimeDef> {
566566
self.params.lifetimes()
567567
}
568568

569-
pub fn ty_params<'a>(&'a self) -> impl Iterator<Item = &'a TyParam> {
569+
pub fn ty_params<'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a TyParam> {
570570
self.params.ty_params()
571571
}
572572
}

0 commit comments

Comments
 (0)