From 9c8bdcf64fbc7994eb34555b8e11cfdf0983e767 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Apr 2024 05:35:08 +0200 Subject: [PATCH 1/2] can completely use rsc without using allow(clippy) --- src/exprs_impl.rs | 2 +- src/lib.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/exprs_impl.rs b/src/exprs_impl.rs index 661959a..a740445 100644 --- a/src/exprs_impl.rs +++ b/src/exprs_impl.rs @@ -1,7 +1,7 @@ use crate::ast::{LitInteger, MathExprs}; -use crate::rsc::{parse, tokenize, Interpreter, Variant}; use proc_macro2::Span; use quote::ToTokens; +use rsc::{parse, tokenize, Interpreter, Variant}; use syn::{spanned::Spanned, Error, LitInt, Result, Stmt}; const ANS: &str = "ANS"; diff --git a/src/lib.rs b/src/lib.rs index bcc6c7e..ba9fe77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,8 +7,6 @@ use crate::ast::{ }; use crate::macros::debug_eprintln; use proc_macro::{self, TokenStream}; -#[allow(clippy::all)] -use rsc; use tnconst_impl::{ nconst_impl_lit_integer, nconst_impl_math_exprs, pconst_impl_lit_integer, pconst_impl_math_exprs, tnconst_impl_lit_integer, tnconst_impl_math_exprs, From 338b80ac470d40465f4bf3c8c2388b7842e41426 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Apr 2024 10:10:36 +0200 Subject: [PATCH 2/2] better error message and new test for testing if invoked with another macro like name e.g. ggenv --- src/ast_macro.rs | 6 +- .../compile_fails/test_compile_fail.rs | 1 + .../compile_fails/test_compile_fail.stderr | 222 +++++++++--------- 3 files changed, 118 insertions(+), 111 deletions(-) diff --git a/src/ast_macro.rs b/src/ast_macro.rs index 77231de..7afd0c9 100644 --- a/src/ast_macro.rs +++ b/src/ast_macro.rs @@ -102,9 +102,9 @@ impl AllowedMacros { let macro_ident = the_macro.path.require_ident()?; match macro_ident.to_string().as_str() { "env" => Ok(Self::Env(the_macro.parse_body::()?)), - other => Err(Error::new_spanned( - other, - "currently only support `env`-like macro invocation", + other => Err(Error::new( + macro_ident.span(), + format!("currently only support `env` macro-like invocation, it currently does not support `{}`", other), )), } } diff --git a/trybuild_tests/compile_fails/test_compile_fail.rs b/trybuild_tests/compile_fails/test_compile_fail.rs index 0e00b67..1cb6ff0 100644 --- a/trybuild_tests/compile_fails/test_compile_fail.rs +++ b/trybuild_tests/compile_fails/test_compile_fail.rs @@ -41,6 +41,7 @@ fn test_tnconst() { type R = tnconst![- env!("ENV_VAR");]; type S = tnconst![+ env!("NENV_VAR");]; type T = tnconst![ env!("NENV_VAR");]; + type U = tnconst![ ggenv!("NENV_VAR");]; println!("test_tnconst Passed!"); } diff --git a/trybuild_tests/compile_fails/test_compile_fail.stderr b/trybuild_tests/compile_fails/test_compile_fail.stderr index 72f9c87..1f5aa6f 100644 --- a/trybuild_tests/compile_fails/test_compile_fail.stderr +++ b/trybuild_tests/compile_fails/test_compile_fail.stderr @@ -118,320 +118,326 @@ error: invocation of `env` macro does not return a positive integer literal 43 | type T = tnconst![ env!("NENV_VAR");]; | ^^^ +error: currently only support `env` macro-like invocation, it currently does not support `ggenv` + --> trybuild_tests/compile_fails/test_compile_fail.rs:44:24 + | +44 | type U = tnconst![ ggenv!("NENV_VAR");]; + | ^^^^^ + error: failed to read `BAD_SECRET` key from the environment, err = environment variable not found - --> trybuild_tests/compile_fails/test_compile_fail.rs:50:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:51:28 | -50 | type A = pconst![ env!("BAD_SECRET");]; +51 | type A = pconst![ env!("BAD_SECRET");]; | ^^^^^^^^^^^^ error: path cannot be empty - --> trybuild_tests/compile_fails/test_compile_fail.rs:51:42 + --> trybuild_tests/compile_fails/test_compile_fail.rs:52:42 | -51 | type B = pconst![ env!("BAD_SECRET", "");]; +52 | type B = pconst![ env!("BAD_SECRET", "");]; | ^^ error: expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:52:41 + --> trybuild_tests/compile_fails/test_compile_fail.rs:53:41 | -52 | type C = pconst![ env!("BAD_SECRET",,);]; +53 | type C = pconst![ env!("BAD_SECRET",,);]; | ^ error: expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:53:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:54:28 | -53 | type D = pconst![ env!(,,"BAD_SECRET");]; +54 | type D = pconst![ env!(,,"BAD_SECRET");]; | ^ error: unexpected end of input, expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:54:32 + --> trybuild_tests/compile_fails/test_compile_fail.rs:55:32 | -54 | type E = pconst![ env!("", );]; +55 | type E = pconst![ env!("", );]; | ^ error: key cannot be empty - --> trybuild_tests/compile_fails/test_compile_fail.rs:55:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:56:28 | -55 | type F = pconst![ env!("", "");]; +56 | type F = pconst![ env!("", "");]; | ^^ error: expected integer literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:56:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:57:22 | -56 | type G = pconst![% env!("", "");]; +57 | type G = pconst![% env!("", "");]; | ^ error: expected `;` - --> trybuild_tests/compile_fails/test_compile_fail.rs:58:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:59:28 | -58 | type J = pconst![ 6969 {};]; +59 | type J = pconst![ 6969 {};]; | ^ error: expected `;` - --> trybuild_tests/compile_fails/test_compile_fail.rs:59:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:60:28 | -59 | type K = pconst![ 6969 {}]; +60 | type K = pconst![ 6969 {}]; | ^ error: VarDoesNotExist("lame") - --> trybuild_tests/compile_fails/test_compile_fail.rs:62:9 + --> trybuild_tests/compile_fails/test_compile_fail.rs:63:9 | -62 | lame; +63 | lame; | ^^^^ error: when using `pconst`, the first character passed cannot be a `+` - --> trybuild_tests/compile_fails/test_compile_fail.rs:64:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:65:22 | -64 | type M = pconst![+ 69]; +65 | type M = pconst![+ 69]; | ^ error: when using `pconst`, the first character passed cannot be a `+` - --> trybuild_tests/compile_fails/test_compile_fail.rs:65:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:66:22 | -65 | type N = pconst![+ env!("ENV_VAR");]; +66 | type N = pconst![+ env!("ENV_VAR");]; | ^ error: when using `pconst`, the first character passed cannot be a `+` - --> trybuild_tests/compile_fails/test_compile_fail.rs:66:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:67:22 | -66 | type O = pconst![+ { +67 | type O = pconst![+ { | ^ error: expressions should be evaluated to a positive integer, got `-5` instead - --> trybuild_tests/compile_fails/test_compile_fail.rs:74:9 + --> trybuild_tests/compile_fails/test_compile_fail.rs:75:9 | -74 | a - b +75 | a - b | ^ error: failed to read `BAD_SECRET` key from the environment, err = environment variable not found - --> trybuild_tests/compile_fails/test_compile_fail.rs:83:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:84:28 | -83 | type A = nconst![ env!("BAD_SECRET");]; +84 | type A = nconst![ env!("BAD_SECRET");]; | ^^^^^^^^^^^^ error: path cannot be empty - --> trybuild_tests/compile_fails/test_compile_fail.rs:84:42 + --> trybuild_tests/compile_fails/test_compile_fail.rs:85:42 | -84 | type B = nconst![ env!("BAD_SECRET", "");]; +85 | type B = nconst![ env!("BAD_SECRET", "");]; | ^^ error: expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:85:41 + --> trybuild_tests/compile_fails/test_compile_fail.rs:86:41 | -85 | type C = nconst![ env!("BAD_SECRET",,);]; +86 | type C = nconst![ env!("BAD_SECRET",,);]; | ^ error: expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:86:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:87:28 | -86 | type D = nconst![ env!(,,"BAD_SECRET");]; +87 | type D = nconst![ env!(,,"BAD_SECRET");]; | ^ error: unexpected end of input, expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:87:32 + --> trybuild_tests/compile_fails/test_compile_fail.rs:88:32 | -87 | type E = nconst![ env!("", );]; +88 | type E = nconst![ env!("", );]; | ^ error: key cannot be empty - --> trybuild_tests/compile_fails/test_compile_fail.rs:88:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:89:28 | -88 | type F = nconst![ env!("", "");]; +89 | type F = nconst![ env!("", "");]; | ^^ error: expected integer literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:89:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:90:22 | -89 | type G = nconst![% env!("", "");]; +90 | type G = nconst![% env!("", "");]; | ^ error: expected `;` - --> trybuild_tests/compile_fails/test_compile_fail.rs:91:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:92:28 | -91 | type J = nconst![ 6969 {};]; +92 | type J = nconst![ 6969 {};]; | ^ error: expected `;` - --> trybuild_tests/compile_fails/test_compile_fail.rs:92:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:93:28 | -92 | type K = nconst![ 6969 {}]; +93 | type K = nconst![ 6969 {}]; | ^ error: VarDoesNotExist("lame") - --> trybuild_tests/compile_fails/test_compile_fail.rs:95:9 + --> trybuild_tests/compile_fails/test_compile_fail.rs:96:9 | -95 | lame; +96 | lame; | ^^^^ error: unexpected end of input, the content within the block delimited by `{...}` must not be empty - --> trybuild_tests/compile_fails/test_compile_fail.rs:97:23 + --> trybuild_tests/compile_fails/test_compile_fail.rs:98:23 | -97 | type M = nconst![{}]; +98 | type M = nconst![{}]; | ^ -error: when using `nconst`, the first character passed cannot be a `-` - --> trybuild_tests/compile_fails/test_compile_fail.rs:98:22 - | -98 | type R = nconst![-69]; - | ^ - error: when using `nconst`, the first character passed cannot be a `-` --> trybuild_tests/compile_fails/test_compile_fail.rs:99:22 | -99 | type N = nconst![- env!("ENV_VAR");]; +99 | type R = nconst![-69]; | ^ error: when using `nconst`, the first character passed cannot be a `-` --> trybuild_tests/compile_fails/test_compile_fail.rs:100:22 | -100 | type O = nconst![-{ +100 | type N = nconst![- env!("ENV_VAR");]; + | ^ + +error: when using `nconst`, the first character passed cannot be a `-` + --> trybuild_tests/compile_fails/test_compile_fail.rs:101:22 + | +101 | type O = nconst![-{ | ^ error: expressions should be evaluated to a negative integer, got `15` instead - --> trybuild_tests/compile_fails/test_compile_fail.rs:108:9 + --> trybuild_tests/compile_fails/test_compile_fail.rs:109:9 | -108 | a + b +109 | a + b | ^ error: failed to read `BAD_SECRET` key from the environment, err = environment variable not found - --> trybuild_tests/compile_fails/test_compile_fail.rs:117:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:118:28 | -117 | type A = uconst![ env!("BAD_SECRET");]; +118 | type A = uconst![ env!("BAD_SECRET");]; | ^^^^^^^^^^^^ error: path cannot be empty - --> trybuild_tests/compile_fails/test_compile_fail.rs:118:42 + --> trybuild_tests/compile_fails/test_compile_fail.rs:119:42 | -118 | type B = uconst![ env!("BAD_SECRET", "");]; +119 | type B = uconst![ env!("BAD_SECRET", "");]; | ^^ error: expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:119:41 + --> trybuild_tests/compile_fails/test_compile_fail.rs:120:41 | -119 | type C = uconst![ env!("BAD_SECRET",,);]; +120 | type C = uconst![ env!("BAD_SECRET",,);]; | ^ error: expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:120:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:121:28 | -120 | type D = uconst![ env!(,,"BAD_SECRET");]; +121 | type D = uconst![ env!(,,"BAD_SECRET");]; | ^ error: unexpected end of input, expected string literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:121:32 + --> trybuild_tests/compile_fails/test_compile_fail.rs:122:32 | -121 | type E = uconst![ env!("", );]; +122 | type E = uconst![ env!("", );]; | ^ error: key cannot be empty - --> trybuild_tests/compile_fails/test_compile_fail.rs:122:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:123:28 | -122 | type F = uconst![ env!("", "");]; +123 | type F = uconst![ env!("", "");]; | ^^ error: expected integer literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:123:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:124:22 | -123 | type G = uconst![% env!("", "");]; +124 | type G = uconst![% env!("", "");]; | ^ error: expected `;` - --> trybuild_tests/compile_fails/test_compile_fail.rs:125:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:126:28 | -125 | type J = uconst![ 6969 {};]; +126 | type J = uconst![ 6969 {};]; | ^ error: expected `;` - --> trybuild_tests/compile_fails/test_compile_fail.rs:126:28 + --> trybuild_tests/compile_fails/test_compile_fail.rs:127:28 | -126 | type K = uconst![ 6969 {}]; +127 | type K = uconst![ 6969 {}]; | ^ error: VarDoesNotExist("lame") - --> trybuild_tests/compile_fails/test_compile_fail.rs:129:9 + --> trybuild_tests/compile_fails/test_compile_fail.rs:130:9 | -129 | lame; +130 | lame; | ^^^^ error: unexpected token - --> trybuild_tests/compile_fails/test_compile_fail.rs:133:38 + --> trybuild_tests/compile_fails/test_compile_fail.rs:134:38 | -133 | type O = uconst![env!("ENV_VAR");;]; +134 | type O = uconst![env!("ENV_VAR");;]; | ^ error: expressions should be evaluated to a non-negative or positive integer, got `-6869` instead - --> trybuild_tests/compile_fails/test_compile_fail.rs:135:9 + --> trybuild_tests/compile_fails/test_compile_fail.rs:136:9 | -135 | 100 - 6969; +136 | 100 - 6969; | ^^^ -error: when using `uconst`, the first character passed cannot be a `-` or a `+` - --> trybuild_tests/compile_fails/test_compile_fail.rs:137:22 - | -137 | type R = uconst![-69]; - | ^ - error: when using `uconst`, the first character passed cannot be a `-` or a `+` --> trybuild_tests/compile_fails/test_compile_fail.rs:138:22 | -138 | type S = uconst![- env!("ENV_VAR");]; +138 | type R = uconst![-69]; | ^ error: when using `uconst`, the first character passed cannot be a `-` or a `+` --> trybuild_tests/compile_fails/test_compile_fail.rs:139:22 | -139 | type T = uconst![-{ +139 | type S = uconst![- env!("ENV_VAR");]; | ^ error: when using `uconst`, the first character passed cannot be a `-` or a `+` - --> trybuild_tests/compile_fails/test_compile_fail.rs:144:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:140:22 | -144 | type X = uconst![-{ +140 | type T = uconst![-{ | ^ error: when using `uconst`, the first character passed cannot be a `-` or a `+` - --> trybuild_tests/compile_fails/test_compile_fail.rs:149:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:145:22 | -149 | type U = uconst![+ 69]; +145 | type X = uconst![-{ | ^ error: when using `uconst`, the first character passed cannot be a `-` or a `+` --> trybuild_tests/compile_fails/test_compile_fail.rs:150:22 | -150 | type V = uconst![+ env!("ENV_VAR");]; +150 | type U = uconst![+ 69]; | ^ error: when using `uconst`, the first character passed cannot be a `-` or a `+` --> trybuild_tests/compile_fails/test_compile_fail.rs:151:22 | -151 | type W = uconst![+ { +151 | type V = uconst![+ env!("ENV_VAR");]; + | ^ + +error: when using `uconst`, the first character passed cannot be a `-` or a `+` + --> trybuild_tests/compile_fails/test_compile_fail.rs:152:22 + | +152 | type W = uconst![+ { | ^ error: when using `uconst`, the first character passed cannot be a `-` or a `+` - --> trybuild_tests/compile_fails/test_compile_fail.rs:156:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:157:22 | -156 | type Y = uconst![+ { +157 | type Y = uconst![+ { | ^ error: expressions should be evaluated to a negative integer, got `15` instead - --> trybuild_tests/compile_fails/test_compile_fail.rs:179:9 + --> trybuild_tests/compile_fails/test_compile_fail.rs:180:9 | -179 | b + a; // Last statement is always the final returned value to be casted into `typenum` type-level integer, U15 +180 | b + a; // Last statement is always the final returned value to be casted into `typenum` type-level integer, U15 | ^ error: invocation of `env` macro does not return a negative integer literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:195:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:196:22 | -195 | type D = nconst![env!("ENV_VAR");]; +196 | type D = nconst![env!("ENV_VAR");]; | ^^^ error: invocation of `env` macro does not return a positive integer literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:211:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:212:22 | -211 | type D = pconst![env!("NENV_VAR");]; +212 | type D = pconst![env!("NENV_VAR");]; | ^^^ error: invocation of `env` macro does not return a positive integer literal - --> trybuild_tests/compile_fails/test_compile_fail.rs:227:22 + --> trybuild_tests/compile_fails/test_compile_fail.rs:228:22 | -227 | type D = uconst![env!("NENV_VAR");]; +228 | type D = uconst![env!("NENV_VAR");]; | ^^^