Skip to content

Commit 2045130

Browse files
committed
fixed remarks
1 parent 468ea83 commit 2045130

File tree

8 files changed

+54
-51
lines changed

8 files changed

+54
-51
lines changed

src/libsyntax/parse/lexer/mod.rs

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a> StringReader<'a> {
167167

168168
fn fail_unterminated_raw_string(&self, start: Span, hash_count: u16, spans: Vec<Span>) -> ! {
169169
const SPAN_THRESHOLD: usize = 3;
170-
const MSG_STR: &str = "Raw string could be meant to end here";
170+
const MSG_STR: &str = "you might have meant to end the raw string here";
171171
let hash_str = format!("\"{}", "#".repeat(hash_count as usize));
172172
let spans_len = spans.len();
173173

@@ -176,15 +176,19 @@ impl<'a> StringReader<'a> {
176176

177177
for s in spans {
178178
if spans_len < SPAN_THRESHOLD {
179-
err.span_suggestion(s,
180-
MSG_STR,
181-
hash_str.clone(),
182-
Applicability::MaybeIncorrect);
179+
err.span_suggestion(
180+
s,
181+
MSG_STR,
182+
hash_str.clone(),
183+
Applicability::MaybeIncorrect
184+
);
183185
} else {
184-
err.tool_only_span_suggestion(s,
185-
MSG_STR,
186-
hash_str.clone(),
187-
Applicability::MaybeIncorrect);
186+
err.tool_only_span_suggestion(
187+
s,
188+
MSG_STR,
189+
hash_str.clone(),
190+
Applicability::MaybeIncorrect
191+
);
188192
}
189193
}
190194

@@ -1329,28 +1333,39 @@ impl<'a> StringReader<'a> {
13291333
while self.ch_is('#') {
13301334
if hash_count == 65535 {
13311335
let bpos = self.next_pos;
1332-
self.fatal_span_(start_bpos,
1333-
bpos,
1334-
"too many `#` symbols: raw strings may be \
1335-
delimited by up to 65535 `#` symbols").raise();
1336+
let msg = match raw_type {
1337+
RawStringType::Unicode => "too many `#` symbols: raw strings may be \
1338+
delimited by up to 65535 `#` symbols",
1339+
RawStringType::Byte => "too many `#` symbols: raw byte strings may be \
1340+
delimited by up to 65535 `#` symbols",
1341+
};
1342+
self.fatal_span_(
1343+
start_bpos,
1344+
bpos,
1345+
msg
1346+
).raise();
13361347
}
13371348
self.bump();
13381349
hash_count += 1;
13391350
}
13401351
let bpos_span = self.mk_sp(start_bpos, self.pos);
13411352

13421353
match self.ch {
1343-
None => self.fail_unterminated_raw_string(bpos_span,
1344-
hash_count,
1345-
vec![self.mk_sp(self.pos, self.pos)]),
1354+
None => self.fail_unterminated_raw_string(
1355+
bpos_span,
1356+
hash_count,
1357+
vec![self.mk_sp(self.pos, self.pos)]
1358+
),
13461359
Some('"') => {},
13471360
Some(c) => {
13481361
let last_bpos = self.pos;
1349-
self.fatal_span_char(start_bpos,
1350-
last_bpos,
1351-
"found invalid character; only `#` is allowed \
1352-
in raw string delimitation",
1353-
c).raise();
1362+
self.fatal_span_char(
1363+
start_bpos,
1364+
last_bpos,
1365+
"found invalid character; only `#` is allowed \
1366+
in raw string delimitation",
1367+
c
1368+
).raise();
13541369
}
13551370
}
13561371

@@ -1363,7 +1378,6 @@ impl<'a> StringReader<'a> {
13631378
'outer: loop {
13641379
match (self.ch, raw_type) {
13651380
(None, _) => {
1366-
spans.push(self.mk_sp(self.pos, self.pos));
13671381
self.fail_unterminated_raw_string(bpos_span, hash_count, spans);
13681382
},
13691383
(Some('"'), _) => {
@@ -1380,10 +1394,11 @@ impl<'a> StringReader<'a> {
13801394
(Some('\r'), RawStringType::Unicode) => {
13811395
if !self.nextch_is('\n') {
13821396
let last_bpos = self.pos;
1383-
self.err_span_(start_bpos,
1384-
last_bpos,
1385-
"bare CR not allowed in raw string, use \\r \
1386-
instead");
1397+
self.err_span_(
1398+
start_bpos,
1399+
last_bpos,
1400+
"bare CR not allowed in raw string, use \\r instead"
1401+
);
13871402
valid = false;
13881403
}
13891404
}
@@ -1412,10 +1427,13 @@ impl<'a> StringReader<'a> {
14121427

14131428
let mut err = self.sess
14141429
.span_diagnostic.struct_span_err(sp, "too many `#` when terminating raw string");
1415-
err.span_label(sp_beg, format!("The raw string has {} leading `#`...", hash_count));
1416-
err.span_label(sp_end,
1417-
format!("...but is closed with {}.",
1418-
self.pos.0 - lo.0 + hash_count as u32));
1430+
err.span_label(sp_beg, format!("this raw string has {} leading `#`...", hash_count));
1431+
err.span_label(
1432+
sp_end,
1433+
format!("...but is closed with {}.",
1434+
self.pos.0 - lo.0 + hash_count as u32
1435+
)
1436+
);
14191437
err.span_suggestion_hidden(
14201438
self.mk_sp(lo, self.pos),
14211439
"remove the unneeded `#`",

src/test/ui/parser/raw/raw-byte-string-eof.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ error: unterminated raw string
33
|
44
LL | br##"a"#;
55
| ^^^^ unterminated raw string
6-
help: Raw string could be meant to end here
6+
help: you might have meant to end the raw string here
77
|
88
LL | br##"a"##;
99
| ^^^
10-
help: Raw string could be meant to end here
11-
|
12-
LL | }"##
13-
| ^^^
1410

1511
error: aborting due to previous error
1612

src/test/ui/parser/raw/raw-literal-too-many-long.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: too many `#` when terminating raw string
22
--> $DIR/raw-literal-too-many-long.rs:2:13
33
|
44
LL | let a = r##"This
5-
| ^-- The raw string has 2 leading `#`...
5+
| ^-- this raw string has 2 leading `#`...
66
| _____________|
77
| |
88
LL | | is

src/test/ui/parser/raw/raw-literal-too-many.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let foo = r##"bar"####;
55
| ^--^^^^^----
66
| | |
77
| | ...but is closed with 4.
8-
| The raw string has 2 leading `#`...
8+
| this raw string has 2 leading `#`...
99
= help: remove the unneeded `#`
1010

1111
error: aborting due to previous error

src/test/ui/parser/raw/raw-str-long.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ error: unterminated raw string
33
|
44
LL | let a = r##"This
55
| ^^^ unterminated raw string
6-
help: Raw string could be meant to end here
6+
help: you might have meant to end the raw string here
77
|
88
LL | "##;
99
| ^^^
10-
help: Raw string could be meant to end here
11-
|
12-
LL | }"##
13-
| ^^^
1410

1511
error: aborting due to previous error
1612

src/test/ui/parser/raw/raw-str-unbalanced.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: too many `#` when terminating raw string
22
--> $DIR/raw-str-unbalanced.rs:2:5
33
|
44
LL | r#"
5-
| ^- The raw string has 1 leading `#`...
5+
| ^- this raw string has 1 leading `#`...
66
| _____|
77
| |
88
LL | | "##;

src/test/ui/parser/raw/raw-str-unterminated.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ error: unterminated raw string
33
|
44
LL | r#" string literal goes on
55
| ^^ unterminated raw string
6-
LL | and on
7-
LL |
8-
| - help: Raw string could be meant to end here: `"#`
96

107
error: aborting due to previous error
118

src/test/ui/parser/raw/raw-str.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ error: unterminated raw string
33
|
44
LL | let x = r##"lol"#;
55
| ^^^ unterminated raw string
6-
help: Raw string could be meant to end here
6+
help: you might have meant to end the raw string here
77
|
88
LL | let x = r##"lol"##;
99
| ^^^
10-
help: Raw string could be meant to end here
11-
|
12-
LL | }"##
13-
| ^^^
1410

1511
error: aborting due to previous error
1612

0 commit comments

Comments
 (0)