aboutsummaryrefslogtreecommitdiff
path: root/crates/cfg/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-21 14:41:27 +0100
committerGitHub <[email protected]>2021-06-21 14:41:27 +0100
commitb48aba009025701c4adb45e2042f0bcdb9d949a7 (patch)
tree9c311ee5e9058a3db66134368c8b84c30ed94f81 /crates/cfg/src
parent4402f2b280f58896ed0696f4243d88a58fd970ca (diff)
parent8b77e2692cd97552b1b8d66eb51cec69695b3a5b (diff)
Merge #9227
9227: Add a config setting to disable the 'test' cfg in specified crates r=matklad a=lf- If you are opening libcore from rust-lang/rust as opposed to e.g. goto definition from some other crate which would use the sysroot instance of libcore, a `#![cfg(not(test))]` would previously have made all the code excluded from the module tree, breaking the editor experience. Core does not need to ever be edited with `#[cfg(test)]` enabled, as the tests are in another crate. This PR puts in a slight hack that checks for the crate name "core" and turns off `#[cfg(test)]` for that crate. Fixes #9203 Fixes #9226 Co-authored-by: Jade <[email protected]>
Diffstat (limited to 'crates/cfg/src')
-rw-r--r--crates/cfg/src/lib.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/cfg/src/lib.rs b/crates/cfg/src/lib.rs
index 03b8dd767..916d39a0b 100644
--- a/crates/cfg/src/lib.rs
+++ b/crates/cfg/src/lib.rs
@@ -1,4 +1,4 @@
1//! cfg defines conditional compiling options, `cfg` attibute parser and evaluator 1//! cfg defines conditional compiling options, `cfg` attribute parser and evaluator
2 2
3mod cfg_expr; 3mod cfg_expr;
4mod dnf; 4mod dnf;
@@ -52,6 +52,7 @@ impl CfgOptions {
52 } 52 }
53} 53}
54 54
55#[derive(Clone, Debug, PartialEq, Eq)]
55pub struct CfgDiff { 56pub struct CfgDiff {
56 // Invariants: No duplicates, no atom that's both in `enable` and `disable`. 57 // Invariants: No duplicates, no atom that's both in `enable` and `disable`.
57 enable: Vec<CfgAtom>, 58 enable: Vec<CfgAtom>,
@@ -59,6 +60,20 @@ pub struct CfgDiff {
59} 60}
60 61
61impl CfgDiff { 62impl CfgDiff {
63 /// Create a new CfgDiff. Will return None if the same item appears more than once in the set
64 /// of both.
65 pub fn new(enable: Vec<CfgAtom>, disable: Vec<CfgAtom>) -> Option<CfgDiff> {
66 let mut occupied = FxHashSet::default();
67 for item in enable.iter().chain(disable.iter()) {
68 if !occupied.insert(item) {
69 // was present
70 return None;
71 }
72 }
73
74 Some(CfgDiff { enable, disable })
75 }
76
62 /// Returns the total number of atoms changed by this diff. 77 /// Returns the total number of atoms changed by this diff.
63 pub fn len(&self) -> usize { 78 pub fn len(&self) -> usize {
64 self.enable.len() + self.disable.len() 79 self.enable.len() + self.disable.len()