mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 03:33:59 +00:00
Change parsing bounds in path_types
Now bounds inside a path are parsed as DYN_TRAIT_TYPE, previously they would be parsed as `PATH_TYPE` followed by `TYPE_BOUND_LIST`. Basically this means `Box<T + 'f>` is now parsed almost the same as `Box<dyn T + 'f>` with the exception of not having the `dyn` keyword.
This commit is contained in:
parent
e3f9d6555b
commit
98cff6ecec
@ -79,16 +79,19 @@ fn lifetime_bounds(p: &mut Parser) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn bounds_without_colon(p: &mut Parser) {
|
pub(super) fn bounds_without_colon_m(p: &mut Parser, marker: Marker) -> CompletedMarker {
|
||||||
let m = p.start();
|
|
||||||
|
|
||||||
while type_bound(p) {
|
while type_bound(p) {
|
||||||
if !p.eat(PLUS) {
|
if !p.eat(PLUS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.complete(p, TYPE_BOUND_LIST);
|
marker.complete(p, TYPE_BOUND_LIST)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn bounds_without_colon(p: &mut Parser) {
|
||||||
|
let m = p.start();
|
||||||
|
bounds_without_colon_m(p, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_bound(p: &mut Parser) -> bool {
|
fn type_bound(p: &mut Parser) -> bool {
|
||||||
|
@ -261,21 +261,47 @@ fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
|
|||||||
PATH_TYPE
|
PATH_TYPE
|
||||||
};
|
};
|
||||||
|
|
||||||
if allow_bounds && p.eat(PLUS) {
|
let path = m.complete(p, kind);
|
||||||
type_params::bounds_without_colon(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
m.complete(p, kind);
|
if allow_bounds {
|
||||||
|
opt_path_type_bounds_as_dyn_trait_type(p, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
|
pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
|
||||||
assert!(paths::is_path_start(p) || p.at(L_ANGLE));
|
assert!(paths::is_path_start(p) || p.at(L_ANGLE));
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
paths::type_path(p);
|
paths::type_path(p);
|
||||||
|
|
||||||
// test path_type_with_bounds
|
// test path_type_with_bounds
|
||||||
// fn foo() -> Box<T + 'f> {}
|
// fn foo() -> Box<T + 'f> {}
|
||||||
if allow_bounds && p.eat(PLUS) {
|
// fn foo() -> Box<dyn T + 'f> {}
|
||||||
type_params::bounds_without_colon(p);
|
let path = m.complete(p, PATH_TYPE);
|
||||||
|
if allow_bounds {
|
||||||
|
opt_path_type_bounds_as_dyn_trait_type(p, path);
|
||||||
}
|
}
|
||||||
m.complete(p, PATH_TYPE);
|
}
|
||||||
|
|
||||||
|
/// This turns a parsed PATH_TYPE optionally into a DYN_TRAIT_TYPE
|
||||||
|
/// with a TYPE_BOUND_LIST
|
||||||
|
fn opt_path_type_bounds_as_dyn_trait_type(p: &mut Parser, path_type_marker: CompletedMarker) {
|
||||||
|
if !p.at(PLUS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First create a TYPE_BOUND from the completed PATH_TYPE
|
||||||
|
let m = path_type_marker.precede(p).complete(p, TYPE_BOUND);
|
||||||
|
|
||||||
|
// Next setup a marker for the TYPE_BOUND_LIST
|
||||||
|
let m = m.precede(p);
|
||||||
|
|
||||||
|
// This gets consumed here so it gets properly set
|
||||||
|
// in the TYPE_BOUND_LIST
|
||||||
|
p.eat(PLUS);
|
||||||
|
|
||||||
|
// Parse rest of the bounds into the TYPE_BOUND_LIST
|
||||||
|
let m = type_params::bounds_without_colon_m(p, m);
|
||||||
|
|
||||||
|
// Finally precede everything with DYN_TRAIT_TYPE
|
||||||
|
m.precede(p).complete(p, DYN_TRAIT_TYPE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user