Rollup merge of #98276 - compiler-errors:const-format-macro, r=oli-obk
Mention formatting macros when encountering `ArgumentV1` method in const Also open to just closing this if it's overkill. There are a lot of other distracting error messages around, so maybe it's not worth fixing just this one. Fixes #93665
This commit is contained in:
commit
5eb7238928
@ -10,7 +10,8 @@ use rustc_middle::mir;
|
|||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
suggest_constraining_type_param, Adt, Closure, FnDef, FnPtr, Param, TraitPredicate, Ty,
|
suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, TraitPredicate,
|
||||||
|
Ty,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::{Binder, BoundConstness, ImplPolarity, TraitRef};
|
use rustc_middle::ty::{Binder, BoundConstness, ImplPolarity, TraitRef};
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
@ -300,6 +301,15 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
|||||||
diag_trait(&mut err, self_ty, tcx.lang_items().deref_trait().unwrap());
|
diag_trait(&mut err, self_ty, tcx.lang_items().deref_trait().unwrap());
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
_ if tcx.opt_parent(callee) == tcx.get_diagnostic_item(sym::ArgumentV1Methods) => {
|
||||||
|
struct_span_err!(
|
||||||
|
ccx.tcx.sess,
|
||||||
|
span,
|
||||||
|
E0015,
|
||||||
|
"cannot call non-const formatting macro in {}s",
|
||||||
|
ccx.const_kind(),
|
||||||
|
)
|
||||||
|
}
|
||||||
_ => struct_span_err!(
|
_ => struct_span_err!(
|
||||||
ccx.tcx.sess,
|
ccx.tcx.sess,
|
||||||
span,
|
span,
|
||||||
|
@ -131,6 +131,7 @@ symbols! {
|
|||||||
Arc,
|
Arc,
|
||||||
Argument,
|
Argument,
|
||||||
ArgumentV1,
|
ArgumentV1,
|
||||||
|
ArgumentV1Methods,
|
||||||
Arguments,
|
Arguments,
|
||||||
AsMut,
|
AsMut,
|
||||||
AsRef,
|
AsRef,
|
||||||
|
@ -320,6 +320,7 @@ macro_rules! arg_new {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_diagnostic_item = "ArgumentV1Methods"]
|
||||||
impl<'a> ArgumentV1<'a> {
|
impl<'a> ArgumentV1<'a> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
|
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
|
||||||
|
21
src/test/ui/consts/const-eval/format.rs
Normal file
21
src/test/ui/consts/const-eval/format.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
const fn failure() {
|
||||||
|
panic!("{:?}", 0);
|
||||||
|
//~^ ERROR cannot call non-const formatting macro in constant functions
|
||||||
|
//~| ERROR erroneous constant used
|
||||||
|
//~| ERROR erroneous constant used
|
||||||
|
//~| WARN this was previously accepted by the compiler
|
||||||
|
//~| WARN this was previously accepted by the compiler
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn print() {
|
||||||
|
println!("{:?}", 0);
|
||||||
|
//~^ ERROR cannot call non-const formatting macro in constant functions
|
||||||
|
//~| ERROR `Arguments::<'a>::new_v1` is not yet stable as a const fn
|
||||||
|
//~| ERROR cannot call non-const fn `_print` in constant functions
|
||||||
|
//~| ERROR erroneous constant used
|
||||||
|
//~| ERROR erroneous constant used
|
||||||
|
//~| WARN this was previously accepted by the compiler
|
||||||
|
//~| WARN this was previously accepted by the compiler
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
78
src/test/ui/consts/const-eval/format.stderr
Normal file
78
src/test/ui/consts/const-eval/format.stderr
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
error[E0015]: cannot call non-const formatting macro in constant functions
|
||||||
|
--> $DIR/format.rs:2:20
|
||||||
|
|
|
||||||
|
LL | panic!("{:?}", 0);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
|
= note: this error originates in the macro `$crate::const_format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error[E0015]: cannot call non-const formatting macro in constant functions
|
||||||
|
--> $DIR/format.rs:11:22
|
||||||
|
|
|
||||||
|
LL | println!("{:?}", 0);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: `Arguments::<'a>::new_v1` is not yet stable as a const fn
|
||||||
|
--> $DIR/format.rs:11:5
|
||||||
|
|
|
||||||
|
LL | println!("{:?}", 0);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(const_fmt_arguments_new)]` to the crate attributes to enable
|
||||||
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error[E0015]: cannot call non-const fn `_print` in constant functions
|
||||||
|
--> $DIR/format.rs:11:5
|
||||||
|
|
|
||||||
|
LL | println!("{:?}", 0);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
|
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: erroneous constant used
|
||||||
|
--> $DIR/format.rs:2:12
|
||||||
|
|
|
||||||
|
LL | panic!("{:?}", 0);
|
||||||
|
| ^^^^^^ referenced constant has errors
|
||||||
|
|
|
||||||
|
= note: `#[deny(const_err)]` on by default
|
||||||
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||||
|
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||||
|
|
||||||
|
error: erroneous constant used
|
||||||
|
--> $DIR/format.rs:2:20
|
||||||
|
|
|
||||||
|
LL | panic!("{:?}", 0);
|
||||||
|
| ^ referenced constant has errors
|
||||||
|
|
|
||||||
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||||
|
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||||
|
= note: this error originates in the macro `$crate::const_format_args` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: erroneous constant used
|
||||||
|
--> $DIR/format.rs:11:14
|
||||||
|
|
|
||||||
|
LL | println!("{:?}", 0);
|
||||||
|
| ^^^^^^ referenced constant has errors
|
||||||
|
|
|
||||||
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||||
|
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||||
|
|
||||||
|
error: erroneous constant used
|
||||||
|
--> $DIR/format.rs:11:22
|
||||||
|
|
|
||||||
|
LL | println!("{:?}", 0);
|
||||||
|
| ^ referenced constant has errors
|
||||||
|
|
|
||||||
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||||
|
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||||
|
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: aborting due to 8 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0015`.
|
Loading…
x
Reference in New Issue
Block a user