Skip to content

Commit 356d1e9

Browse files
authored
Rollup merge of rust-lang#72772 - RalfJung:valid-char, r=petrochenkov
miri validation: clarify valid values of 'char' The old text said "expected a valid unicode codepoint", which is not actually correct -- it has to be a scalar value (which is a code point that is not part of a surrogate pair).
2 parents 32481bc + f8d3805 commit 356d1e9

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/librustc_mir/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
485485
try_validation!(
486486
value.to_char(),
487487
self.path,
488-
err_ub!(InvalidChar(..)) => { "{}", value } expected { "a valid unicode codepoint" },
488+
err_ub!(InvalidChar(..)) => { "{}", value } expected { "a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)" },
489489
);
490490
Ok(true)
491491
}

src/test/ui/consts/const-eval/ub-enum.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ error[E0080]: it is undefined behavior to use this value
8282
--> $DIR/ub-enum.rs:87:1
8383
|
8484
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
85-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0xffffffff at .<enum-variant(Some)>.0.1, but expected a valid unicode codepoint
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0xffffffff at .<enum-variant(Some)>.0.1, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)
8686
|
8787
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8888

0 commit comments

Comments
 (0)