Skip to content

Commit

Permalink
Fix review nits
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed Apr 6, 2024
1 parent e8ff942 commit 273ce09
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
1 change: 0 additions & 1 deletion crates/parser2/src/ast/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,6 @@ mod tests {
let u: Use = parse_item(source);
let use_tree = u.use_tree().unwrap();
let mut count = 0;
dbg!(use_tree.path().unwrap());
for segment in use_tree.path().unwrap() {
match count {
0 => {
Expand Down
5 changes: 3 additions & 2 deletions crates/parser2/src/parser/expr_atom.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::convert::Infallible;

use rowan::Checkpoint;
use unwrap_infallible::UnwrapInfallible;

use crate::{
parser::{lit, path},
Expand Down Expand Up @@ -40,9 +41,9 @@ pub(super) fn parse_expr_atom<S: TokenStream>(
Some(LBrace) => parser.parse_cp(BlockExprScope::default(), None),
Some(LParen) => parser.parse_cp(ParenScope::default(), None),
Some(LBracket) => parser.parse_cp(ArrayScope::default(), None),
Some(kind) if lit::is_lit(kind) => parser
Some(kind) if lit::is_lit(kind) => Ok(parser
.parse_cp(LitExprScope::default(), None)
.map_err(|e| e.into()),
.unwrap_infallible()),
Some(kind) if path::is_path_segment(kind) => {
parser.parse_cp(PathExprScope::new(allow_record_init), None)
}
Expand Down
13 changes: 0 additions & 13 deletions crates/parser2/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub struct Parser<S: TokenStream> {
stream: BackTrackableTokenStream<S>,

builder: rowan::GreenNodeBuilder<'static>,
/// The second element holds `is_newline_trivia` of the parent.
parents: Vec<ScopeEntry>,
errors: Vec<ParseError>,

Expand Down Expand Up @@ -641,18 +640,6 @@ impl Recovery<()> {
#[derive(Debug)]
pub struct ErrProof(());

impl<T> From<Infallible> for Recovery<T> {
fn from(_value: Infallible) -> Self {
unreachable!()
}
}

impl From<Recovery<ErrProof>> for Recovery<()> {
fn from(r: Recovery<ErrProof>) -> Self {
Recovery(r.0, ())
}
}

pub trait Recoverable {
fn is_local_recovery<S: TokenStream>(&self, _parser: &Parser<S>) -> bool {
false
Expand Down
8 changes: 6 additions & 2 deletions crates/parser2/src/parser/param.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::convert::Infallible;

use unwrap_infallible::UnwrapInfallible;

use crate::{ExpectedKind, ParseError, SyntaxKind};

use super::{
Expand Down Expand Up @@ -224,7 +226,9 @@ fn parse_kind_bound<S: TokenStream>(parser: &mut Parser<S>) -> Result<(), Recove
parser.bump();
}
} else if parser.current_kind() == Some(SyntaxKind::Star) {
parser.parse(KindBoundMonoScope::default())?;
parser
.parse(KindBoundMonoScope::default())
.unwrap_infallible();
} else {
// guaranteed by `expected`, unless other recovery
// other tokens are added to the current scope
Expand Down Expand Up @@ -309,7 +313,7 @@ impl super::Parse for GenericArgScope {

Some(kind) if kind.is_literal_leaf() => {
self.set_kind(SyntaxKind::ConstGenericArg);
parser.parse(LitExprScope::default())?;
parser.parse(LitExprScope::default()).unwrap_infallible();
}

_ => {
Expand Down
18 changes: 12 additions & 6 deletions crates/parser2/src/parser/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::convert::Infallible;

use unwrap_infallible::UnwrapInfallible;

use crate::{ExpectedKind, SyntaxKind};

use super::{
Expand All @@ -19,12 +21,16 @@ pub fn parse_stmt<S: TokenStream>(parser: &mut Parser<S>) -> Result<(), Recovery
Some(LetKw) => parser.parse(LetStmtScope::default()),
Some(ForKw) => parser.parse(ForStmtScope::default()),
Some(WhileKw) => parser.parse(WhileStmtScope::default()),
Some(ContinueKw) => parser
.parse(ContinueStmtScope::default())
.map_err(|e| e.into()),
Some(BreakKw) => parser
.parse(BreakStmtScope::default())
.map_err(|e| e.into()),
Some(ContinueKw) => {
parser
.parse(ContinueStmtScope::default())
.unwrap_infallible();
Ok(())
}
Some(BreakKw) => {
parser.parse(BreakStmtScope::default()).unwrap_infallible();
Ok(())
}
Some(ReturnKw) => parser.parse(ReturnStmtScope::default()),
_ => parser.parse(ExprStmtScope::default()),
}
Expand Down

0 comments on commit 273ce09

Please sign in to comment.