Skip to content

Commit cacda2d

Browse files
authored
Rollup merge of rust-lang#68084 - estebank:ice-68000, r=varkor
Do not ICE on unicode next point Use `shrink_to_hi` instead of `next_point` and fix `next_point`. Fix rust-lang#68000, fix rust-lang#68091, fix rust-lang#68092.
2 parents ba14f94 + f6e9fd0 commit cacda2d

16 files changed

+83
-21
lines changed

src/librustc_builtin_macros/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn parse_assert<'a>(
106106
let custom_message =
107107
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
108108
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
109-
let comma_span = cx.source_map().next_point(parser.prev_span);
109+
let comma_span = parser.prev_span.shrink_to_hi();
110110
err.span_suggestion_short(
111111
comma_span,
112112
"try adding a comma",

src/librustc_errors/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl CodeSuggestion {
182182

183183
// Find the bounding span.
184184
let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap();
185-
let hi = substitution.parts.iter().map(|part| part.span.hi()).min().unwrap();
185+
let hi = substitution.parts.iter().map(|part| part.span.hi()).max().unwrap();
186186
let bounding_span = Span::with_root_ctxt(lo, hi);
187187
let lines = cm.span_to_lines(bounding_span).unwrap();
188188
assert!(!lines.lines.is_empty());

src/librustc_expand/mbe/macro_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ pub(super) fn parse(
696696
if parser.token.span.is_dummy() {
697697
parser.token.span
698698
} else {
699-
sess.source_map().next_point(parser.token.span)
699+
parser.token.span.shrink_to_hi()
700700
},
701701
),
702702
"missing tokens in macro arguments",

src/librustc_parse/parser/diagnostics.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,7 @@ impl<'a> Parser<'a> {
259259
};
260260
(
261261
format!("expected one of {}, found {}", expect, actual),
262-
(
263-
self.sess.source_map().next_point(self.prev_span),
264-
format!("expected one of {}", short_expect),
265-
),
262+
(self.prev_span.shrink_to_hi(), format!("expected one of {}", short_expect)),
266263
)
267264
} else if expected.is_empty() {
268265
(
@@ -272,7 +269,7 @@ impl<'a> Parser<'a> {
272269
} else {
273270
(
274271
format!("expected {}, found {}", expect, actual),
275-
(self.sess.source_map().next_point(self.prev_span), format!("expected {}", expect)),
272+
(self.prev_span.shrink_to_hi(), format!("expected {}", expect)),
276273
)
277274
};
278275
self.last_unexpected_token_span = Some(self.token.span);
@@ -803,7 +800,7 @@ impl<'a> Parser<'a> {
803800
_ if self.prev_span == DUMMY_SP => (self.token.span, self.token.span),
804801
// EOF, don't want to point at the following char, but rather the last token.
805802
(token::Eof, None) => (self.prev_span, self.token.span),
806-
_ => (self.sess.source_map().next_point(self.prev_span), self.token.span),
803+
_ => (self.prev_span.shrink_to_hi(), self.token.span),
807804
};
808805
let msg = format!(
809806
"expected `{}`, found {}",
@@ -1126,7 +1123,7 @@ impl<'a> Parser<'a> {
11261123
err.span_label(sp, "unclosed delimiter");
11271124
}
11281125
err.span_suggestion_short(
1129-
self.sess.source_map().next_point(self.prev_span),
1126+
self.prev_span.shrink_to_hi(),
11301127
&format!("{} may belong here", delim.to_string()),
11311128
delim.to_string(),
11321129
Applicability::MaybeIncorrect,

src/librustc_parse/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ impl<'a> Parser<'a> {
16451645
// | |
16461646
// | parsed until here as `"y" & X`
16471647
err.span_suggestion_short(
1648-
cm.next_point(arm_start_span),
1648+
arm_start_span.shrink_to_hi(),
16491649
"missing a comma here to end this `match` arm",
16501650
",".to_owned(),
16511651
Applicability::MachineApplicable,

src/librustc_parse/parser/item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ impl<'a> Parser<'a> {
15101510
}
15111511
}
15121512
_ => {
1513-
let sp = self.sess.source_map().next_point(self.prev_span);
1513+
let sp = self.prev_span.shrink_to_hi();
15141514
let mut err = self.struct_span_err(
15151515
sp,
15161516
&format!("expected `,`, or `}}`, found {}", super::token_descr(&self.token)),
@@ -1649,7 +1649,7 @@ impl<'a> Parser<'a> {
16491649
// it's safe to peel off one character only when it has the close delim
16501650
self.prev_span.with_lo(self.prev_span.hi() - BytePos(1))
16511651
} else {
1652-
self.sess.source_map().next_point(self.prev_span)
1652+
self.prev_span.shrink_to_hi()
16531653
};
16541654

16551655
self.struct_span_err(
@@ -1665,7 +1665,7 @@ impl<'a> Parser<'a> {
16651665
Applicability::MaybeIncorrect,
16661666
)
16671667
.span_suggestion(
1668-
self.sess.source_map().next_point(self.prev_span),
1668+
self.prev_span.shrink_to_hi(),
16691669
"add a semicolon",
16701670
';'.to_string(),
16711671
Applicability::MaybeIncorrect,

src/librustc_parse/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl<'a> Parser<'a> {
765765
break;
766766
}
767767
Err(mut expect_err) => {
768-
let sp = self.sess.source_map().next_point(self.prev_span);
768+
let sp = self.prev_span.shrink_to_hi();
769769
let token_str = pprust::token_kind_to_string(t);
770770

771771
// Attempt to keep parsing if it was a similar separator.

src/librustc_span/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl SourceMap {
710710
pub fn next_point(&self, sp: Span) -> Span {
711711
let start_of_next_point = sp.hi().0;
712712

713-
let width = self.find_width_of_character_at_span(sp, true);
713+
let width = self.find_width_of_character_at_span(sp.shrink_to_hi(), true);
714714
// If the width is 1, then the next span should point to the same `lo` and `hi`. However,
715715
// in the case of a multibyte character, where the width != 1, the next span should
716716
// span multiple bytes to include the whole character.

src/librustc_typeck/check/callee.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
240240
) = (parent_node, callee_node)
241241
{
242242
let start = sp.shrink_to_lo();
243-
let end = self.tcx.sess.source_map().next_point(callee_span);
243+
let end = callee_span.shrink_to_hi();
244244
err.multipart_suggestion(
245245
"if you meant to create this closure and immediately call it, surround the \
246246
closure with parenthesis",
@@ -317,9 +317,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
317317
let call_is_multiline =
318318
self.tcx.sess.source_map().is_multiline(call_expr.span);
319319
if call_is_multiline {
320-
let span = self.tcx.sess.source_map().next_point(callee.span);
321320
err.span_suggestion(
322-
span,
321+
callee.span.shrink_to_hi(),
323322
"try adding a semicolon",
324323
";".to_owned(),
325324
Applicability::MaybeIncorrect,

src/librustc_typeck/check/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4952,9 +4952,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
49524952
| ExprKind::Loop(..)
49534953
| ExprKind::Match(..)
49544954
| ExprKind::Block(..) => {
4955-
let sp = self.tcx.sess.source_map().next_point(cause_span);
49564955
err.span_suggestion(
4957-
sp,
4956+
cause_span.shrink_to_hi(),
49584957
"try adding a semicolon",
49594958
";".to_string(),
49604959
Applicability::MachineApplicable,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub struct Foo {
2+
pub bar: Vec<i32>ö
3+
//~^ ERROR expected `,`, or `}`, found `ö`
4+
} //~ ERROR expected `:`, found `}`
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: expected `,`, or `}`, found `ö`
2+
--> $DIR/issue-68000-unicode-ident-after-missing-comma.rs:2:22
3+
|
4+
LL | pub bar: Vec<i32>ö
5+
| ^ help: try adding a comma: `,`
6+
7+
error: expected `:`, found `}`
8+
--> $DIR/issue-68000-unicode-ident-after-missing-comma.rs:4:1
9+
|
10+
LL | pub bar: Vec<i32>ö
11+
| - expected `:`
12+
LL |
13+
LL | }
14+
| ^ unexpected token
15+
16+
error: aborting due to 2 previous errors
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
macro_rules! x {
2+
($($c:tt)*) => {
3+
$($c)ö* {} //~ ERROR missing condition for `if` expression
4+
}; //~| ERROR mismatched types
5+
}
6+
7+
fn main() {
8+
x!(if);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: missing condition for `if` expression
2+
--> $DIR/issue-68091-unicode-ident-after-if.rs:3:14
3+
|
4+
LL | $($c)ö* {}
5+
| ^ expected if condition here
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/issue-68091-unicode-ident-after-if.rs:3:17
9+
|
10+
LL | $($c)ö* {}
11+
| ^^ expected `bool`, found `()`
12+
...
13+
LL | x!(if);
14+
| ------- in this macro invocation
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
macro_rules! x {
2+
($($c:tt)*) => {
3+
$($c)ö* //~ ERROR macro expansion ends with an incomplete expression: expected expression
4+
};
5+
}
6+
7+
fn main() {
8+
x!(!);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: macro expansion ends with an incomplete expression: expected expression
2+
--> $DIR/issue-68092-unicode-ident-after-incomplete-expr.rs:3:14
3+
|
4+
LL | $($c)ö*
5+
| ^ expected expression
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)