Skip to content

Commit

Permalink
chore(toolchain): bump rust toolchain + simple Nix
Browse files Browse the repository at this point in the history
  • Loading branch information
bhoudebert committed Oct 27, 2022
1 parent 0b4409b commit 07540a8
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 50 deletions.
Empty file added .direnv/.keep
Empty file.
1 change: 1 addition & 0 deletions .direnv/flake-profile
1 change: 1 addition & 0 deletions .direnv/flake-profile-1-link
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
7 changes: 2 additions & 5 deletions examples/readme-basic.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use ::function_name::named;

#[named]
fn my_super_duper_function ()
{
fn my_super_duper_function() {
dbg!(function_name!());
}

fn main ()
{
fn main() {
my_super_duper_function();
}

18 changes: 9 additions & 9 deletions examples/readme-function_path.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#[macro_use] extern crate function_name;
#[macro_use]
extern crate function_name;

macro_rules! function_path {() => (concat!(
module_path!(), "::", function_name!()
))}
macro_rules! function_path {
() => {
concat!(module_path!(), "::", function_name!())
};
}

pub mod foo {
pub mod bar {
#[named]
pub fn baz ()
{
pub fn baz() {
dbg!(function_path!());
}
}
}

fn main ()
{
fn main() {
foo::bar::baz();
}

41 changes: 41 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
description = "Rust Function Name";

inputs = {
utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, utils }:
utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
packages.${system}.default = pkgs.stdenv.mkDerivation {
name = "rust-function_name";
src = self;
};
devShells.default = import ./shell.nix { inherit pkgs; };
}
);

}
33 changes: 10 additions & 23 deletions proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
#[allow(unused_imports)]
use {
::core::{
ops::Not as _,
},
::proc_macro::{*,
TokenStream,
},
::core::ops::Not as _,
::proc_macro::{TokenStream, *},
};

#[proc_macro_attribute] pub
fn named (
params: TokenStream,
input: TokenStream,
) -> TokenStream
{
#[proc_macro_attribute]
pub fn named(params: TokenStream, input: TokenStream) -> TokenStream {
named_impl(params.into(), input.into())
.unwrap_or_else(|err| {
let err = Some(TokenTree::from(Literal::string(err)));
quote!(
::core::compile_error! { #err }
)
quote!(::core::compile_error! { #err })
})
.into()
}

fn named_impl (
params: TokenStream,
input: TokenStream,
) -> Result<TokenStream, &'static str>
{
fn named_impl(params: TokenStream, input: TokenStream) -> Result<TokenStream, &'static str> {
// parse::Nothing for `params`.
if let Some(_) = params.into_iter().next() {
return Err("unexpected attribute arguments".into());
Expand Down Expand Up @@ -56,8 +42,8 @@ fn named_impl (
};

let g = match input.last_mut() {
| Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Brace => g,
| _ => return Err("expected a `fn`"),
Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Brace => g,
_ => return Err("expected a `fn`"),
};
let g_span = g.span();
*g = Group::new(g.delimiter(), {
Expand Down Expand Up @@ -150,4 +136,5 @@ macro_rules! quote_ {
quote!(@_q $($code)*);
_q.into_iter().collect::<TokenStream>()
});
} use quote_ as quote;
}
use quote_ as quote;
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.45.0
1.64.0
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tab_spaces = 4
edition = "2021"
32 changes: 32 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{ pkgs ? import <nixpkgs> { } }:
let
in
with pkgs;

stdenv.mkDerivation {
name = "rust-function_name";
buildInputs = [
## Rust
cargo
rustup
rustc
pkg-config
openssl
openssl.dev
llvm
wllvm
rust-bindgen
rust-analyzer
rustfmt
# extra tools
cargo-audit
cargo-edit
cargo-outdated
cargo-watch
## Nix
nixpkgs-fmt
];
# OPENSSL_DEV=openssl.dev;
# IS_DEV=1;
RUST_LOG = "info";
}
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#![cfg_attr(feature = "better-docs",
cfg_attr(all(), doc = include_str!("../README.md")),
)]
#![doc(test(attr(
deny(warnings), allow(unused),
)))]
#![doc(test(attr(deny(warnings), allow(unused),)))]
//!
#![warn(missing_docs)]

#![no_std]

/// Entry point of the crate.
Expand Down
9 changes: 3 additions & 6 deletions tests/double_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
extern crate function_name;

#[named]
fn foo ()
{
fn foo() {
assert_eq!(function_name!(), "foo");
}

#[named]
fn bar ()
{
fn bar() {
assert_eq!(function_name!(), "bar");
}

#[test]
fn main ()
{
fn main() {
foo();
bar();
}
3 changes: 1 addition & 2 deletions tests/raw_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extern crate function_name;

#[test]
#[named]
fn r#if ()
{
fn r#if() {
assert_eq!(function_name!(), "r#if");
}

0 comments on commit 07540a8

Please sign in to comment.