aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirmal Patel <nirmal@nirmal.dev>2022-06-12 19:23:30 -0400
committerNirmal Patel <nirmal@nirmal.dev>2022-06-12 19:23:30 -0400
commit11493cccd7e7fc5ea31e37581323f85eca58ca0c (patch)
treef4d27ee7d37d619511ef1510379d36d320f0ca2a
parente6d32d59f1e6524df667262c509910e44151bbf2 (diff)
downloadgcc-11493cccd7e7fc5ea31e37581323f85eca58ca0c.zip
gcc-11493cccd7e7fc5ea31e37581323f85eca58ca0c.tar.gz
gcc-11493cccd7e7fc5ea31e37581323f85eca58ca0c.tar.bz2
Fix lexing of empty comments continuing till next line
Empty comments (comments without any characters including spaces after //) had a bug during lexing. The lexer did not recheck the current character after skipping / characters. When there was no character after //, the lexer skipped the next newline character. This caused lexer to count the next line as a part of the comment to. This commit fixes this bug by rechecking current character after skipping two / characters. Signed-off-by: Nirmal Patel <nirmal@nirmal.dev>
-rw-r--r--gcc/rust/lex/rust-lex.cc1
-rw-r--r--gcc/testsuite/rust/compile/empty_comment_before_match.rs7
2 files changed, 8 insertions, 0 deletions
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index 023b676..9e0595b 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -489,6 +489,7 @@ Lexer::build_token ()
// (but not an inner or outer doc comment)
skip_input ();
current_column += 2;
+ current_char = peek_input ();
// basically ignore until line finishes
while (current_char != '\n' && current_char != EOF)
diff --git a/gcc/testsuite/rust/compile/empty_comment_before_match.rs b/gcc/testsuite/rust/compile/empty_comment_before_match.rs
new file mode 100644
index 0000000..3d344d3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/empty_comment_before_match.rs
@@ -0,0 +1,7 @@
+fn foo (x: i8) -> i32 { // { dg-warning "function is never used" }
+ //
+ match x {
+ 1 => { return 1; }
+ _ => { return 0; }
+ }
+}