about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/expand.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-06-10 10:02:18 +0000
committerbors <bors@rust-lang.org>2023-06-10 10:02:18 +0000
commit4b71d79c972a605959b0a7c82b323fbd8562f070 (patch)
tree1b4cb2c2cb64500f4efa7f45dfe39cfe38ccc537 /compiler/rustc_expand/src/expand.rs
parentd0ee1908ed791d3e91d2ad74ba502eaa203cff6d (diff)
parentdcdfff61d299954557c1a6e3fa9ebb83fe8af30c (diff)
downloadrust-4b71d79c972a605959b0a7c82b323fbd8562f070.tar.gz
rust-4b71d79c972a605959b0a7c82b323fbd8562f070.zip
Auto merge of #112485 - matthiaskrgr:rollup-ta84xje, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #110141 (expand: Change how `#![cfg(FALSE)]` behaves on crate root)
 - #112369 (More CGU cleanups)
 - #112467 (Compile rustc_driver by default)
 - #112468 (Change format of rustdoc-js tests by putting query and correction directly alongside the expected values)
 - #112473 (Update cargo)
 - #112481 (Ignore tests that hang in new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_expand/src/expand.rs')
-rw-r--r--compiler/rustc_expand/src/expand.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs
index dd8863df195..9850723a857 100644
--- a/compiler/rustc_expand/src/expand.rs
+++ b/compiler/rustc_expand/src/expand.rs
@@ -1039,7 +1039,12 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
     ) -> Result<Self::OutputTy, Self> {
         Ok(noop_flat_map(node, collector))
     }
-    fn expand_cfg_false(&mut self, collector: &mut InvocationCollector<'_, '_>, span: Span) {
+    fn expand_cfg_false(
+        &mut self,
+        collector: &mut InvocationCollector<'_, '_>,
+        _pos: usize,
+        span: Span,
+    ) {
         collector.cx.emit_err(RemoveNodeNotSupported { span, descr: Self::descr() });
     }
 
@@ -1409,8 +1414,15 @@ impl InvocationCollectorNode for ast::Crate {
     fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
         noop_visit_crate(self, visitor)
     }
-    fn expand_cfg_false(&mut self, collector: &mut InvocationCollector<'_, '_>, _span: Span) {
-        self.attrs.clear();
+    fn expand_cfg_false(
+        &mut self,
+        collector: &mut InvocationCollector<'_, '_>,
+        pos: usize,
+        _span: Span,
+    ) {
+        // Attributes above `cfg(FALSE)` are left in place, because we may want to configure
+        // some global crate properties even on fully unconfigured crates.
+        self.attrs.truncate(pos);
         // Standard prelude imports are left in the crate for backward compatibility.
         self.items.truncate(collector.cx.num_standard_library_imports);
     }
@@ -1804,7 +1816,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
                             continue;
                         }
 
-                        node.expand_cfg_false(self, span);
+                        node.expand_cfg_false(self, pos, span);
                         continue;
                     }
                     sym::cfg_attr => {