Skip to content

Conversation

@edwin0cheng
Copy link
Contributor

@edwin0cheng edwin0cheng commented Mar 5, 2020

There is a regression from #3451 such that the following code has failed to parse in raw item collecting phase:

macro_rules! with_std { 
 	($($i:item)*) => ($(#[cfg(feature = "std")]$i)*) 
}

with_std! {
	mod macros;
	mod others;
}

Rationale

We always assume the last token of an statement will not end with a whitespace, which is true. It is because in parsing phase, we always emit SyntaxNode before any whitespace. Such that in various parts of RA code, we solely check the semi-colon by using SyntaxNode::last_child_token() == ";" .

However, in #3451, we insert some whitespaces between puncts such that we broke above assumption. This PR fixed this bug by make sure we don't add any whitespace if it is a semicolon.

@edwin0cheng
Copy link
Contributor Author

edwin0cheng commented Mar 5, 2020

PS: This bug is a pretty hard to trace.... :(

@matklad
Copy link
Contributor

matklad commented Mar 6, 2020

PS: This bug is a pretty hard to trace.... :(

I wonder if we should have

impl SyntaxNode {
    fn check_invariants(&self)
}

which would, for example, check that there's no floating whitespace and which we can debug_assert in macro expansion and parsing

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 6, 2020

@bors bors bot merged commit 670895a into rust-lang:master Mar 6, 2020
@edwin0cheng edwin0cheng deleted the fix-regression branch March 6, 2020 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants