Skip to content

Commit 53eed5d

Browse files
authored
Merge pull request #60 from kas-gui/push-kyvwuxtssmuv
nightly-diagnostics; warn on trait autoimpl with Sized bounded fns
2 parents fe02556 + 3d6d59c commit 53eed5d

17 files changed

Lines changed: 108 additions & 20 deletions

.github/workflows/test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- os: ubuntu-latest
1616
toolchain: nightly
1717
variant: docs
18+
features: "--features nightly-diagnostics"
1819
- os: macos-latest
1920
toolchain: beta
2021
- os: windows-latest
@@ -41,13 +42,13 @@ jobs:
4142

4243
- name: Build docs
4344
if: ${{ matrix.variant == 'docs' }}
44-
run: cargo doc --all-features --all --no-deps
45+
run: cargo doc ${{ matrix.features }} --all --no-deps
4546

4647
- name: Test impl-tools-lib
47-
run: cargo test --manifest-path lib/Cargo.toml --all-features ${{ matrix.targets }}
48+
run: cargo test --manifest-path lib/Cargo.toml ${{ matrix.targets }}
4849

4950
- name: Test impl-tools
50-
run: cargo test --all-features ${{ matrix.targets }}
51+
run: cargo test ${{ matrix.features }} ${{ matrix.targets }}
5152

5253
- name: Test test-cfg
5354
working-directory: tests/test-cfg

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ edition.workspace = true
2525
[lib]
2626
proc-macro = true
2727

28+
[features]
29+
# Enables better proc-macro diagnostics (including warnings); nightly only.
30+
nightly-diagnostics = ["proc-macro-error2/nightly"]
31+
# Squelch lint: "autoimpl on trait that has a method with Self: Sized bound"
32+
allow-trait-autoimpl-with-sized-fn-bound = ["impl-tools-lib/allow-trait-autoimpl-with-sized-fn-bound"]
33+
2834
[dependencies.proc-macro-error2]
2935
version = "2.0"
3036
default-features = false
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected `Self` or `A` or `A<...>` or `Trait for Self`, etc
2-
--> compile-errors/expect-self.rs:5:10
2+
--> compile-errors/common/expect-self.rs:5:10
33
|
44
5 | impl () {
55
| ^^

compile-errors/wrong-item-type.stderr renamed to compile-errors/common/wrong-item-type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: #[autoimpl(Trait)] can only be used on enum or struct items
2-
--> compile-errors/wrong-item-type.rs:3:1
2+
--> compile-errors/common/wrong-item-type.rs:3:1
33
|
44
3 | #[impl_tools::autoimpl(Copy)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: expected `Self` or `Trait for Self`
2+
--> compile-errors/nightly/expect-self-anon.rs:6:14
3+
|
4+
6 | impl () {
5+
| ^^
6+
7+
error: expected expression, found end of macro arguments
8+
--> compile-errors/nightly/expect-self-anon.rs:2:13
9+
|
10+
2 | let _ = impl_tools::impl_anon! {
11+
| _____________^
12+
3 | | #[derive(Clone, Debug)]
13+
4 | | struct (i32 = 123);
14+
... |
15+
11 | | };
16+
| |_____^
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use impl_tools::autoimpl;
2+
use core::fmt::Debug;
3+
4+
#[autoimpl(for<'a, T> &'a T, &'a mut T, Box<T> where T: trait + ?Sized)]
5+
trait G<V>
6+
where
7+
V: Debug,
8+
{
9+
fn g(&self) -> V;
10+
11+
fn s<X>(&self, f: impl Fn(V) -> X) -> X
12+
where
13+
Self: Sized,
14+
{
15+
f(self.g())
16+
}
17+
}
18+
19+
fn main() {
20+
compile_error!("Warnings verification");
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
warning: autoimpl on trait that has a method with Self: Sized bound
2+
--> compile-errors/nightly/trait-autoimpl-with-sized-fn-bound.rs:4:1
3+
|
4+
4 | #[autoimpl(for<'a, T> &'a T, &'a mut T, Box<T> where T: trait + ?Sized)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: method impl uses default implementation, not deref
8+
--> compile-errors/nightly/trait-autoimpl-with-sized-fn-bound.rs:11:5
9+
|
10+
11 | / fn s<X>(&self, f: impl Fn(V) -> X) -> X
11+
12 | | where
12+
13 | | Self: Sized,
13+
... |
14+
16 | | }
15+
| |_____^
16+
= note: this warning originates in the attribute macro `autoimpl` (in Nightly builds, run with -Z macro-backtrace for more info)
17+
18+
error: Warnings verification
19+
--> compile-errors/nightly/trait-autoimpl-with-sized-fn-bound.rs:20:5
20+
|
21+
20 | compile_error!("Warnings verification");
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)