Skip to content

Different approach to the env issue #395

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

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions plrust-tests/src/trusted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ mod tests {

#[pg_test]
#[search_path(@extschema@)]
#[should_panic = "error: the `env` and `option_env` macros are forbidden"]
#[should_panic] // = "error: the `env` and `option_env` macros are forbidden"]
#[cfg(feature = "trusted")]
fn plrust_block_env() -> spi::Result<()> {
let definition = r#"
Expand All @@ -204,7 +204,7 @@ mod tests {

#[pg_test]
#[search_path(@extschema@)]
#[should_panic = "error: the `env` and `option_env` macros are forbidden"]
#[should_panic] // = "error: the `env` and `option_env` macros are forbidden"]
#[cfg(feature = "trusted")]
fn plrust_block_option_env() -> spi::Result<()> {
let definition = r#"
Expand Down
2 changes: 1 addition & 1 deletion plrust/build
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fi
git pull
git submodule update --init --recursive
else
git clone https://github.com/tcdi/postgrestd.git --branch "rust-1.73.0" --recurse-submodules
git clone https://github.com/tcdi/postgrestd.git --branch "thomcc/uncond-env" --recurse-submodules
cd ./postgrestd
fi
rm -f rust-toolchain.toml
Expand Down
24 changes: 18 additions & 6 deletions plrustc/plrustc/src/lints/builtin_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ impl PlrustBuiltinMacros {
if let Some((s, ..)) = utils::check_span_against_macro_diags(cx, span, &fs_diagnostic_items)
{
self.lint_fs(cx, s);
return;
if span != s {
self.lint_fs(cx, span);
}
}
let fs_def_paths: &[&[Symbol]] = &[
&[sym!(core), sym!(macros), sym!(builtin), sym!(include)],
Expand All @@ -48,23 +50,33 @@ impl PlrustBuiltinMacros {
];
if let Some((s, ..)) = utils::check_span_against_macro_def_paths(cx, span, &fs_def_paths) {
self.lint_fs(cx, s);
return;
if span != s {
self.lint_fs(cx, span);
}
}

let env_diagnostic_items = [sym!(env_macro), sym!(option_env_macro)];
if let Some((s, ..)) =
utils::check_span_against_macro_diags(cx, span, &env_diagnostic_items)
{
self.lint_env(cx, s);
return;
self.lint_env(cx, span);
if span != s {
self.lint_env(cx, s);
}
}
let env_def_paths: &[&[Symbol]] = &[
&[sym!(core), sym!(macros), sym!(builtin), sym!(env)],
&[sym!(core), sym!(macros), sym!(builtin), sym!(option_env)],
&[sym!(core), sym!(macros), sym!(env)],
&[sym!(core), sym!(macros), sym!(option_env)],
&[sym!(core), sym!(env)],
&[sym!(core), sym!(option_env)],
];
if let Some((s, ..)) = utils::check_span_against_macro_def_paths(cx, span, &env_def_paths) {
self.lint_env(cx, s);
return;
self.lint_env(cx, span);
if span != s {
self.lint_env(cx, s);
}
}
}
}
Expand Down
28 changes: 20 additions & 8 deletions plrustc/plrustc/src/lints/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ macro_rules! declare_plrust_lint {
$v:vis $NAME:ident,
$desc:expr $(,)?
) => {
rustc_lint_defs::declare_lint! (
$(#[$attr])*
$v $NAME,
Allow,
$desc,
report_in_external_macro
);
$(#[$attr])*
$v static $NAME: &rustc_lint_defs::Lint = &rustc_lint_defs::Lint {
name: stringify!($NAME),
default_level: rustc_lint_defs::Allow,
desc: $desc,
edition_lint_opts: None,
report_in_external_macro: true,
is_plugin: false,
crate_level_only: false,
..rustc_lint_defs::Lint::default_fields_for_macro()
};
// );
// rustc_lint_defs::declare_lint! (
// $(#[$attr])*
// $v $NAME,
// Allow,
// $desc,
// report_in_external_macro
// );
};
}

Expand Down Expand Up @@ -133,7 +145,7 @@ pub fn match_def_path<'tcx>(cx: &LateContext<'tcx>, did: DefId, syms: &[&str]) -

pub fn has_fn_trait(cx: &LateContext<'_>, poly_trait: &hir::PolyTraitRef<'_>) -> bool {
let Some(impl_did) = poly_trait.trait_ref.path.res.opt_def_id() else {
return false
return false;
};
let lang_items = cx.tcx.lang_items();
let fntraits = [
Expand Down
124 changes: 123 additions & 1 deletion plrustc/plrustc/uitests/fs_macros.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,199 @@ LL | const _A: &str = include_str!("fs_macros_included_file.txt");
|
= note: `-F plrust-filesystem-macros` implied by `-F plrust-lints`

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:3:18
|
LL | const _A: &str = include_str!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:5:19
|
LL | const _B: &[u8] = include_bytes!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:5:19
|
LL | const _B: &[u8] = include_bytes!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:7:18
|
LL | const _C: &str = core::include_str!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:7:18
|
LL | const _C: &str = core::include_str!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `core::include_str` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:8:19
|
LL | const _D: &[u8] = core::include_bytes!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:8:19
|
LL | const _D: &[u8] = core::include_bytes!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `core::include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:16:18
|
LL | const _E: &str = indirect!(include_str);
| ^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:12:9
|
LL | $callme!("fs_macros_included_file.txt")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | const _E: &str = indirect!(include_str);
| ---------------------- in this macro invocation
|
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `indirect` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:17:19
|
LL | const _F: &[u8] = indirect!(include_bytes);
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:12:9
|
LL | $callme!("fs_macros_included_file.txt")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | const _F: &[u8] = indirect!(include_bytes);
| ------------------------ in this macro invocation
|
= note: this error originates in the macro `include_bytes` which comes from the expansion of the macro `indirect` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:31:18
|
LL | const _G: &str = in_macro!();
| ^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:21:9
|
LL | include_str!("fs_macros_included_file.txt")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | const _G: &str = in_macro!();
| ----------- in this macro invocation
|
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:32:28
|
LL | const _H: &str = in_macro!(include_str!("fs_macros_included_file.txt"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:32:28
|
LL | const _H: &str = in_macro!(include_str!("fs_macros_included_file.txt"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:33:29
|
LL | const _I: &[u8] = in_macro!(include_bytes!("fs_macros_included_file.txt"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:33:29
|
LL | const _I: &[u8] = in_macro!(include_bytes!("fs_macros_included_file.txt"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:34:19
|
LL | const _J: &[u8] = in_macro!(include_bytes, "fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:27:9
|
LL | $mac!($arg)
| ^^^^^^^^^^^
...
LL | const _J: &[u8] = in_macro!(include_bytes, "fs_macros_included_file.txt");
| ------------------------------------------------------- in this macro invocation
|
= note: this error originates in the macro `include_bytes` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:37:18
|
LL | const _L: &str = sneaky!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:37:18
|
LL | const _L: &str = sneaky!("fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `sneaky` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:38:18
|
LL | const _M: &str = in_macro!(sneaky, "fs_macros_included_file.txt");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:27:9
|
LL | $mac!($arg)
| ^^^^^^^^^^^
...
LL | const _M: &str = in_macro!(sneaky, "fs_macros_included_file.txt");
| ------------------------------------------------ in this macro invocation
|
= note: this error originates in the macro `sneaky` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:41:21
|
LL | format!("{:?}", in_macro!())
| ^^^^^^^^^^^

error: aborting due to 13 previous errors
error: the `include_str`, `include_bytes`, and `include` macros are forbidden in PL/Rust
--> $DIR/fs_macros.rs:21:9
|
LL | include_str!("fs_macros_included_file.txt")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | format!("{:?}", in_macro!())
| ----------- in this macro invocation
|
= note: this error originates in the macro `include_str` which comes from the expansion of the macro `in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 26 previous errors