mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Improve non-boolean literal error in cfg predicate
This commit is contained in:
parent
781f1840cd
commit
a3ffa1eae5
@ -107,6 +107,8 @@ attr_unknown_version_literal =
|
|||||||
attr_unstable_cfg_target_compact =
|
attr_unstable_cfg_target_compact =
|
||||||
compact `cfg(target(..))` is experimental and subject to change
|
compact `cfg(target(..))` is experimental and subject to change
|
||||||
|
|
||||||
|
attr_unsupported_literal_cfg_boolean =
|
||||||
|
literal in `cfg` predicate value must be a boolean
|
||||||
attr_unsupported_literal_cfg_string =
|
attr_unsupported_literal_cfg_string =
|
||||||
literal in `cfg` predicate value must be a string
|
literal in `cfg` predicate value must be a string
|
||||||
attr_unsupported_literal_deprecated_kv_pair =
|
attr_unsupported_literal_deprecated_kv_pair =
|
||||||
|
@ -36,6 +36,7 @@ pub fn is_builtin_attr(attr: &Attribute) -> bool {
|
|||||||
pub(crate) enum UnsupportedLiteralReason {
|
pub(crate) enum UnsupportedLiteralReason {
|
||||||
Generic,
|
Generic,
|
||||||
CfgString,
|
CfgString,
|
||||||
|
CfgBoolean,
|
||||||
DeprecatedString,
|
DeprecatedString,
|
||||||
DeprecatedKvPair,
|
DeprecatedKvPair,
|
||||||
}
|
}
|
||||||
@ -623,7 +624,7 @@ pub fn eval_condition(
|
|||||||
_ => {
|
_ => {
|
||||||
dcx.emit_err(session_diagnostics::UnsupportedLiteral {
|
dcx.emit_err(session_diagnostics::UnsupportedLiteral {
|
||||||
span: cfg.span(),
|
span: cfg.span(),
|
||||||
reason: UnsupportedLiteralReason::Generic,
|
reason: UnsupportedLiteralReason::CfgBoolean,
|
||||||
is_bytestr: false,
|
is_bytestr: false,
|
||||||
start_point_span: sess.source_map().start_point(cfg.span()),
|
start_point_span: sess.source_map().start_point(cfg.span()),
|
||||||
});
|
});
|
||||||
|
@ -206,6 +206,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
|
|||||||
let mut diag = Diag::new(dcx, level, match self.reason {
|
let mut diag = Diag::new(dcx, level, match self.reason {
|
||||||
UnsupportedLiteralReason::Generic => fluent::attr_unsupported_literal_generic,
|
UnsupportedLiteralReason::Generic => fluent::attr_unsupported_literal_generic,
|
||||||
UnsupportedLiteralReason::CfgString => fluent::attr_unsupported_literal_cfg_string,
|
UnsupportedLiteralReason::CfgString => fluent::attr_unsupported_literal_cfg_string,
|
||||||
|
UnsupportedLiteralReason::CfgBoolean => fluent::attr_unsupported_literal_cfg_boolean,
|
||||||
UnsupportedLiteralReason::DeprecatedString => {
|
UnsupportedLiteralReason::DeprecatedString => {
|
||||||
fluent::attr_unsupported_literal_deprecated_string
|
fluent::attr_unsupported_literal_deprecated_string
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
cfg!(); //~ ERROR macro requires a cfg-pattern
|
cfg!(); //~ ERROR macro requires a cfg-pattern
|
||||||
cfg!(123); //~ ERROR unsupported literal
|
cfg!(123); //~ ERROR literal in `cfg` predicate value must be a boolean
|
||||||
cfg!(foo = 123); //~ ERROR literal in `cfg` predicate value must be a string
|
cfg!(foo = 123); //~ ERROR literal in `cfg` predicate value must be a string
|
||||||
cfg!(foo, bar); //~ ERROR expected 1 cfg-pattern
|
cfg!(foo, bar); //~ ERROR expected 1 cfg-pattern
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ LL | cfg!();
|
|||||||
|
|
|
|
||||||
= note: this error originates in the macro `cfg` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `cfg` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0565]: unsupported literal
|
error[E0565]: literal in `cfg` predicate value must be a boolean
|
||||||
--> $DIR/cfg.rs:3:10
|
--> $DIR/cfg.rs:3:10
|
||||||
|
|
|
|
||||||
LL | cfg!(123);
|
LL | cfg!(123);
|
||||||
|
Loading…
Reference in New Issue
Block a user