mirror of
https://gitee.com/openharmony/third_party_rust_syn
synced 2024-11-30 11:20:26 +00:00
ObjectSum and PolyTraitRef types
This commit is contained in:
parent
1241783c01
commit
6414da71fb
45
src/ty.rs
45
src/ty.rs
@ -195,12 +195,15 @@ pub enum FunctionRetTy {
|
||||
#[cfg(feature = "parsing")]
|
||||
pub mod parsing {
|
||||
use super::*;
|
||||
use {TraitBoundModifier, TyParamBound};
|
||||
use constant::parsing::const_expr;
|
||||
use generics::parsing::{lifetime, lifetime_def, ty_param_bound, bound_lifetimes};
|
||||
use ident::parsing::ident;
|
||||
use std::str;
|
||||
|
||||
named!(pub ty -> Ty, alt!(
|
||||
ty_poly_trait_ref // must be before ty_path
|
||||
|
|
||||
ty_vec
|
||||
|
|
||||
ty_array
|
||||
@ -296,7 +299,18 @@ pub mod parsing {
|
||||
(Ty::Tup(elems))
|
||||
));
|
||||
|
||||
named!(ty_path -> Ty, map!(qpath, |(qself, p)| Ty::Path(qself, p)));
|
||||
named!(ty_path -> Ty, do_parse!(
|
||||
qpath: qpath >>
|
||||
bounds: many0!(preceded!(punct!("+"), ty_param_bound)) >>
|
||||
({
|
||||
let path = Ty::Path(qpath.0, qpath.1);
|
||||
if bounds.is_empty() {
|
||||
path
|
||||
} else {
|
||||
Ty::ObjectSum(Box::new(path), bounds)
|
||||
}
|
||||
})
|
||||
));
|
||||
|
||||
named!(pub qpath -> (Option<QSelf>, Path), alt!(
|
||||
map!(path, |p| (None, p))
|
||||
@ -329,6 +343,23 @@ pub mod parsing {
|
||||
)
|
||||
));
|
||||
|
||||
named!(ty_poly_trait_ref -> Ty, do_parse!(
|
||||
keyword!("for") >>
|
||||
punct!("<") >>
|
||||
lifetimes: separated_list!(punct!(","), lifetime_def) >>
|
||||
punct!(">") >>
|
||||
trait_ref: path >>
|
||||
(Ty::PolyTraitRef(vec![
|
||||
TyParamBound::Trait(
|
||||
PolyTraitRef {
|
||||
bound_lifetimes: lifetimes,
|
||||
trait_ref: trait_ref,
|
||||
},
|
||||
TraitBoundModifier::None,
|
||||
),
|
||||
]))
|
||||
));
|
||||
|
||||
named!(ty_impl_trait -> Ty, do_parse!(
|
||||
keyword!("impl") >>
|
||||
elem: separated_nonempty_list!(punct!("+"), ty_param_bound) >>
|
||||
@ -490,8 +521,16 @@ mod printing {
|
||||
segment.to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
Ty::ObjectSum(_, _) => unimplemented!(),
|
||||
Ty::PolyTraitRef(_) => unimplemented!(),
|
||||
Ty::ObjectSum(ref ty, ref bounds) => {
|
||||
ty.to_tokens(tokens);
|
||||
for bound in bounds {
|
||||
tokens.append("+");
|
||||
bound.to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
Ty::PolyTraitRef(ref bounds) => {
|
||||
tokens.append_separated(bounds, "+");
|
||||
}
|
||||
Ty::ImplTrait(ref bounds) => {
|
||||
tokens.append("impl");
|
||||
tokens.append_separated(bounds, "+");
|
||||
|
@ -1,3 +1,7 @@
|
||||
const A: usize = unimplemented!();
|
||||
|
||||
const A: [T; std::u16::MAX as usize] = unimplemented!();
|
||||
|
||||
const A: for<'a> A<&'a B> = unimplemented!();
|
||||
|
||||
const A: Box<A + 'a> = unimplemented!();
|
||||
|
Loading…
Reference in New Issue
Block a user