X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fparser%2Fsrc%2Fgrammar%2Fpaths.rs;h=0cc0ed31aaf05940fe5a8e18fb10fd6cc0a44729;hb=55c0b86cdec534aa0397e3d69335265cbfd0f5c3;hp=5d297e2d62b56020e5410ca82ee6d2ecbd573bab;hpb=dddc4c6370ab8e7684352302a5ff282673c6e8ec;p=rust.git diff --git a/crates/parser/src/grammar/paths.rs b/crates/parser/src/grammar/paths.rs index 5d297e2d62b..0cc0ed31aaf 100644 --- a/crates/parser/src/grammar/paths.rs +++ b/crates/parser/src/grammar/paths.rs @@ -1,5 +1,3 @@ -//! FIXME: write short doc here - use super::*; pub(super) const PATH_FIRST: TokenSet = @@ -18,15 +16,19 @@ pub(super) fn is_use_path_start(p: &Parser) -> bool { } pub(super) fn use_path(p: &mut Parser) { - path(p, Mode::Use) + path(p, Mode::Use); } pub(crate) fn type_path(p: &mut Parser) { - path(p, Mode::Type) + path(p, Mode::Type); } pub(super) fn expr_path(p: &mut Parser) { - path(p, Mode::Expr) + path(p, Mode::Expr); +} + +pub(crate) fn type_path_for_qualifier(p: &mut Parser, qual: CompletedMarker) -> CompletedMarker { + path_for_qualifier(p, Mode::Type, qual) } #[derive(Clone, Copy, Eq, PartialEq)] @@ -39,7 +41,11 @@ enum Mode { fn path(p: &mut Parser, mode: Mode) { let path = p.start(); path_segment(p, mode, true); - let mut qual = path.complete(p, PATH); + let qual = path.complete(p, PATH); + path_for_qualifier(p, mode, qual); +} + +fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) -> CompletedMarker { loop { let use_tree = matches!(p.nth(2), T![*] | T!['{']); if p.at(T![::]) && !use_tree { @@ -49,7 +55,7 @@ fn path(p: &mut Parser, mode: Mode) { let path = path.complete(p, PATH); qual = path; } else { - break; + return qual; } } } @@ -82,7 +88,11 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { } // test crate_path // use crate::foo; - T![self] | T![super] | T![crate] => p.bump_any(), + T![self] | T![super] | T![crate] => { + let m = p.start(); + p.bump_any(); + m.complete(p, NAME_REF); + } _ => { p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); if empty { @@ -107,9 +117,9 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) { params::param_list_fn_trait(p); opt_ret_type(p); } else { - type_args::opt_generic_arg_list(p, false) + generic_args::opt_generic_arg_list(p, false); } } - Mode::Expr => type_args::opt_generic_arg_list(p, true), + Mode::Expr => generic_args::opt_generic_arg_list(p, true), } }