Rename "parameter" to "arg"

This commit is contained in:
varkor 2018-02-23 17:48:54 +00:00
parent 3e89753283
commit 76c0d68745
35 changed files with 242 additions and 355 deletions

View File

@ -648,15 +648,15 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
path_span: Span,
segment: &'v PathSegment) {
visitor.visit_name(path_span, segment.name);
if let Some(ref parameters) = segment.parameters {
visitor.visit_generic_args(path_span, parameters);
if let Some(ref args) = segment.args {
visitor.visit_generic_args(path_span, args);
}
}
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V,
_path_span: Span,
generic_args: &'v GenericArgs) {
walk_list!(visitor, visit_generic_arg, &generic_args.parameters);
walk_list!(visitor, visit_generic_arg, &generic_args.args);
walk_list!(visitor, visit_assoc_type_binding, &generic_args.bindings);
}

View File

@ -59,6 +59,7 @@ use std::fmt::Debug;
use std::iter;
use std::mem;
use syntax::attr;
use syntax::ast;
use syntax::ast::*;
use syntax::errors;
use syntax::ext::hygiene::{Mark, SyntaxContext};
@ -1039,14 +1040,14 @@ impl<'a> LoweringContext<'a> {
}
fn lower_generic_arg(&mut self,
p: &AngleBracketedParam,
p: &ast::GenericArg,
itctx: ImplTraitContext)
-> GenericArg {
-> hir::GenericArg {
match p {
AngleBracketedParam::Lifetime(lt) => {
ast::GenericArg::Lifetime(lt) => {
GenericArg::Lifetime(self.lower_lifetime(&lt))
}
AngleBracketedParam::Type(ty) => {
ast::GenericArg::Type(ty) => {
GenericArg::Type(self.lower_ty(&ty, itctx))
}
}
@ -1684,8 +1685,7 @@ impl<'a> LoweringContext<'a> {
parenthesized_generic_args: ParenthesizedGenericArgs,
itctx: ImplTraitContext,
) -> hir::PathSegment {
let (mut generic_args, infer_types) =
if let Some(ref generic_args) = segment.parameters {
let (mut generic_args, infer_types) = if let Some(ref generic_args) = segment.args {
let msg = "parenthesized parameters may only be used with a trait";
match **generic_args {
GenericArgs::AngleBracketed(ref data) => {
@ -1715,13 +1715,16 @@ impl<'a> LoweringContext<'a> {
};
if !generic_args.parenthesized && generic_args.lifetimes().count() == 0 {
generic_args.parameters = (0..expected_lifetimes).map(|_| {
GenericArg::Lifetime(self.elided_lifetime(path_span))
}).chain(generic_args.parameters.into_iter()).collect();
generic_args.args =
self.elided_path_lifetimes(path_span, expected_lifetimes)
.into_iter()
.map(|lt| GenericArg::Lifetime(lt))
.chain(generic_args.args.into_iter())
.collect();
}
hir::PathSegment::new(
self.lower_ident(segment.identifier),
self.lower_ident(segment.ident),
generic_args,
infer_types
)
@ -1729,13 +1732,13 @@ impl<'a> LoweringContext<'a> {
fn lower_angle_bracketed_parameter_data(
&mut self,
data: &AngleBracketedParameterData,
data: &AngleBracketedArgs,
param_mode: ParamMode,
itctx: ImplTraitContext,
) -> (hir::GenericArgs, bool) {
let &AngleBracketedParameterData { ref parameters, ref bindings, .. } = data;
let &AngleBracketedArgs { ref args, ref bindings, .. } = data;
(hir::GenericArgs {
parameters: parameters.iter().map(|p| self.lower_generic_arg(p, itctx)).collect(),
args: args.iter().map(|p| self.lower_generic_arg(p, itctx)).collect(),
bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(),
parenthesized: false,
},
@ -1755,23 +1758,11 @@ impl<'a> LoweringContext<'a> {
AnonymousLifetimeMode::PassThrough,
|this| {
const DISALLOWED: ImplTraitContext = ImplTraitContext::Disallowed;
let &ParenthesizedParameterData {
ref inputs,
ref output,
span,
} = data;
let inputs = inputs
.iter()
.map(|ty| this.lower_ty(ty, DISALLOWED))
.collect();
let &ParenthesizedParameterData { ref inputs, ref output, span } = data;
let inputs = inputs.iter().map(|ty| this.lower_ty(ty, DISALLOWED)).collect();
let mk_tup = |this: &mut Self, tys, span| {
let LoweredNodeId { node_id, hir_id } = this.next_id();
P(hir::Ty {
node: hir::TyTup(tys),
id: node_id,
hir_id,
span,
})
P(hir::Ty { node: hir::TyTup(tys), id: node_id, hir_id, span })
};
(

View File

@ -327,7 +327,7 @@ pub struct PathSegment {
/// this is more than just simple syntactic sugar; the use of
/// parens affects the region binding rules, so we preserve the
/// distinction.
pub parameters: Option<P<GenericArgs>>,
pub args: Option<P<GenericArgs>>,
/// Whether to infer remaining type parameters, if any.
/// This only applies to expression and pattern paths, and
@ -342,30 +342,30 @@ impl PathSegment {
PathSegment {
name,
infer_types: true,
parameters: None
args: None,
}
}
pub fn new(name: Name, parameters: GenericArgs, infer_types: bool) -> Self {
pub fn new(name: Name, args: GenericArgs, infer_types: bool) -> Self {
PathSegment {
name,
infer_types,
parameters: if parameters.is_empty() {
args: if args.is_empty() {
None
} else {
Some(P(parameters))
Some(P(args))
}
}
}
// FIXME: hack required because you can't create a static
// GenericArgs, so you can't just return a &GenericArgs.
pub fn with_parameters<F, R>(&self, f: F) -> R
pub fn with_args<F, R>(&self, f: F) -> R
where F: FnOnce(&GenericArgs) -> R
{
let dummy = GenericArgs::none();
f(if let Some(ref params) = self.parameters {
&params
f(if let Some(ref args) = self.args {
&args
} else {
&dummy
})
@ -380,12 +380,12 @@ pub enum GenericArg {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct GenericArgs {
/// The generic parameters for this path segment.
pub parameters: HirVec<GenericArg>,
/// The generic arguments for this path segment.
pub args: HirVec<GenericArg>,
/// Bindings (equality constraints) on associated types, if present.
/// E.g., `Foo<A=Bar>`.
pub bindings: HirVec<TypeBinding>,
/// Were parameters written in parenthesized form `Fn(T) -> U`?
/// Were arguments written in parenthesized form `Fn(T) -> U`?
/// This is required mostly for pretty-printing and diagnostics,
/// but also for changing lifetime elision rules to be "function-like".
pub parenthesized: bool,
@ -394,14 +394,14 @@ pub struct GenericArgs {
impl GenericArgs {
pub fn none() -> Self {
Self {
parameters: HirVec::new(),
args: HirVec::new(),
bindings: HirVec::new(),
parenthesized: false,
}
}
pub fn is_empty(&self) -> bool {
self.parameters.is_empty() && self.bindings.is_empty() && !self.parenthesized
self.args.is_empty() && self.bindings.is_empty() && !self.parenthesized
}
pub fn inputs(&self) -> &[P<Ty>] {
@ -416,7 +416,7 @@ impl GenericArgs {
}
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> {
self.parameters.iter().filter_map(|p| {
self.args.iter().filter_map(|p| {
if let GenericArg::Lifetime(lt) = p {
Some(lt)
} else {
@ -426,7 +426,7 @@ impl GenericArgs {
}
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> {
self.parameters.iter().filter_map(|p| {
self.args.iter().filter_map(|p| {
if let GenericArg::Type(ty) = p {
Some(ty)
} else {

View File

@ -1269,11 +1269,11 @@ impl<'a> State<'a> {
self.s.word(".")?;
self.print_name(segment.name)?;
segment.with_parameters(|parameters| {
if !parameters.parameters.is_empty() ||
!parameters.bindings.is_empty()
segment.with_args(|args| {
if !args.args.is_empty() ||
!args.bindings.is_empty()
{
self.print_generic_args(&parameters, segment.infer_types, true)
self.print_generic_args(&args, segment.infer_types, true)
} else {
Ok(())
}
@ -1641,7 +1641,7 @@ impl<'a> State<'a> {
if segment.name != keywords::CrateRoot.name() &&
segment.name != keywords::DollarCrate.name() {
self.print_name(segment.name)?;
segment.with_parameters(|parameters| {
segment.with_args(|parameters| {
self.print_generic_args(parameters,
segment.infer_types,
colons_before_params)
@ -1673,7 +1673,7 @@ impl<'a> State<'a> {
if segment.name != keywords::CrateRoot.name() &&
segment.name != keywords::DollarCrate.name() {
self.print_name(segment.name)?;
segment.with_parameters(|parameters| {
segment.with_args(|parameters| {
self.print_generic_args(parameters,
segment.infer_types,
colons_before_params)
@ -1685,7 +1685,7 @@ impl<'a> State<'a> {
self.s.word("::")?;
let item_segment = path.segments.last().unwrap();
self.print_name(item_segment.name)?;
item_segment.with_parameters(|parameters| {
item_segment.with_args(|parameters| {
self.print_generic_args(parameters,
item_segment.infer_types,
colons_before_params)
@ -1697,7 +1697,7 @@ impl<'a> State<'a> {
self.s.word(">")?;
self.s.word("::")?;
self.print_name(item_segment.name)?;
item_segment.with_parameters(|parameters| {
item_segment.with_args(|parameters| {
self.print_generic_args(parameters,
item_segment.infer_types,
colons_before_params)
@ -1734,7 +1734,7 @@ impl<'a> State<'a> {
let elide_lifetimes = generic_args.lifetimes().all(|lt| lt.is_elided());
if !elide_lifetimes {
start_or_comma(self)?;
self.commasep(Inconsistent, &generic_args.parameters, |s, p| {
self.commasep(Inconsistent, &generic_args.args, |s, p| {
match p {
GenericArg::Lifetime(lt) => s.print_lifetime(lt),
GenericArg::Type(ty) => s.print_type(ty),

View File

@ -177,7 +177,7 @@ impl_stable_hash_for!(struct hir::Path {
impl_stable_hash_for!(struct hir::PathSegment {
name,
infer_types,
parameters
args
});
impl_stable_hash_for!(enum hir::GenericArg {
@ -186,7 +186,7 @@ impl_stable_hash_for!(enum hir::GenericArg {
});
impl_stable_hash_for!(struct hir::GenericArgs {
parameters,
args,
bindings,
parenthesized
});

View File

@ -28,7 +28,6 @@ use rustc_data_structures::sync::Lrc;
use session::Session;
use std::cell::Cell;
use std::mem::replace;
use std::slice;
use syntax::ast;
use syntax::attr;
use syntax::ptr::P;
@ -155,11 +154,10 @@ impl Region {
}
}
fn subst(self, params: Vec<&hir::Lifetime>, map: &NamedRegionMap) -> Option<Region> {
fn subst<'a, L>(self, mut params: L, map: &NamedRegionMap) -> Option<Region>
where L: Iterator<Item = &'a hir::Lifetime> {
if let Region::EarlyBound(index, _, _) = self {
params
.get(index as usize)
.and_then(|lifetime| map.defs.get(&lifetime.id).cloned())
params.nth(index as usize).and_then(|lifetime| map.defs.get(&lifetime.id).cloned())
} else {
Some(self)
}
@ -603,7 +601,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
// resolved the same as the `'_` in `&'_ Foo`.
//
// cc #48468
self.resolve_elided_lifetimes(slice::from_ref(lifetime), false)
self.resolve_elided_lifetimes(vec![lifetime], false)
}
LifetimeName::Fresh(_) | LifetimeName::Static | LifetimeName::Name(_) => {
// If the user wrote an explicit name, use that.
@ -833,8 +831,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
fn visit_path(&mut self, path: &'tcx hir::Path, _: ast::NodeId) {
for (i, segment) in path.segments.iter().enumerate() {
let depth = path.segments.len() - i - 1;
if let Some(ref parameters) = segment.parameters {
self.visit_segment_parameters(path.def, depth, parameters);
if let Some(ref args) = segment.args {
self.visit_segment_args(path.def, depth, args);
}
}
}
@ -1599,24 +1597,24 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
fn visit_segment_parameters(
fn visit_segment_args(
&mut self,
def: Def,
depth: usize,
params: &'tcx hir::GenericArgs,
args: &'tcx hir::GenericArgs,
) {
if params.parenthesized {
if args.parenthesized {
let was_in_fn_syntax = self.is_in_fn_syntax;
self.is_in_fn_syntax = true;
self.visit_fn_like_elision(params.inputs(), Some(&params.bindings[0].ty));
self.visit_fn_like_elision(args.inputs(), Some(&args.bindings[0].ty));
self.is_in_fn_syntax = was_in_fn_syntax;
return;
}
if params.lifetimes().all(|l| l.is_elided()) {
self.resolve_elided_lifetimes(params.lifetimes().collect(), true);
if args.lifetimes().all(|l| l.is_elided()) {
self.resolve_elided_lifetimes(args.lifetimes().collect(), true);
} else {
for l in params.lifetimes() {
for l in args.lifetimes() {
self.visit_lifetime(l);
}
}
@ -1688,13 +1686,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
} else {
Some(Region::Static)
},
Set1::One(r) => r.subst(params.lifetimes().collect(), map),
Set1::One(r) => r.subst(args.lifetimes(), map),
Set1::Many => None,
})
.collect()
});
for (i, ty) in params.types().enumerate() {
for (i, ty) in args.types().enumerate() {
if let Some(&lt) = object_lifetime_defaults.get(i) {
let scope = Scope::ObjectLifetimeDefault {
lifetime: lt,
@ -1706,7 +1704,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
for b in &params.bindings {
for b in &args.bindings {
self.visit_assoc_type_binding(b);
}
}

View File

@ -10,6 +10,7 @@
use hir::def_id::DefId;
use ty::{self, Ty, TypeFoldable, Substs, TyCtxt};
use ty::subst::Kind;
use traits;
use rustc_target::spec::abi::Abi;
use util::ppaux;

View File

@ -885,73 +885,6 @@ pub struct GenericParamCount {
pub types: usize,
}
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub enum GenericParam {
Lifetime(RegionParameterDef),
Type(TypeParameterDef),
}
impl GenericParam {
pub fn index(&self) -> u32 {
match self {
GenericParam::Lifetime(lt) => lt.index,
GenericParam::Type(ty) => ty.index,
}
}
}
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub enum KindIndex {
Lifetime,
Type,
}
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
pub struct KindIndexed<L, T> {
pub lt: L,
pub ty: T,
}
impl<T> KindIndexed<T, T> {
pub fn get(&self, idx: KindIndex) -> &T {
match idx {
KindIndex::Lifetime => &self.lt,
KindIndex::Type => &self.ty,
}
}
pub fn iter(&self) -> KindIndexIterator<T> {
KindIndexIterator {
index: self,
next: Some(KindIndex::Lifetime),
}
}
}
#[derive(Clone, Debug)]
pub struct KindIndexIterator<'a, T: 'a> {
pub index: &'a KindIndexed<T, T>,
pub next: Option<KindIndex>,
}
impl<'a, T> Iterator for KindIndexIterator<'a, T> {
type Item = &'a T;
fn next(&mut self) -> Option<Self::Item> {
match self.next {
Some(KindIndex::Lifetime) => {
self.next = Some(KindIndex::Type);
Some(&self.index.lt)
}
Some(KindIndex::Type) => {
self.next = None;
Some(&self.index.ty)
},
None => None,
}
}
}
/// Information about the formal type/lifetime parameters associated
/// with an item or method. Analogous to hir::Generics.
///
@ -1009,34 +942,6 @@ impl<'a, 'gcx, 'tcx> Generics {
}
}
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &RegionParameterDef> {
self.parameters.iter().filter_map(|p| {
if let GenericParam::Lifetime(lt) = p {
Some(lt)
} else {
None
}
})
}
pub fn types(&self) -> impl DoubleEndedIterator<Item = &TypeParameterDef> {
self.parameters.iter().filter_map(|p| {
if let GenericParam::Type(ty) = p {
Some(ty)
} else {
None
}
})
}
pub fn parent_lifetimes(&self) -> u32 {
*self.parent_params.get(KindIndex::Lifetime)
}
pub fn parent_types(&self) -> u32 {
*self.parent_params.get(KindIndex::Type)
}
pub fn region_param(&'tcx self,
param: &EarlyBoundRegion,
tcx: TyCtxt<'a, 'gcx, 'tcx>)

View File

@ -40,6 +40,7 @@ use rustc::middle::weak_lang_items;
use rustc::mir::mono::{Linkage, Visibility, Stats};
use rustc::middle::cstore::{EncodedMetadata};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::subst::Kind;
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf};
use rustc::ty::query::Providers;
use rustc::dep_graph::{DepNode, DepConstructor};

View File

@ -677,7 +677,7 @@ impl<'a> ReplaceBodyWithLoop<'a> {
ast::TyKind::Paren(ref subty) => involves_impl_trait(subty),
ast::TyKind::Tup(ref tys) => any_involves_impl_trait(tys.iter()),
ast::TyKind::Path(_, ref path) => path.segments.iter().any(|seg| {
match seg.parameters.as_ref().map(|p| &**p) {
match seg.args.as_ref().map(|p| &**p) {
None => false,
Some(&ast::GenericArgs::AngleBracketed(ref data)) =>
any_involves_impl_trait(data.types().into_iter()) ||

View File

@ -295,7 +295,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
);
let label_msg = match pat.node {
PatKind::Path(hir::QPath::Resolved(None, ref path))
if path.segments.len() == 1 && path.segments[0].parameters.is_none() => {
if path.segments.len() == 1 && path.segments[0].args.is_none() => {
format!("interpreted as a {} pattern, not new variable", path.def.kind_name())
}
_ => format!("pattern `{}` not covered", pattern_string),

View File

@ -13,6 +13,7 @@ use rustc::middle::lang_items::DropInPlaceFnLangItem;
use rustc::traits;
use rustc::ty::adjustment::CustomCoerceUnsized;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::subst::Kind;
pub use rustc::ty::Instance;
pub use self::item::{MonoItem, MonoItemExt};

View File

@ -230,9 +230,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
// }
// foo!(bar::baz<T>);
use_tree.prefix.segments.iter().find(|segment| {
segment.parameters.is_some()
segment.args.is_some()
}).map(|segment| {
self.err_handler().span_err(segment.parameters.as_ref().unwrap().span(),
self.err_handler().span_err(segment.args.as_ref().unwrap().span(),
"generic arguments in import path");
});
@ -398,8 +398,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_vis(&mut self, vis: &'a Visibility) {
match vis.node {
VisibilityKind::Restricted { ref path, .. } => {
path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| {
self.err_handler().span_err(segment.parameters.as_ref().unwrap().span(),
path.segments.iter().find(|segment| segment.args.is_some()).map(|segment| {
self.err_handler().span_err(segment.args.as_ref().unwrap().span(),
"generic arguments in visibility path");
});
}
@ -521,10 +521,10 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> {
visit::walk_ty(self, t);
}
}
fn visit_path_parameters(&mut self, _: Span, path_parameters: &'a PathParameters) {
match *path_parameters {
PathParameters::AngleBracketed(ref params) => {
for type_ in &params.types {
fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
match *generic_args {
GenericArgs::AngleBracketed(ref params) => {
for type_ in params.types() {
self.visit_ty(type_);
}
for type_binding in &params.bindings {
@ -533,7 +533,7 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> {
self.with_impl_trait(None, |this| visit::walk_ty(this, &type_binding.ty));
}
}
PathParameters::Parenthesized(ref params) => {
GenericArgs::Parenthesized(ref params) => {
for type_ in &params.inputs {
self.visit_ty(type_);
}
@ -590,7 +590,7 @@ impl<'a> Visitor<'a> for ImplTraitProjectionVisitor<'a> {
//
// To implement this, we disallow `impl Trait` from `qself`
// (for cases like `<impl Trait>::Foo>`)
// but we allow `impl Trait` in `PathParameters`
// but we allow `impl Trait` in `GenericArgs`
// iff there are no more PathSegments.
if let Some(ref qself) = *qself {
// `impl Trait` in `qself` is always illegal

View File

@ -437,8 +437,8 @@ impl<'a> Resolver<'a> {
let def = self.resolve_macro_to_def_inner(scope, path, kind, force);
if def != Err(Determinacy::Undetermined) {
// Do not report duplicated errors on every undetermined resolution.
path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| {
self.session.span_err(segment.parameters.as_ref().unwrap().span(),
path.segments.iter().find(|segment| segment.args.is_some()).map(|segment| {
self.session.span_err(segment.args.as_ref().unwrap().span(),
"generic arguments in macro path");
});
}

View File

@ -818,10 +818,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
}
self.dump_path_ref(id, path);
// Type parameters
// Type arguments
for seg in &path.segments {
if let Some(ref params) = seg.parameters {
match **params {
if let Some(ref args) = seg.args {
match **args {
ast::GenericArgs::AngleBracketed(ref data) => for t in data.types() {
self.visit_ty(t);
},
@ -905,8 +905,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
}
// Explicit types in the turbo-fish.
if let Some(ref params) = seg.parameters {
if let ast::GenericArgs::AngleBracketed(ref data) = **params {
if let Some(ref args) = seg.args {
if let ast::GenericArgs::AngleBracketed(ref data) = **args {
for t in data.types() {
self.visit_ty(t);
}

View File

@ -692,8 +692,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
if path.segments.len() != 1 {
return false;
}
if let Some(ref params) = path.segments[0].parameters {
if let ast::GenericArgs::Parenthesized(_) = **params {
if let Some(ref args) = path.segments[0].args {
if let ast::GenericArgs::Parenthesized(_) = **args {
return true;
}
}

View File

@ -177,11 +177,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
{
let (substs, assoc_bindings) =
item_segment.with_parameters(|parameters| {
item_segment.with_args(|args| {
self.create_substs_for_ast_path(
span,
def_id,
parameters,
args,
item_segment.infer_types,
None)
});
@ -199,7 +199,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
fn create_substs_for_ast_path(&self,
span: Span,
def_id: DefId,
parameters: &hir::GenericArgs,
args: &hir::GenericArgs,
infer_types: bool,
self_ty: Option<Ty<'tcx>>)
-> (&'tcx Substs<'tcx>, Vec<ConvertedBinding<'tcx>>)
@ -207,15 +207,15 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let tcx = self.tcx();
debug!("create_substs_for_ast_path(def_id={:?}, self_ty={:?}, \
parameters={:?})",
def_id, self_ty, parameters);
args={:?})",
def_id, self_ty, args);
// If the type is parameterized by this region, then replace this
// region with the current anon region binding (in other words,
// whatever & would get replaced with).
let decl_generics = tcx.generics_of(def_id);
let ty_provided = parameters.types().len();
let lt_provided = parameters.lifetimes().len();
let ty_provided = args.types().count();
let lt_provided = args.lifetimes().count();
let mut lt_accepted = 0;
let mut ty_params = ParamRange { required: 0, accepted: 0 };
@ -269,7 +269,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
match param.kind {
GenericParamDefKind::Lifetime => {
let i = param.index as usize - own_self;
if let Some(lifetime) = parameters.lifetimes().get(i) {
if let Some(lifetime) = args.lifetimes().nth(i) {
self.ast_region_to_region(lifetime, Some(param)).into()
} else {
tcx.types.re_static.into()
@ -286,7 +286,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let i = i - (lt_accepted + own_self);
if i < ty_provided {
// A provided type parameter.
self.ast_ty_to_ty(&parameters.types()[i]).into()
self.ast_ty_to_ty(&args.types().nth(i).unwrap()).into()
} else if infer_types {
// No type parameters were provided, we can infer all.
if !default_needs_object_self(param) {
@ -330,7 +330,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
}
});
let assoc_bindings = parameters.bindings.iter().map(|binding| {
let assoc_bindings = args.bindings.iter().map(|binding| {
ConvertedBinding {
item_name: binding.name,
ty: self.ast_ty_to_ty(&binding.ty),
@ -451,7 +451,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let trait_def = self.tcx().trait_def(trait_def_id);
if !self.tcx().features().unboxed_closures &&
trait_segment.with_parameters(|p| p.parenthesized) != trait_def.paren_sugar {
trait_segment.with_args(|p| p.parenthesized) != trait_def.paren_sugar {
// For now, require that parenthetical notation be used only with `Fn()` etc.
let msg = if trait_def.paren_sugar {
"the precise format of `Fn`-family traits' type parameters is subject to change. \
@ -463,7 +463,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
span, GateIssue::Language, msg);
}
trait_segment.with_parameters(|parameters| {
trait_segment.with_args(|parameters| {
self.create_substs_for_ast_path(span,
trait_def_id,
parameters,
@ -970,8 +970,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
for segment in segments {
segment.with_parameters(|params| {
for p in &params.parameters {
segment.with_args(|params| {
for p in &params.args {
let (mut span_err, span, kind) = match p {
hir::GenericArg::Lifetime(lt) => {
(struct_span_err!(self.tcx().sess, lt.span, E0110,

View File

@ -59,7 +59,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"confirm(unadjusted_self_ty={:?}, pick={:?}, generic_args={:?})",
unadjusted_self_ty,
pick,
segment.parameters,
segment.args,
);
let mut confirm_cx = ConfirmContext::new(self, span, self_expr, call_expr);
@ -321,7 +321,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
// Create subst for early-bound lifetime parameters, combining
// parameters from the type and those from the method.
assert_eq!(method_generics.parent_count, parent_substs.len());
let provided = &segment.parameters;
let provided = &segment.args;
let own_counts = method_generics.own_counts();
Substs::for_item(self.tcx, pick.item.def_id, |param, _| {
let i = param.index as usize;
@ -331,7 +331,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
match param.kind {
GenericParamDefKind::Lifetime => {
if let Some(lifetime) = provided.as_ref().and_then(|p| {
p.lifetimes().get(i - parent_substs.len())
p.lifetimes().nth(i - parent_substs.len())
}) {
return AstConv::ast_region_to_region(
self.fcx, lifetime, Some(param)).into();
@ -339,7 +339,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
}
GenericParamDefKind::Type {..} => {
if let Some(ast_ty) = provided.as_ref().and_then(|p| {
p.types().get(i - parent_substs.len() - own_counts.lifetimes)
p.types().nth(i - parent_substs.len() - own_counts.lifetimes)
}) {
return self.to_ty(ast_ty).into();
}
@ -347,7 +347,6 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
}
self.var_for_def(self.span, param)
}
self.type_var_for_def(self.span, def, cur_substs)
})
}

View File

@ -4834,7 +4834,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
match param.kind {
GenericParamDefKind::Lifetime => {
let lifetimes = segment.map_or(vec![], |(s, _)| {
s.parameters.as_ref().map_or(vec![], |p| p.lifetimes())
s.args.as_ref().map_or(vec![], |p| p.lifetimes().collect())
});
if let Some(lifetime) = lifetimes.get(i) {
@ -4845,7 +4845,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
GenericParamDefKind::Type {..} => {
let (types, infer_types) = segment.map_or((vec![], true), |(s, _)| {
(s.parameters.as_ref().map_or(vec![], |p| |p| p.types()), s.infer_types)
(s.args.as_ref().map_or(vec![], |p| p.types().collect()), s.infer_types)
});
// Skip over the lifetimes in the same segment.
@ -4962,7 +4962,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
supress_mismatch_error: bool) {
let (lifetimes, types, infer_types, bindings) = segment.map_or(
(vec![], vec![], true, &[][..]),
|(s, _)| s.parameters.as_ref().map_or(
|(s, _)| s.args.as_ref().map_or(
(vec![], vec![], s.infer_types, &[][..]),
|p| (p.lifetimes().collect(), p.types().collect(),
s.infer_types, &p.bindings[..])));

View File

@ -973,13 +973,6 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
.map(|param| (param.def_id, param.index))
.collect();
let parent_params = ty::KindIndexed { lt: parent_regions, ty: parent_types };
let lifetimes: Vec<ty::GenericParam> =
regions.into_iter().map(|lt| ty::GenericParam::Lifetime(lt)).collect();
let types: Vec<ty::GenericParam> =
types.into_iter().map(|ty| ty::GenericParam::Type(ty)).collect();
let parameters = lifetimes.into_iter().chain(types.into_iter()).collect();
tcx.alloc_generics(ty::Generics {
parent: parent_def_id,
parent_count,

View File

@ -244,9 +244,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
None
}
fn generics_to_path_params(&self, generics: ty::Generics) -> hir::PathParameters {
let mut lifetimes = vec![];
let mut types = vec![];
fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs {
let mut args = vec![];
for param in generics.params.iter() {
match param.kind {
@ -257,21 +256,20 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
hir::LifetimeName::Name(param.name.as_symbol())
};
lifetimes.push(hir::Lifetime {
args.push(hir::GenericArg::Lifetime(hir::Lifetime {
id: ast::DUMMY_NODE_ID,
span: DUMMY_SP,
name,
});
}));
}
ty::GenericParamDefKind::Type {..} => {
types.push(P(self.ty_param_to_ty(param.clone())));
args.push(hir::GenericArg::Type(P(self.ty_param_to_ty(param.clone()))));
}
}
}
hir::PathParameters {
lifetimes: HirVec::from_vec(lifetimes),
types: HirVec::from_vec(types),
hir::GenericArgs {
args: HirVec::from_vec(args),
bindings: HirVec::new(),
parenthesized: false,
}
@ -555,9 +553,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
let mut new_path = path.clone();
let last_segment = new_path.segments.pop().unwrap();
let (old_input, old_output) = match last_segment.params {
PathParameters::AngleBracketed { types, .. } => (types, None),
PathParameters::Parenthesized { inputs, output, .. } => {
let (old_input, old_output) = match last_segment.args {
GenericArgs::AngleBracketed { types, .. } => (types, None),
GenericArgs::Parenthesized { inputs, output, .. } => {
(inputs, output)
}
};
@ -569,14 +567,14 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
);
}
let new_params = PathParameters::Parenthesized {
let new_params = GenericArgs::Parenthesized {
inputs: old_input,
output,
};
new_path.segments.push(PathSegment {
name: last_segment.name,
params: new_params,
args: new_params,
});
Type::ResolvedPath {
@ -793,13 +791,13 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
// FIXME: Remove this scope when NLL lands
{
let params =
&mut new_trait_path.segments.last_mut().unwrap().params;
let args =
&mut new_trait_path.segments.last_mut().unwrap().args;
match params {
match args {
// Convert somethiung like '<T as Iterator::Item> = u8'
// to 'T: Iterator<Item=u8>'
&mut PathParameters::AngleBracketed {
&mut GenericArgs::AngleBracketed {
ref mut bindings,
..
} => {
@ -808,7 +806,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
ty: rhs,
});
}
&mut PathParameters::Parenthesized { .. } => {
&mut GenericArgs::Parenthesized { .. } => {
existing_predicates.push(
WherePredicate::EqPredicate {
lhs: lhs.clone(),

View File

@ -1607,7 +1607,7 @@ fn external_path(cx: &DocContext, name: &str, trait_did: Option<DefId>, has_self
def: Def::Err,
segments: vec![PathSegment {
name: name.to_string(),
params: external_generic_args(cx, trait_did, has_self, bindings, substs)
args: external_generic_args(cx, trait_did, has_self, bindings, substs)
}],
}
}
@ -2656,7 +2656,7 @@ impl Type {
match *self {
ResolvedPath { ref path, .. } => {
path.segments.last().and_then(|seg| {
if let GenericArgs::AngleBracketed { ref types, .. } = seg.params {
if let GenericArgs::AngleBracketed { ref types, .. } = seg.args {
Some(&**types)
} else {
None
@ -2851,7 +2851,7 @@ impl Clean<Type> for hir::Ty {
let provided_params = &path.segments.last().unwrap();
let mut ty_substs = FxHashMap();
let mut lt_substs = FxHashMap();
provided_params.with_parameters(|provided_params| {
provided_params.with_args(|provided_params| {
let mut indices = GenericParamCount {
lifetimes: 0,
types: 0
@ -2859,8 +2859,8 @@ impl Clean<Type> for hir::Ty {
for param in generics.params.iter() {
match param {
hir::GenericParam::Lifetime(lt_param) => {
if let Some(lt) = provided_params.lifetimes
.get(indices.lifetimes).cloned() {
if let Some(lt) = provided_params.lifetimes()
.nth(indices.lifetimes).cloned() {
if !lt.is_elided() {
let lt_def_id =
cx.tcx.hir.local_def_id(lt_param.lifetime.id);
@ -2872,8 +2872,8 @@ impl Clean<Type> for hir::Ty {
hir::GenericParam::Type(ty_param) => {
let ty_param_def =
Def::TyParam(cx.tcx.hir.local_def_id(ty_param.id));
if let Some(ty) = provided_params.types
.get(indices.types).cloned() {
if let Some(ty) = provided_params.types()
.nth(indices.types).cloned() {
ty_substs.insert(ty_param_def, ty.into_inner().clean(cx));
} else if let Some(default) = ty_param.default.clone() {
ty_substs.insert(ty_param_def,
@ -3447,7 +3447,7 @@ impl Path {
def: Def::Err,
segments: vec![PathSegment {
name,
params: GenericArgs::AngleBracketed {
args: GenericArgs::AngleBracketed {
lifetimes: Vec::new(),
types: Vec::new(),
bindings: Vec::new(),
@ -3471,7 +3471,7 @@ impl Clean<Path> for hir::Path {
}
}
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eg, Debug, Hash)]
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
pub enum GenericArgs {
AngleBracketed {
lifetimes: Vec<Lifetime>,
@ -3509,14 +3509,14 @@ impl Clean<GenericArgs> for hir::GenericArgs {
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
pub struct PathSegment {
pub name: String,
pub params: GenericArgs,
pub args: GenericArgs,
}
impl Clean<PathSegment> for hir::PathSegment {
fn clean(&self, cx: &DocContext) -> PathSegment {
PathSegment {
name: self.name.clean(cx),
params: self.with_parameters(|parameters| parameters.clean(cx))
args: self.with_args(|args| args.clean(cx))
}
}
}
@ -3550,7 +3550,7 @@ fn strip_path(path: &Path) -> Path {
let segments = path.segments.iter().map(|s| {
PathSegment {
name: s.name.clone(),
params: PathParameters::AngleBracketed {
args: GenericArgs::AngleBracketed {
lifetimes: Vec::new(),
types: Vec::new(),
bindings: Vec::new(),
@ -4365,7 +4365,7 @@ where F: Fn(DefId) -> Def {
def: def_ctor(def_id),
segments: hir::HirVec::from_vec(apb.names.iter().map(|s| hir::PathSegment {
name: ast::Name::intern(&s),
parameters: None,
args: None,
infer_types: false,
}).collect())
}

View File

@ -97,7 +97,7 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
return false
}
let last = path.segments.last_mut().unwrap();
match last.params {
match last.args {
PP::AngleBracketed { ref mut bindings, .. } => {
bindings.push(clean::TypeBinding {
name: name.clone(),

View File

@ -369,9 +369,9 @@ impl fmt::Display for clean::PathSegment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.name)?;
if f.alternate() {
write!(f, "{:#}", self.params)
write!(f, "{:#}", self.args)
} else {
write!(f, "{}", self.params)
write!(f, "{}", self.args)
}
}
}
@ -447,7 +447,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
}
}
if w.alternate() {
write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.params)?;
write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.args)?;
} else {
let path = if use_absolute {
match href(did) {
@ -461,7 +461,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path,
} else {
format!("{}", HRef::new(did, &last.name))
};
write!(w, "{}{}", path, last.params)?;
write!(w, "{}{}", path, last.args)?;
}
Ok(())
}
@ -757,7 +757,7 @@ fn fmt_impl(i: &clean::Impl,
clean::ResolvedPath { typarams: None, ref path, is_generic: false, .. } => {
let last = path.segments.last().unwrap();
fmt::Display::fmt(&last.name, f)?;
fmt::Display::fmt(&last.params, f)?;
fmt::Display::fmt(&last.args, f)?;
}
_ => unreachable!(),
}

View File

@ -135,27 +135,27 @@ pub struct PathSegment {
/// `Some` means that parameter list is supplied (`Path<X, Y>`)
/// but it can be empty (`Path<>`).
/// `P` is used as a size optimization for the common case with no parameters.
pub parameters: Option<P<GenericArgs>>,
pub args: Option<P<GenericArgs>>,
}
impl PathSegment {
pub fn from_ident(ident: Ident) -> Self {
PathSegment { ident, parameters: None }
PathSegment { ident, args: None }
}
pub fn crate_root(span: Span) -> Self {
PathSegment::from_ident(Ident::new(keywords::CrateRoot.name(), span))
}
}
/// Parameters of a path segment.
/// Arguments of a path segment.
///
/// E.g. `<A, B>` as in `Foo<A, B>` or `(A, B)` as in `Foo(A, B)`
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum GenericArgs {
/// The `<'a, A,B,C>` in `foo::bar::baz::<'a, A,B,C>`
AngleBracketed(AngleBracketedParameterData),
AngleBracketed(AngleBracketedArgs),
/// The `(A,B)` and `C` in `Foo(A,B) -> C`
Parenthesized(ParenthesizedParameterData),
Parenthesized(ParenthesizedArgData),
}
impl GenericArgs {
@ -168,28 +168,28 @@ impl GenericArgs {
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum AngleBracketedParam {
pub enum GenericArg {
Lifetime(Lifetime),
Type(P<Ty>),
}
/// A path like `Foo<'a, T>`
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Default)]
pub struct AngleBracketedParameterData {
pub struct AngleBracketedArgs {
/// Overall span
pub span: Span,
/// The parameters for this path segment.
pub parameters: Vec<AngleBracketedParam>,
/// The arguments for this path segment.
pub args: Vec<GenericArg>,
/// Bindings (equality constraints) on associated types, if present.
///
/// E.g., `Foo<A=Bar>`.
pub bindings: Vec<TypeBinding>,
}
impl AngleBracketedParameterData {
impl AngleBracketedArgs {
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> {
self.parameters.iter().filter_map(|p| {
if let AngleBracketedParam::Lifetime(lt) = p {
self.args.iter().filter_map(|p| {
if let GenericArg::Lifetime(lt) = p {
Some(lt)
} else {
None
@ -198,8 +198,8 @@ impl AngleBracketedParameterData {
}
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> {
self.parameters.iter().filter_map(|p| {
if let AngleBracketedParam::Type(ty) = p {
self.args.iter().filter_map(|p| {
if let GenericArg::Type(ty) = p {
Some(ty)
} else {
None
@ -208,13 +208,13 @@ impl AngleBracketedParameterData {
}
}
impl Into<Option<P<GenericArgs>>> for AngleBracketedParameterData {
impl Into<Option<P<GenericArgs>>> for AngleBracketedArgs {
fn into(self) -> Option<P<GenericArgs>> {
Some(P(GenericArgs::AngleBracketed(self)))
}
}
impl Into<Option<P<GenericArgs>>> for ParenthesizedParameterData {
impl Into<Option<P<GenericArgs>>> for ParenthesizedArgData {
fn into(self) -> Option<P<GenericArgs>> {
Some(P(GenericArgs::Parenthesized(self)))
}
@ -222,7 +222,7 @@ impl Into<Option<P<GenericArgs>>> for ParenthesizedParameterData {
/// A path like `Foo(A,B) -> C`
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct ParenthesizedParameterData {
pub struct ParenthesizedArgData {
/// Overall span
pub span: Span,

View File

@ -31,7 +31,7 @@ pub trait AstBuilder {
fn path_all(&self, sp: Span,
global: bool,
idents: Vec<ast::Ident>,
parameters: Vec<ast::AngleBracketedParam>,
parameters: Vec<ast::GenericArg>,
bindings: Vec<ast::TypeBinding>)
-> ast::Path;
@ -42,7 +42,7 @@ pub trait AstBuilder {
fn qpath_all(&self, self_type: P<ast::Ty>,
trait_path: ast::Path,
ident: ast::Ident,
parameters: Vec<ast::AngleBracketedParam>,
parameters: Vec<ast::GenericArg>,
bindings: Vec<ast::TypeBinding>)
-> (ast::QSelf, ast::Path);
@ -314,7 +314,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
span: Span,
global: bool,
mut idents: Vec<ast::Ident> ,
parameters: Vec<ast::AngleBracketedParam>,
args: Vec<ast::GenericArg>,
bindings: Vec<ast::TypeBinding> )
-> ast::Path {
let last_ident = idents.pop().unwrap();
@ -323,12 +323,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
segments.extend(idents.into_iter().map(|ident| {
ast::PathSegment::from_ident(ident.with_span_pos(span))
}));
let parameters = if !parameters.is_empty() !bindings.is_empty() {
ast::AngleBracketedParameterData { parameters, bindings, span }.into()
let args = if !args.is_empty() || !bindings.is_empty() {
ast::AngleBracketedArgs { args, bindings, span }.into()
} else {
None
};
segments.push(ast::PathSegment { ident: last_ident.with_span_pos(span), parameters });
segments.push(ast::PathSegment { ident: last_ident.with_span_pos(span), args });
let mut path = ast::Path { span, segments };
if global {
if let Some(seg) = path.make_root() {
@ -356,16 +356,16 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self_type: P<ast::Ty>,
trait_path: ast::Path,
ident: ast::Ident,
parameters: Vec<ast::AngleBracketedParam>,
args: Vec<ast::GenericArg>,
bindings: Vec<ast::TypeBinding>)
-> (ast::QSelf, ast::Path) {
let mut path = trait_path;
let parameters = if !parameters.is_empty() || !bindings.is_empty() {
ast::AngleBracketedParameterData { parameters, bindings, span: ident.span }.into()
let args = if !args.is_empty() || !bindings.is_empty() {
ast::AngleBracketedArgs { args, bindings, span: ident.span }.into()
} else {
None
};
path.segments.push(ast::PathSegment { ident, parameters });
path.segments.push(ast::PathSegment { ident, args });
(ast::QSelf {
ty: self_type,
@ -424,7 +424,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.path_all(DUMMY_SP,
true,
self.std_path(&["option", "Option"]),
vec![ ast::AngleBracketedParam::Type(ty) ],
vec![ ast::GenericArg::Type(ty) ],
Vec::new()))
}

View File

@ -132,11 +132,11 @@ pub trait Folder : Sized {
noop_fold_exprs(es, self)
}
fn fold_param(&mut self, p: AngleBracketedParam) -> AngleBracketedParam {
fn fold_param(&mut self, p: GenericArg) -> GenericArg {
match p {
AngleBracketedParam::Lifetime(lt) =>
AngleBracketedParam::Lifetime(self.fold_lifetime(lt)),
AngleBracketedParam::Type(ty) => AngleBracketedParam::Type(self.fold_ty(ty)),
GenericArg::Lifetime(lt) =>
GenericArg::Lifetime(self.fold_lifetime(lt)),
GenericArg::Type(ty) => GenericArg::Type(self.fold_ty(ty)),
}
}
@ -184,14 +184,14 @@ pub trait Folder : Sized {
noop_fold_generic_args(p, self)
}
fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedParameterData)
-> AngleBracketedParameterData
fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedArgs)
-> AngleBracketedArgs
{
noop_fold_angle_bracketed_parameter_data(p, self)
}
fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedParameterData)
-> ParenthesizedParameterData
fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedArgData)
-> ParenthesizedArgData
{
noop_fold_parenthesized_parameter_data(p, self)
}
@ -441,9 +441,9 @@ pub fn noop_fold_usize<T: Folder>(i: usize, _: &mut T) -> usize {
pub fn noop_fold_path<T: Folder>(Path { segments, span }: Path, fld: &mut T) -> Path {
Path {
segments: segments.move_map(|PathSegment {ident, parameters}| PathSegment {
segments: segments.move_map(|PathSegment {ident, args}| PathSegment {
ident: fld.fold_ident(ident),
parameters: parameters.map(|ps| ps.map(|ps| fld.fold_generic_args(ps))),
args: args.map(|ps| ps.map(|ps| fld.fold_generic_args(ps))),
}),
span: fld.new_span(span)
}
@ -473,22 +473,22 @@ pub fn noop_fold_generic_args<T: Folder>(generic_args: GenericArgs, fld: &mut T)
}
}
pub fn noop_fold_angle_bracketed_parameter_data<T: Folder>(data: AngleBracketedParameterData,
pub fn noop_fold_angle_bracketed_parameter_data<T: Folder>(data: AngleBracketedArgs,
fld: &mut T)
-> AngleBracketedParameterData
-> AngleBracketedArgs
{
let AngleBracketedParameterData { parameters, bindings, span } = data;
AngleBracketedParameterData { parameters: parameters.move_map(|p| fld.fold_param(p)),
let AngleBracketedArgs { args, bindings, span } = data;
AngleBracketedArgs { args: args.move_map(|p| fld.fold_param(p)),
bindings: bindings.move_map(|b| fld.fold_ty_binding(b)),
span: fld.new_span(span) }
}
pub fn noop_fold_parenthesized_parameter_data<T: Folder>(data: ParenthesizedParameterData,
pub fn noop_fold_parenthesized_parameter_data<T: Folder>(data: ParenthesizedArgData,
fld: &mut T)
-> ParenthesizedParameterData
-> ParenthesizedArgData
{
let ParenthesizedParameterData { inputs, output, span } = data;
ParenthesizedParameterData { inputs: inputs.move_map(|ty| fld.fold_ty(ty)),
let ParenthesizedArgData { inputs, output, span } = data;
ParenthesizedArgData { inputs: inputs.move_map(|ty| fld.fold_ty(ty)),
output: output.map(|ty| fld.fold_ty(ty)),
span: fld.new_span(span) }
}
@ -1191,7 +1191,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
ExprKind::MethodCall(
PathSegment {
ident: folder.fold_ident(seg.ident),
parameters: seg.parameters.map(|ps| {
args: seg.args.map(|ps| {
ps.map(|ps| folder.fold_generic_args(ps))
}),
},

View File

@ -9,7 +9,7 @@
// except according to those terms.
use rustc_target::spec::abi::{self, Abi};
use ast::{AngleBracketedParameterData, ParenthesizedParameterData, AttrStyle, BareFnTy};
use ast::{AngleBracketedArgs, ParenthesizedArgData, AttrStyle, BareFnTy};
use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
use ast::Unsafety;
use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind};
@ -22,7 +22,7 @@ use ast::{Expr, ExprKind, RangeLimits};
use ast::{Field, FnDecl};
use ast::{ForeignItem, ForeignItemKind, FunctionRetTy};
use ast::GenericParam;
use ast::AngleBracketedParam;
use ast::GenericArg;
use ast::{Ident, ImplItem, IsAuto, Item, ItemKind};
use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind};
use ast::Local;
@ -1895,7 +1895,7 @@ impl<'a> Parser<'a> {
-> PResult<'a, ast::Path> {
maybe_whole!(self, NtPath, |path| {
if style == PathStyle::Mod &&
path.segments.iter().any(|segment| segment.parameters.is_some()) {
path.segments.iter().any(|segment| segment.args.is_some()) {
self.diagnostic().span_err(path.span, "unexpected generic arguments in path");
}
path
@ -1970,12 +1970,12 @@ impl<'a> Parser<'a> {
.span_label(self.prev_span, "try removing `::`").emit();
}
let parameters = if self.eat_lt() {
let args = if self.eat_lt() {
// `<'a, T, A = U>`
let (parameters, bindings) = self.parse_generic_args()?;
let (args, bindings) = self.parse_generic_args()?;
self.expect_gt()?;
let span = lo.to(self.prev_span);
AngleBracketedParameterData { parameters, bindings, span }.into()
AngleBracketedArgs { args, bindings, span }.into()
} else {
// `(T, U) -> R`
self.bump(); // `(`
@ -1991,10 +1991,10 @@ impl<'a> Parser<'a> {
None
};
let span = lo.to(self.prev_span);
ParenthesizedParameterData { inputs, output, span }.into()
ParenthesizedArgData { inputs, output, span }.into()
};
PathSegment { ident, parameters }
PathSegment { ident, args }
} else {
// Generic arguments are not found.
PathSegment::from_ident(ident)
@ -2544,8 +2544,8 @@ impl<'a> Parser<'a> {
}
_ => {
// Field access `expr.f`
if let Some(parameters) = segment.parameters {
self.span_err(parameters.span(),
if let Some(args) = segment.args {
self.span_err(args.span(),
"field expressions may not have generic arguments");
}
@ -4938,15 +4938,15 @@ impl<'a> Parser<'a> {
/// Parses (possibly empty) list of lifetime and type arguments and associated type bindings,
/// possibly including trailing comma.
fn parse_generic_args(&mut self)
-> PResult<'a, (Vec<AngleBracketedParam>, Vec<TypeBinding>)> {
let mut parameters = Vec::new();
-> PResult<'a, (Vec<GenericArg>, Vec<TypeBinding>)> {
let mut args = Vec::new();
let mut bindings = Vec::new();
let mut seen_type = false;
let mut seen_binding = false;
loop {
if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
// Parse lifetime argument.
parameters.push(AngleBracketedParam::Lifetime(self.expect_lifetime()));
args.push(GenericArg::Lifetime(self.expect_lifetime()));
if seen_type || seen_binding {
self.span_err(self.prev_span,
"lifetime parameters must be declared prior to type parameters");
@ -4971,7 +4971,7 @@ impl<'a> Parser<'a> {
self.span_err(ty_param.span,
"type parameters must be declared prior to associated type bindings");
}
parameters.push(AngleBracketedParam::Type(ty_param));
args.push(GenericArg::Type(ty_param));
seen_type = true;
} else {
break
@ -4981,7 +4981,7 @@ impl<'a> Parser<'a> {
break
}
}
Ok((parameters, bindings))
Ok((args, bindings))
}
/// Parses an optional `where` clause and places it in `generics`.

View File

@ -13,7 +13,7 @@ pub use self::AnnNode::*;
use rustc_target::spec::abi::{self, Abi};
use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
use ast::{Attribute, MacDelimiter, AngleBracketedParam};
use ast::{Attribute, MacDelimiter, GenericArg};
use util::parser::{self, AssocOp, Fixity};
use attr;
use codemap::{self, CodeMap};
@ -1017,10 +1017,10 @@ impl<'a> State<'a> {
Ok(())
}
pub fn print_param(&mut self, param: &AngleBracketedParam) -> io::Result<()> {
pub fn print_param(&mut self, param: &GenericArg) -> io::Result<()> {
match param {
AngleBracketedParam::Lifetime(lt) => self.print_lifetime(lt),
AngleBracketedParam::Type(ty) => self.print_type(ty),
GenericArg::Lifetime(lt) => self.print_lifetime(lt),
GenericArg::Type(ty) => self.print_type(ty),
}
}
@ -1991,8 +1991,8 @@ impl<'a> State<'a> {
self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX)?;
self.s.word(".")?;
self.print_ident(segment.ident)?;
if let Some(ref parameters) = segment.parameters {
self.print_generic_args(parameters, true)?;
if let Some(ref args) = segment.args {
self.print_generic_args(args, true)?;
}
self.print_call_post(base_args)
}
@ -2435,8 +2435,8 @@ impl<'a> State<'a> {
if segment.ident.name != keywords::CrateRoot.name() &&
segment.ident.name != keywords::DollarCrate.name() {
self.print_ident(segment.ident)?;
if let Some(ref parameters) = segment.parameters {
self.print_generic_args(parameters, colons_before_params)?;
if let Some(ref args) = segment.args {
self.print_generic_args(args, colons_before_params)?;
}
} else if segment.ident.name == keywords::DollarCrate.name() {
self.print_dollar_crate(segment.ident.span.ctxt())?;
@ -2462,14 +2462,14 @@ impl<'a> State<'a> {
self.s.word("::")?;
let item_segment = path.segments.last().unwrap();
self.print_ident(item_segment.ident)?;
match item_segment.parameters {
Some(ref parameters) => self.print_generic_args(parameters, colons_before_params),
match item_segment.args {
Some(ref args) => self.print_generic_args(args, colons_before_params),
None => Ok(()),
}
}
fn print_generic_args(&mut self,
parameters: &ast::GenericArgs,
args: &ast::GenericArgs,
colons_before_params: bool)
-> io::Result<()>
{
@ -2477,13 +2477,13 @@ impl<'a> State<'a> {
self.s.word("::")?
}
match *parameters {
match *args {
ast::GenericArgs::AngleBracketed(ref data) => {
self.s.word("<")?;
self.commasep(Inconsistent, &data.parameters, |s, p| s.print_param(p))?;
self.commasep(Inconsistent, &data.args, |s, p| s.print_param(p))?;
let mut comma = data.parameters.len() != 0;
let mut comma = data.args.len() != 0;
for binding in data.bindings.iter() {
if comma {

View File

@ -131,10 +131,10 @@ pub trait Visitor<'ast>: Sized {
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArgs) {
walk_generic_args(self, path_span, generic_args)
}
fn visit_angle_bracketed_param(&mut self, param: &'ast AngleBracketedParam) {
fn visit_angle_bracketed_param(&mut self, param: &'ast GenericArg) {
match param {
AngleBracketedParam::Lifetime(lt) => self.visit_lifetime(lt),
AngleBracketedParam::Type(ty) => self.visit_ty(ty),
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
GenericArg::Type(ty) => self.visit_ty(ty),
}
}
fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) {
@ -381,8 +381,8 @@ pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V,
path_span: Span,
segment: &'a PathSegment) {
visitor.visit_ident(segment.ident);
if let Some(ref parameters) = segment.parameters {
visitor.visit_generic_args(path_span, parameters);
if let Some(ref args) = segment.args {
visitor.visit_generic_args(path_span, args);
}
}
@ -393,7 +393,7 @@ pub fn walk_generic_args<'a, V>(visitor: &mut V,
{
match *generic_args {
GenericArgs::AngleBracketed(ref data) => {
walk_list!(visitor, visit_angle_bracketed_param, &data.parameters);
walk_list!(visitor, visit_angle_bracketed_param, &data.args);
walk_list!(visitor, visit_assoc_type_binding, &data.bindings);
}
GenericArgs::Parenthesized(ref data) => {

View File

@ -13,7 +13,7 @@ use deriving::generic::*;
use deriving::generic::ty::*;
use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData};
use syntax::ast::AngleBracketedParam;
use syntax::ast::GenericArg;
use syntax::attr;
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
@ -124,7 +124,7 @@ fn cs_clone_shallow(name: &str,
let span = span.with_ctxt(cx.backtrace());
let assert_path = cx.path_all(span, true,
cx.std_path(&["clone", helper_name]),
vec![AngleBracketedParam::Type(ty)], vec![]);
vec![GenericArg::Type(ty)], vec![]);
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
}
fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec<ast::Stmt>, variant: &VariantData) {

View File

@ -12,7 +12,7 @@ use deriving::path_std;
use deriving::generic::*;
use deriving::generic::ty::*;
use syntax::ast::{self, Expr, MetaItem, AngleBracketedParam};
use syntax::ast::{self, Expr, MetaItem, GenericArg};
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
use syntax::ptr::P;
@ -62,7 +62,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
let span = span.with_ctxt(cx.backtrace());
let assert_path = cx.path_all(span, true,
cx.std_path(&["cmp", helper_name]),
vec![AngleBracketedParam::Type(ty)], vec![]);
vec![GenericArg::Type(ty)], vec![]);
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
}
fn process_variant(cx: &mut ExtCtxt, stmts: &mut Vec<ast::Stmt>, variant: &ast::VariantData) {

View File

@ -193,7 +193,7 @@ use std::vec;
use rustc_target::spec::abi::Abi;
use syntax::ast::{self, BinOpKind, EnumDef, Expr, GenericParam, Generics, Ident, PatKind};
use syntax::ast::{VariantData, AngleBracketedParam};
use syntax::ast::{VariantData, GenericArg};
use syntax::attr;
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder;
@ -683,9 +683,9 @@ impl<'a> TraitDef<'a> {
.collect();
let self_params = self_lifetimes.into_iter()
.map(|lt| AngleBracketedParam::Lifetime(lt))
.map(|lt| GenericArg::Lifetime(lt))
.chain(self_ty_params.into_iter().map(|ty|
AngleBracketedParam::Type(ty)))
GenericArg::Type(ty)))
.collect();
// Create the type of `self`.

View File

@ -15,7 +15,7 @@ pub use self::PtrTy::*;
pub use self::Ty::*;
use syntax::ast;
use syntax::ast::{Expr, GenericParam, Generics, Ident, SelfKind, AngleBracketedParam};
use syntax::ast::{Expr, GenericParam, Generics, Ident, SelfKind, GenericArg};
use syntax::ext::base::ExtCtxt;
use syntax::ext::build::AstBuilder;
use syntax::codemap::{respan, DUMMY_SP};
@ -89,8 +89,8 @@ impl<'a> Path<'a> {
let tys: Vec<P<ast::Ty>> =
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
let params = lt.into_iter()
.map(|lt| AngleBracketedParam::Lifetime(lt))
.chain(tys.into_iter().map(|ty| AngleBracketedParam::Type(ty)))
.map(|lt| GenericArg::Lifetime(lt))
.chain(tys.into_iter().map(|ty| GenericArg::Type(ty)))
.collect();
match self.kind {
@ -206,9 +206,9 @@ impl<'a> Ty<'a> {
.collect();
let params = lifetimes.into_iter()
.map(|lt| AngleBracketedParam::Lifetime(lt))
.map(|lt| GenericArg::Lifetime(lt))
.chain(ty_params.into_iter().map(|ty|
AngleBracketedParam::Type(ty)))
GenericArg::Type(ty)))
.collect();
cx.path_all(span,

View File

@ -13,7 +13,7 @@
// interface.
//
use syntax::ast::{self, Ident, AngleBracketedParam};
use syntax::ast::{self, Ident, GenericArg};
use syntax::ext::base::*;
use syntax::ext::base;
use syntax::ext::build::AstBuilder;
@ -39,10 +39,10 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
cx.expr_path(cx.path_all(sp,
true,
cx.std_path(&["option", "Option", "None"]),
vec![AngleBracketedParam::Type(cx.ty_rptr(sp,
vec![GenericArg::Type(cx.ty_rptr(sp,
cx.ty_ident(sp, Ident::from_str("str")),
Some(lt),
ast::Mutability::Immutable)],
ast::Mutability::Immutable))],
Vec::new()))
}
Ok(s) => {