From e8fb46090e938d52f2637c973e1e13886289ee3d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 2 Jun 2020 14:13:03 +0200 Subject: [PATCH 1/2] Create new error code E0758 for unterminated multi-line comments --- src/librustc_error_codes/error_codes.rs | 1 + src/librustc_error_codes/error_codes/E0758.md | 20 +++++++++++++++++++ src/librustc_parse/lexer/mod.rs | 10 +++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/librustc_error_codes/error_codes/E0758.md diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 7abe75a375a0b..760b4d7ba00a3 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -437,6 +437,7 @@ E0751: include_str!("./error_codes/E0751.md"), E0752: include_str!("./error_codes/E0752.md"), E0753: include_str!("./error_codes/E0753.md"), E0754: include_str!("./error_codes/E0754.md"), +E0758: include_str!("./error_codes/E0758.md"), E0760: include_str!("./error_codes/E0760.md"), ; // E0006, // merged with E0005 diff --git a/src/librustc_error_codes/error_codes/E0758.md b/src/librustc_error_codes/error_codes/E0758.md new file mode 100644 index 0000000000000..ddca4b3d75f77 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0758.md @@ -0,0 +1,20 @@ +A multi-line (doc-)comment is unterminated. + +Erroneous code example: + +```compile_fail,E0758 +/* I am not terminated! +``` + +The same goes for doc comments: + +```compile_fail,E0758 +/*! I am not terminated! +``` + +You need to end your multi-line comment with `*/` in order to fix this error: + +``` +/* I am terminated! */ +/*! I am also terminated! */ +``` diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 7e59f06e44ae3..9bc6a50acad04 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -191,7 +191,15 @@ impl<'a> StringReader<'a> { "unterminated block comment" }; let last_bpos = self.pos; - self.fatal_span_(start, last_bpos, msg).raise(); + self.sess + .span_diagnostic + .struct_span_fatal_with_code( + self.mk_sp(start, last_bpos), + msg, + error_code!(E0758), + ) + .emit(); + FatalError.raise(); } if is_doc_comment { From fbf7d27791c524c60637ff2b7e738494e6dfaef5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 2 Jun 2020 14:16:46 +0200 Subject: [PATCH 2/2] Add tests for E0758 --- src/test/ui/unterminated-comment.rs | 1 + src/test/ui/unterminated-comment.stderr | 9 +++++++++ src/test/ui/unterminated-doc-comment.rs | 1 + src/test/ui/unterminated-doc-comment.stderr | 9 +++++++++ 4 files changed, 20 insertions(+) create mode 100644 src/test/ui/unterminated-comment.rs create mode 100644 src/test/ui/unterminated-comment.stderr create mode 100644 src/test/ui/unterminated-doc-comment.rs create mode 100644 src/test/ui/unterminated-doc-comment.stderr diff --git a/src/test/ui/unterminated-comment.rs b/src/test/ui/unterminated-comment.rs new file mode 100644 index 0000000000000..1cfdfb1fb4575 --- /dev/null +++ b/src/test/ui/unterminated-comment.rs @@ -0,0 +1 @@ +/* //~ ERROR E0758 diff --git a/src/test/ui/unterminated-comment.stderr b/src/test/ui/unterminated-comment.stderr new file mode 100644 index 0000000000000..c513fafeeb35c --- /dev/null +++ b/src/test/ui/unterminated-comment.stderr @@ -0,0 +1,9 @@ +error[E0758]: unterminated block comment + --> $DIR/unterminated-comment.rs:1:1 + | +LL | /* + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0758`. diff --git a/src/test/ui/unterminated-doc-comment.rs b/src/test/ui/unterminated-doc-comment.rs new file mode 100644 index 0000000000000..82546fe73da4f --- /dev/null +++ b/src/test/ui/unterminated-doc-comment.rs @@ -0,0 +1 @@ +/*! //~ ERROR E0758 diff --git a/src/test/ui/unterminated-doc-comment.stderr b/src/test/ui/unterminated-doc-comment.stderr new file mode 100644 index 0000000000000..2d5e537973ea8 --- /dev/null +++ b/src/test/ui/unterminated-doc-comment.stderr @@ -0,0 +1,9 @@ +error[E0758]: unterminated block doc-comment + --> $DIR/unterminated-doc-comment.rs:1:1 + | +LL | /*! + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0758`.