Merge pull request #1355 from wjwrh/main

Fix the problem of different edition between rustc and rust-analyzer
This commit is contained in:
liv 2023-02-05 11:51:35 +01:00 committed by GitHub
commit 23c3620001
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,7 @@ use std::path::PathBuf;
use std::process::{self, Command}; use std::process::{self, Command};
const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"]; const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"];
const RUSTC_EDITION_ARGS: &[&str] = &["--edition", "2021"];
const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE"; const I_AM_DONE_REGEX: &str = r"(?m)^\s*///?\s*I\s+AM\s+NOT\s+DONE";
const CONTEXT: usize = 2; const CONTEXT: usize = 2;
const CLIPPY_CARGO_TOML_PATH: &str = "./exercises/clippy/Cargo.toml"; const CLIPPY_CARGO_TOML_PATH: &str = "./exercises/clippy/Cargo.toml";
@ -111,10 +112,12 @@ impl Exercise {
Mode::Compile => Command::new("rustc") Mode::Compile => Command::new("rustc")
.args(&[self.path.to_str().unwrap(), "-o", &temp_file()]) .args(&[self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS) .args(RUSTC_COLOR_ARGS)
.args(RUSTC_EDITION_ARGS)
.output(), .output(),
Mode::Test => Command::new("rustc") Mode::Test => Command::new("rustc")
.args(&["--test", self.path.to_str().unwrap(), "-o", &temp_file()]) .args(&["--test", self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS) .args(RUSTC_COLOR_ARGS)
.args(RUSTC_EDITION_ARGS)
.output(), .output(),
Mode::Clippy => { Mode::Clippy => {
let cargo_toml = format!( let cargo_toml = format!(
@ -140,6 +143,7 @@ path = "{}.rs""#,
Command::new("rustc") Command::new("rustc")
.args(&[self.path.to_str().unwrap(), "-o", &temp_file()]) .args(&[self.path.to_str().unwrap(), "-o", &temp_file()])
.args(RUSTC_COLOR_ARGS) .args(RUSTC_COLOR_ARGS)
.args(RUSTC_EDITION_ARGS)
.output() .output()
.expect("Failed to compile!"); .expect("Failed to compile!");
// Due to an issue with Clippy, a cargo clean is required to catch all lints. // Due to an issue with Clippy, a cargo clean is required to catch all lints.