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

Fix #856 #866

Merged
merged 1 commit into from
Oct 3, 2023
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
16 changes: 16 additions & 0 deletions cargo-dylint/fixtures/depinfo_dylint_libs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "depinfo_dylint_libs"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
anyhow = "1.0"

[workspace]

[workspace.metadata.dylint]
libraries = [
{ path = "../../../examples/restriction/question_mark_in_expression" },
{ path = "../../../examples/restriction/try_io_result" },
]
10 changes: 10 additions & 0 deletions cargo-dylint/fixtures/depinfo_dylint_libs/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use anyhow::Result;
use std::{
io::{stdout, Write},
str::from_utf8,
};

fn main() -> Result<()> {
write!(stdout(), "{}", from_utf8(b"Hello, world!")?)?;
Ok(())
}
31 changes: 31 additions & 0 deletions cargo-dylint/tests/depinfo_dylint_libs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use assert_cmd::prelude::*;
use dylint_internal::env;
use predicates::prelude::*;
use std::{env::set_var, process::Command};

#[ctor::ctor]
fn initialize() {
set_var(env::CARGO_TERM_COLOR, "never");
}

#[test]
fn depinfo_dylint_libs() {
Command::cargo_bin("cargo-dylint")
.unwrap()
.current_dir("fixtures/depinfo_dylint_libs")
.args(["dylint", "--lib", "question_mark_in_expression"])
.assert()
.stderr(predicate::str::contains(
"\nwarning: using the `?` operator within an expression\n",
));

Command::cargo_bin("cargo-dylint")
.unwrap()
.current_dir("fixtures/depinfo_dylint_libs")
.args(["dylint", "--lib", "try_io_result"])
.assert()
.stderr(predicate::str::contains(
"\nwarning: returning a `std::io::Result` could discard relevant context (e.g., files \
or paths involved)\n",
));
}
5 changes: 5 additions & 0 deletions driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,17 @@ impl rustc_driver::Callbacks for Callbacks {
previous(sess, lint_store);
}

let dylint_libs = env::var(env::DYLINT_LIBS).ok();
let dylint_metadata = env::var(env::DYLINT_METADATA).ok();
let dylint_no_deps = env::var(env::DYLINT_NO_DEPS).ok();
let dylint_no_deps_enabled =
dylint_no_deps.as_ref().map_or(false, |value| value != "0");
let cargo_primary_package_is_set = env::var(env::CARGO_PRIMARY_PACKAGE).is_ok();

sess.parse_sess.env_depinfo.lock().insert((
rustc_span::Symbol::intern(env::DYLINT_LIBS),
dylint_libs.as_deref().map(rustc_span::Symbol::intern),
));
sess.parse_sess.env_depinfo.lock().insert((
rustc_span::Symbol::intern(env::DYLINT_METADATA),
dylint_metadata.as_deref().map(rustc_span::Symbol::intern),
Expand Down