Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #94331

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c00f635
Remove in-band lifetimes
compiler-errors Feb 10, 2022
43dbd83
Remove LifetimeDefOrigin
compiler-errors Feb 20, 2022
8ca47d7
Stop manually SIMDing in swap_nonoverlapping
scottmcm Feb 21, 2022
da896d3
Improve CheckCfg internal representation
Urgau Feb 19, 2022
fbe1c15
Add test for well known names defined by rustc
Urgau Feb 19, 2022
3d23477
Improve diagnostic of the unexpected_cfgs lint
Urgau Feb 19, 2022
8d3de56
Continue improvements on the --check-cfg implementation
Urgau Feb 20, 2022
a556a2a
Add compiler flag `--check-cfg` to the unstable book
Urgau Feb 21, 2022
c73a2f8
properly handle fat pointers to uninhabitable types
compiler-errors Feb 23, 2022
f047af2
Normalize main return type during mono item collection & codegen
tmiasko Feb 23, 2022
37d9ea7
Improve `scan_escape`.
nnethercote Feb 24, 2022
44308dc
Inline a hot closure in `from_lit_token`.
nnethercote Feb 24, 2022
70018c1
update auto trait lint
lcnr Feb 24, 2022
34319ff
Avoid emitting full macro body into JSON
Mark-Simulacrum Feb 24, 2022
8ba7436
better ObligationCause for normalization errors in can_type_implement…
compiler-errors Feb 6, 2022
ee98dc8
restore spans for issue-50480
compiler-errors Feb 6, 2022
44de8c0
Rollup merge of #93714 - compiler-errors:can-type-impl-copy-error-spa…
Dylan-DPC Feb 24, 2022
b33098f
Rollup merge of #93845 - compiler-errors:in-band-lifetimes, r=cjgillot
Dylan-DPC Feb 24, 2022
92b5d1d
Rollup merge of #94175 - Urgau:check-cfg-improvements, r=petrochenkov
Dylan-DPC Feb 24, 2022
87f826d
Rollup merge of #94212 - scottmcm:swapper, r=dtolnay
Dylan-DPC Feb 24, 2022
2da2737
Rollup merge of #94242 - compiler-errors:fat-uninhabitable-pointer, r…
Dylan-DPC Feb 24, 2022
c20ed90
Rollup merge of #94308 - tmiasko:normalize-main-ret-ty, r=oli-obk
Dylan-DPC Feb 24, 2022
d4db2be
Rollup merge of #94315 - lcnr:auto-trait-lint-update, r=oli-obk
Dylan-DPC Feb 24, 2022
25cc094
Rollup merge of #94316 - nnethercote:improve-string-literal-unescapin…
Dylan-DPC Feb 24, 2022
39d8195
Rollup merge of #94327 - Mark-Simulacrum:avoid-macro-sp, r=petrochenkov
Dylan-DPC Feb 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve CheckCfg internal representation
  • Loading branch information
