Skip to content

Commit

Permalink
Fix #856
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Oct 2, 2023
1 parent 807e435 commit cc00959
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
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

0 comments on commit cc00959

Please sign in to comment.