Skip to content

Commit 454e7ae

Browse files
authored
Merge pull request #30 from kas-gui/work2
Fix autoimpl for traits: copy cfg attrs for trait items
2 parents daa26b2 + f70a5ff commit 454e7ae

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
33
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## [0.6.2], `impl-tools-lib` [0.7.1] — 2022-12-16
6+
7+
- Fix `#[autoimpl]` on traits: copy `#[cfg(..)]` attributes (#30)
8+
59
## [0.6.1], `impl-tools-lib` [0.7.0] — 2022-12-01
610

711
- Better diagnostics for trait-redefinition: require `Deref` bound (#28)

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "impl-tools"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
authors = ["Diggory Hardy <git@dhardy.name>"]
55
edition = "2021"
66
license = "MIT/Apache-2.0"
@@ -21,7 +21,7 @@ proc-macro-error = "1.0"
2121
version = "1.0.14"
2222

2323
[dependencies.impl-tools-lib]
24-
version = "0.7.0"
24+
version = "0.7.1"
2525
path = "lib"
2626

2727
[dev-dependencies]

lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "impl-tools-lib"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
authors = ["Diggory Hardy <git@dhardy.name>"]
55
edition = "2021"
66
license = "MIT/Apache-2.0"

lib/src/for_deref.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ impl ForDeref {
181181
for item in &trait_def.items {
182182
match item {
183183
TraitItem::Const(item) => {
184+
for attr in item.attrs.iter() {
185+
if attr.path == parse_quote! { cfg } {
186+
attr.to_tokens(tokens);
187+
}
188+
}
189+
184190
item.const_token.to_tokens(tokens);
185191
item.ident.to_tokens(tokens);
186192
item.colon_token.to_tokens(tokens);
@@ -194,6 +200,12 @@ impl ForDeref {
194200
item.semi_token.to_tokens(tokens);
195201
}
196202
TraitItem::Method(item) => {
203+
for attr in item.attrs.iter() {
204+
if attr.path == parse_quote! { cfg } {
205+
attr.to_tokens(tokens);
206+
}
207+
}
208+
197209
if has_bound_on_self(&item.sig.generics) {
198210
// If the method has a bound on Self, we cannot use a dereferencing
199211
// implementation since the definitive type is not guaranteed to match
@@ -242,6 +254,12 @@ impl ForDeref {
242254
} });
243255
}
244256
TraitItem::Type(item) => {
257+
for attr in item.attrs.iter() {
258+
if attr.path == parse_quote! { cfg } {
259+
attr.to_tokens(tokens);
260+
}
261+
}
262+
245263
if has_bound_on_self(&item.generics) {
246264
emit_call_site_error!(
247265
"cannot autoimpl trait with Deref";

tests/for_deref.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,12 @@ fn custom_deref_target() {
144144
z.increment();
145145
assert_eq!(y, 12);
146146
}
147+
148+
#[autoimpl(for<T: trait + ?Sized> &T)]
149+
trait Cfgs {
150+
#[cfg(test)]
151+
fn included(&self);
152+
153+
#[cfg(feature = "never")]
154+
fn excluded(&self);
155+
}

0 commit comments

Comments
 (0)