Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/lib.rs')
-rw-r--r--crates/syntax/src/lib.rs49
1 files changed, 24 insertions, 25 deletions
diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs
index 27c8a13e58..4939ab3904 100644
--- a/crates/syntax/src/lib.rs
+++ b/crates/syntax/src/lib.rs
@@ -19,6 +19,7 @@
//! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256>
//! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md>
+#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
#[allow(unused)]
@@ -74,7 +75,7 @@ pub use smol_str::SmolStr;
#[derive(Debug, PartialEq, Eq)]
pub struct Parse<T> {
green: GreenNode,
- errors: Arc<Vec<SyntaxError>>,
+ errors: Arc<[SyntaxError]>,
_ty: PhantomData<fn() -> T>,
}
@@ -86,7 +87,7 @@ impl<T> Clone for Parse<T> {
impl<T> Parse<T> {
fn new(green: GreenNode, errors: Vec<SyntaxError>) -> Parse<T> {
- Parse { green, errors: Arc::new(errors), _ty: PhantomData }
+ Parse { green, errors: errors.into(), _ty: PhantomData }
}
pub fn syntax_node(&self) -> SyntaxNode {
@@ -106,7 +107,7 @@ impl<T: AstNode> Parse<T> {
T::cast(self.syntax_node()).unwrap()
}
- pub fn ok(self) -> Result<T, Arc<Vec<SyntaxError>>> {
+ pub fn ok(self) -> Result<T, Arc<[SyntaxError]>> {
if self.errors.is_empty() {
Ok(self.tree())
} else {
@@ -143,7 +144,7 @@ impl Parse<SourceFile> {
parsing::incremental_reparse(self.tree().syntax(), indel, self.errors.to_vec()).map(
|(green_node, errors, _reparsed_range)| Parse {
green: green_node,
- errors: Arc::new(errors),
+ errors: errors.into(),
_ty: PhantomData,
},
)
@@ -167,7 +168,7 @@ impl SourceFile {
errors.extend(validation::validate(&root));
assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE);
- Parse { green, errors: Arc::new(errors), _ty: PhantomData }
+ Parse { green, errors: errors.into(), _ty: PhantomData }
}
}
@@ -181,29 +182,27 @@ impl ast::TokenTree {
let kind = t.kind();
if kind.is_trivia() {
was_joint = false
+ } else if kind == SyntaxKind::IDENT {
+ let token_text = t.text();
+ let contextual_kw =
+ SyntaxKind::from_contextual_keyword(token_text).unwrap_or(SyntaxKind::IDENT);
+ parser_input.push_ident(contextual_kw);
} else {
- if kind == SyntaxKind::IDENT {
- let token_text = t.text();
- let contextual_kw = SyntaxKind::from_contextual_keyword(token_text)
- .unwrap_or(SyntaxKind::IDENT);
- parser_input.push_ident(contextual_kw);
- } else {
- if was_joint {
+ if was_joint {
+ parser_input.was_joint();
+ }
+ parser_input.push(kind);
+ // Tag the token as joint if it is float with a fractional part
+ // we use this jointness to inform the parser about what token split
+ // event to emit when we encounter a float literal in a field access
+ if kind == SyntaxKind::FLOAT_NUMBER {
+ if !t.text().ends_with('.') {
parser_input.was_joint();
- }
- parser_input.push(kind);
- // Tag the token as joint if it is float with a fractional part
- // we use this jointness to inform the parser about what token split
- // event to emit when we encounter a float literal in a field access
- if kind == SyntaxKind::FLOAT_NUMBER {
- if !t.text().ends_with('.') {
- parser_input.was_joint();
- } else {
- was_joint = false;
- }
} else {
- was_joint = true;
+ was_joint = false;
}
+ } else {
+ was_joint = true;
}
}
}
@@ -276,7 +275,7 @@ impl ast::TokenTree {
let (green, errors) = builder.finish_raw();
- Parse { green, errors: Arc::new(errors), _ty: PhantomData }
+ Parse { green, errors: errors.into(), _ty: PhantomData }
}
}