diff options
| author | Urgau <urgau@numericable.fr> | 2023-04-30 14:43:59 +0200 |
|---|---|---|
| committer | Urgau <urgau@numericable.fr> | 2023-05-05 13:06:47 +0200 |
| commit | d327d5b16840346d838a29fdbac49a66be216a08 (patch) | |
| tree | 3a95babdc860ad30ce04e370fee3befd178c6c1b /compiler/rustc_interface/src/interface.rs | |
| parent | ad6f4b73ebfc26859a3a6b70b3790ab55d285440 (diff) | |
Improve internal representation of check-cfg
This is done to simplify to relationship between names() and values() but also make thing clearer (having an Any to represent that any values are allowed) but also to allow the (none) + values expected cases that wasn't possible before.
Diffstat (limited to 'compiler/rustc_interface/src/interface.rs')
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index de24a25f133..9d9f4ee13f4 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -9,7 +9,7 @@ use rustc_data_structures::OnDrop; use rustc_errors::registry::Registry; use rustc_errors::{ErrorGuaranteed, Handler}; use rustc_lint::LintStore; -use rustc_middle::ty; +use rustc_middle::{bug, ty}; use rustc_parse::maybe_new_parser_from_source_str; use rustc_query_impl::QueryCtxt; use rustc_query_system::query::print_query_stack; @@ -154,12 +154,14 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg { Ok(meta_item) if parser.token == token::Eof => { if let Some(args) = meta_item.meta_item_list() { if meta_item.has_name(sym::names) { - let names_valid = - check_cfg.names_valid.get_or_insert_with(|| FxHashSet::default()); + check_cfg.exhaustive_names = true; for arg in args { if arg.is_word() && arg.ident().is_some() { let ident = arg.ident().expect("multi-segment cfg key"); - names_valid.insert(ident.name.to_string()); + check_cfg + .expecteds + .entry(ident.name.to_string()) + .or_insert(ExpectedValues::Any); } else { error!("`names()` arguments must be simple identifiers"); } @@ -168,8 +170,8 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg { if let Some((name, values)) = args.split_first() { if name.is_word() && name.ident().is_some() { let ident = name.ident().expect("multi-segment cfg key"); - let ident_values = check_cfg - .values_valid + let expected_values = check_cfg + .expecteds .entry(ident.name.to_string()) .or_insert_with(|| { ExpectedValues::Some(FxHashSet::default()) @@ -183,20 +185,24 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg { if let Some(LitKind::Str(s, _)) = val.lit().map(|lit| &lit.kind) { - ident_values.insert(s.to_string()); + expected_values.insert(Some(s.to_string())); } else { error!( "`values()` arguments must be string literals" ); } } + + if values.is_empty() { + expected_values.insert(None); + } } else { error!( "`values()` first argument must be a simple identifier" ); } } else if args.is_empty() { - check_cfg.well_known_values = true; + check_cfg.exhaustive_values = true; } else { expected_error(); } @@ -220,9 +226,6 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg { } } - if let Some(names_valid) = &mut check_cfg.names_valid { - names_valid.extend(check_cfg.values_valid.keys().cloned()); - } check_cfg }) } |
