|
11 | 11 | //! |
12 | 12 | //! [`Platform`]: enum.Platform.html |
13 | 13 |
|
14 | | -use std::fmt; |
15 | 14 | use std::str::FromStr; |
| 15 | +use std::{fmt, path::Path}; |
16 | 16 |
|
17 | 17 | mod cfg; |
18 | 18 | mod error; |
19 | 19 |
|
| 20 | +use cfg::KEYWORDS; |
20 | 21 | pub use cfg::{Cfg, CfgExpr}; |
21 | 22 | pub use error::{ParseError, ParseErrorKind}; |
22 | 23 |
|
@@ -104,6 +105,46 @@ impl Platform { |
104 | 105 | check_cfg_expr(cfg, warnings); |
105 | 106 | } |
106 | 107 | } |
| 108 | + |
| 109 | + pub fn check_cfg_keywords(&self, warnings: &mut Vec<String>, path: &Path) { |
| 110 | + fn check_cfg_expr(expr: &CfgExpr, warnings: &mut Vec<String>, path: &Path) { |
| 111 | + match *expr { |
| 112 | + CfgExpr::Not(ref e) => check_cfg_expr(e, warnings, path), |
| 113 | + CfgExpr::All(ref e) | CfgExpr::Any(ref e) => { |
| 114 | + for e in e { |
| 115 | + check_cfg_expr(e, warnings, path); |
| 116 | + } |
| 117 | + } |
| 118 | + CfgExpr::Value(ref e) => match e { |
| 119 | + Cfg::Name(name) | Cfg::KeyPair(name, _) => { |
| 120 | + if KEYWORDS.contains(&name.as_str()) { |
| 121 | + if name.as_str() == "true" || name.as_str() == "false" { |
| 122 | + warnings.push(format!( |
| 123 | + "[{}] future-incompatibility: the meaning of `cfg({e})` will change in the future\n \ |
| 124 | + | Cargo is erroneously allowing `cfg(true)` and `cfg(false)`, but both forms are interpreted as false unless manually overridden with `--cfg`.\n \ |
| 125 | + | In the future these will be built-in defines that will have the corresponding true/false value.\n \ |
| 126 | + | It is recommended to avoid using these configs until they are properly supported.\n \ |
| 127 | + | See <https://github.com/rust-lang/rust/issues/131204> for more information.", |
| 128 | + path.display() |
| 129 | + )); |
| 130 | + } else { |
| 131 | + warnings.push(format!( |
| 132 | + "[{}] future-incompatibility: `cfg({e})` is deprecated as `{name}` is a keyword \ |
| 133 | + and not an identifier and should not have have been accepted in this position.\n \ |
| 134 | + | this was previously accepted by Cargo but is being phased out; it will become a hard error in a future release!", |
| 135 | + path.display() |
| 136 | + )); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + }, |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + if let Platform::Cfg(cfg) = self { |
| 145 | + check_cfg_expr(cfg, warnings, path); |
| 146 | + } |
| 147 | + } |
107 | 148 | } |
108 | 149 |
|
109 | 150 | impl serde::Serialize for Platform { |
|
0 commit comments