Skip to content

Commit 2834b16

Browse files
Rollup merge of #155068 - lapla-cogito:multibyte_char, r=mati865
Fix ICE in `span_extend_prev_while` with multibyte characters Fixes #155037 The function assumed that the character found by `rfind` was always one byte wide, using a hardcoded `1` instead of `c.len_utf8()`. When a multibyte character appeared immediately before the span, this caused the resulting span to point into the middle of a UTF-8 sequence, triggering an assertion failure in `bytepos_to_file_charpos`.
2 parents 5daeaa9 + 2754a83 commit 2834b16

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

compiler/rustc_span/src/source_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ impl SourceMap {
743743
let n = s[..start]
744744
.char_indices()
745745
.rfind(|&(_, c)| !f(c))
746-
.map_or(start, |(i, _)| start - i - 1);
746+
.map_or(start, |(i, c)| start - i - c.len_utf8());
747747
Ok(span.with_lo(span.lo() - BytePos(n as u32)))
748748
})
749749
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ build-pass
2+
// Regression test for https://github.com/rust-lang/rust/issues/155037
3+
#![feature(associated_type_defaults)]
4+
5+
trait Trait {
6+
type where = ();
7+
//~^ WARNING where clause not allowed here
8+
}
9+
10+
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: where clause not allowed here
2+
--> $DIR/span-extend-prev-while-multibyte.rs:6:12
3+
|
4+
LL | type 否 where = ();
5+
| ^^^^^
6+
|
7+
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
8+
= note: `#[warn(deprecated_where_clause_location)]` on by default
9+
help: move it to the end of the type declaration
10+
|
11+
LL - type 否 where = ();
12+
LL + type 否 = () where;
13+
|
14+
15+
warning: 1 warning emitted
16+

0 commit comments

Comments
 (0)