Auto merge of #93179 - Urgau:unreachable-2021, r=m-ou-se,oli-obk
Fix invalid special casing of the unreachable! macro This pull-request fix an invalid special casing of the `unreachable!` macro in the same way the `panic!` macro was solved, by adding two new internal only macros `unreachable_2015` and `unreachable_2021` edition dependent and turn `unreachable!` into a built-in macro that do dispatching. This logic is stolen from the `panic!` macro. ~~This pull-request also adds an internal feature `format_args_capture_non_literal` that allows capturing arguments from formatted string that expanded from macros. The original RFC #2795 mentioned this as a future possibility. This feature is [required](https://github.com/rust-lang/rust/issues/92137#issuecomment-1018630522) because of concatenation that needs to be done inside the macro:~~ ```rust $crate::concat!("internal error: entered unreachable code: ", $fmt) ``` **In summary** the new behavior for the `unreachable!` macro with this pr is: Edition 2021: ```rust let x = 5; unreachable!("x is {x}"); ``` ``` internal error: entered unreachable code: x is 5 ``` Edition <= 2018: ```rust let x = 5; unreachable!("x is {x}"); ``` ``` internal error: entered unreachable code: x is {x} ``` Also note that the change in this PR are **insta-stable** and **breaking changes** but this a considered as being a [bug](https://github.com/rust-lang/rust/issues/92137#issuecomment-998441613). If someone could start a perf run and then a crater run this would be appreciated. Fixes https://github.com/rust-lang/rust/issues/92137
This commit is contained in:
commit
25b21a1d16
22 changed files with 326 additions and 80 deletions
|
@ -1,4 +1,4 @@
|
||||||
use crate::panic::use_panic_2021;
|
use crate::edition_panic::use_panic_2021;
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::token;
|
use rustc_ast::token;
|
||||||
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
|
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
|
||||||
|
|
|
@ -20,8 +20,29 @@ pub fn expand_panic<'cx>(
|
||||||
sp: Span,
|
sp: Span,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
) -> Box<dyn MacResult + 'cx> {
|
) -> Box<dyn MacResult + 'cx> {
|
||||||
let panic = if use_panic_2021(sp) { sym::panic_2021 } else { sym::panic_2015 };
|
let mac = if use_panic_2021(sp) { sym::panic_2021 } else { sym::panic_2015 };
|
||||||
|
expand(mac, cx, sp, tts)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This expands to either
|
||||||
|
// - `$crate::panic::unreachable_2015!(...)` or
|
||||||
|
// - `$crate::panic::unreachable_2021!(...)`
|
||||||
|
// depending on the edition.
|
||||||
|
pub fn expand_unreachable<'cx>(
|
||||||
|
cx: &'cx mut ExtCtxt<'_>,
|
||||||
|
sp: Span,
|
||||||
|
tts: TokenStream,
|
||||||
|
) -> Box<dyn MacResult + 'cx> {
|
||||||
|
let mac = if use_panic_2021(sp) { sym::unreachable_2021 } else { sym::unreachable_2015 };
|
||||||
|
expand(mac, cx, sp, tts)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn expand<'cx>(
|
||||||
|
mac: rustc_span::Symbol,
|
||||||
|
cx: &'cx mut ExtCtxt<'_>,
|
||||||
|
sp: Span,
|
||||||
|
tts: TokenStream,
|
||||||
|
) -> Box<dyn MacResult + 'cx> {
|
||||||
let sp = cx.with_call_site_ctxt(sp);
|
let sp = cx.with_call_site_ctxt(sp);
|
||||||
|
|
||||||
MacEager::expr(
|
MacEager::expr(
|
||||||
|
@ -31,7 +52,7 @@ pub fn expand_panic<'cx>(
|
||||||
path: Path {
|
path: Path {
|
||||||
span: sp,
|
span: sp,
|
||||||
segments: cx
|
segments: cx
|
||||||
.std_path(&[sym::panic, panic])
|
.std_path(&[sym::panic, mac])
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|ident| PathSegment::from_ident(ident))
|
.map(|ident| PathSegment::from_ident(ident))
|
||||||
.collect(),
|
.collect(),
|
|
@ -32,12 +32,12 @@ mod concat_bytes;
|
||||||
mod concat_idents;
|
mod concat_idents;
|
||||||
mod derive;
|
mod derive;
|
||||||
mod deriving;
|
mod deriving;
|
||||||
|
mod edition_panic;
|
||||||
mod env;
|
mod env;
|
||||||
mod format;
|
mod format;
|
||||||
mod format_foreign;
|
mod format_foreign;
|
||||||
mod global_allocator;
|
mod global_allocator;
|
||||||
mod log_syntax;
|
mod log_syntax;
|
||||||
mod panic;
|
|
||||||
mod source_util;
|
mod source_util;
|
||||||
mod test;
|
mod test;
|
||||||
mod trace_macros;
|
mod trace_macros;
|
||||||
|
@ -83,8 +83,9 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
|
||||||
log_syntax: log_syntax::expand_log_syntax,
|
log_syntax: log_syntax::expand_log_syntax,
|
||||||
module_path: source_util::expand_mod,
|
module_path: source_util::expand_mod,
|
||||||
option_env: env::expand_option_env,
|
option_env: env::expand_option_env,
|
||||||
core_panic: panic::expand_panic,
|
core_panic: edition_panic::expand_panic,
|
||||||
std_panic: panic::expand_panic,
|
std_panic: edition_panic::expand_panic,
|
||||||
|
unreachable: edition_panic::expand_unreachable,
|
||||||
stringify: source_util::expand_stringify,
|
stringify: source_util::expand_stringify,
|
||||||
trace_macros: trace_macros::expand_trace_macros,
|
trace_macros: trace_macros::expand_trace_macros,
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,6 @@ language_item_table! {
|
||||||
Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::Exact(0);
|
Panic, sym::panic, panic_fn, Target::Fn, GenericRequirement::Exact(0);
|
||||||
PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn, GenericRequirement::None;
|
PanicFmt, sym::panic_fmt, panic_fmt, Target::Fn, GenericRequirement::None;
|
||||||
PanicDisplay, sym::panic_display, panic_display, Target::Fn, GenericRequirement::None;
|
PanicDisplay, sym::panic_display, panic_display, Target::Fn, GenericRequirement::None;
|
||||||
PanicStr, sym::panic_str, panic_str, Target::Fn, GenericRequirement::None;
|
|
||||||
ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None;
|
ConstPanicFmt, sym::const_panic_fmt, const_panic_fmt, Target::Fn, GenericRequirement::None;
|
||||||
PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::Exact(0);
|
PanicBoundsCheck, sym::panic_bounds_check, panic_bounds_check_fn, Target::Fn, GenericRequirement::Exact(0);
|
||||||
PanicInfo, sym::panic_info, panic_info, Target::Struct, GenericRequirement::None;
|
PanicInfo, sym::panic_info, panic_info, Target::Struct, GenericRequirement::None;
|
||||||
|
|
|
@ -49,9 +49,11 @@ impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
|
||||||
if let hir::ExprKind::Call(f, [arg]) = &expr.kind {
|
if let hir::ExprKind::Call(f, [arg]) = &expr.kind {
|
||||||
if let &ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(f).kind() {
|
if let &ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(f).kind() {
|
||||||
|
let f_diagnostic_name = cx.tcx.get_diagnostic_name(def_id);
|
||||||
|
|
||||||
if Some(def_id) == cx.tcx.lang_items().begin_panic_fn()
|
if Some(def_id) == cx.tcx.lang_items().begin_panic_fn()
|
||||||
|| Some(def_id) == cx.tcx.lang_items().panic_fn()
|
|| Some(def_id) == cx.tcx.lang_items().panic_fn()
|
||||||
|| Some(def_id) == cx.tcx.lang_items().panic_str()
|
|| f_diagnostic_name == Some(sym::panic_str)
|
||||||
{
|
{
|
||||||
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
|
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
|
||||||
if matches!(
|
if matches!(
|
||||||
|
@ -61,6 +63,22 @@ impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
|
||||||
check_panic(cx, f, arg);
|
check_panic(cx, f, arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if f_diagnostic_name == Some(sym::unreachable_display) {
|
||||||
|
if let Some(id) = f.span.ctxt().outer_expn_data().macro_def_id {
|
||||||
|
if cx.tcx.is_diagnostic_item(sym::unreachable_2015_macro, id) {
|
||||||
|
check_panic(
|
||||||
|
cx,
|
||||||
|
f,
|
||||||
|
// This is safe because we checked above that the callee is indeed
|
||||||
|
// unreachable_display
|
||||||
|
match &arg.kind {
|
||||||
|
// Get the borrowed arg not the borrow
|
||||||
|
hir::ExprKind::AddrOf(ast::BorrowKind::Ref, _, arg) => arg,
|
||||||
|
_ => bug!("call to unreachable_display without borrow"),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,8 +103,8 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the span of the argument to `panic!()`, before expansion in the
|
// Find the span of the argument to `panic!()` or `unreachable!`, before expansion in the
|
||||||
// case of `panic!(some_macro!())`.
|
// case of `panic!(some_macro!())` or `unreachable!(some_macro!())`.
|
||||||
// We don't use source_callsite(), because this `panic!(..)` might itself
|
// We don't use source_callsite(), because this `panic!(..)` might itself
|
||||||
// be expanded from another macro, in which case we want to stop at that
|
// be expanded from another macro, in which case we want to stop at that
|
||||||
// expansion.
|
// expansion.
|
||||||
|
@ -319,6 +337,7 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span,
|
||||||
| sym::std_panic_macro
|
| sym::std_panic_macro
|
||||||
| sym::assert_macro
|
| sym::assert_macro
|
||||||
| sym::debug_assert_macro
|
| sym::debug_assert_macro
|
||||||
|
| sym::unreachable_macro
|
||||||
) {
|
) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1437,7 +1437,12 @@ symbols! {
|
||||||
unmarked_api,
|
unmarked_api,
|
||||||
unpin,
|
unpin,
|
||||||
unreachable,
|
unreachable,
|
||||||
|
unreachable_2015,
|
||||||
|
unreachable_2015_macro,
|
||||||
|
unreachable_2021,
|
||||||
|
unreachable_2021_macro,
|
||||||
unreachable_code,
|
unreachable_code,
|
||||||
|
unreachable_display,
|
||||||
unreachable_macro,
|
unreachable_macro,
|
||||||
unrestricted_attribute_tokens,
|
unrestricted_attribute_tokens,
|
||||||
unsafe_block_in_unsafe_fn,
|
unsafe_block_in_unsafe_fn,
|
||||||
|
|
|
@ -594,6 +594,22 @@ macro_rules! writeln {
|
||||||
/// unreachable!("The loop should always return");
|
/// unreachable!("The loop should always return");
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
#[macro_export]
|
||||||
|
#[rustc_builtin_macro(unreachable)]
|
||||||
|
#[allow_internal_unstable(edition_panic)]
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "unreachable_macro")]
|
||||||
|
macro_rules! unreachable {
|
||||||
|
// Expands to either `$crate::panic::unreachable_2015` or `$crate::panic::unreachable_2021`
|
||||||
|
// depending on the edition of the caller.
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
/* compiler built-in */
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// unreachable!() macro
|
||||||
|
#[cfg(bootstrap)]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "unreachable_macro")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "unreachable_macro")]
|
||||||
|
|
|
@ -58,6 +58,39 @@ pub macro panic_2021 {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
|
||||||
|
#[allow_internal_unstable(core_panic)]
|
||||||
|
#[rustc_diagnostic_item = "unreachable_2015_macro"]
|
||||||
|
#[rustc_macro_transparency = "semitransparent"]
|
||||||
|
pub macro unreachable_2015 {
|
||||||
|
() => (
|
||||||
|
$crate::panicking::panic("internal error: entered unreachable code")
|
||||||
|
),
|
||||||
|
// Use of `unreachable_display` for non_fmt_panic lint.
|
||||||
|
// NOTE: the message ("internal error ...") is embeded directly in unreachable_display
|
||||||
|
($msg:expr $(,)?) => (
|
||||||
|
$crate::panicking::unreachable_display(&$msg)
|
||||||
|
),
|
||||||
|
($fmt:expr, $($arg:tt)*) => (
|
||||||
|
$crate::panic!($crate::concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[unstable(feature = "edition_panic", issue = "none", reason = "use unreachable!() instead")]
|
||||||
|
#[allow_internal_unstable(core_panic)]
|
||||||
|
#[rustc_diagnostic_item = "unreachable_2021_macro"]
|
||||||
|
#[rustc_macro_transparency = "semitransparent"]
|
||||||
|
pub macro unreachable_2021 {
|
||||||
|
() => (
|
||||||
|
$crate::panicking::panic("internal error: entered unreachable code")
|
||||||
|
),
|
||||||
|
($($t:tt)+) => (
|
||||||
|
$crate::panic!("internal error: entered unreachable code: {}", $crate::format_args!($($t)+))
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
/// An internal trait used by libstd to pass data from libstd to `panic_unwind`
|
/// An internal trait used by libstd to pass data from libstd to `panic_unwind`
|
||||||
/// and other panic runtimes. Not intended to be stabilized any time soon, do
|
/// and other panic runtimes. Not intended to be stabilized any time soon, do
|
||||||
/// not use.
|
/// not use.
|
||||||
|
|
|
@ -50,12 +50,20 @@ pub const fn panic(expr: &'static str) -> ! {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[lang = "panic_str"] // needed for `non-fmt-panics` lint
|
#[rustc_diagnostic_item = "panic_str"]
|
||||||
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
|
#[rustc_const_unstable(feature = "core_panic", issue = "none")]
|
||||||
pub const fn panic_str(expr: &str) -> ! {
|
pub const fn panic_str(expr: &str) -> ! {
|
||||||
panic_display(&expr);
|
panic_display(&expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
#[inline]
|
||||||
|
#[track_caller]
|
||||||
|
#[rustc_diagnostic_item = "unreachable_display"] // needed for `non-fmt-panics` lint
|
||||||
|
pub fn unreachable_display<T: fmt::Display>(x: &T) -> ! {
|
||||||
|
panic_fmt(format_args!("internal error: entered unreachable code: {}", *x));
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[lang = "panic_display"] // needed for const-evaluated panics
|
#[lang = "panic_display"] // needed for const-evaluated panics
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
let mut _19: *const T; // in scope 0 at $DIR/issue_76432.rs:9:54: 9:68
|
let mut _19: *const T; // in scope 0 at $DIR/issue_76432.rs:9:54: 9:68
|
||||||
let mut _20: *const T; // in scope 0 at $DIR/issue_76432.rs:9:70: 9:84
|
let mut _20: *const T; // in scope 0 at $DIR/issue_76432.rs:9:70: 9:84
|
||||||
let mut _21: *const T; // in scope 0 at $DIR/issue_76432.rs:9:70: 9:84
|
let mut _21: *const T; // in scope 0 at $DIR/issue_76432.rs:9:70: 9:84
|
||||||
let mut _22: !; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
let mut _22: !; // in scope 0 at $SRC_DIR/core/src/panic.rs:LL:COL
|
||||||
let mut _23: &[T; 3]; // in scope 0 at $DIR/issue_76432.rs:7:19: 7:29
|
let mut _23: &[T; 3]; // in scope 0 at $DIR/issue_76432.rs:7:19: 7:29
|
||||||
scope 1 {
|
scope 1 {
|
||||||
debug v => _2; // in scope 1 at $DIR/issue_76432.rs:7:9: 7:10
|
debug v => _2; // in scope 1 at $DIR/issue_76432.rs:7:9: 7:10
|
||||||
|
@ -66,16 +66,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
bb1: {
|
bb1: {
|
||||||
StorageLive(_22); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
StorageLive(_22); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
|
||||||
core::panicking::panic(const "internal error: entered unreachable code"); // scope 1 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
core::panicking::panic(const "internal error: entered unreachable code"); // scope 1 at $SRC_DIR/core/src/panic.rs:LL:COL
|
||||||
// mir::Constant
|
// mir::Constant
|
||||||
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
// + span: $SRC_DIR/core/src/panic.rs:LL:COL
|
||||||
// + literal: Const { ty: fn(&'static str) -> ! {core::panicking::panic}, val: Value(Scalar(<ZST>)) }
|
// + literal: Const { ty: fn(&'static str) -> ! {core::panicking::panic}, val: Value(Scalar(<ZST>)) }
|
||||||
// ty::Const
|
// ty::Const
|
||||||
// + ty: &str
|
// + ty: &str
|
||||||
// + val: Value(Slice { data: Allocation { bytes: [105, 110, 116, 101, 114, 110, 97, 108, 32, 101, 114, 114, 111, 114, 58, 32, 101, 110, 116, 101, 114, 101, 100, 32, 117, 110, 114, 101, 97, 99, 104, 97, 98, 108, 101, 32, 99, 111, 100, 101], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1099511627775], len: Size { raw: 40 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 40 })
|
// + val: Value(Slice { data: Allocation { bytes: [105, 110, 116, 101, 114, 110, 97, 108, 32, 101, 114, 114, 111, 114, 58, 32, 101, 110, 116, 101, 114, 101, 100, 32, 117, 110, 114, 101, 97, 99, 104, 97, 98, 108, 101, 32, 99, 111, 100, 101], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1099511627775], len: Size { raw: 40 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 40 })
|
||||||
// mir::Constant
|
// mir::Constant
|
||||||
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
// + span: $SRC_DIR/core/src/panic.rs:LL:COL
|
||||||
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [105, 110, 116, 101, 114, 110, 97, 108, 32, 101, 114, 114, 111, 114, 58, 32, 101, 110, 116, 101, 114, 101, 100, 32, 117, 110, 114, 101, 97, 99, 104, 97, 98, 108, 101, 32, 99, 111, 100, 101], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1099511627775], len: Size { raw: 40 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 40 }) }
|
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [105, 110, 116, 101, 114, 110, 97, 108, 32, 101, 114, 114, 111, 114, 58, 32, 101, 110, 116, 101, 114, 101, 100, 32, 117, 110, 114, 101, 97, 99, 104, 97, 98, 108, 101, 32, 99, 111, 100, 101], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1099511627775], len: Size { raw: 40 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 40 }) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ error[E0080]: evaluation of constant value failed
|
||||||
LL | const Y: () = std::unreachable!();
|
LL | const Y: () = std::unreachable!();
|
||||||
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:12:15
|
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:12:15
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `std::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `$crate::panic::unreachable_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/const_panic.rs:15:15
|
--> $DIR/const_panic.rs:15:15
|
||||||
|
@ -68,7 +68,7 @@ error[E0080]: evaluation of constant value failed
|
||||||
LL | const Y_CORE: () = core::unreachable!();
|
LL | const Y_CORE: () = core::unreachable!();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:30:20
|
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic.rs:30:20
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `core::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `$crate::panic::unreachable_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/const_panic.rs:33:20
|
--> $DIR/const_panic.rs:33:20
|
||||||
|
|
|
@ -20,7 +20,7 @@ error[E0080]: evaluation of constant value failed
|
||||||
LL | const C: () = std::unreachable!();
|
LL | const C: () = std::unreachable!();
|
||||||
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:12:15
|
| ^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:12:15
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `std::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `$crate::panic::unreachable_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/const_panic_2021.rs:15:15
|
--> $DIR/const_panic_2021.rs:15:15
|
||||||
|
@ -60,7 +60,7 @@ error[E0080]: evaluation of constant value failed
|
||||||
LL | const C_CORE: () = core::unreachable!();
|
LL | const C_CORE: () = core::unreachable!();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:27:20
|
| ^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_2021.rs:27:20
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `core::unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `$crate::panic::unreachable_2021` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/const_panic_2021.rs:30:20
|
--> $DIR/const_panic_2021.rs:30:20
|
||||||
|
|
|
@ -12,7 +12,7 @@ error[E0080]: evaluation of constant value failed
|
||||||
LL | const Y: () = unreachable!();
|
LL | const Y: () = unreachable!();
|
||||||
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_bin.rs:11:15
|
| ^^^^^^^^^^^^^^ the evaluated program panicked at 'internal error: entered unreachable code', $DIR/const_panic_libcore_bin.rs:11:15
|
||||||
|
|
|
|
||||||
= note: this error originates in the macro `unreachable` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `$crate::panic::unreachable_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/const_panic_libcore_bin.rs:14:15
|
--> $DIR/const_panic_libcore_bin.rs:14:15
|
||||||
|
|
13
src/test/ui/macros/unreachable-arg.edition_2021.stderr
Normal file
13
src/test/ui/macros/unreachable-arg.edition_2021.stderr
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
error: format argument must be a string literal
|
||||||
|
--> $DIR/unreachable-arg.rs:15:18
|
||||||
|
|
|
||||||
|
LL | unreachable!(a);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
help: you might be missing a string literal to format with
|
||||||
|
|
|
||||||
|
LL | unreachable!("{}", a);
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
16
src/test/ui/macros/unreachable-arg.rs
Normal file
16
src/test/ui/macros/unreachable-arg.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// ignore-emscripten no processes
|
||||||
|
|
||||||
|
// revisions: edition_2015 edition_2021
|
||||||
|
// [edition_2015]edition:2015
|
||||||
|
// [edition_2021]edition:2021
|
||||||
|
// [edition_2015]run-fail
|
||||||
|
// [edition_2021]check-fail
|
||||||
|
// [edition_2015]error-pattern:internal error: entered unreachable code: hello
|
||||||
|
// [edition_2021]error-pattern:format argument must be a string literal
|
||||||
|
|
||||||
|
#![allow(non_fmt_panics)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let a = "hello";
|
||||||
|
unreachable!(a);
|
||||||
|
}
|
15
src/test/ui/macros/unreachable-format-arg.rs
Normal file
15
src/test/ui/macros/unreachable-format-arg.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// run-fail
|
||||||
|
// ignore-emscripten no processes
|
||||||
|
|
||||||
|
// revisions: edition_2015 edition_2021
|
||||||
|
// [edition_2015]edition:2015
|
||||||
|
// [edition_2021]edition:2021
|
||||||
|
// [edition_2015]error-pattern:internal error: entered unreachable code: x is {x}
|
||||||
|
// [edition_2021]error-pattern:internal error: entered unreachable code: x is 5
|
||||||
|
|
||||||
|
#![allow(non_fmt_panics)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = 5;
|
||||||
|
unreachable!("x is {x}");
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
error: there is no argument named `x`
|
||||||
|
--> $DIR/unreachable-format-args.rs:13:5
|
||||||
|
|
|
||||||
|
LL | unreachable!("x is {x} and y is {y}", y = 0);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: did you intend to capture a variable `x` from the surrounding scope?
|
||||||
|
= note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro
|
||||||
|
= note: this error originates in the macro `$crate::concat` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
14
src/test/ui/macros/unreachable-format-args.rs
Normal file
14
src/test/ui/macros/unreachable-format-args.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// ignore-emscripten no processes
|
||||||
|
|
||||||
|
// revisions: edition_2015 edition_2021
|
||||||
|
// [edition_2015]edition:2015
|
||||||
|
// [edition_2021]edition:2021
|
||||||
|
// [edition_2015]check-fail
|
||||||
|
// [edition_2021]run-fail
|
||||||
|
// [edition_2015]error-pattern:there is no argument named `x`
|
||||||
|
// [edition_2021]error-pattern:internal error: entered unreachable code: x is 5 and y is 0
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = 5;
|
||||||
|
unreachable!("x is {x} and y is {y}", y = 0);
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ static S: &str = "{bla}";
|
||||||
#[allow(unreachable_code)]
|
#[allow(unreachable_code)]
|
||||||
fn main() {
|
fn main() {
|
||||||
panic!("{}", "here's a brace: {"); //~ WARN panic message contains a brace
|
panic!("{}", "here's a brace: {"); //~ WARN panic message contains a brace
|
||||||
|
unreachable!("{}", "here's a brace: {"); //~ WARN panic message contains a brace
|
||||||
std::panic!("{}", "another one: }"); //~ WARN panic message contains a brace
|
std::panic!("{}", "another one: }"); //~ WARN panic message contains a brace
|
||||||
core::panic!("{}", "Hello {}"); //~ WARN panic message contains an unused formatting placeholder
|
core::panic!("{}", "Hello {}"); //~ WARN panic message contains an unused formatting placeholder
|
||||||
assert!(false, "{}", "{:03x} {test} bla");
|
assert!(false, "{}", "{:03x} {test} bla");
|
||||||
|
@ -24,6 +25,8 @@ fn main() {
|
||||||
debug_assert!(false, "{}", "{{}} bla"); //~ WARN panic message contains braces
|
debug_assert!(false, "{}", "{{}} bla"); //~ WARN panic message contains braces
|
||||||
panic!("{}", C); //~ WARN panic message is not a string literal
|
panic!("{}", C); //~ WARN panic message is not a string literal
|
||||||
panic!("{}", S); //~ WARN panic message is not a string literal
|
panic!("{}", S); //~ WARN panic message is not a string literal
|
||||||
|
unreachable!("{}", S); //~ WARN panic message is not a string literal
|
||||||
|
unreachable!("{}", S); //~ WARN panic message is not a string literal
|
||||||
std::panic::panic_any(123); //~ WARN panic message is not a string literal
|
std::panic::panic_any(123); //~ WARN panic message is not a string literal
|
||||||
core::panic!("{}", &*"abc"); //~ WARN panic message is not a string literal
|
core::panic!("{}", &*"abc"); //~ WARN panic message is not a string literal
|
||||||
std::panic::panic_any(Some(123)); //~ WARN panic message is not a string literal
|
std::panic::panic_any(Some(123)); //~ WARN panic message is not a string literal
|
||||||
|
@ -41,8 +44,10 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::panic::panic_any(a!()); //~ WARN panic message is not a string literal
|
std::panic::panic_any(a!()); //~ WARN panic message is not a string literal
|
||||||
|
unreachable!("{}", a!()); //~ WARN panic message is not a string literal
|
||||||
|
|
||||||
panic!("{}", 1); //~ WARN panic message is not a string literal
|
panic!("{}", 1); //~ WARN panic message is not a string literal
|
||||||
|
unreachable!("{}", 1); //~ WARN panic message is not a string literal
|
||||||
assert!(false, "{}", 1); //~ WARN panic message is not a string literal
|
assert!(false, "{}", 1); //~ WARN panic message is not a string literal
|
||||||
debug_assert!(false, "{}", 1); //~ WARN panic message is not a string literal
|
debug_assert!(false, "{}", 1); //~ WARN panic message is not a string literal
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ static S: &str = "{bla}";
|
||||||
#[allow(unreachable_code)]
|
#[allow(unreachable_code)]
|
||||||
fn main() {
|
fn main() {
|
||||||
panic!("here's a brace: {"); //~ WARN panic message contains a brace
|
panic!("here's a brace: {"); //~ WARN panic message contains a brace
|
||||||
|
unreachable!("here's a brace: {"); //~ WARN panic message contains a brace
|
||||||
std::panic!("another one: }"); //~ WARN panic message contains a brace
|
std::panic!("another one: }"); //~ WARN panic message contains a brace
|
||||||
core::panic!("Hello {}"); //~ WARN panic message contains an unused formatting placeholder
|
core::panic!("Hello {}"); //~ WARN panic message contains an unused formatting placeholder
|
||||||
assert!(false, "{:03x} {test} bla");
|
assert!(false, "{:03x} {test} bla");
|
||||||
|
@ -24,6 +25,8 @@ fn main() {
|
||||||
debug_assert!(false, "{{}} bla"); //~ WARN panic message contains braces
|
debug_assert!(false, "{{}} bla"); //~ WARN panic message contains braces
|
||||||
panic!(C); //~ WARN panic message is not a string literal
|
panic!(C); //~ WARN panic message is not a string literal
|
||||||
panic!(S); //~ WARN panic message is not a string literal
|
panic!(S); //~ WARN panic message is not a string literal
|
||||||
|
unreachable!(S); //~ WARN panic message is not a string literal
|
||||||
|
unreachable!(S); //~ WARN panic message is not a string literal
|
||||||
std::panic!(123); //~ WARN panic message is not a string literal
|
std::panic!(123); //~ WARN panic message is not a string literal
|
||||||
core::panic!(&*"abc"); //~ WARN panic message is not a string literal
|
core::panic!(&*"abc"); //~ WARN panic message is not a string literal
|
||||||
panic!(Some(123)); //~ WARN panic message is not a string literal
|
panic!(Some(123)); //~ WARN panic message is not a string literal
|
||||||
|
@ -41,8 +44,10 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
panic!(a!()); //~ WARN panic message is not a string literal
|
panic!(a!()); //~ WARN panic message is not a string literal
|
||||||
|
unreachable!(a!()); //~ WARN panic message is not a string literal
|
||||||
|
|
||||||
panic!(format!("{}", 1)); //~ WARN panic message is not a string literal
|
panic!(format!("{}", 1)); //~ WARN panic message is not a string literal
|
||||||
|
unreachable!(format!("{}", 1)); //~ WARN panic message is not a string literal
|
||||||
assert!(false, format!("{}", 1)); //~ WARN panic message is not a string literal
|
assert!(false, format!("{}", 1)); //~ WARN panic message is not a string literal
|
||||||
debug_assert!(false, format!("{}", 1)); //~ WARN panic message is not a string literal
|
debug_assert!(false, format!("{}", 1)); //~ WARN panic message is not a string literal
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,19 @@ LL | panic!("{}", "here's a brace: {");
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message contains a brace
|
warning: panic message contains a brace
|
||||||
--> $DIR/non-fmt-panic.rs:14:31
|
--> $DIR/non-fmt-panic.rs:14:35
|
||||||
|
|
|
||||||
|
LL | unreachable!("here's a brace: {");
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: this message is not used as a format string, but will be in Rust 2021
|
||||||
|
help: add a "{}" format string to use the message literally
|
||||||
|
|
|
||||||
|
LL | unreachable!("{}", "here's a brace: {");
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
warning: panic message contains a brace
|
||||||
|
--> $DIR/non-fmt-panic.rs:15:31
|
||||||
|
|
|
|
||||||
LL | std::panic!("another one: }");
|
LL | std::panic!("another one: }");
|
||||||
| ^
|
| ^
|
||||||
|
@ -24,7 +36,7 @@ LL | std::panic!("{}", "another one: }");
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message contains an unused formatting placeholder
|
warning: panic message contains an unused formatting placeholder
|
||||||
--> $DIR/non-fmt-panic.rs:15:25
|
--> $DIR/non-fmt-panic.rs:16:25
|
||||||
|
|
|
|
||||||
LL | core::panic!("Hello {}");
|
LL | core::panic!("Hello {}");
|
||||||
| ^^
|
| ^^
|
||||||
|
@ -40,7 +52,7 @@ LL | core::panic!("{}", "Hello {}");
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message contains unused formatting placeholders
|
warning: panic message contains unused formatting placeholders
|
||||||
--> $DIR/non-fmt-panic.rs:16:21
|
--> $DIR/non-fmt-panic.rs:17:21
|
||||||
|
|
|
|
||||||
LL | assert!(false, "{:03x} {test} bla");
|
LL | assert!(false, "{:03x} {test} bla");
|
||||||
| ^^^^^^ ^^^^^^
|
| ^^^^^^ ^^^^^^
|
||||||
|
@ -56,7 +68,7 @@ LL | assert!(false, "{}", "{:03x} {test} bla");
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:18:20
|
--> $DIR/non-fmt-panic.rs:19:20
|
||||||
|
|
|
|
||||||
LL | assert!(false, S);
|
LL | assert!(false, S);
|
||||||
| ^
|
| ^
|
||||||
|
@ -69,7 +81,7 @@ LL | assert!(false, "{}", S);
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:20:20
|
--> $DIR/non-fmt-panic.rs:21:20
|
||||||
|
|
|
|
||||||
LL | assert!(false, 123);
|
LL | assert!(false, 123);
|
||||||
| ^^^
|
| ^^^
|
||||||
|
@ -82,7 +94,7 @@ LL | assert!(false, "{}", 123);
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:22:20
|
--> $DIR/non-fmt-panic.rs:23:20
|
||||||
|
|
|
|
||||||
LL | assert!(false, Some(123));
|
LL | assert!(false, Some(123));
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
@ -95,7 +107,7 @@ LL | assert!(false, "{:?}", Some(123));
|
||||||
| +++++++
|
| +++++++
|
||||||
|
|
||||||
warning: panic message contains braces
|
warning: panic message contains braces
|
||||||
--> $DIR/non-fmt-panic.rs:24:27
|
--> $DIR/non-fmt-panic.rs:25:27
|
||||||
|
|
|
|
||||||
LL | debug_assert!(false, "{{}} bla");
|
LL | debug_assert!(false, "{{}} bla");
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
@ -107,7 +119,7 @@ LL | debug_assert!(false, "{}", "{{}} bla");
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:25:12
|
--> $DIR/non-fmt-panic.rs:26:12
|
||||||
|
|
|
|
||||||
LL | panic!(C);
|
LL | panic!(C);
|
||||||
| ^
|
| ^
|
||||||
|
@ -120,7 +132,7 @@ LL | panic!("{}", C);
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:26:12
|
--> $DIR/non-fmt-panic.rs:27:12
|
||||||
|
|
|
|
||||||
LL | panic!(S);
|
LL | panic!(S);
|
||||||
| ^
|
| ^
|
||||||
|
@ -133,7 +145,33 @@ LL | panic!("{}", S);
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:27:17
|
--> $DIR/non-fmt-panic.rs:28:18
|
||||||
|
|
|
||||||
|
LL | unreachable!(S);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: this usage of unreachable!() is deprecated; it will be a hard error in Rust 2021
|
||||||
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||||
|
help: add a "{}" format string to Display the message
|
||||||
|
|
|
||||||
|
LL | unreachable!("{}", S);
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
warning: panic message is not a string literal
|
||||||
|
--> $DIR/non-fmt-panic.rs:29:18
|
||||||
|
|
|
||||||
|
LL | unreachable!(S);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: this usage of unreachable!() is deprecated; it will be a hard error in Rust 2021
|
||||||
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||||
|
help: add a "{}" format string to Display the message
|
||||||
|
|
|
||||||
|
LL | unreachable!("{}", S);
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
warning: panic message is not a string literal
|
||||||
|
--> $DIR/non-fmt-panic.rs:30:17
|
||||||
|
|
|
|
||||||
LL | std::panic!(123);
|
LL | std::panic!(123);
|
||||||
| ^^^
|
| ^^^
|
||||||
|
@ -150,7 +188,7 @@ LL | std::panic::panic_any(123);
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:28:18
|
--> $DIR/non-fmt-panic.rs:31:18
|
||||||
|
|
|
|
||||||
LL | core::panic!(&*"abc");
|
LL | core::panic!(&*"abc");
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
@ -163,7 +201,7 @@ LL | core::panic!("{}", &*"abc");
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:29:12
|
--> $DIR/non-fmt-panic.rs:32:12
|
||||||
|
|
|
|
||||||
LL | panic!(Some(123));
|
LL | panic!(Some(123));
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
@ -180,7 +218,7 @@ LL | std::panic::panic_any(Some(123));
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
warning: panic message contains an unused formatting placeholder
|
warning: panic message contains an unused formatting placeholder
|
||||||
--> $DIR/non-fmt-panic.rs:30:12
|
--> $DIR/non-fmt-panic.rs:33:12
|
||||||
|
|
|
|
||||||
LL | panic!(concat!("{", "}"));
|
LL | panic!(concat!("{", "}"));
|
||||||
| ^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^
|
||||||
|
@ -196,7 +234,7 @@ LL | panic!("{}", concat!("{", "}"));
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message contains braces
|
warning: panic message contains braces
|
||||||
--> $DIR/non-fmt-panic.rs:31:5
|
--> $DIR/non-fmt-panic.rs:34:5
|
||||||
|
|
|
|
||||||
LL | panic!(concat!("{", "{"));
|
LL | panic!(concat!("{", "{"));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -208,7 +246,7 @@ LL | panic!("{}", concat!("{", "{"));
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: panic message contains an unused formatting placeholder
|
warning: panic message contains an unused formatting placeholder
|
||||||
--> $DIR/non-fmt-panic.rs:33:37
|
--> $DIR/non-fmt-panic.rs:36:37
|
||||||
|
|
|
|
||||||
LL | fancy_panic::fancy_panic!("test {} 123");
|
LL | fancy_panic::fancy_panic!("test {} 123");
|
||||||
| ^^
|
| ^^
|
||||||
|
@ -216,7 +254,7 @@ LL | fancy_panic::fancy_panic!("test {} 123");
|
||||||
= note: this message is not used as a format string when given without arguments, but will be in Rust 2021
|
= note: this message is not used as a format string when given without arguments, but will be in Rust 2021
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:43:12
|
--> $DIR/non-fmt-panic.rs:46:12
|
||||||
|
|
|
|
||||||
LL | panic!(a!());
|
LL | panic!(a!());
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
@ -233,7 +271,20 @@ LL | std::panic::panic_any(a!());
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:45:12
|
--> $DIR/non-fmt-panic.rs:47:18
|
||||||
|
|
|
||||||
|
LL | unreachable!(a!());
|
||||||
|
| ^^^^
|
||||||
|
|
|
||||||
|
= note: this usage of unreachable!() is deprecated; it will be a hard error in Rust 2021
|
||||||
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||||
|
help: add a "{}" format string to Display the message
|
||||||
|
|
|
||||||
|
LL | unreachable!("{}", a!());
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
warning: panic message is not a string literal
|
||||||
|
--> $DIR/non-fmt-panic.rs:49:12
|
||||||
|
|
|
|
||||||
LL | panic!(format!("{}", 1));
|
LL | panic!(format!("{}", 1));
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
@ -248,7 +299,22 @@ LL + panic!("{}", 1);
|
||||||
|
|
|
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:46:20
|
--> $DIR/non-fmt-panic.rs:50:18
|
||||||
|
|
|
||||||
|
LL | unreachable!(format!("{}", 1));
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: this usage of unreachable!() is deprecated; it will be a hard error in Rust 2021
|
||||||
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||||
|
= note: the unreachable!() macro supports formatting, so there's no need for the format!() macro here
|
||||||
|
help: remove the `format!(..)` macro call
|
||||||
|
|
|
||||||
|
LL - unreachable!(format!("{}", 1));
|
||||||
|
LL + unreachable!("{}", 1);
|
||||||
|
|
|
||||||
|
|
||||||
|
warning: panic message is not a string literal
|
||||||
|
--> $DIR/non-fmt-panic.rs:51:20
|
||||||
|
|
|
|
||||||
LL | assert!(false, format!("{}", 1));
|
LL | assert!(false, format!("{}", 1));
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
@ -263,7 +329,7 @@ LL + assert!(false, "{}", 1);
|
||||||
|
|
|
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:47:26
|
--> $DIR/non-fmt-panic.rs:52:26
|
||||||
|
|
|
|
||||||
LL | debug_assert!(false, format!("{}", 1));
|
LL | debug_assert!(false, format!("{}", 1));
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
@ -278,7 +344,7 @@ LL + debug_assert!(false, "{}", 1);
|
||||||
|
|
|
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:49:12
|
--> $DIR/non-fmt-panic.rs:54:12
|
||||||
|
|
|
|
||||||
LL | panic![123];
|
LL | panic![123];
|
||||||
| ^^^
|
| ^^^
|
||||||
|
@ -295,7 +361,7 @@ LL | std::panic::panic_any(123);
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~ ~
|
| ~~~~~~~~~~~~~~~~~~~~~~ ~
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:50:12
|
--> $DIR/non-fmt-panic.rs:55:12
|
||||||
|
|
|
|
||||||
LL | panic!{123};
|
LL | panic!{123};
|
||||||
| ^^^
|
| ^^^
|
||||||
|
@ -312,7 +378,7 @@ LL | std::panic::panic_any(123);
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~ ~
|
| ~~~~~~~~~~~~~~~~~~~~~~ ~
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:67:12
|
--> $DIR/non-fmt-panic.rs:72:12
|
||||||
|
|
|
|
||||||
LL | panic!(v);
|
LL | panic!(v);
|
||||||
| ------ ^
|
| ------ ^
|
||||||
|
@ -323,7 +389,7 @@ LL | panic!(v);
|
||||||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:68:20
|
--> $DIR/non-fmt-panic.rs:73:20
|
||||||
|
|
|
|
||||||
LL | assert!(false, v);
|
LL | assert!(false, v);
|
||||||
| ^
|
| ^
|
||||||
|
@ -332,7 +398,7 @@ LL | assert!(false, v);
|
||||||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:72:12
|
--> $DIR/non-fmt-panic.rs:77:12
|
||||||
|
|
|
|
||||||
LL | panic!(v);
|
LL | panic!(v);
|
||||||
| ^
|
| ^
|
||||||
|
@ -349,7 +415,7 @@ LL | std::panic::panic_any(v);
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:73:20
|
--> $DIR/non-fmt-panic.rs:78:20
|
||||||
|
|
|
|
||||||
LL | assert!(false, v);
|
LL | assert!(false, v);
|
||||||
| ^
|
| ^
|
||||||
|
@ -361,36 +427,6 @@ help: add a "{:?}" format string to use the Debug implementation of `T`
|
||||||
LL | assert!(false, "{:?}", v);
|
LL | assert!(false, "{:?}", v);
|
||||||
| +++++++
|
| +++++++
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
|
||||||
--> $DIR/non-fmt-panic.rs:77:12
|
|
||||||
|
|
|
||||||
LL | panic!(v);
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
|
|
||||||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
|
||||||
help: add a "{}" format string to Display the message
|
|
||||||
|
|
|
||||||
LL | panic!("{}", v);
|
|
||||||
| +++++
|
|
||||||
help: or use std::panic::panic_any instead
|
|
||||||
|
|
|
||||||
LL | std::panic::panic_any(v);
|
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
|
||||||
--> $DIR/non-fmt-panic.rs:78:20
|
|
||||||
|
|
|
||||||
LL | assert!(false, v);
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
= note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021
|
|
||||||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
|
||||||
help: add a "{}" format string to Display the message
|
|
||||||
|
|
|
||||||
LL | assert!(false, "{}", v);
|
|
||||||
| +++++
|
|
||||||
|
|
||||||
warning: panic message is not a string literal
|
warning: panic message is not a string literal
|
||||||
--> $DIR/non-fmt-panic.rs:82:12
|
--> $DIR/non-fmt-panic.rs:82:12
|
||||||
|
|
|
|
||||||
|
@ -421,5 +457,35 @@ help: add a "{}" format string to Display the message
|
||||||
LL | assert!(false, "{}", v);
|
LL | assert!(false, "{}", v);
|
||||||
| +++++
|
| +++++
|
||||||
|
|
||||||
warning: 30 warnings emitted
|
warning: panic message is not a string literal
|
||||||
|
--> $DIR/non-fmt-panic.rs:87:12
|
||||||
|
|
|
||||||
|
LL | panic!(v);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: this usage of panic!() is deprecated; it will be a hard error in Rust 2021
|
||||||
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||||
|
help: add a "{}" format string to Display the message
|
||||||
|
|
|
||||||
|
LL | panic!("{}", v);
|
||||||
|
| +++++
|
||||||
|
help: or use std::panic::panic_any instead
|
||||||
|
|
|
||||||
|
LL | std::panic::panic_any(v);
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
warning: panic message is not a string literal
|
||||||
|
--> $DIR/non-fmt-panic.rs:88:20
|
||||||
|
|
|
||||||
|
LL | assert!(false, v);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: this usage of assert!() is deprecated; it will be a hard error in Rust 2021
|
||||||
|
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||||
|
help: add a "{}" format string to Display the message
|
||||||
|
|
|
||||||
|
LL | assert!(false, "{}", v);
|
||||||
|
| +++++
|
||||||
|
|
||||||
|
warning: 35 warnings emitted
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,8 @@ fn main() {
|
||||||
lit.set_span(crate::Span::recover_proc_macro_span(2));
|
lit.set_span(crate::Span::recover_proc_macro_span(2));
|
||||||
lit
|
lit
|
||||||
} else {
|
} else {
|
||||||
{
|
|
||||||
::core::panicking::panic("internal error: entered unreachable code")
|
::core::panicking::panic("internal error: entered unreachable code")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})),
|
})),
|
||||||
crate::TokenStream::from(crate::TokenTree::Punct(crate::Punct::new('\u{3b}',
|
crate::TokenStream::from(crate::TokenTree::Punct(crate::Punct::new('\u{3b}',
|
||||||
crate::Spacing::Alone)))].iter().cloned().collect::<crate::TokenStream>()
|
crate::Spacing::Alone)))].iter().cloned().collect::<crate::TokenStream>()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue