1
Fork 0

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, path_span: Span,
segment: &'v PathSegment) { segment: &'v PathSegment) {
visitor.visit_name(path_span, segment.name); visitor.visit_name(path_span, segment.name);
if let Some(ref parameters) = segment.parameters { if let Some(ref args) = segment.args {
visitor.visit_generic_args(path_span, parameters); visitor.visit_generic_args(path_span, args);
} }
} }
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V,
_path_span: Span, _path_span: Span,
generic_args: &'v GenericArgs) { 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); 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::iter;
use std::mem; use std::mem;
use syntax::attr; use syntax::attr;
use syntax::ast;
use syntax::ast::*; use syntax::ast::*;
use syntax::errors; use syntax::errors;
use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::ext::hygiene::{Mark, SyntaxContext};
@ -1039,14 +1040,14 @@ impl<'a> LoweringContext<'a> {
} }
fn lower_generic_arg(&mut self, fn lower_generic_arg(&mut self,
p: &AngleBracketedParam, p: &ast::GenericArg,
itctx: ImplTraitContext) itctx: ImplTraitContext)
-> GenericArg { -> hir::GenericArg {
match p { match p {
AngleBracketedParam::Lifetime(lt) => { ast::GenericArg::Lifetime(lt) => {
GenericArg::Lifetime(self.lower_lifetime(&lt)) GenericArg::Lifetime(self.lower_lifetime(&lt))
} }
AngleBracketedParam::Type(ty) => { ast::GenericArg::Type(ty) => {
GenericArg::Type(self.lower_ty(&ty, itctx)) GenericArg::Type(self.lower_ty(&ty, itctx))
} }
} }
@ -1684,8 +1685,7 @@ impl<'a> LoweringContext<'a> {
parenthesized_generic_args: ParenthesizedGenericArgs, parenthesized_generic_args: ParenthesizedGenericArgs,
itctx: ImplTraitContext, itctx: ImplTraitContext,
) -> hir::PathSegment { ) -> hir::PathSegment {
let (mut generic_args, infer_types) = let (mut generic_args, infer_types) = if let Some(ref generic_args) = segment.args {
if let Some(ref generic_args) = segment.parameters {
let msg = "parenthesized parameters may only be used with a trait"; let msg = "parenthesized parameters may only be used with a trait";
match **generic_args { match **generic_args {
GenericArgs::AngleBracketed(ref data) => { GenericArgs::AngleBracketed(ref data) => {
@ -1715,13 +1715,16 @@ impl<'a> LoweringContext<'a> {
}; };
if !generic_args.parenthesized && generic_args.lifetimes().count() == 0 { if !generic_args.parenthesized && generic_args.lifetimes().count() == 0 {
generic_args.parameters = (0..expected_lifetimes).map(|_| { generic_args.args =
GenericArg::Lifetime(self.elided_lifetime(path_span)) self.elided_path_lifetimes(path_span, expected_lifetimes)
}).chain(generic_args.parameters.into_iter()).collect(); .into_iter()
.map(|lt| GenericArg::Lifetime(lt))
.chain(generic_args.args.into_iter())
.collect();
} }
hir::PathSegment::new( hir::PathSegment::new(
self.lower_ident(segment.identifier), self.lower_ident(segment.ident),
generic_args, generic_args,
infer_types infer_types
) )
@ -1729,13 +1732,13 @@ impl<'a> LoweringContext<'a> {
fn lower_angle_bracketed_parameter_data( fn lower_angle_bracketed_parameter_data(
&mut self, &mut self,
data: &AngleBracketedParameterData, data: &AngleBracketedArgs,
param_mode: ParamMode, param_mode: ParamMode,
itctx: ImplTraitContext, itctx: ImplTraitContext,
) -> (hir::GenericArgs, bool) { ) -> (hir::GenericArgs, bool) {
let &AngleBracketedParameterData { ref parameters, ref bindings, .. } = data; let &AngleBracketedArgs { ref args, ref bindings, .. } = data;
(hir::GenericArgs { (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(), bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(),
parenthesized: false, parenthesized: false,
}, },
@ -1755,23 +1758,11 @@ impl<'a> LoweringContext<'a> {
AnonymousLifetimeMode::PassThrough, AnonymousLifetimeMode::PassThrough,
|this| { |this| {
const DISALLOWED: ImplTraitContext = ImplTraitContext::Disallowed; const DISALLOWED: ImplTraitContext = ImplTraitContext::Disallowed;
let &ParenthesizedParameterData { let &ParenthesizedParameterData { ref inputs, ref output, span } = data;
ref inputs, let inputs = inputs.iter().map(|ty| this.lower_ty(ty, DISALLOWED)).collect();
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 mk_tup = |this: &mut Self, tys, span| {
let LoweredNodeId { node_id, hir_id } = this.next_id(); let LoweredNodeId { node_id, hir_id } = this.next_id();
P(hir::Ty { P(hir::Ty { node: hir::TyTup(tys), id: node_id, hir_id, span })
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 /// this is more than just simple syntactic sugar; the use of
/// parens affects the region binding rules, so we preserve the /// parens affects the region binding rules, so we preserve the
/// distinction. /// distinction.
pub parameters: Option<P<GenericArgs>>, pub args: Option<P<GenericArgs>>,
/// Whether to infer remaining type parameters, if any. /// Whether to infer remaining type parameters, if any.
/// This only applies to expression and pattern paths, and /// This only applies to expression and pattern paths, and
@ -342,30 +342,30 @@ impl PathSegment {
PathSegment { PathSegment {
name, name,
infer_types: true, 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 { PathSegment {
name, name,
infer_types, infer_types,
parameters: if parameters.is_empty() { args: if args.is_empty() {
None None
} else { } else {
Some(P(parameters)) Some(P(args))
} }
} }
} }
// FIXME: hack required because you can't create a static // FIXME: hack required because you can't create a static
// GenericArgs, so you can't just return a &GenericArgs. // 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 where F: FnOnce(&GenericArgs) -> R
{ {
let dummy = GenericArgs::none(); let dummy = GenericArgs::none();
f(if let Some(ref params) = self.parameters { f(if let Some(ref args) = self.args {
&params &args
} else { } else {
&dummy &dummy
}) })
@ -380,12 +380,12 @@ pub enum GenericArg {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct GenericArgs { pub struct GenericArgs {
/// The generic parameters for this path segment. /// The generic arguments for this path segment.
pub parameters: HirVec<GenericArg>, pub args: HirVec<GenericArg>,
/// Bindings (equality constraints) on associated types, if present. /// Bindings (equality constraints) on associated types, if present.
/// E.g., `Foo<A=Bar>`. /// E.g., `Foo<A=Bar>`.
pub bindings: HirVec<TypeBinding>, 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, /// This is required mostly for pretty-printing and diagnostics,
/// but also for changing lifetime elision rules to be "function-like". /// but also for changing lifetime elision rules to be "function-like".
pub parenthesized: bool, pub parenthesized: bool,
@ -394,14 +394,14 @@ pub struct GenericArgs {
impl GenericArgs { impl GenericArgs {
pub fn none() -> Self { pub fn none() -> Self {
Self { Self {
parameters: HirVec::new(), args: HirVec::new(),
bindings: HirVec::new(), bindings: HirVec::new(),
parenthesized: false, parenthesized: false,
} }
} }
pub fn is_empty(&self) -> bool { 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>] { pub fn inputs(&self) -> &[P<Ty>] {
@ -416,7 +416,7 @@ impl GenericArgs {
} }
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> { 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 { if let GenericArg::Lifetime(lt) = p {
Some(lt) Some(lt)
} else { } else {
@ -426,7 +426,7 @@ impl GenericArgs {
} }
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> { 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 { if let GenericArg::Type(ty) = p {
Some(ty) Some(ty)
} else { } else {

View file

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

View file

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

View file

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

View file

@ -885,73 +885,6 @@ pub struct GenericParamCount {
pub types: usize, 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 /// Information about the formal type/lifetime parameters associated
/// with an item or method. Analogous to hir::Generics. /// 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, pub fn region_param(&'tcx self,
param: &EarlyBoundRegion, param: &EarlyBoundRegion,
tcx: TyCtxt<'a, 'gcx, 'tcx>) 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::mir::mono::{Linkage, Visibility, Stats};
use rustc::middle::cstore::{EncodedMetadata}; use rustc::middle::cstore::{EncodedMetadata};
use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::subst::Kind;
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf}; use rustc::ty::layout::{self, Align, TyLayout, LayoutOf};
use rustc::ty::query::Providers; use rustc::ty::query::Providers;
use rustc::dep_graph::{DepNode, DepConstructor}; 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::Paren(ref subty) => involves_impl_trait(subty),
ast::TyKind::Tup(ref tys) => any_involves_impl_trait(tys.iter()), ast::TyKind::Tup(ref tys) => any_involves_impl_trait(tys.iter()),
ast::TyKind::Path(_, ref path) => path.segments.iter().any(|seg| { 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, None => false,
Some(&ast::GenericArgs::AngleBracketed(ref data)) => Some(&ast::GenericArgs::AngleBracketed(ref data)) =>
any_involves_impl_trait(data.types().into_iter()) || 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 { let label_msg = match pat.node {
PatKind::Path(hir::QPath::Resolved(None, ref path)) 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!("interpreted as a {} pattern, not new variable", path.def.kind_name())
} }
_ => format!("pattern `{}` not covered", pattern_string), _ => format!("pattern `{}` not covered", pattern_string),

View file

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

View file

@ -230,9 +230,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
// } // }
// foo!(bar::baz<T>); // foo!(bar::baz<T>);
use_tree.prefix.segments.iter().find(|segment| { use_tree.prefix.segments.iter().find(|segment| {
segment.parameters.is_some() segment.args.is_some()
}).map(|segment| { }).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"); "generic arguments in import path");
}); });
@ -398,8 +398,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_vis(&mut self, vis: &'a Visibility) { fn visit_vis(&mut self, vis: &'a Visibility) {
match vis.node { match vis.node {
VisibilityKind::Restricted { ref path, .. } => { VisibilityKind::Restricted { ref path, .. } => {
path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| { path.segments.iter().find(|segment| 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 visibility path"); "generic arguments in visibility path");
}); });
} }
@ -521,10 +521,10 @@ impl<'a> Visitor<'a> for NestedImplTraitVisitor<'a> {
visit::walk_ty(self, t); visit::walk_ty(self, t);
} }
} }
fn visit_path_parameters(&mut self, _: Span, path_parameters: &'a PathParameters) { fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
match *path_parameters { match *generic_args {
PathParameters::AngleBracketed(ref params) => { GenericArgs::AngleBracketed(ref params) => {
for type_ in &params.types { for type_ in params.types() {
self.visit_ty(type_); self.visit_ty(type_);
} }
for type_binding in &params.bindings { 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)); 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 { for type_ in &params.inputs {
self.visit_ty(type_); self.visit_ty(type_);
} }
@ -590,7 +590,7 @@ impl<'a> Visitor<'a> for ImplTraitProjectionVisitor<'a> {
// //
// To implement this, we disallow `impl Trait` from `qself` // To implement this, we disallow `impl Trait` from `qself`
// (for cases like `<impl Trait>::Foo>`) // (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. // iff there are no more PathSegments.
if let Some(ref qself) = *qself { if let Some(ref qself) = *qself {
// `impl Trait` in `qself` is always illegal // `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); let def = self.resolve_macro_to_def_inner(scope, path, kind, force);
if def != Err(Determinacy::Undetermined) { if def != Err(Determinacy::Undetermined) {
// Do not report duplicated errors on every undetermined resolution. // Do not report duplicated errors on every undetermined resolution.
path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| { path.segments.iter().find(|segment| segment.args.is_some()).map(|segment| {
self.session.span_err(segment.parameters.as_ref().unwrap().span(), self.session.span_err(segment.args.as_ref().unwrap().span(),
"generic arguments in macro path"); "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); self.dump_path_ref(id, path);
// Type parameters // Type arguments
for seg in &path.segments { for seg in &path.segments {
if let Some(ref params) = seg.parameters { if let Some(ref args) = seg.args {
match **params { match **args {
ast::GenericArgs::AngleBracketed(ref data) => for t in data.types() { ast::GenericArgs::AngleBracketed(ref data) => for t in data.types() {
self.visit_ty(t); 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. // Explicit types in the turbo-fish.
if let Some(ref params) = seg.parameters { if let Some(ref args) = seg.args {
if let ast::GenericArgs::AngleBracketed(ref data) = **params { if let ast::GenericArgs::AngleBracketed(ref data) = **args {
for t in data.types() { for t in data.types() {
self.visit_ty(t); self.visit_ty(t);
} }

View file

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

View file

@ -177,11 +177,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
{ {
let (substs, assoc_bindings) = let (substs, assoc_bindings) =
item_segment.with_parameters(|parameters| { item_segment.with_args(|args| {
self.create_substs_for_ast_path( self.create_substs_for_ast_path(
span, span,
def_id, def_id,
parameters, args,
item_segment.infer_types, item_segment.infer_types,
None) None)
}); });
@ -199,7 +199,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
fn create_substs_for_ast_path(&self, fn create_substs_for_ast_path(&self,
span: Span, span: Span,
def_id: DefId, def_id: DefId,
parameters: &hir::GenericArgs, args: &hir::GenericArgs,
infer_types: bool, infer_types: bool,
self_ty: Option<Ty<'tcx>>) self_ty: Option<Ty<'tcx>>)
-> (&'tcx Substs<'tcx>, Vec<ConvertedBinding<'tcx>>) -> (&'tcx Substs<'tcx>, Vec<ConvertedBinding<'tcx>>)
@ -207,15 +207,15 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let tcx = self.tcx(); let tcx = self.tcx();
debug!("create_substs_for_ast_path(def_id={:?}, self_ty={:?}, \ debug!("create_substs_for_ast_path(def_id={:?}, self_ty={:?}, \
parameters={:?})", args={:?})",
def_id, self_ty, parameters); def_id, self_ty, args);
// If the type is parameterized by this region, then replace this // If the type is parameterized by this region, then replace this
// region with the current anon region binding (in other words, // region with the current anon region binding (in other words,
// whatever & would get replaced with). // whatever & would get replaced with).
let decl_generics = tcx.generics_of(def_id); let decl_generics = tcx.generics_of(def_id);
let ty_provided = parameters.types().len(); let ty_provided = args.types().count();
let lt_provided = parameters.lifetimes().len(); let lt_provided = args.lifetimes().count();
let mut lt_accepted = 0; let mut lt_accepted = 0;
let mut ty_params = ParamRange { required: 0, 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 { match param.kind {
GenericParamDefKind::Lifetime => { GenericParamDefKind::Lifetime => {
let i = param.index as usize - own_self; 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() self.ast_region_to_region(lifetime, Some(param)).into()
} else { } else {
tcx.types.re_static.into() 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); let i = i - (lt_accepted + own_self);
if i < ty_provided { if i < ty_provided {
// A provided type parameter. // 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 { } else if infer_types {
// No type parameters were provided, we can infer all. // No type parameters were provided, we can infer all.
if !default_needs_object_self(param) { 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 { ConvertedBinding {
item_name: binding.name, item_name: binding.name,
ty: self.ast_ty_to_ty(&binding.ty), 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); let trait_def = self.tcx().trait_def(trait_def_id);
if !self.tcx().features().unboxed_closures && 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. // For now, require that parenthetical notation be used only with `Fn()` etc.
let msg = if trait_def.paren_sugar { let msg = if trait_def.paren_sugar {
"the precise format of `Fn`-family traits' type parameters is subject to change. \ "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); span, GateIssue::Language, msg);
} }
trait_segment.with_parameters(|parameters| { trait_segment.with_args(|parameters| {
self.create_substs_for_ast_path(span, self.create_substs_for_ast_path(span,
trait_def_id, trait_def_id,
parameters, parameters,
@ -970,8 +970,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) { pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
for segment in segments { for segment in segments {
segment.with_parameters(|params| { segment.with_args(|params| {
for p in &params.parameters { for p in &params.args {
let (mut span_err, span, kind) = match p { let (mut span_err, span, kind) = match p {
hir::GenericArg::Lifetime(lt) => { hir::GenericArg::Lifetime(lt) => {
(struct_span_err!(self.tcx().sess, lt.span, E0110, (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={:?})", "confirm(unadjusted_self_ty={:?}, pick={:?}, generic_args={:?})",
unadjusted_self_ty, unadjusted_self_ty,
pick, pick,
segment.parameters, segment.args,
); );
let mut confirm_cx = ConfirmContext::new(self, span, self_expr, call_expr); 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 // Create subst for early-bound lifetime parameters, combining
// parameters from the type and those from the method. // parameters from the type and those from the method.
assert_eq!(method_generics.parent_count, parent_substs.len()); assert_eq!(method_generics.parent_count, parent_substs.len());
let provided = &segment.parameters; let provided = &segment.args;
let own_counts = method_generics.own_counts(); let own_counts = method_generics.own_counts();
Substs::for_item(self.tcx, pick.item.def_id, |param, _| { Substs::for_item(self.tcx, pick.item.def_id, |param, _| {
let i = param.index as usize; let i = param.index as usize;
@ -331,7 +331,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
match param.kind { match param.kind {
GenericParamDefKind::Lifetime => { GenericParamDefKind::Lifetime => {
if let Some(lifetime) = provided.as_ref().and_then(|p| { 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( return AstConv::ast_region_to_region(
self.fcx, lifetime, Some(param)).into(); self.fcx, lifetime, Some(param)).into();
@ -339,7 +339,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
} }
GenericParamDefKind::Type {..} => { GenericParamDefKind::Type {..} => {
if let Some(ast_ty) = provided.as_ref().and_then(|p| { 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(); 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.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 { match param.kind {
GenericParamDefKind::Lifetime => { GenericParamDefKind::Lifetime => {
let lifetimes = segment.map_or(vec![], |(s, _)| { 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) { if let Some(lifetime) = lifetimes.get(i) {
@ -4845,7 +4845,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} }
GenericParamDefKind::Type {..} => { GenericParamDefKind::Type {..} => {
let (types, infer_types) = segment.map_or((vec![], true), |(s, _)| { 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. // Skip over the lifetimes in the same segment.
@ -4962,7 +4962,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
supress_mismatch_error: bool) { supress_mismatch_error: bool) {
let (lifetimes, types, infer_types, bindings) = segment.map_or( let (lifetimes, types, infer_types, bindings) = segment.map_or(
(vec![], vec![], true, &[][..]), (vec![], vec![], true, &[][..]),
|(s, _)| s.parameters.as_ref().map_or( |(s, _)| s.args.as_ref().map_or(
(vec![], vec![], s.infer_types, &[][..]), (vec![], vec![], s.infer_types, &[][..]),
|p| (p.lifetimes().collect(), p.types().collect(), |p| (p.lifetimes().collect(), p.types().collect(),
s.infer_types, &p.bindings[..]))); 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)) .map(|param| (param.def_id, param.index))
.collect(); .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 { tcx.alloc_generics(ty::Generics {
parent: parent_def_id, parent: parent_def_id,
parent_count, parent_count,

View file

@ -244,9 +244,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
None None
} }
fn generics_to_path_params(&self, generics: ty::Generics) -> hir::PathParameters { fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs {
let mut lifetimes = vec![]; let mut args = vec![];
let mut types = vec![];
for param in generics.params.iter() { for param in generics.params.iter() {
match param.kind { match param.kind {
@ -257,21 +256,20 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
hir::LifetimeName::Name(param.name.as_symbol()) hir::LifetimeName::Name(param.name.as_symbol())
}; };
lifetimes.push(hir::Lifetime { args.push(hir::GenericArg::Lifetime(hir::Lifetime {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
span: DUMMY_SP, span: DUMMY_SP,
name, name,
}); }));
} }
ty::GenericParamDefKind::Type {..} => { 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 { hir::GenericArgs {
lifetimes: HirVec::from_vec(lifetimes), args: HirVec::from_vec(args),
types: HirVec::from_vec(types),
bindings: HirVec::new(), bindings: HirVec::new(),
parenthesized: false, parenthesized: false,
} }
@ -555,9 +553,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
let mut new_path = path.clone(); let mut new_path = path.clone();
let last_segment = new_path.segments.pop().unwrap(); let last_segment = new_path.segments.pop().unwrap();
let (old_input, old_output) = match last_segment.params { let (old_input, old_output) = match last_segment.args {
PathParameters::AngleBracketed { types, .. } => (types, None), GenericArgs::AngleBracketed { types, .. } => (types, None),
PathParameters::Parenthesized { inputs, output, .. } => { GenericArgs::Parenthesized { inputs, output, .. } => {
(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, inputs: old_input,
output, output,
}; };
new_path.segments.push(PathSegment { new_path.segments.push(PathSegment {
name: last_segment.name, name: last_segment.name,
params: new_params, args: new_params,
}); });
Type::ResolvedPath { Type::ResolvedPath {
@ -793,13 +791,13 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
// FIXME: Remove this scope when NLL lands // FIXME: Remove this scope when NLL lands
{ {
let params = let args =
&mut new_trait_path.segments.last_mut().unwrap().params; &mut new_trait_path.segments.last_mut().unwrap().args;
match params { match args {
// Convert somethiung like '<T as Iterator::Item> = u8' // Convert somethiung like '<T as Iterator::Item> = u8'
// to 'T: Iterator<Item=u8>' // to 'T: Iterator<Item=u8>'
&mut PathParameters::AngleBracketed { &mut GenericArgs::AngleBracketed {
ref mut bindings, ref mut bindings,
.. ..
} => { } => {
@ -808,7 +806,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
ty: rhs, ty: rhs,
}); });
} }
&mut PathParameters::Parenthesized { .. } => { &mut GenericArgs::Parenthesized { .. } => {
existing_predicates.push( existing_predicates.push(
WherePredicate::EqPredicate { WherePredicate::EqPredicate {
lhs: lhs.clone(), 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, def: Def::Err,
segments: vec![PathSegment { segments: vec![PathSegment {
name: name.to_string(), 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 { match *self {
ResolvedPath { ref path, .. } => { ResolvedPath { ref path, .. } => {
path.segments.last().and_then(|seg| { path.segments.last().and_then(|seg| {
if let GenericArgs::AngleBracketed { ref types, .. } = seg.params { if let GenericArgs::AngleBracketed { ref types, .. } = seg.args {
Some(&**types) Some(&**types)
} else { } else {
None None
@ -2851,7 +2851,7 @@ impl Clean<Type> for hir::Ty {
let provided_params = &path.segments.last().unwrap(); let provided_params = &path.segments.last().unwrap();
let mut ty_substs = FxHashMap(); let mut ty_substs = FxHashMap();
let mut lt_substs = FxHashMap(); let mut lt_substs = FxHashMap();
provided_params.with_parameters(|provided_params| { provided_params.with_args(|provided_params| {
let mut indices = GenericParamCount { let mut indices = GenericParamCount {
lifetimes: 0, lifetimes: 0,
types: 0 types: 0
@ -2859,8 +2859,8 @@ impl Clean<Type> for hir::Ty {
for param in generics.params.iter() { for param in generics.params.iter() {
match param { match param {
hir::GenericParam::Lifetime(lt_param) => { hir::GenericParam::Lifetime(lt_param) => {
if let Some(lt) = provided_params.lifetimes if let Some(lt) = provided_params.lifetimes()
.get(indices.lifetimes).cloned() { .nth(indices.lifetimes).cloned() {
if !lt.is_elided() { if !lt.is_elided() {
let lt_def_id = let lt_def_id =
cx.tcx.hir.local_def_id(lt_param.lifetime.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) => { hir::GenericParam::Type(ty_param) => {
let ty_param_def = let ty_param_def =
Def::TyParam(cx.tcx.hir.local_def_id(ty_param.id)); Def::TyParam(cx.tcx.hir.local_def_id(ty_param.id));
if let Some(ty) = provided_params.types if let Some(ty) = provided_params.types()
.get(indices.types).cloned() { .nth(indices.types).cloned() {
ty_substs.insert(ty_param_def, ty.into_inner().clean(cx)); ty_substs.insert(ty_param_def, ty.into_inner().clean(cx));
} else if let Some(default) = ty_param.default.clone() { } else if let Some(default) = ty_param.default.clone() {
ty_substs.insert(ty_param_def, ty_substs.insert(ty_param_def,
@ -3447,7 +3447,7 @@ impl Path {
def: Def::Err, def: Def::Err,
segments: vec![PathSegment { segments: vec![PathSegment {
name, name,
params: GenericArgs::AngleBracketed { args: GenericArgs::AngleBracketed {
lifetimes: Vec::new(), lifetimes: Vec::new(),
types: Vec::new(), types: Vec::new(),
bindings: 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 { pub enum GenericArgs {
AngleBracketed { AngleBracketed {
lifetimes: Vec<Lifetime>, lifetimes: Vec<Lifetime>,
@ -3509,14 +3509,14 @@ impl Clean<GenericArgs> for hir::GenericArgs {
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
pub struct PathSegment { pub struct PathSegment {
pub name: String, pub name: String,
pub params: GenericArgs, pub args: GenericArgs,
} }
impl Clean<PathSegment> for hir::PathSegment { impl Clean<PathSegment> for hir::PathSegment {
fn clean(&self, cx: &DocContext) -> PathSegment { fn clean(&self, cx: &DocContext) -> PathSegment {
PathSegment { PathSegment {
name: self.name.clean(cx), 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| { let segments = path.segments.iter().map(|s| {
PathSegment { PathSegment {
name: s.name.clone(), name: s.name.clone(),
params: PathParameters::AngleBracketed { args: GenericArgs::AngleBracketed {
lifetimes: Vec::new(), lifetimes: Vec::new(),
types: Vec::new(), types: Vec::new(),
bindings: Vec::new(), bindings: Vec::new(),
@ -4365,7 +4365,7 @@ where F: Fn(DefId) -> Def {
def: def_ctor(def_id), def: def_ctor(def_id),
segments: hir::HirVec::from_vec(apb.names.iter().map(|s| hir::PathSegment { segments: hir::HirVec::from_vec(apb.names.iter().map(|s| hir::PathSegment {
name: ast::Name::intern(&s), name: ast::Name::intern(&s),
parameters: None, args: None,
infer_types: false, infer_types: false,
}).collect()) }).collect())
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -132,11 +132,11 @@ pub trait Folder : Sized {
noop_fold_exprs(es, self) noop_fold_exprs(es, self)
} }
fn fold_param(&mut self, p: AngleBracketedParam) -> AngleBracketedParam { fn fold_param(&mut self, p: GenericArg) -> GenericArg {
match p { match p {
AngleBracketedParam::Lifetime(lt) => GenericArg::Lifetime(lt) =>
AngleBracketedParam::Lifetime(self.fold_lifetime(lt)), GenericArg::Lifetime(self.fold_lifetime(lt)),
AngleBracketedParam::Type(ty) => AngleBracketedParam::Type(self.fold_ty(ty)), GenericArg::Type(ty) => GenericArg::Type(self.fold_ty(ty)),
} }
} }
@ -184,14 +184,14 @@ pub trait Folder : Sized {
noop_fold_generic_args(p, self) noop_fold_generic_args(p, self)
} }
fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedParameterData) fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedArgs)
-> AngleBracketedParameterData -> AngleBracketedArgs
{ {
noop_fold_angle_bracketed_parameter_data(p, self) noop_fold_angle_bracketed_parameter_data(p, self)
} }
fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedParameterData) fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedArgData)
-> ParenthesizedParameterData -> ParenthesizedArgData
{ {
noop_fold_parenthesized_parameter_data(p, self) 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 { pub fn noop_fold_path<T: Folder>(Path { segments, span }: Path, fld: &mut T) -> Path {
Path { Path {
segments: segments.move_map(|PathSegment {ident, parameters}| PathSegment { segments: segments.move_map(|PathSegment {ident, args}| PathSegment {
ident: fld.fold_ident(ident), 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) 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) fld: &mut T)
-> AngleBracketedParameterData -> AngleBracketedArgs
{ {
let AngleBracketedParameterData { parameters, bindings, span } = data; let AngleBracketedArgs { args, bindings, span } = data;
AngleBracketedParameterData { parameters: parameters.move_map(|p| fld.fold_param(p)), AngleBracketedArgs { args: args.move_map(|p| fld.fold_param(p)),
bindings: bindings.move_map(|b| fld.fold_ty_binding(b)), bindings: bindings.move_map(|b| fld.fold_ty_binding(b)),
span: fld.new_span(span) } 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) fld: &mut T)
-> ParenthesizedParameterData -> ParenthesizedArgData
{ {
let ParenthesizedParameterData { inputs, output, span } = data; let ParenthesizedArgData { inputs, output, span } = data;
ParenthesizedParameterData { inputs: inputs.move_map(|ty| fld.fold_ty(ty)), ParenthesizedArgData { inputs: inputs.move_map(|ty| fld.fold_ty(ty)),
output: output.map(|ty| fld.fold_ty(ty)), output: output.map(|ty| fld.fold_ty(ty)),
span: fld.new_span(span) } 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( ExprKind::MethodCall(
PathSegment { PathSegment {
ident: folder.fold_ident(seg.ident), ident: folder.fold_ident(seg.ident),
parameters: seg.parameters.map(|ps| { args: seg.args.map(|ps| {
ps.map(|ps| folder.fold_generic_args(ps)) ps.map(|ps| folder.fold_generic_args(ps))
}), }),
}, },

View file

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use rustc_target::spec::abi::{self, Abi}; 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::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
use ast::Unsafety; use ast::Unsafety;
use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind}; use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind};
@ -22,7 +22,7 @@ use ast::{Expr, ExprKind, RangeLimits};
use ast::{Field, FnDecl}; use ast::{Field, FnDecl};
use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy};
use ast::GenericParam; use ast::GenericParam;
use ast::AngleBracketedParam; use ast::GenericArg;
use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; use ast::{Ident, ImplItem, IsAuto, Item, ItemKind};
use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind}; use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind};
use ast::Local; use ast::Local;
@ -1895,7 +1895,7 @@ impl<'a> Parser<'a> {
-> PResult<'a, ast::Path> { -> PResult<'a, ast::Path> {
maybe_whole!(self, NtPath, |path| { maybe_whole!(self, NtPath, |path| {
if style == PathStyle::Mod && 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"); self.diagnostic().span_err(path.span, "unexpected generic arguments in path");
} }
path path
@ -1970,12 +1970,12 @@ impl<'a> Parser<'a> {
.span_label(self.prev_span, "try removing `::`").emit(); .span_label(self.prev_span, "try removing `::`").emit();
} }
let parameters = if self.eat_lt() { let args = if self.eat_lt() {
// `<'a, T, A = U>` // `<'a, T, A = U>`
let (parameters, bindings) = self.parse_generic_args()?; let (args, bindings) = self.parse_generic_args()?;
self.expect_gt()?; self.expect_gt()?;
let span = lo.to(self.prev_span); let span = lo.to(self.prev_span);
AngleBracketedParameterData { parameters, bindings, span }.into() AngleBracketedArgs { args, bindings, span }.into()
} else { } else {
// `(T, U) -> R` // `(T, U) -> R`
self.bump(); // `(` self.bump(); // `(`
@ -1991,10 +1991,10 @@ impl<'a> Parser<'a> {
None None
}; };
let span = lo.to(self.prev_span); let span = lo.to(self.prev_span);
ParenthesizedParameterData { inputs, output, span }.into() ParenthesizedArgData { inputs, output, span }.into()
}; };
PathSegment { ident, parameters } PathSegment { ident, args }
} else { } else {
// Generic arguments are not found. // Generic arguments are not found.
PathSegment::from_ident(ident) PathSegment::from_ident(ident)
@ -2544,8 +2544,8 @@ impl<'a> Parser<'a> {
} }
_ => { _ => {
// Field access `expr.f` // Field access `expr.f`
if let Some(parameters) = segment.parameters { if let Some(args) = segment.args {
self.span_err(parameters.span(), self.span_err(args.span(),
"field expressions may not have generic arguments"); "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, /// Parses (possibly empty) list of lifetime and type arguments and associated type bindings,
/// possibly including trailing comma. /// possibly including trailing comma.
fn parse_generic_args(&mut self) fn parse_generic_args(&mut self)
-> PResult<'a, (Vec<AngleBracketedParam>, Vec<TypeBinding>)> { -> PResult<'a, (Vec<GenericArg>, Vec<TypeBinding>)> {
let mut parameters = Vec::new(); let mut args = Vec::new();
let mut bindings = Vec::new(); let mut bindings = Vec::new();
let mut seen_type = false; let mut seen_type = false;
let mut seen_binding = false; let mut seen_binding = false;
loop { loop {
if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) { if self.check_lifetime() && self.look_ahead(1, |t| !t.is_like_plus()) {
// Parse lifetime argument. // Parse lifetime argument.
parameters.push(AngleBracketedParam::Lifetime(self.expect_lifetime())); args.push(GenericArg::Lifetime(self.expect_lifetime()));
if seen_type || seen_binding { if seen_type || seen_binding {
self.span_err(self.prev_span, self.span_err(self.prev_span,
"lifetime parameters must be declared prior to type parameters"); "lifetime parameters must be declared prior to type parameters");
@ -4971,7 +4971,7 @@ impl<'a> Parser<'a> {
self.span_err(ty_param.span, self.span_err(ty_param.span,
"type parameters must be declared prior to associated type bindings"); "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; seen_type = true;
} else { } else {
break break
@ -4981,7 +4981,7 @@ impl<'a> Parser<'a> {
break break
} }
} }
Ok((parameters, bindings)) Ok((args, bindings))
} }
/// Parses an optional `where` clause and places it in `generics`. /// 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 rustc_target::spec::abi::{self, Abi};
use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax}; use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
use ast::{Attribute, MacDelimiter, AngleBracketedParam}; use ast::{Attribute, MacDelimiter, GenericArg};
use util::parser::{self, AssocOp, Fixity}; use util::parser::{self, AssocOp, Fixity};
use attr; use attr;
use codemap::{self, CodeMap}; use codemap::{self, CodeMap};
@ -1017,10 +1017,10 @@ impl<'a> State<'a> {
Ok(()) Ok(())
} }
pub fn print_param(&mut self, param: &AngleBracketedParam) -> io::Result<()> { pub fn print_param(&mut self, param: &GenericArg) -> io::Result<()> {
match param { match param {
AngleBracketedParam::Lifetime(lt) => self.print_lifetime(lt), GenericArg::Lifetime(lt) => self.print_lifetime(lt),
AngleBracketedParam::Type(ty) => self.print_type(ty), 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.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX)?;
self.s.word(".")?; self.s.word(".")?;
self.print_ident(segment.ident)?; self.print_ident(segment.ident)?;
if let Some(ref parameters) = segment.parameters { if let Some(ref args) = segment.args {
self.print_generic_args(parameters, true)?; self.print_generic_args(args, true)?;
} }
self.print_call_post(base_args) self.print_call_post(base_args)
} }
@ -2435,8 +2435,8 @@ impl<'a> State<'a> {
if segment.ident.name != keywords::CrateRoot.name() && if segment.ident.name != keywords::CrateRoot.name() &&
segment.ident.name != keywords::DollarCrate.name() { segment.ident.name != keywords::DollarCrate.name() {
self.print_ident(segment.ident)?; self.print_ident(segment.ident)?;
if let Some(ref parameters) = segment.parameters { if let Some(ref args) = segment.args {
self.print_generic_args(parameters, colons_before_params)?; self.print_generic_args(args, colons_before_params)?;
} }
} else if segment.ident.name == keywords::DollarCrate.name() { } else if segment.ident.name == keywords::DollarCrate.name() {
self.print_dollar_crate(segment.ident.span.ctxt())?; self.print_dollar_crate(segment.ident.span.ctxt())?;
@ -2462,14 +2462,14 @@ impl<'a> State<'a> {
self.s.word("::")?; self.s.word("::")?;
let item_segment = path.segments.last().unwrap(); let item_segment = path.segments.last().unwrap();
self.print_ident(item_segment.ident)?; self.print_ident(item_segment.ident)?;
match item_segment.parameters { match item_segment.args {
Some(ref parameters) => self.print_generic_args(parameters, colons_before_params), Some(ref args) => self.print_generic_args(args, colons_before_params),
None => Ok(()), None => Ok(()),
} }
} }
fn print_generic_args(&mut self, fn print_generic_args(&mut self,
parameters: &ast::GenericArgs, args: &ast::GenericArgs,
colons_before_params: bool) colons_before_params: bool)
-> io::Result<()> -> io::Result<()>
{ {
@ -2477,13 +2477,13 @@ impl<'a> State<'a> {
self.s.word("::")? self.s.word("::")?
} }
match *parameters { match *args {
ast::GenericArgs::AngleBracketed(ref data) => { ast::GenericArgs::AngleBracketed(ref data) => {
self.s.word("<")?; 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() { for binding in data.bindings.iter() {
if comma { 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) { fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArgs) {
walk_generic_args(self, path_span, generic_args) 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 { match param {
AngleBracketedParam::Lifetime(lt) => self.visit_lifetime(lt), GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
AngleBracketedParam::Type(ty) => self.visit_ty(ty), GenericArg::Type(ty) => self.visit_ty(ty),
} }
} }
fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) { 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, path_span: Span,
segment: &'a PathSegment) { segment: &'a PathSegment) {
visitor.visit_ident(segment.ident); visitor.visit_ident(segment.ident);
if let Some(ref parameters) = segment.parameters { if let Some(ref args) = segment.args {
visitor.visit_generic_args(path_span, parameters); visitor.visit_generic_args(path_span, args);
} }
} }
@ -393,7 +393,7 @@ pub fn walk_generic_args<'a, V>(visitor: &mut V,
{ {
match *generic_args { match *generic_args {
GenericArgs::AngleBracketed(ref data) => { 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); walk_list!(visitor, visit_assoc_type_binding, &data.bindings);
} }
GenericArgs::Parenthesized(ref data) => { GenericArgs::Parenthesized(ref data) => {

View file

@ -13,7 +13,7 @@ use deriving::generic::*;
use deriving::generic::ty::*; use deriving::generic::ty::*;
use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData}; use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData};
use syntax::ast::AngleBracketedParam; use syntax::ast::GenericArg;
use syntax::attr; use syntax::attr;
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
@ -124,7 +124,7 @@ fn cs_clone_shallow(name: &str,
let span = span.with_ctxt(cx.backtrace()); let span = span.with_ctxt(cx.backtrace());
let assert_path = cx.path_all(span, true, let assert_path = cx.path_all(span, true,
cx.std_path(&["clone", helper_name]), 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))); 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) { 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::*;
use deriving::generic::ty::*; 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::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ptr::P; 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 span = span.with_ctxt(cx.backtrace());
let assert_path = cx.path_all(span, true, let assert_path = cx.path_all(span, true,
cx.std_path(&["cmp", helper_name]), 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))); 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) { 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 rustc_target::spec::abi::Abi;
use syntax::ast::{self, BinOpKind, EnumDef, Expr, GenericParam, Generics, Ident, PatKind}; 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::attr;
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
@ -683,9 +683,9 @@ impl<'a> TraitDef<'a> {
.collect(); .collect();
let self_params = self_lifetimes.into_iter() 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| .chain(self_ty_params.into_iter().map(|ty|
AngleBracketedParam::Type(ty))) GenericArg::Type(ty)))
.collect(); .collect();
// Create the type of `self`. // Create the type of `self`.

View file

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

View file

@ -13,7 +13,7 @@
// interface. // interface.
// //
use syntax::ast::{self, Ident, AngleBracketedParam}; use syntax::ast::{self, Ident, GenericArg};
use syntax::ext::base::*; use syntax::ext::base::*;
use syntax::ext::base; use syntax::ext::base;
use syntax::ext::build::AstBuilder; 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, cx.expr_path(cx.path_all(sp,
true, true,
cx.std_path(&["option", "Option", "None"]), 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")), cx.ty_ident(sp, Ident::from_str("str")),
Some(lt), Some(lt),
ast::Mutability::Immutable)], ast::Mutability::Immutable))],
Vec::new())) Vec::new()))
} }
Ok(s) => { Ok(s) => {