Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of all dependencies #1

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,35 @@ jobs:
run: cargo clean
- name: cargo test
run: cargo test --all-targets
allow:

allow-check:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: ["1.43.0", "1.80.0"]
env:
RUSTFLAGS: "-D warnings"
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
- name: cargo check
run: cargo check --all-targets
- name: cargo clean
run: cargo clean
- name: cargo test
run: cargo test --all-targets

allow-clippy:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: ["1.64.0", "1.80.0"] # rustversion only works with clippy >= 1.64.0
env:
RUSTFLAGS: "-D warnings"
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ keywords = [ "expect", "lint", "macro", "clippy", "warnings"]
proc-macro = true

[dependencies]
proc-macro2 = "=1.0.60" # pinned for 1.38.0 compatibility
quote = "=1.0.28" # pinned for 1.38.0 compatibility
rustversion = "1.0.17"
46 changes: 28 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@ pub fn expect(
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
use proc_macro2::TokenStream;
use quote::quote;
let attr = TokenStream::from(attr);
let item = TokenStream::from(item);
let expanded = quote! {
#[allow(#attr)]
#item
};
expanded.into()
replace_attr_name_with(attr, item, "allow")
}

#[rustversion::any(since(1.81), all(nightly, since(2024-06-27)))]
Expand All @@ -35,13 +27,31 @@ pub fn expect(
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
use proc_macro2::TokenStream;
use quote::quote;
let attr = TokenStream::from(attr);
let item = TokenStream::from(item);
let expanded = quote! {
#[expect(#attr)]
#item
};
expanded.into()
replace_attr_name_with(attr, item, "expect")
}

fn replace_attr_name_with(
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
allow_or_expect: &str,
) -> proc_macro::TokenStream {
use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
use std::iter::once;
let mut s = TokenStream::new();
s.extend(once(TokenTree::from(Punct::new('#', Spacing::Alone))));
let mut attr_inner = TokenStream::new();
attr_inner.extend(once(TokenTree::from(Ident::new(
allow_or_expect,
Span::call_site(),
))));
attr_inner.extend(once(TokenTree::from(Group::new(
Delimiter::Parenthesis,
attr,
))));
s.extend(once(TokenTree::from(Group::new(
Delimiter::Bracket,
attr_inner,
))));
s.extend(item);
s
}