diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index ec335e7b4339..02fee25aad82 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -743,7 +743,7 @@ pub fn span_extend_prev_while( let n = s[..start] .char_indices() .rfind(|&(_, c)| !f(c)) - .map_or(start, |(i, _)| start - i - 1); + .map_or(start, |(i, c)| start - i - c.len_utf8()); Ok(span.with_lo(span.lo() - BytePos(n as u32))) }) } diff --git a/tests/ui/span/span-extend-prev-while-multibyte.rs b/tests/ui/span/span-extend-prev-while-multibyte.rs new file mode 100644 index 000000000000..292699d6aa3e --- /dev/null +++ b/tests/ui/span/span-extend-prev-while-multibyte.rs @@ -0,0 +1,10 @@ +//@ build-pass +// Regression test for https://github.com/rust-lang/rust/issues/155037 +#![feature(associated_type_defaults)] + +trait Trait { + type 否 where = (); + //~^ WARNING where clause not allowed here +} + +fn main() {} diff --git a/tests/ui/span/span-extend-prev-while-multibyte.stderr b/tests/ui/span/span-extend-prev-while-multibyte.stderr new file mode 100644 index 000000000000..20232baa992b --- /dev/null +++ b/tests/ui/span/span-extend-prev-while-multibyte.stderr @@ -0,0 +1,16 @@ +warning: where clause not allowed here + --> $DIR/span-extend-prev-while-multibyte.rs:6:12 + | +LL | type 否 where = (); + | ^^^^^ + | + = note: see issue #89122 for more information + = note: `#[warn(deprecated_where_clause_location)]` on by default +help: move it to the end of the type declaration + | +LL - type 否 where = (); +LL + type 否 = () where; + | + +warning: 1 warning emitted +