mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Merge #1676
1676: Fix for<'lifetime> for types specified by path r=matklad a=eupn Fixes #1467. Co-authored-by: Evgenii P <eupn@protonmail.com>
This commit is contained in:
commit
19e0d7d596
10 changed files with 100 additions and 13 deletions
|
@ -554,7 +554,7 @@ fn arg_list(p: &mut Parser) {
|
|||
// let _ = format!();
|
||||
// }
|
||||
fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
|
||||
assert!(paths::is_path_start(p) || p.at(T![<]));
|
||||
assert!(paths::is_path_start(p));
|
||||
let m = p.start();
|
||||
paths::expr_path(p);
|
||||
match p.current() {
|
||||
|
|
|
@ -62,7 +62,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
|
|||
if let Some(m) = literal(p) {
|
||||
return Some((m, BlockLike::NotBlock));
|
||||
}
|
||||
if paths::is_path_start(p) || p.at(T![<]) {
|
||||
if paths::is_path_start(p) {
|
||||
return Some(path_expr(p, r));
|
||||
}
|
||||
let la = p.nth(1);
|
||||
|
|
|
@ -49,7 +49,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
|
|||
}
|
||||
Err(m) => m,
|
||||
};
|
||||
if paths::is_path_start(p) {
|
||||
if paths::is_use_path_start(p) {
|
||||
match macro_call(p) {
|
||||
BlockLike::Block => (),
|
||||
BlockLike::NotBlock => {
|
||||
|
@ -378,7 +378,7 @@ pub(crate) fn mod_item_list(p: &mut Parser) {
|
|||
}
|
||||
|
||||
fn macro_call(p: &mut Parser) -> BlockLike {
|
||||
assert!(paths::is_path_start(p));
|
||||
assert!(paths::is_use_path_start(p));
|
||||
paths::use_path(p);
|
||||
macro_call_after_excl(p)
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ fn use_tree(p: &mut Parser) {
|
|||
// use crate::Item;
|
||||
// use self::some::Struct;
|
||||
// use crate_name::some_item;
|
||||
_ if paths::is_path_start(p) => {
|
||||
_ if paths::is_use_path_start(p) => {
|
||||
paths::use_path(p);
|
||||
match p.current() {
|
||||
T![as] => {
|
||||
|
|
|
@ -4,6 +4,10 @@ pub(super) const PATH_FIRST: TokenSet =
|
|||
token_set![IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, L_ANGLE];
|
||||
|
||||
pub(super) fn is_path_start(p: &Parser) -> bool {
|
||||
is_use_path_start(p) || p.at(T![<])
|
||||
}
|
||||
|
||||
pub(super) fn is_use_path_start(p: &Parser) -> bool {
|
||||
match p.current() {
|
||||
IDENT | T![self] | T![super] | T![crate] | T![::] => true,
|
||||
_ => false,
|
||||
|
@ -58,7 +62,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
|
|||
if first && p.eat(T![<]) {
|
||||
types::type_(p);
|
||||
if p.eat(T![as]) {
|
||||
if is_path_start(p) {
|
||||
if is_use_path_start(p) {
|
||||
types::path_type(p);
|
||||
} else {
|
||||
p.error("expected a trait");
|
||||
|
|
|
@ -65,7 +65,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
|
|||
{
|
||||
return Some(bind_pat(p, true));
|
||||
}
|
||||
if paths::is_path_start(p) {
|
||||
if paths::is_use_path_start(p) {
|
||||
return Some(path_pat(p));
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker {
|
|||
// let Bar(..) = ();
|
||||
// }
|
||||
fn path_pat(p: &mut Parser) -> CompletedMarker {
|
||||
assert!(paths::is_path_start(p));
|
||||
assert!(paths::is_use_path_start(p));
|
||||
let m = p.start();
|
||||
paths::expr_path(p);
|
||||
let kind = match p.current() {
|
||||
|
|
|
@ -101,7 +101,7 @@ fn type_bound(p: &mut Parser) -> bool {
|
|||
match p.current() {
|
||||
LIFETIME => p.bump(),
|
||||
T![for] => types::for_type(p),
|
||||
_ if paths::is_path_start(p) => types::path_type_(p, false),
|
||||
_ if paths::is_use_path_start(p) => types::path_type_(p, false),
|
||||
_ => {
|
||||
m.abandon(p);
|
||||
return false;
|
||||
|
|
|
@ -29,7 +29,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
|
|||
T![dyn ] => dyn_trait_type(p),
|
||||
// Some path types are not allowed to have bounds (no plus)
|
||||
T![<] => path_type_(p, allow_bounds),
|
||||
_ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds),
|
||||
_ if paths::is_use_path_start(p) => path_or_macro_type_(p, allow_bounds),
|
||||
_ => {
|
||||
p.err_recover("expected type", TYPE_RECOVERY_SET);
|
||||
}
|
||||
|
@ -205,6 +205,7 @@ pub(super) fn for_binder(p: &mut Parser) {
|
|||
// type A = for<'a> fn() -> ();
|
||||
// fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {}
|
||||
// fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {}
|
||||
// fn baz<T>(_t: &T) where for<'a> <&'a T as Baz>::Foo: Iterator {}
|
||||
pub(super) fn for_type(p: &mut Parser) {
|
||||
assert!(p.at(T![for]));
|
||||
let m = p.start();
|
||||
|
@ -251,7 +252,7 @@ pub(super) fn path_type(p: &mut Parser) {
|
|||
// type A = foo!();
|
||||
// type B = crate::foo!();
|
||||
fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
|
||||
assert!(paths::is_path_start(p) || p.at(T![<]));
|
||||
assert!(paths::is_path_start(p));
|
||||
let m = p.start();
|
||||
paths::type_path(p);
|
||||
|
||||
|
@ -270,7 +271,7 @@ fn path_or_macro_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(T![<]));
|
||||
assert!(paths::is_path_start(p));
|
||||
let m = p.start();
|
||||
paths::type_path(p);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue