From 0e8e45c74068b72301f9045f0efc38ba8b51e0a4 Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Mon, 8 May 2017 22:29:24 +0900 Subject: [PATCH] Allow bare CR in ////-style comment. --- src/libsyntax/parse/lexer/mod.rs | 2 +- .../lex-bare-cr-string-literal-doc-comment.rs | 6 ++++++ .../run-pass/lex-bare-cr-nondoc-comment.rs | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/lex-bare-cr-nondoc-comment.rs diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 7d2a1b3c4a4d2..ded1f0b599a61 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -504,7 +504,7 @@ impl<'a> StringReader<'a> { self.bump(); // line comments starting with "///" or "//!" are doc-comments - let doc_comment = self.ch_is('/') || self.ch_is('!'); + let doc_comment = (self.ch_is('/') && !self.nextch_is('/')) || self.ch_is('!'); let start_bpos = self.pos - BytePos(2); while !self.is_eof() { diff --git a/src/test/parse-fail/lex-bare-cr-string-literal-doc-comment.rs b/src/test/parse-fail/lex-bare-cr-string-literal-doc-comment.rs index f894305754319..ac085d475114e 100644 --- a/src/test/parse-fail/lex-bare-cr-string-literal-doc-comment.rs +++ b/src/test/parse-fail/lex-bare-cr-string-literal-doc-comment.rs @@ -21,6 +21,12 @@ pub fn bar() {} //~^^ ERROR: bare CR not allowed in block doc-comment fn main() { + //! doc comment with bare CR: ' ' + //~^ ERROR: bare CR not allowed in doc-comment + + /*! block doc comment with bare CR: ' ' */ + //~^ ERROR: bare CR not allowed in block doc-comment + // the following string literal has a bare CR in it let _s = "foo bar"; //~ ERROR: bare CR not allowed in string diff --git a/src/test/run-pass/lex-bare-cr-nondoc-comment.rs b/src/test/run-pass/lex-bare-cr-nondoc-comment.rs new file mode 100644 index 0000000000000..ba949ca88814d --- /dev/null +++ b/src/test/run-pass/lex-bare-cr-nondoc-comment.rs @@ -0,0 +1,18 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-tidy-cr + +// nondoc comment with bare CR: ' ' +//// nondoc comment with bare CR: ' ' +/* block nondoc comment with bare CR: ' ' */ + +fn main() { +}