Urgau committed Feb 22, 2022
commit da896d35f471a27eb7b9385d6eadf50a5f761265
31 changes: 17 additions & 14 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,27 +463,30 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
let name = cfg.ident().expect("multi-segment cfg predicate").name;
let value = cfg.value_str();
if sess.check_config.names_checked && !sess.check_config.names_valid.contains(&name)
{
sess.buffer_lint(
UNEXPECTED_CFGS,
cfg.span,
CRATE_NODE_ID,
"unexpected `cfg` condition name",
);
}
if let Some(val) = value {
if sess.check_config.values_checked.contains(&name)
&& !sess.check_config.values_valid.contains(&(name, val))
{
if let Some(names_valid) = &sess.check_config.names_valid {
if !names_valid.contains(&name) {
sess.buffer_lint(
UNEXPECTED_CFGS,
cfg.span,
CRATE_NODE_ID,
"unexpected `cfg` condition value",
"unexpected `cfg` condition name",
);
}
}
if let Some(val) = value {
if let Some(values_valid) = &sess.check_config.values_valid {
if let Some(values) = values_valid.get(&name) {
if !values.contains(&val) {
sess.buffer_lint(
UNEXPECTED_CFGS,
cfg.span,
CRATE_NODE_ID,
"unexpected `cfg` condition value",
);
}
}
}
}
sess.config.contains(&(name, value))
}
}
Expand Down
22 changes: 16 additions & 6 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ 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) {
cfg.names_checked = true;
let names_valid =
cfg.names_valid.get_or_insert_with(|| FxHashSet::default());
for arg in args {
if arg.is_word() && arg.ident().is_some() {
let ident = arg.ident().expect("multi-segment cfg key");
cfg.names_valid.insert(ident.name.to_string());
names_valid.insert(ident.name.to_string());
} else {
error!("`names()` arguments must be simple identifers");
}
Expand All @@ -182,14 +183,19 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
} else if meta_item.has_name(sym::values) {
if let Some((name, values)) = args.split_first() {
if name.is_word() && name.ident().is_some() {
let values_valid = cfg
.values_valid
.get_or_insert_with(|| FxHashMap::default());
let ident = name.ident().expect("multi-segment cfg key");
cfg.values_checked.insert(ident.to_string());
let ident_values = values_valid
.entry(ident.to_string())
.or_insert_with(|| FxHashSet::default());

for val in values {
if let Some(LitKind::Str(s, _)) =
val.literal().map(|lit| &lit.kind)
{
cfg.values_valid
.insert((ident.to_string(), s.to_string()));
ident_values.insert(s.to_string());
} else {
error!(
"`values()` arguments must be string literals"
Expand Down Expand Up @@ -219,7 +225,11 @@ pub fn parse_check_cfg(specs: Vec<String>) -> CheckCfg {
);
}

cfg.names_valid.extend(cfg.values_checked.iter().cloned());
if let Some(values_valid) = &cfg.values_valid {
if let Some(names_valid) = &mut cfg.names_valid {
names_valid.extend(values_valid.keys().cloned());
}
}
cfg
})
}
Expand Down
48 changes: 25 additions & 23 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::search_paths::SearchPath;
use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
use crate::{early_error, early_warn, Session};

use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::impl_stable_hash_via_hash;

use rustc_target::abi::{Align, TargetDataLayout};
Expand Down Expand Up @@ -1023,34 +1023,28 @@ pub fn to_crate_config(cfg: FxHashSet<(String, Option<String>)>) -> CrateConfig

/// The parsed `--check-cfg` options
pub struct CheckCfg<T = String> {
/// Set if `names()` checking is enabled
pub names_checked: bool,
/// The union of all `names()`
pub names_valid: FxHashSet<T>,
/// The set of names for which `values()` was used
pub values_checked: FxHashSet<T>,
/// The set of all (name, value) pairs passed in `values()`
pub values_valid: FxHashSet<(T, T)>,
/// The set of all `names()`, if none no names checking is performed
pub names_valid: Option<FxHashSet<T>>,
/// The set of all `values()`, if none no values chcking is performed
pub values_valid: Option<FxHashMap<T, FxHashSet<T>>>,
}

impl<T> Default for CheckCfg<T> {
fn default() -> Self {
CheckCfg {
names_checked: false,
names_valid: FxHashSet::default(),
values_checked: FxHashSet::default(),
values_valid: FxHashSet::default(),
}
CheckCfg { names_valid: Default::default(), values_valid: Default::default() }
}
}

impl<T> CheckCfg<T> {
fn map_data<O: Eq + Hash>(&self, f: impl Fn(&T) -> O) -> CheckCfg<O> {
CheckCfg {
names_checked: self.names_checked,
names_valid: self.names_valid.iter().map(|a| f(a)).collect(),
values_checked: self.values_checked.iter().map(|a| f(a)).collect(),
values_valid: self.values_valid.iter().map(|(a, b)| (f(a), f(b))).collect(),
names_valid: self
.names_valid
.as_ref()
.map(|names_valid| names_valid.iter().map(|a| f(a)).collect()),
values_valid: self.values_valid.as_ref().map(|values_valid| {
values_valid.iter().map(|(a, b)| (f(a), b.iter().map(|b| f(b)).collect())).collect()
}),
}
}
}
Expand Down Expand Up @@ -1090,17 +1084,25 @@ impl CrateCheckConfig {
sym::doctest,
sym::feature,
];
for &name in WELL_KNOWN_NAMES {
self.names_valid.insert(name);
if let Some(names_valid) = &mut self.names_valid {
for &name in WELL_KNOWN_NAMES {
names_valid.insert(name);
}
}
}

/// Fills a `CrateCheckConfig` with configuration names and values that are actually active.
pub fn fill_actual(&mut self, cfg: &CrateConfig) {
for &(k, v) in cfg {
self.names_valid.insert(k);
if let Some(names_valid) = &mut self.names_valid {
names_valid.insert(k);
}
if let Some(v) = v {
self.values_valid.insert((k, v));
if let Some(values_valid) = &mut self.values_valid {
values_valid.entry(k).and_modify(|values| {
values.insert(v);
});
}
}
}
}
Expand Down