From a1df1329ced590a287558510878feb17509e09b5 Mon Sep 17 00:00:00 2001 From: chansuke Date: Thu, 18 Jul 2019 01:43:10 +0900 Subject: [PATCH] Deduplicate some error messages --- src/librustc_mir/const_eval.rs | 11 +++++++---- src/librustc_mir/interpret/intern.rs | 6 +----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 37d4c5b2f09ce..78be2de019ab7 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -527,6 +527,12 @@ pub fn error_to_const_error<'mir, 'tcx>( ConstEvalErr { error: error.kind, stacktrace, span: ecx.tcx.span } } +pub fn note_on_undefined_behavior_error() -> &'static str { + "The rules on what exactly is undefined behavior aren't clear, \ + so this check might be overzealous. Please open an issue on the rust compiler \ + repository if you believe it should not be considered undefined behavior" +} + fn validate_and_turn_into_const<'tcx>( tcx: TyCtxt<'tcx>, constant: RawConst<'tcx>, @@ -567,10 +573,7 @@ fn validate_and_turn_into_const<'tcx>( let err = error_to_const_error(&ecx, error); match err.struct_error(ecx.tcx, "it is undefined behavior to use this value") { Ok(mut diag) => { - diag.note("The rules on what exactly is undefined behavior aren't clear, \ - so this check might be overzealous. Please open an issue on the rust compiler \ - repository if you believe it should not be considered undefined behavior", - ); + diag.note(note_on_undefined_behavior_error()); diag.emit(); ErrorHandled::Reported } diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index bcd36ac547c73..ea32bd0d52ae1 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -297,11 +297,7 @@ pub fn intern_const_alloc_recursive( let err = crate::const_eval::error_to_const_error(&ecx, error); match err.struct_error(ecx.tcx, "it is undefined behavior to use this value") { Ok(mut diag) => { - diag.note("The rules on what exactly is undefined behavior aren't clear, \ - so this check might be overzealous. Please open an issue on the rust \ - compiler repository if you believe it should not be considered \ - undefined behavior", - ); + diag.note(crate::const_eval::note_on_undefined_behavior_error()); diag.emit(); } Err(ErrorHandled::TooGeneric) |