Skip to content

Commit ccfaaa7

Browse files
committed
Auto merge of #34031 - jseyfried:fix_cfg_bug, r=eddyb
Fix a regression in the configuration folder This fixes #34028, a regression caused by #33706 in which unconfigured impl items generated by a macro in an impl item position are not removed. r? @nrc
2 parents 12238b9 + 9639ec8 commit ccfaaa7

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/libsyntax/config.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,6 @@ impl<T: CfgFolder> fold::Folder for T {
166166
};
167167

168168
let item = match item {
169-
ast::ItemKind::Impl(u, o, a, b, c, items) => {
170-
let items = items.into_iter().filter_map(|item| self.configure(item)).collect();
171-
ast::ItemKind::Impl(u, o, a, b, c, items)
172-
}
173-
ast::ItemKind::Trait(u, a, b, items) => {
174-
let items = items.into_iter().filter_map(|item| self.configure(item)).collect();
175-
ast::ItemKind::Trait(u, a, b, items)
176-
}
177169
ast::ItemKind::Struct(def, generics) => {
178170
ast::ItemKind::Struct(fold_struct(self, def), generics)
179171
}
@@ -242,7 +234,17 @@ impl<T: CfgFolder> fold::Folder for T {
242234
}
243235

244236
fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
245-
self.configure(item).map(|item| SmallVector::one(item.map(|i| self.fold_item_simple(i))))
237+
self.configure(item).map(|item| fold::noop_fold_item(item, self))
238+
.unwrap_or(SmallVector::zero())
239+
}
240+
241+
fn fold_impl_item(&mut self, item: ast::ImplItem) -> SmallVector<ast::ImplItem> {
242+
self.configure(item).map(|item| fold::noop_fold_impl_item(item, self))
243+
.unwrap_or(SmallVector::zero())
244+
}
245+
246+
fn fold_trait_item(&mut self, item: ast::TraitItem) -> SmallVector<ast::TraitItem> {
247+
self.configure(item).map(|item| fold::noop_fold_trait_item(item, self))
246248
.unwrap_or(SmallVector::zero())
247249
}
248250
}

src/test/compile-fail/issue-34028.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(rustc_attrs)]
12+
13+
macro_rules! m {
14+
() => { #[cfg(any())] fn f() {} }
15+
}
16+
17+
trait T {}
18+
impl T for () { m!(); }
19+
20+
#[rustc_error]
21+
fn main() {} //~ ERROR compilation successful

0 commit comments

Comments
 (0)