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

[DO NOT MERGE] Force edition 2024 lint into action on crater #14447

Draft
wants to merge 1 commit into
base: master
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
58 changes: 52 additions & 6 deletions src/bin/cargo/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::command_prelude::*;

use cargo::ops;

use crate::command_prelude::*;

pub fn cli() -> Command {
subcommand("check")
// subcommand aliases are handled in aliased_command()
Expand Down Expand Up @@ -44,16 +44,62 @@ pub fn cli() -> Command {
}

pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
if std::env::var("CARGO_REAL_CHECK").is_err() {
fixit()?;
return Ok(());
}
let ws = args.workspace(gctx)?;
// This is a legacy behavior that causes `cargo check` to pass `--test`.
let test = matches!(
args.get_one::<String>("profile").map(String::as_str),
Some("test")
);
let test = matches!(args.get_one::<String>("profile").map(String::as_str), Some("test"));
let mode = CompileMode::Check { test };
let compile_opts =
args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;

ops::compile(&ws, &compile_opts)?;
Ok(())
}

fn fixit() -> CliResult {
use std::path::Path;

use anyhow::Context;
use cargo_util::{paths, ProcessBuilder};

eprintln!("Copying to /tmp/fixit");
ProcessBuilder::new("cp").args(&["-a", ".", "/tmp/fixit"]).exec()?;
std::env::set_current_dir("/tmp/fixit").map_err(|e| anyhow::format_err!("cd failed {}", e))?;

let ed_re = regex::Regex::new(r#"(?m)^ *edition *= *['"]([^'"]+)['"]"#).unwrap();
let manifest = paths::read(Path::new("Cargo.toml"))?;
let ed_cap = match ed_re.captures(&manifest) {
None => {
eprintln!("no edition found in manifest, probably 2015, skipping");
return Ok(());
}
Some(caps) => caps.get(1).unwrap(),
};
if ed_cap.as_str() != "2021" {
eprintln!("skipping non-2021 edition `{}`", ed_cap.as_str());
return Ok(());
}
eprintln!("Running `cargo fix --edition`");
// Skip "cargo check"
let args: Vec<_> = std::env::args().skip(2).collect();
ProcessBuilder::new("cargo")
.args(&["fix", "--edition", "--allow-no-vcs", "--allow-dirty"])
.args(&args)
.exec()
.with_context(|| "failed to migrate to next edition")?;
let mut manifest = paths::read(Path::new("Cargo.toml"))?;
let ed_cap = ed_re.captures(&manifest).unwrap().get(1).unwrap();
manifest.replace_range(ed_cap.range(), "2024");
paths::write("Cargo.toml", manifest)?;
eprintln!("Running `cargo check` to verify 2024");
ProcessBuilder::new("cargo")
.args(&["check"])
.args(&args)
.env("CARGO_REAL_CHECK", "1")
.exec()
.with_context(|| "failed to check after updating to 2024")?;
Ok(())
}
18 changes: 9 additions & 9 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,15 +1257,15 @@ pub fn to_real_manifest(
// features.require(Feature::edition20xx())?;
// }
// ```
if edition == Edition::Edition2024 {
features.require(Feature::edition2024())?;
} else if !edition.is_stable() {
// Guard in case someone forgets to add .require()
return Err(util::errors::internal(format!(
"edition {} should be gated",
edition
)));
}
// if edition == Edition::Edition2024 {
// features.require(Feature::edition2024())?;
// } else if !edition.is_stable() {
// // Guard in case someone forgets to add .require()
// return Err(util::errors::internal(format!(
// "edition {} should be gated",
// edition
// )));
// }

if original_toml.project.is_some() {
if Edition::Edition2024 <= edition {
Expand Down
Loading