mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Merge #7211
7211: Fixed expr meta var after path colons in mbe r=matklad a=edwin0cheng Fixes #7207 Added `L_DOLLAR` in `ITEM_RECOVERY_SET` , but I don't know whether it is a good idea. r? @matklad Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
commit
d76143da19
2 changed files with 35 additions and 4 deletions
|
@ -1,7 +1,11 @@
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use ::parser::FragmentKind;
|
use ::parser::FragmentKind;
|
||||||
use syntax::{ast, AstNode, NodeOrToken, SyntaxKind::IDENT, SyntaxNode, WalkEvent, T};
|
use syntax::{
|
||||||
|
ast, AstNode, NodeOrToken,
|
||||||
|
SyntaxKind::{ERROR, IDENT},
|
||||||
|
SyntaxNode, WalkEvent, T,
|
||||||
|
};
|
||||||
use test_utils::assert_eq_text;
|
use test_utils::assert_eq_text;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -1194,6 +1198,23 @@ macro_rules! foo {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_expr_after_path_colons() {
|
||||||
|
assert!(parse_macro(
|
||||||
|
r#"
|
||||||
|
macro_rules! m {
|
||||||
|
($k:expr) => {
|
||||||
|
f(K::$k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.expand_statements(r#"m!(C("0"))"#)
|
||||||
|
.descendants()
|
||||||
|
.find(|token| token.kind() == ERROR)
|
||||||
|
.is_some());
|
||||||
|
}
|
||||||
|
|
||||||
// The following tests are based on real world situations
|
// The following tests are based on real world situations
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec() {
|
fn test_vec() {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use drop_bomb::DropBomb;
|
||||||
use crate::{
|
use crate::{
|
||||||
event::Event,
|
event::Event,
|
||||||
ParseError,
|
ParseError,
|
||||||
SyntaxKind::{self, EOF, ERROR, TOMBSTONE},
|
SyntaxKind::{self, EOF, ERROR, L_DOLLAR, R_DOLLAR, TOMBSTONE},
|
||||||
TokenSet, TokenSource, T,
|
TokenSet, TokenSource, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -215,13 +215,23 @@ impl<'t> Parser<'t> {
|
||||||
|
|
||||||
/// Create an error node and consume the next token.
|
/// Create an error node and consume the next token.
|
||||||
pub(crate) fn err_and_bump(&mut self, message: &str) {
|
pub(crate) fn err_and_bump(&mut self, message: &str) {
|
||||||
|
match self.current() {
|
||||||
|
L_DOLLAR | R_DOLLAR => {
|
||||||
|
let m = self.start();
|
||||||
|
self.error(message);
|
||||||
|
self.bump_any();
|
||||||
|
m.complete(self, ERROR);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
self.err_recover(message, TokenSet::EMPTY);
|
self.err_recover(message, TokenSet::EMPTY);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Create an error node and consume the next token.
|
/// Create an error node and consume the next token.
|
||||||
pub(crate) fn err_recover(&mut self, message: &str, recovery: TokenSet) {
|
pub(crate) fn err_recover(&mut self, message: &str, recovery: TokenSet) {
|
||||||
match self.current() {
|
match self.current() {
|
||||||
T!['{'] | T!['}'] => {
|
T!['{'] | T!['}'] | L_DOLLAR | R_DOLLAR => {
|
||||||
self.error(message);
|
self.error(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue