Skip to content

Commit e9f5a09

Browse files
committed
Add an ignore! macro, remove support for nested block comments, re: #2755.
1 parent 249668f commit e9f5a09

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

src/libcore/dvec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ impl<A: copy> DVec<A> {
235235
}
236236
}
237237
238-
/*
239238
/**
240239
* Append all elements of an iterable.
241240
*
242241
* Failure will occur if the iterable's `each()` method
243242
* attempts to access this vector.
244243
*/
244+
/*
245245
fn append_iter<A, I:iter::base_iter<A>>(ts: I) {
246246
do self.swap |v| {
247247
let mut v = match ts.size_hint() {

src/libsyntax/ext/expand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ fn new_span(cx: ext_ctxt, sp: span) -> span {
243243
fn core_macros() -> ~str {
244244
return
245245
~"{
246+
macro_rules! ignore (($($x:tt)*) => (()))
246247
#macro[[#error[f, ...], log(core::error, #fmt[f, ...])]];
247248
#macro[[#warn[f, ...], log(core::warn, #fmt[f, ...])]];
248249
#macro[[#info[f, ...], log(core::info, #fmt[f, ...])]];

src/libsyntax/parse/lexer.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -267,21 +267,16 @@ fn consume_block_comment(rdr: string_reader)
267267
sp: ast_util::mk_sp(start_chpos, rdr.chpos)
268268
});
269269
}
270-
}
271-
272-
let mut level: int = 1;
273-
while level > 0 {
274-
if is_eof(rdr) { rdr.fatal(~"unterminated block comment"); }
275-
if rdr.curr == '/' && nextch(rdr) == '*' {
276-
bump(rdr);
277-
bump(rdr);
278-
level += 1;
279-
} else {
270+
} else {
271+
loop {
272+
if is_eof(rdr) { rdr.fatal(~"unterminated block comment"); }
280273
if rdr.curr == '*' && nextch(rdr) == '/' {
281274
bump(rdr);
282275
bump(rdr);
283-
level -= 1;
284-
} else { bump(rdr); }
276+
break;
277+
} else {
278+
bump(rdr);
279+
}
285280
}
286281
}
287282
// restart whitespace munch.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// error-pattern:
2+
3+
/* This is a test to ensure that we do _not_ support nested/balanced comments. I know you might be
4+
thinking "but nested comments are cool", and that would be a valid point, but they are also a
5+
thing that would make our lexical syntax non-regular, and we do not want that to be true.
6+
7+
omitting-things at a higher level (tokens) should be done via token-trees / macros,
8+
not comments.
9+
10+
/*
11+
fail here
12+
*/
13+
*/
14+
15+
fn main() {
16+
}

src/test/compile-fail/unbalanced-comment.rs

-11
This file was deleted.
+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
2-
3-
41
// -*- rust -*-
52

63
/*
7-
* This is a /* depth-balanced */ multi-line comment.
4+
* This is a multi-line comment.
85
*/
96
fn main() { }

0 commit comments

Comments
 (0)