Skip to content

Commit a1df132

Browse files
author
chansuke
committed
Deduplicate some error messages
1 parent f690098 commit a1df132

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/librustc_mir/const_eval.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,12 @@ pub fn error_to_const_error<'mir, 'tcx>(
527527
ConstEvalErr { error: error.kind, stacktrace, span: ecx.tcx.span }
528528
}
529529

530+
pub fn note_on_undefined_behavior_error() -> &'static str {
531+
"The rules on what exactly is undefined behavior aren't clear, \
532+
so this check might be overzealous. Please open an issue on the rust compiler \
533+
repository if you believe it should not be considered undefined behavior"
534+
}
535+
530536
fn validate_and_turn_into_const<'tcx>(
531537
tcx: TyCtxt<'tcx>,
532538
constant: RawConst<'tcx>,
@@ -567,10 +573,7 @@ fn validate_and_turn_into_const<'tcx>(
567573
let err = error_to_const_error(&ecx, error);
568574
match err.struct_error(ecx.tcx, "it is undefined behavior to use this value") {
569575
Ok(mut diag) => {
570-
diag.note("The rules on what exactly is undefined behavior aren't clear, \
571-
so this check might be overzealous. Please open an issue on the rust compiler \
572-
repository if you believe it should not be considered undefined behavior",
573-
);
576+
diag.note(note_on_undefined_behavior_error());
574577
diag.emit();
575578
ErrorHandled::Reported
576579
}

src/librustc_mir/interpret/intern.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,7 @@ pub fn intern_const_alloc_recursive(
297297
let err = crate::const_eval::error_to_const_error(&ecx, error);
298298
match err.struct_error(ecx.tcx, "it is undefined behavior to use this value") {
299299
Ok(mut diag) => {
300-
diag.note("The rules on what exactly is undefined behavior aren't clear, \
301-
so this check might be overzealous. Please open an issue on the rust \
302-
compiler repository if you believe it should not be considered \
303-
undefined behavior",
304-
);
300+
diag.note(crate::const_eval::note_on_undefined_behavior_error());
305301
diag.emit();
306302
}
307303
Err(ErrorHandled::TooGeneric) |

0 commit comments

Comments
 (0)