|
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,35 @@ 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 | + warnings.push(format!( |
| 122 | + "[{}] future-incompatibility: `cfg({e})` is deprecated as `{name}` is a keyword \ |
| 123 | + and not an identifier and should not have have been accepted in this position.\n \ |
| 124 | + | this was previously accepted by Cargo but is being phased out; it will become a hard error in a future release!", |
| 125 | + path.display() |
| 126 | + )); |
| 127 | + } |
| 128 | + } |
| 129 | + }, |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + if let Platform::Cfg(cfg) = self { |
| 134 | + check_cfg_expr(cfg, warnings, path); |
| 135 | + } |
| 136 | + } |
107 | 137 | } |
108 | 138 |
|
109 | 139 | impl serde::Serialize for Platform { |
|
0 commit comments