Rename PathParameter(s) to GenericArg(s)
This commit is contained in:
parent
e05ad4f31a
commit
3e89753283
24 changed files with 194 additions and 203 deletions
|
|
@ -344,10 +344,10 @@ pub trait Visitor<'v> : Sized {
|
|||
fn visit_label(&mut self, label: &'v Label) {
|
||||
walk_label(self, label)
|
||||
}
|
||||
fn visit_path_param(&mut self, path_param: &'v PathParam) {
|
||||
match path_param {
|
||||
PathParam::Lifetime(lt) => self.visit_lifetime(lt),
|
||||
PathParam::Type(ty) => self.visit_ty(ty),
|
||||
fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg) {
|
||||
match generic_arg {
|
||||
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
|
||||
GenericArg::Type(ty) => self.visit_ty(ty),
|
||||
}
|
||||
}
|
||||
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
|
||||
|
|
@ -362,8 +362,8 @@ pub trait Visitor<'v> : Sized {
|
|||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
|
||||
walk_path_segment(self, path_span, path_segment)
|
||||
}
|
||||
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'v PathParameters) {
|
||||
walk_path_parameters(self, path_span, path_parameters)
|
||||
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs) {
|
||||
walk_generic_args(self, path_span, generic_args)
|
||||
}
|
||||
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) {
|
||||
walk_assoc_type_binding(self, type_binding)
|
||||
|
|
@ -649,15 +649,15 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
|
|||
segment: &'v PathSegment) {
|
||||
visitor.visit_name(path_span, segment.name);
|
||||
if let Some(ref parameters) = segment.parameters {
|
||||
visitor.visit_path_parameters(path_span, parameters);
|
||||
visitor.visit_generic_args(path_span, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_path_parameters<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
_path_span: Span,
|
||||
path_parameters: &'v PathParameters) {
|
||||
walk_list!(visitor, visit_path_param, &path_parameters.parameters);
|
||||
walk_list!(visitor, visit_assoc_type_binding, &path_parameters.bindings);
|
||||
generic_args: &'v GenericArgs) {
|
||||
walk_list!(visitor, visit_generic_arg, &generic_args.parameters);
|
||||
walk_list!(visitor, visit_assoc_type_binding, &generic_args.bindings);
|
||||
}
|
||||
|
||||
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ use hir::HirVec;
|
|||
use hir::map::{DefKey, DefPathData, Definitions};
|
||||
use hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX};
|
||||
use hir::def::{Def, PathResolution, PerNS};
|
||||
use hir::PathParam;
|
||||
use hir::GenericArg;
|
||||
use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES};
|
||||
use middle::cstore::CrateStore;
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
|
|
@ -1038,16 +1038,16 @@ impl<'a> LoweringContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lower_path_param(&mut self,
|
||||
fn lower_generic_arg(&mut self,
|
||||
p: &AngleBracketedParam,
|
||||
itctx: ImplTraitContext)
|
||||
-> PathParam {
|
||||
-> GenericArg {
|
||||
match p {
|
||||
AngleBracketedParam::Lifetime(lt) => {
|
||||
PathParam::Lifetime(self.lower_lifetime(<))
|
||||
GenericArg::Lifetime(self.lower_lifetime(<))
|
||||
}
|
||||
AngleBracketedParam::Type(ty) => {
|
||||
PathParam::Type(self.lower_ty(&ty, itctx))
|
||||
GenericArg::Type(self.lower_ty(&ty, itctx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1322,15 +1322,15 @@ impl<'a> LoweringContext<'a> {
|
|||
hir::intravisit::NestedVisitorMap::None
|
||||
}
|
||||
|
||||
fn visit_path_parameters(&mut self, span: Span, parameters: &'v hir::PathParameters) {
|
||||
fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs) {
|
||||
// Don't collect elided lifetimes used inside of `Fn()` syntax.
|
||||
if parameters.parenthesized {
|
||||
let old_collect_elided_lifetimes = self.collect_elided_lifetimes;
|
||||
self.collect_elided_lifetimes = false;
|
||||
hir::intravisit::walk_path_parameters(self, span, parameters);
|
||||
hir::intravisit::walk_generic_args(self, span, parameters);
|
||||
self.collect_elided_lifetimes = old_collect_elided_lifetimes;
|
||||
} else {
|
||||
hir::intravisit::walk_path_parameters(self, span, parameters);
|
||||
hir::intravisit::walk_generic_args(self, span, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1567,7 +1567,7 @@ impl<'a> LoweringContext<'a> {
|
|||
assert!(!def_id.is_local());
|
||||
let item_generics =
|
||||
self.cstore.item_generics_cloned_untracked(def_id, self.sess);
|
||||
let n = item_generics.own_counts().lifetimes();
|
||||
let n = item_generics.own_counts().lifetimes;
|
||||
self.type_def_lifetime_params.insert(def_id, n);
|
||||
n
|
||||
});
|
||||
|
|
@ -1684,13 +1684,14 @@ impl<'a> LoweringContext<'a> {
|
|||
parenthesized_generic_args: ParenthesizedGenericArgs,
|
||||
itctx: ImplTraitContext,
|
||||
) -> hir::PathSegment {
|
||||
let (mut parameters, infer_types) = if let Some(ref parameters) = segment.parameters {
|
||||
let (mut generic_args, infer_types) =
|
||||
if let Some(ref generic_args) = segment.parameters {
|
||||
let msg = "parenthesized parameters may only be used with a trait";
|
||||
match **path_params {
|
||||
PathParameters::AngleBracketed(ref data) => {
|
||||
match **generic_args {
|
||||
GenericArgs::AngleBracketed(ref data) => {
|
||||
self.lower_angle_bracketed_parameter_data(data, param_mode, itctx)
|
||||
}
|
||||
PathParameters::Parenthesized(ref data) => match parenthesized_generic_args {
|
||||
GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args {
|
||||
ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data),
|
||||
ParenthesizedGenericArgs::Warn => {
|
||||
self.sess.buffer_lint(
|
||||
|
|
@ -1699,13 +1700,13 @@ impl<'a> LoweringContext<'a> {
|
|||
data.span,
|
||||
msg.into(),
|
||||
);
|
||||
(hir::PathParameters::none(), true)
|
||||
(hir::GenericArgs::none(), true)
|
||||
}
|
||||
ParenthesizedGenericArgs::Err => {
|
||||
struct_span_err!(self.sess, data.span, E0214, "{}", msg)
|
||||
.span_label(data.span, "only traits may use parentheses")
|
||||
.emit();
|
||||
(hir::PathParameters::none(), true)
|
||||
(hir::GenericArgs::none(), true)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
@ -1713,16 +1714,16 @@ impl<'a> LoweringContext<'a> {
|
|||
self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx)
|
||||
};
|
||||
|
||||
if !parameters.parenthesized && parameters.lifetimes.is_empty() {
|
||||
path_params.parameters = (0..expected_lifetimes).map(|_| {
|
||||
PathParam::Lifetime(self.elided_lifetime(path_span))
|
||||
}).chain(path_params.parameters.into_iter()).collect();
|
||||
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();
|
||||
}
|
||||
|
||||
hir::PathSegment::new(
|
||||
self.lower_ident(segment.ident),
|
||||
path_params,
|
||||
infer_types,
|
||||
self.lower_ident(segment.identifier),
|
||||
generic_args,
|
||||
infer_types
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -1731,14 +1732,14 @@ impl<'a> LoweringContext<'a> {
|
|||
data: &AngleBracketedParameterData,
|
||||
param_mode: ParamMode,
|
||||
itctx: ImplTraitContext,
|
||||
) -> (hir::PathParameters, bool) {
|
||||
) -> (hir::GenericArgs, bool) {
|
||||
let &AngleBracketedParameterData { ref parameters, ref bindings, .. } = data;
|
||||
(hir::PathParameters {
|
||||
parameters: parameters.iter().map(|p| self.lower_path_param(p, itctx)).collect(),
|
||||
(hir::GenericArgs {
|
||||
parameters: parameters.iter().map(|p| self.lower_generic_arg(p, itctx)).collect(),
|
||||
bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx)).collect(),
|
||||
parenthesized: false,
|
||||
},
|
||||
types.is_empty() && param_mode == ParamMode::Optional)
|
||||
data.types().count() == 0 && param_mode == ParamMode::Optional)
|
||||
}
|
||||
|
||||
fn lower_parenthesized_parameter_data(
|
||||
|
|
@ -1774,8 +1775,8 @@ impl<'a> LoweringContext<'a> {
|
|||
};
|
||||
|
||||
(
|
||||
hir::PathParameters {
|
||||
parameters: hir_vec![PathParam::Type(mk_tup(this, inputs, span))],
|
||||
hir::GenericArgs {
|
||||
parameters: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))],
|
||||
bindings: hir_vec![
|
||||
hir::TypeBinding {
|
||||
id: this.next_id().node_id,
|
||||
|
|
|
|||
|
|
@ -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<PathParameters>>,
|
||||
pub parameters: Option<P<GenericArgs>>,
|
||||
|
||||
/// Whether to infer remaining type parameters, if any.
|
||||
/// This only applies to expression and pattern paths, and
|
||||
|
|
@ -346,7 +346,7 @@ impl PathSegment {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(name: Name, parameters: PathParameters, infer_types: bool) -> Self {
|
||||
pub fn new(name: Name, parameters: GenericArgs, infer_types: bool) -> Self {
|
||||
PathSegment {
|
||||
name,
|
||||
infer_types,
|
||||
|
|
@ -359,11 +359,11 @@ impl PathSegment {
|
|||
}
|
||||
|
||||
// FIXME: hack required because you can't create a static
|
||||
// PathParameters, so you can't just return a &PathParameters.
|
||||
// GenericArgs, so you can't just return a &GenericArgs.
|
||||
pub fn with_parameters<F, R>(&self, f: F) -> R
|
||||
where F: FnOnce(&PathParameters) -> R
|
||||
where F: FnOnce(&GenericArgs) -> R
|
||||
{
|
||||
let dummy = PathParameters::none();
|
||||
let dummy = GenericArgs::none();
|
||||
f(if let Some(ref params) = self.parameters {
|
||||
¶ms
|
||||
} else {
|
||||
|
|
@ -373,15 +373,15 @@ impl PathSegment {
|
|||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum PathParam {
|
||||
pub enum GenericArg {
|
||||
Lifetime(Lifetime),
|
||||
Type(P<Ty>),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct PathParameters {
|
||||
pub struct GenericArgs {
|
||||
/// The generic parameters for this path segment.
|
||||
pub parameters: HirVec<PathParam>,
|
||||
pub parameters: HirVec<GenericArg>,
|
||||
/// Bindings (equality constraints) on associated types, if present.
|
||||
/// E.g., `Foo<A=Bar>`.
|
||||
pub bindings: HirVec<TypeBinding>,
|
||||
|
|
@ -391,7 +391,7 @@ pub struct PathParameters {
|
|||
pub parenthesized: bool,
|
||||
}
|
||||
|
||||
impl PathParameters {
|
||||
impl GenericArgs {
|
||||
pub fn none() -> Self {
|
||||
Self {
|
||||
parameters: HirVec::new(),
|
||||
|
|
@ -406,33 +406,33 @@ impl PathParameters {
|
|||
|
||||
pub fn inputs(&self) -> &[P<Ty>] {
|
||||
if self.parenthesized {
|
||||
if let Some(ref ty) = self.types().get(0) {
|
||||
if let Some(ref ty) = self.types().next() {
|
||||
if let TyTup(ref tys) = ty.node {
|
||||
return tys;
|
||||
}
|
||||
}
|
||||
}
|
||||
bug!("PathParameters::inputs: not a `Fn(T) -> U`");
|
||||
bug!("GenericArgs::inputs: not a `Fn(T) -> U`");
|
||||
}
|
||||
|
||||
pub fn lifetimes(&self) -> Vec<&Lifetime> {
|
||||
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> {
|
||||
self.parameters.iter().filter_map(|p| {
|
||||
if let PathParam::Lifetime(lt) = p {
|
||||
if let GenericArg::Lifetime(lt) = p {
|
||||
Some(lt)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn types(&self) -> Vec<&P<Ty>> {
|
||||
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> {
|
||||
self.parameters.iter().filter_map(|p| {
|
||||
if let PathParam::Type(ty) = p {
|
||||
if let GenericArg::Type(ty) = p {
|
||||
Some(ty)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -562,11 +562,11 @@ impl Generics {
|
|||
self.params.iter().any(|param| param.is_type_param())
|
||||
}
|
||||
|
||||
pub fn lifetimes<'a>(&'a self) -> impl Iterator<Item = &'a LifetimeDef> {
|
||||
pub fn lifetimes<'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a LifetimeDef> {
|
||||
self.params.lifetimes()
|
||||
}
|
||||
|
||||
pub fn ty_params<'a>(&'a self) -> impl Iterator<Item = &'a TyParam> {
|
||||
pub fn ty_params<'a>(&'a self) -> impl DoubleEndedIterator<Item = &'a TyParam> {
|
||||
self.params.ty_params()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ use syntax_pos::{self, BytePos, FileName};
|
|||
|
||||
use hir;
|
||||
use hir::{PatKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier, RangeEnd};
|
||||
use hir::PathParam;
|
||||
use hir::GenericArg;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::io::{self, Write, Read};
|
||||
|
|
@ -1273,7 +1273,7 @@ impl<'a> State<'a> {
|
|||
if !parameters.parameters.is_empty() ||
|
||||
!parameters.bindings.is_empty()
|
||||
{
|
||||
self.print_path_parameters(¶meters, segment.infer_types, true)
|
||||
self.print_generic_args(¶meters, segment.infer_types, true)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1642,7 +1642,7 @@ impl<'a> State<'a> {
|
|||
segment.name != keywords::DollarCrate.name() {
|
||||
self.print_name(segment.name)?;
|
||||
segment.with_parameters(|parameters| {
|
||||
self.print_path_parameters(parameters,
|
||||
self.print_generic_args(parameters,
|
||||
segment.infer_types,
|
||||
colons_before_params)
|
||||
})?;
|
||||
|
|
@ -1674,7 +1674,7 @@ impl<'a> State<'a> {
|
|||
segment.name != keywords::DollarCrate.name() {
|
||||
self.print_name(segment.name)?;
|
||||
segment.with_parameters(|parameters| {
|
||||
self.print_path_parameters(parameters,
|
||||
self.print_generic_args(parameters,
|
||||
segment.infer_types,
|
||||
colons_before_params)
|
||||
})?;
|
||||
|
|
@ -1686,7 +1686,7 @@ impl<'a> State<'a> {
|
|||
let item_segment = path.segments.last().unwrap();
|
||||
self.print_name(item_segment.name)?;
|
||||
item_segment.with_parameters(|parameters| {
|
||||
self.print_path_parameters(parameters,
|
||||
self.print_generic_args(parameters,
|
||||
item_segment.infer_types,
|
||||
colons_before_params)
|
||||
})
|
||||
|
|
@ -1698,7 +1698,7 @@ impl<'a> State<'a> {
|
|||
self.s.word("::")?;
|
||||
self.print_name(item_segment.name)?;
|
||||
item_segment.with_parameters(|parameters| {
|
||||
self.print_path_parameters(parameters,
|
||||
self.print_generic_args(parameters,
|
||||
item_segment.infer_types,
|
||||
colons_before_params)
|
||||
})
|
||||
|
|
@ -1706,19 +1706,19 @@ impl<'a> State<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_path_parameters(&mut self,
|
||||
path_params: &hir::PathParameters,
|
||||
fn print_generic_args(&mut self,
|
||||
generic_args: &hir::GenericArgs,
|
||||
infer_types: bool,
|
||||
colons_before_params: bool)
|
||||
-> io::Result<()> {
|
||||
if path_params.parenthesized {
|
||||
if generic_args.parenthesized {
|
||||
self.s.word("(")?;
|
||||
self.commasep(Inconsistent, path_params.inputs(), |s, ty| s.print_type(&ty))?;
|
||||
self.commasep(Inconsistent, generic_args.inputs(), |s, ty| s.print_type(&ty))?;
|
||||
self.s.word(")")?;
|
||||
|
||||
self.space_if_not_bol()?;
|
||||
self.word_space("->")?;
|
||||
self.print_type(&path_params.bindings[0].ty)?;
|
||||
self.print_type(&generic_args.bindings[0].ty)?;
|
||||
} else {
|
||||
let start = if colons_before_params { "::<" } else { "<" };
|
||||
let empty = Cell::new(true);
|
||||
|
|
@ -1731,30 +1731,20 @@ impl<'a> State<'a> {
|
|||
}
|
||||
};
|
||||
|
||||
let elide_lifetimes = path_params.parameters.iter().all(|p| {
|
||||
if let PathParam::Lifetime(lt) = p {
|
||||
if !lt.is_elided() {
|
||||
return false;
|
||||
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| {
|
||||
match p {
|
||||
GenericArg::Lifetime(lt) => s.print_lifetime(lt),
|
||||
GenericArg::Type(ty) => s.print_type(ty),
|
||||
}
|
||||
}
|
||||
true
|
||||
});
|
||||
|
||||
self.commasep(Inconsistent, &path_params.parameters, |s, p| {
|
||||
match p {
|
||||
PathParam::Lifetime(lt) => {
|
||||
if !elide_lifetimes {
|
||||
s.print_lifetime(lt)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
PathParam::Type(ty) => s.print_type(ty),
|
||||
}
|
||||
})?;
|
||||
|
||||
if !path_params.parameters.is_empty() {
|
||||
empty.set(false);
|
||||
})?;
|
||||
} else if generic_args.types().count() != 0 {
|
||||
start_or_comma(self)?;
|
||||
self.commasep(Inconsistent,
|
||||
&generic_args.types().collect::<Vec<_>>(),
|
||||
|s, ty| s.print_type(&ty))?;
|
||||
}
|
||||
|
||||
// FIXME(eddyb) This would leak into error messages, e.g.:
|
||||
|
|
@ -1764,7 +1754,7 @@ impl<'a> State<'a> {
|
|||
self.s.word("..")?;
|
||||
}
|
||||
|
||||
for binding in path_params.bindings.iter() {
|
||||
for binding in generic_args.bindings.iter() {
|
||||
start_or_comma(self)?;
|
||||
self.print_name(binding.name)?;
|
||||
self.s.space()?;
|
||||
|
|
|
|||
|
|
@ -180,12 +180,12 @@ impl_stable_hash_for!(struct hir::PathSegment {
|
|||
parameters
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(enum hir::PathParam {
|
||||
impl_stable_hash_for!(enum hir::GenericArg {
|
||||
Lifetime(lt),
|
||||
Type(ty)
|
||||
});
|
||||
|
||||
impl_stable_hash_for!(struct hir::PathParameters {
|
||||
impl_stable_hash_for!(struct hir::GenericArgs {
|
||||
parameters,
|
||||
bindings,
|
||||
parenthesized
|
||||
|
|
|
|||
|
|
@ -1603,7 +1603,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
&mut self,
|
||||
def: Def,
|
||||
depth: usize,
|
||||
params: &'tcx hir::PathParameters,
|
||||
params: &'tcx hir::GenericArgs,
|
||||
) {
|
||||
if params.parenthesized {
|
||||
let was_in_fn_syntax = self.is_in_fn_syntax;
|
||||
|
|
@ -1613,10 +1613,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
if params.lifetimes().iter().all(|l| l.is_elided()) {
|
||||
self.resolve_elided_lifetimes(params.lifetimes(), true);
|
||||
if params.lifetimes().all(|l| l.is_elided()) {
|
||||
self.resolve_elided_lifetimes(params.lifetimes().collect(), true);
|
||||
} else {
|
||||
for l in ¶ms.lifetimes() {
|
||||
for l in params.lifetimes() {
|
||||
self.visit_lifetime(l);
|
||||
}
|
||||
}
|
||||
|
|
@ -1688,13 +1688,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
} else {
|
||||
Some(Region::Static)
|
||||
},
|
||||
Set1::One(r) => r.subst(params.lifetimes(), map),
|
||||
Set1::One(r) => r.subst(params.lifetimes().collect(), map),
|
||||
Set1::Many => None,
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
|
||||
for (i, ty) in params.types().iter().enumerate() {
|
||||
for (i, ty) in params.types().enumerate() {
|
||||
if let Some(<) = object_lifetime_defaults.get(i) {
|
||||
let scope = Scope::ObjectLifetimeDefault {
|
||||
lifetime: lt,
|
||||
|
|
|
|||
|
|
@ -1009,24 +1009,24 @@ impl<'a, 'gcx, 'tcx> Generics {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn lifetimes(&self) -> Vec<&RegionParameterDef> {
|
||||
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &RegionParameterDef> {
|
||||
self.parameters.iter().filter_map(|p| {
|
||||
if let GenericParam::Lifetime(lt) = p {
|
||||
Some(lt)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn types(&self) -> Vec<&TypeParameterDef> {
|
||||
pub fn types(&self) -> impl DoubleEndedIterator<Item = &TypeParameterDef> {
|
||||
self.parameters.iter().filter_map(|p| {
|
||||
if let GenericParam::Type(ty) = p {
|
||||
Some(ty)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parent_lifetimes(&self) -> u32 {
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ impl<'tcx> From<Ty<'tcx>> for Kind<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Into<Kind<'tcx>> for ty::Region<'tcx> {}
|
||||
|
||||
impl<'tcx> Into<Kind<'tcx>> for Ty<'tcx> {}
|
||||
|
||||
impl<'tcx> Kind<'tcx> {
|
||||
#[inline]
|
||||
pub fn unpack(self) -> UnpackedKind<'tcx> {
|
||||
|
|
|
|||
|
|
@ -679,10 +679,10 @@ impl<'a> ReplaceBodyWithLoop<'a> {
|
|||
ast::TyKind::Path(_, ref path) => path.segments.iter().any(|seg| {
|
||||
match seg.parameters.as_ref().map(|p| &**p) {
|
||||
None => false,
|
||||
Some(&ast::PathParameters::AngleBracketed(ref data)) =>
|
||||
Some(&ast::GenericArgs::AngleBracketed(ref data)) =>
|
||||
any_involves_impl_trait(data.types().into_iter()) ||
|
||||
any_involves_impl_trait(data.bindings.iter().map(|b| &b.ty)),
|
||||
Some(&ast::PathParameters::Parenthesized(ref data)) =>
|
||||
Some(&ast::GenericArgs::Parenthesized(ref data)) =>
|
||||
any_involves_impl_trait(data.inputs.iter()) ||
|
||||
any_involves_impl_trait(data.output.iter()),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -822,10 +822,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
|
|||
for seg in &path.segments {
|
||||
if let Some(ref params) = seg.parameters {
|
||||
match **params {
|
||||
ast::PathParameters::AngleBracketed(ref data) => for t in data.types() {
|
||||
ast::GenericArgs::AngleBracketed(ref data) => for t in data.types() {
|
||||
self.visit_ty(t);
|
||||
},
|
||||
ast::PathParameters::Parenthesized(ref data) => {
|
||||
ast::GenericArgs::Parenthesized(ref data) => {
|
||||
for t in &data.inputs {
|
||||
self.visit_ty(t);
|
||||
}
|
||||
|
|
@ -906,7 +906,7 @@ 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::PathParameters::AngleBracketed(ref data) = **params {
|
||||
if let ast::GenericArgs::AngleBracketed(ref data) = **params {
|
||||
for t in data.types() {
|
||||
self.visit_ty(t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -693,7 +693,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
|||
return false;
|
||||
}
|
||||
if let Some(ref params) = path.segments[0].parameters {
|
||||
if let ast::PathParameters::Parenthesized(_) = **params {
|
||||
if let ast::GenericArgs::Parenthesized(_) = **params {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::PathParameters,
|
||||
parameters: &hir::GenericArgs,
|
||||
infer_types: bool,
|
||||
self_ty: Option<Ty<'tcx>>)
|
||||
-> (&'tcx Substs<'tcx>, Vec<ConvertedBinding<'tcx>>)
|
||||
|
|
@ -973,13 +973,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
segment.with_parameters(|params| {
|
||||
for p in ¶ms.parameters {
|
||||
let (mut span_err, span, kind) = match p {
|
||||
hir::PathParam::Lifetime(lt) => {
|
||||
hir::GenericArg::Lifetime(lt) => {
|
||||
(struct_span_err!(self.tcx().sess, lt.span, E0110,
|
||||
"lifetime parameters are not allowed on this type"),
|
||||
lt.span,
|
||||
"lifetime")
|
||||
}
|
||||
hir::PathParam::Type(ty) => {
|
||||
hir::GenericArg::Type(ty) => {
|
||||
(struct_span_err!(self.tcx().sess, ty.span, E0109,
|
||||
"type parameters are not allowed on this type"),
|
||||
ty.span,
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
|
|||
let method_generics = self.tcx.generics_of(pick.item.def_id);
|
||||
let mut fn_segment = Some((segment, method_generics));
|
||||
let supress_mismatch = self.fcx.check_impl_trait(self.span, fn_segment);
|
||||
self.fcx.check_path_parameter_count(self.span, &mut fn_segment, true, supress_mismatch);
|
||||
self.fcx.check_generic_arg_count(self.span, &mut fn_segment, true, supress_mismatch);
|
||||
|
||||
// Create subst for early-bound lifetime parameters, combining
|
||||
// parameters from the type and those from the method.
|
||||
|
|
|
|||
|
|
@ -4800,8 +4800,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
// to add defaults. If the user provided *too many* types, that's
|
||||
// a problem.
|
||||
let supress_mismatch = self.check_impl_trait(span, fn_segment);
|
||||
self.check_path_parameter_count(span, &mut type_segment, false, supress_mismatch);
|
||||
self.check_path_parameter_count(span, &mut fn_segment, false, supress_mismatch);
|
||||
self.check_generic_arg_count(span, &mut type_segment, false, supress_mismatch);
|
||||
self.check_generic_arg_count(span, &mut fn_segment, false, supress_mismatch);
|
||||
|
||||
let (fn_start, has_self) = match (type_segment, fn_segment) {
|
||||
(_, Some((_, generics))) => {
|
||||
|
|
@ -4955,7 +4955,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
/// Report errors if the provided parameters are too few or too many.
|
||||
fn check_path_parameter_count(&self,
|
||||
fn check_generic_arg_count(&self,
|
||||
span: Span,
|
||||
segment: &mut Option<(&hir::PathSegment, &ty::Generics)>,
|
||||
is_method_call: bool,
|
||||
|
|
@ -4964,7 +4964,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
(vec![], vec![], true, &[][..]),
|
||||
|(s, _)| s.parameters.as_ref().map_or(
|
||||
(vec![], vec![], s.infer_types, &[][..]),
|
||||
|p| (p.lifetimes(), p.types(),
|
||||
|p| (p.lifetimes().collect(), p.types().collect(),
|
||||
s.infer_types, &p.bindings[..])));
|
||||
let infer_lifetimes = lifetimes.len() == 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -1558,8 +1558,8 @@ impl Clean<TyParamBound> for hir::TyParamBound {
|
|||
}
|
||||
}
|
||||
|
||||
fn external_path_params(cx: &DocContext, trait_did: Option<DefId>, has_self: bool,
|
||||
bindings: Vec<TypeBinding>, substs: &Substs) -> PathParameters {
|
||||
fn external_generic_args(cx: &DocContext, trait_did: Option<DefId>, has_self: bool,
|
||||
bindings: Vec<TypeBinding>, substs: &Substs) -> GenericArgs {
|
||||
let lifetimes = substs.regions().filter_map(|v| v.clean(cx)).collect();
|
||||
let types = substs.types().skip(has_self as usize).collect::<Vec<_>>();
|
||||
|
||||
|
|
@ -1570,7 +1570,7 @@ fn external_path_params(cx: &DocContext, trait_did: Option<DefId>, has_self: boo
|
|||
let inputs = match types[0].sty {
|
||||
ty::TyTuple(ref tys) => tys.iter().map(|t| t.clean(cx)).collect(),
|
||||
_ => {
|
||||
return PathParameters::AngleBracketed {
|
||||
return GenericArgs::AngleBracketed {
|
||||
lifetimes,
|
||||
types: types.clean(cx),
|
||||
bindings,
|
||||
|
|
@ -1583,13 +1583,13 @@ fn external_path_params(cx: &DocContext, trait_did: Option<DefId>, has_self: boo
|
|||
// ty::TyTuple(ref v) if v.is_empty() => None, // -> ()
|
||||
// _ => Some(types[1].clean(cx))
|
||||
// };
|
||||
PathParameters::Parenthesized {
|
||||
GenericArgs::Parenthesized {
|
||||
inputs,
|
||||
output,
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
PathParameters::AngleBracketed {
|
||||
GenericArgs::AngleBracketed {
|
||||
lifetimes,
|
||||
types: types.clean(cx),
|
||||
bindings,
|
||||
|
|
@ -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_path_params(cx, trait_did, has_self, bindings, substs)
|
||||
params: 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 PathParameters::AngleBracketed { ref types, .. } = seg.params {
|
||||
if let GenericArgs::AngleBracketed { ref types, .. } = seg.params {
|
||||
Some(&**types)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -3447,7 +3447,7 @@ impl Path {
|
|||
def: Def::Err,
|
||||
segments: vec![PathSegment {
|
||||
name,
|
||||
params: PathParameters::AngleBracketed {
|
||||
params: GenericArgs::AngleBracketed {
|
||||
lifetimes: Vec::new(),
|
||||
types: Vec::new(),
|
||||
bindings: Vec::new(),
|
||||
|
|
@ -3471,8 +3471,8 @@ impl Clean<Path> for hir::Path {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum PathParameters {
|
||||
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eg, Debug, Hash)]
|
||||
pub enum GenericArgs {
|
||||
AngleBracketed {
|
||||
lifetimes: Vec<Lifetime>,
|
||||
types: Vec<Type>,
|
||||
|
|
@ -3484,22 +3484,22 @@ pub enum PathParameters {
|
|||
}
|
||||
}
|
||||
|
||||
impl Clean<PathParameters> for hir::PathParameters {
|
||||
fn clean(&self, cx: &DocContext) -> PathParameters {
|
||||
impl Clean<GenericArgs> for hir::GenericArgs {
|
||||
fn clean(&self, cx: &DocContext) -> GenericArgs {
|
||||
if self.parenthesized {
|
||||
let output = self.bindings[0].ty.clean(cx);
|
||||
PathParameters::Parenthesized {
|
||||
GenericArgs::Parenthesized {
|
||||
inputs: self.inputs().clean(cx),
|
||||
output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None }
|
||||
}
|
||||
} else {
|
||||
PathParameters::AngleBracketed {
|
||||
lifetimes: if self.lifetimes().iter().all(|lt| lt.is_elided()) {
|
||||
GenericArgs::AngleBracketed {
|
||||
lifetimes: if self.lifetimes().all(|lt| lt.is_elided()) {
|
||||
vec![]
|
||||
} else {
|
||||
self.lifetimes().iter().map(|lp| lp.clean(cx)).collect()
|
||||
self.lifetimes().map(|lp| lp.clean(cx)).collect()
|
||||
},
|
||||
types: self.types().iter().map(|tp| tp.clean(cx)).collect(),
|
||||
types: self.types().map(|tp| tp.clean(cx)).collect(),
|
||||
bindings: self.bindings.clean(cx),
|
||||
}
|
||||
}
|
||||
|
|
@ -3509,7 +3509,7 @@ impl Clean<PathParameters> for hir::PathParameters {
|
|||
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
|
||||
pub struct PathSegment {
|
||||
pub name: String,
|
||||
pub params: PathParameters,
|
||||
pub params: GenericArgs,
|
||||
}
|
||||
|
||||
impl Clean<PathSegment> for hir::PathSegment {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use std::collections::BTreeMap;
|
|||
use rustc::hir::def_id::DefId;
|
||||
use rustc::ty;
|
||||
|
||||
use clean::PathParameters as PP;
|
||||
use clean::GenericArgs as PP;
|
||||
use clean::WherePredicate as WP;
|
||||
use clean;
|
||||
use core::DocContext;
|
||||
|
|
|
|||
|
|
@ -288,10 +288,10 @@ impl fmt::Display for clean::TyParamBound {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for clean::PathParameters {
|
||||
impl fmt::Display for clean::GenericArgs {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
clean::PathParameters::AngleBracketed {
|
||||
clean::GenericArgs::AngleBracketed {
|
||||
ref lifetimes, ref types, ref bindings
|
||||
} => {
|
||||
if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() {
|
||||
|
|
@ -337,7 +337,7 @@ impl fmt::Display for clean::PathParameters {
|
|||
}
|
||||
}
|
||||
}
|
||||
clean::PathParameters::Parenthesized { ref inputs, ref output } => {
|
||||
clean::GenericArgs::Parenthesized { ref inputs, ref output } => {
|
||||
f.write_str("(")?;
|
||||
let mut comma = false;
|
||||
for ty in inputs {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
pub use self::TyParamBound::*;
|
||||
pub use self::UnsafeSource::*;
|
||||
pub use self::PathParameters::*;
|
||||
pub use self::GenericArgs::*;
|
||||
pub use symbol::{Ident, Symbol as Name};
|
||||
pub use util::ThinVec;
|
||||
pub use util::parser::ExprPrecedence;
|
||||
|
|
@ -135,7 +135,7 @@ 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<PathParameters>>,
|
||||
pub parameters: Option<P<GenericArgs>>,
|
||||
}
|
||||
|
||||
impl PathSegment {
|
||||
|
|
@ -151,14 +151,14 @@ impl PathSegment {
|
|||
///
|
||||
/// 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 PathParameters {
|
||||
pub enum GenericArgs {
|
||||
/// The `<'a, A,B,C>` in `foo::bar::baz::<'a, A,B,C>`
|
||||
AngleBracketed(AngleBracketedParameterData),
|
||||
/// The `(A,B)` and `C` in `Foo(A,B) -> C`
|
||||
Parenthesized(ParenthesizedParameterData),
|
||||
}
|
||||
|
||||
impl PathParameters {
|
||||
impl GenericArgs {
|
||||
pub fn span(&self) -> Span {
|
||||
match *self {
|
||||
AngleBracketed(ref data) => data.span,
|
||||
|
|
@ -187,36 +187,36 @@ pub struct AngleBracketedParameterData {
|
|||
}
|
||||
|
||||
impl AngleBracketedParameterData {
|
||||
pub fn lifetimes(&self) -> Vec<&Lifetime> {
|
||||
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &Lifetime> {
|
||||
self.parameters.iter().filter_map(|p| {
|
||||
if let AngleBracketedParam::Lifetime(lt) = p {
|
||||
Some(lt)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn types(&self) -> Vec<&P<Ty>> {
|
||||
pub fn types(&self) -> impl DoubleEndedIterator<Item = &P<Ty>> {
|
||||
self.parameters.iter().filter_map(|p| {
|
||||
if let AngleBracketedParam::Type(ty) = p {
|
||||
Some(ty)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Option<P<PathParameters>>> for AngleBracketedParameterData {
|
||||
fn into(self) -> Option<P<PathParameters>> {
|
||||
Some(P(PathParameters::AngleBracketed(self)))
|
||||
impl Into<Option<P<GenericArgs>>> for AngleBracketedParameterData {
|
||||
fn into(self) -> Option<P<GenericArgs>> {
|
||||
Some(P(GenericArgs::AngleBracketed(self)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Option<P<PathParameters>>> for ParenthesizedParameterData {
|
||||
fn into(self) -> Option<P<PathParameters>> {
|
||||
Some(P(PathParameters::Parenthesized(self)))
|
||||
impl Into<Option<P<GenericArgs>>> for ParenthesizedParameterData {
|
||||
fn into(self) -> Option<P<GenericArgs>> {
|
||||
Some(P(GenericArgs::Parenthesized(self)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -133,7 +133,11 @@ pub trait Folder : Sized {
|
|||
}
|
||||
|
||||
fn fold_param(&mut self, p: AngleBracketedParam) -> AngleBracketedParam {
|
||||
noop_fold_param(p, self)
|
||||
match p {
|
||||
AngleBracketedParam::Lifetime(lt) =>
|
||||
AngleBracketedParam::Lifetime(self.fold_lifetime(lt)),
|
||||
AngleBracketedParam::Type(ty) => AngleBracketedParam::Type(self.fold_ty(ty)),
|
||||
}
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, t: P<Ty>) -> P<Ty> {
|
||||
|
|
@ -176,8 +180,8 @@ pub trait Folder : Sized {
|
|||
noop_fold_qpath(qs, p, self)
|
||||
}
|
||||
|
||||
fn fold_path_parameters(&mut self, p: PathParameters) -> PathParameters {
|
||||
noop_fold_path_parameters(p, self)
|
||||
fn fold_generic_args(&mut self, p: GenericArgs) -> GenericArgs {
|
||||
noop_fold_generic_args(p, self)
|
||||
}
|
||||
|
||||
fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedParameterData)
|
||||
|
|
@ -357,19 +361,6 @@ pub fn noop_fold_ty_binding<T: Folder>(b: TypeBinding, fld: &mut T) -> TypeBindi
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_param<T: Folder>(p: AngleBracketedParam,
|
||||
fld: &mut T)
|
||||
-> AngleBracketedParam {
|
||||
match p {
|
||||
AngleBracketedParam::Lifetime(lt) => {
|
||||
AngleBracketedParam::Lifetime(noop_fold_lifetime(lt, fld))
|
||||
}
|
||||
AngleBracketedParam::Type(ty) => {
|
||||
AngleBracketedParam::Type(noop_fold_ty(ty, fld))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
|
||||
t.map(|Ty {id, node, span}| Ty {
|
||||
id: fld.new_id(id),
|
||||
|
|
@ -452,7 +443,7 @@ pub fn noop_fold_path<T: Folder>(Path { segments, span }: Path, fld: &mut T) ->
|
|||
Path {
|
||||
segments: segments.move_map(|PathSegment {ident, parameters}| PathSegment {
|
||||
ident: fld.fold_ident(ident),
|
||||
parameters: parameters.map(|ps| ps.map(|ps| fld.fold_path_parameters(ps))),
|
||||
parameters: parameters.map(|ps| ps.map(|ps| fld.fold_generic_args(ps))),
|
||||
}),
|
||||
span: fld.new_span(span)
|
||||
}
|
||||
|
|
@ -471,14 +462,14 @@ pub fn noop_fold_qpath<T: Folder>(qself: Option<QSelf>,
|
|||
(qself, fld.fold_path(path))
|
||||
}
|
||||
|
||||
pub fn noop_fold_path_parameters<T: Folder>(path_parameters: PathParameters, fld: &mut T)
|
||||
-> PathParameters
|
||||
pub fn noop_fold_generic_args<T: Folder>(generic_args: GenericArgs, fld: &mut T)
|
||||
-> GenericArgs
|
||||
{
|
||||
match path_parameters {
|
||||
PathParameters::AngleBracketed(data) =>
|
||||
PathParameters::AngleBracketed(fld.fold_angle_bracketed_parameter_data(data)),
|
||||
PathParameters::Parenthesized(data) =>
|
||||
PathParameters::Parenthesized(fld.fold_parenthesized_parameter_data(data)),
|
||||
match generic_args {
|
||||
GenericArgs::AngleBracketed(data) =>
|
||||
GenericArgs::AngleBracketed(fld.fold_angle_bracketed_parameter_data(data)),
|
||||
GenericArgs::Parenthesized(data) =>
|
||||
GenericArgs::Parenthesized(fld.fold_parenthesized_parameter_data(data)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1201,7 +1192,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
|
|||
PathSegment {
|
||||
ident: folder.fold_ident(seg.ident),
|
||||
parameters: seg.parameters.map(|ps| {
|
||||
ps.map(|ps| folder.fold_path_parameters(ps))
|
||||
ps.map(|ps| folder.fold_generic_args(ps))
|
||||
}),
|
||||
},
|
||||
folder.fold_exprs(args))
|
||||
|
|
|
|||
|
|
@ -1992,7 +1992,7 @@ impl<'a> State<'a> {
|
|||
self.s.word(".")?;
|
||||
self.print_ident(segment.ident)?;
|
||||
if let Some(ref parameters) = segment.parameters {
|
||||
self.print_path_parameters(parameters, true)?;
|
||||
self.print_generic_args(parameters, true)?;
|
||||
}
|
||||
self.print_call_post(base_args)
|
||||
}
|
||||
|
|
@ -2436,7 +2436,7 @@ impl<'a> State<'a> {
|
|||
segment.ident.name != keywords::DollarCrate.name() {
|
||||
self.print_ident(segment.ident)?;
|
||||
if let Some(ref parameters) = segment.parameters {
|
||||
self.print_path_parameters(parameters, colons_before_params)?;
|
||||
self.print_generic_args(parameters, colons_before_params)?;
|
||||
}
|
||||
} else if segment.ident.name == keywords::DollarCrate.name() {
|
||||
self.print_dollar_crate(segment.ident.span.ctxt())?;
|
||||
|
|
@ -2463,13 +2463,13 @@ impl<'a> State<'a> {
|
|||
let item_segment = path.segments.last().unwrap();
|
||||
self.print_ident(item_segment.ident)?;
|
||||
match item_segment.parameters {
|
||||
Some(ref parameters) => self.print_path_parameters(parameters, colons_before_params),
|
||||
Some(ref parameters) => self.print_generic_args(parameters, colons_before_params),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_path_parameters(&mut self,
|
||||
parameters: &ast::PathParameters,
|
||||
fn print_generic_args(&mut self,
|
||||
parameters: &ast::GenericArgs,
|
||||
colons_before_params: bool)
|
||||
-> io::Result<()>
|
||||
{
|
||||
|
|
@ -2478,7 +2478,7 @@ impl<'a> State<'a> {
|
|||
}
|
||||
|
||||
match *parameters {
|
||||
ast::PathParameters::AngleBracketed(ref data) => {
|
||||
ast::GenericArgs::AngleBracketed(ref data) => {
|
||||
self.s.word("<")?;
|
||||
|
||||
self.commasep(Inconsistent, &data.parameters, |s, p| s.print_param(p))?;
|
||||
|
|
@ -2499,7 +2499,7 @@ impl<'a> State<'a> {
|
|||
self.s.word(">")?
|
||||
}
|
||||
|
||||
ast::PathParameters::Parenthesized(ref data) => {
|
||||
ast::GenericArgs::Parenthesized(ref data) => {
|
||||
self.s.word("(")?;
|
||||
self.commasep(
|
||||
Inconsistent,
|
||||
|
|
|
|||
|
|
@ -137,9 +137,9 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
|||
self.count += 1;
|
||||
walk_use_tree(self, use_tree, id)
|
||||
}
|
||||
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &PathParameters) {
|
||||
fn visit_generic_args(&mut self, path_span: Span, generic_args: &GenericArgs) {
|
||||
self.count += 1;
|
||||
walk_path_parameters(self, path_span, path_parameters)
|
||||
walk_generic_args(self, path_span, generic_args)
|
||||
}
|
||||
fn visit_assoc_type_binding(&mut self, type_binding: &TypeBinding) {
|
||||
self.count += 1;
|
||||
|
|
|
|||
|
|
@ -128,8 +128,14 @@ pub trait Visitor<'ast>: Sized {
|
|||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
|
||||
walk_path_segment(self, path_span, path_segment)
|
||||
}
|
||||
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'ast PathParameters) {
|
||||
walk_path_parameters(self, path_span, path_parameters)
|
||||
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) {
|
||||
match param {
|
||||
AngleBracketedParam::Lifetime(lt) => self.visit_lifetime(lt),
|
||||
AngleBracketedParam::Type(ty) => self.visit_ty(ty),
|
||||
}
|
||||
}
|
||||
fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) {
|
||||
walk_assoc_type_binding(self, type_binding)
|
||||
|
|
@ -376,22 +382,21 @@ pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V,
|
|||
segment: &'a PathSegment) {
|
||||
visitor.visit_ident(segment.ident);
|
||||
if let Some(ref parameters) = segment.parameters {
|
||||
visitor.visit_path_parameters(path_span, parameters);
|
||||
visitor.visit_generic_args(path_span, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_path_parameters<'a, V>(visitor: &mut V,
|
||||
_path_span: Span,
|
||||
path_parameters: &'a PathParameters)
|
||||
pub fn walk_generic_args<'a, V>(visitor: &mut V,
|
||||
_path_span: Span,
|
||||
generic_args: &'a GenericArgs)
|
||||
where V: Visitor<'a>,
|
||||
{
|
||||
match *path_parameters {
|
||||
PathParameters::AngleBracketed(ref data) => {
|
||||
walk_list!(visitor, visit_lifetime, data.lifetimes());
|
||||
walk_list!(visitor, visit_ty, data.types());
|
||||
match *generic_args {
|
||||
GenericArgs::AngleBracketed(ref data) => {
|
||||
walk_list!(visitor, visit_angle_bracketed_param, &data.parameters);
|
||||
walk_list!(visitor, visit_assoc_type_binding, &data.bindings);
|
||||
}
|
||||
PathParameters::Parenthesized(ref data) => {
|
||||
GenericArgs::Parenthesized(ref data) => {
|
||||
walk_list!(visitor, visit_ty, &data.inputs);
|
||||
walk_list!(visitor, visit_ty, &data.output);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ struct S04_TyParamBound(S05_PolyTraitRef);
|
|||
struct S05_PolyTraitRef(S06_TraitRef);
|
||||
struct S06_TraitRef(S07_Path);
|
||||
struct S07_Path(Vec<S08_PathSegment>);
|
||||
struct S08_PathSegment(S09_PathParameters);
|
||||
struct S09_PathParameters(P<S10_ParenthesizedParameterData>);
|
||||
struct S08_PathSegment(S09_GenericArgs);
|
||||
struct S09_GenericArgs(P<S10_ParenthesizedParameterData>);
|
||||
struct S10_ParenthesizedParameterData(Option<P<S11_Ty>>);
|
||||
struct S11_Ty(P<S12_Expr>);
|
||||
struct S12_Expr(P<S13_Block>);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#![feature(generic_associated_types)]
|
||||
|
||||
//FIXME(#44265): "lifetime parameter not allowed on this type" errors will be addressed in a
|
||||
//FIXME(#44265): "lifetime parameter not allowed" errors will be addressed in a
|
||||
// follow-up PR
|
||||
|
||||
use std::fmt::Display;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue