about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-20 09:37:39 +0000
committerbors <bors@rust-lang.org>2024-03-20 09:37:39 +0000
commit0f706af330022b46efb5bcc8da7ad7276dfdeb69 (patch)
treec2dbee18d83faf4b78a8e577924dc5a7958aa122 /src
parentb7dcabe55e3b915ba9488dc374f752404c2c8945 (diff)
parent53a753e31f87280abaf342f2e235366901716ea5 (diff)
Auto merge of #122763 - matthiaskrgr:rollup-o8a2mye, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #121543 (various clippy fixes)
 - #122540 (Do not use `?`-induced skewing of type inference in the compiler)
 - #122730 (Expose `ucred::peer_cred` on QNX targets to enable dist builds)
 - #122732 (Remove redundant coroutine captures note)
 - #122739 (Add "put" as a confusable for insert on hash map/set)
 - #122748 (Reduce `pub` usage in `rustc_session`.)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/src/core/build_steps/check.rs42
-rw-r--r--src/bootstrap/src/core/config/tests.rs54
2 files changed, 84 insertions, 12 deletions
diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs
index a90139a070a..55180a82885 100644
--- a/src/bootstrap/src/core/build_steps/check.rs
+++ b/src/bootstrap/src/core/build_steps/check.rs
@@ -61,14 +61,16 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
             }
         }
 
-        args.extend(strings(&["--", "--cap-lints", "warn"]));
+        args.extend(strings(&["--"]));
+
+        if deny.is_empty() && forbid.is_empty() {
+            args.extend(strings(&["--cap-lints", "warn"]));
+        }
+
+        let all_args = std::env::args().collect::<Vec<_>>();
+        args.extend(get_clippy_rules_in_order(&all_args, allow, deny, warn, forbid));
+
         args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
-        let mut clippy_lint_levels: Vec<String> = Vec::new();
-        allow.iter().for_each(|v| clippy_lint_levels.push(format!("-A{}", v)));
-        deny.iter().for_each(|v| clippy_lint_levels.push(format!("-D{}", v)));
-        warn.iter().for_each(|v| clippy_lint_levels.push(format!("-W{}", v)));
-        forbid.iter().for_each(|v| clippy_lint_levels.push(format!("-F{}", v)));
-        args.extend(clippy_lint_levels);
         args.extend(builder.config.free_args.clone());
         args
     } else {
@@ -76,6 +78,32 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
     }
 }
 
+/// We need to keep the order of the given clippy lint rules before passing them.
+/// Since clap doesn't offer any useful interface for this purpose out of the box,
+/// we have to handle it manually.
+pub(crate) fn get_clippy_rules_in_order(
+    all_args: &[String],
+    allow_rules: &[String],
+    deny_rules: &[String],
+    warn_rules: &[String],
+    forbid_rules: &[String],
+) -> Vec<String> {
+    let mut result = vec![];
+
+    for (prefix, item) in
+        [("-A", allow_rules), ("-D", deny_rules), ("-W", warn_rules), ("-F", forbid_rules)]
+    {
+        item.iter().for_each(|v| {
+            let rule = format!("{prefix}{v}");
+            let position = all_args.iter().position(|t| t == &rule).unwrap();
+            result.push((position, rule));
+        });
+    }
+
+    result.sort_by_key(|&(position, _)| position);
+    result.into_iter().map(|v| v.1).collect()
+}
+
 fn cargo_subcommand(kind: Kind) -> &'static str {
     match kind {
         Kind::Check => "check",
diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs
index 93ba5f4120a..8cd538953c5 100644
--- a/src/bootstrap/src/core/config/tests.rs
+++ b/src/bootstrap/src/core/config/tests.rs
@@ -1,4 +1,5 @@
 use super::{flags::Flags, ChangeIdWrapper, Config};
+use crate::core::build_steps::check::get_clippy_rules_in_order;
 use crate::core::config::{LldMode, TomlConfig};
 
 use clap::CommandFactory;
@@ -11,12 +12,13 @@ use std::{
 };
 
 fn parse(config: &str) -> Config {
-    let config = format!("{config} \r\n build.rustc = \"/does-not-exists\" ");
     Config::parse_inner(
         &[
-            "check".to_owned(),
-            "--config=/does/not/exist".to_owned(),
-            "--skip-stage0-validation".to_owned(),
+            "check".to_string(),
+            "--set=build.rustc=/does/not/exist".to_string(),
+            "--set=build.cargo=/does/not/exist".to_string(),
+            "--config=/does/not/exist".to_string(),
+            "--skip-stage0-validation".to_string(),
         ],
         |&_| toml::from_str(&config).unwrap(),
     )
@@ -169,7 +171,10 @@ fn override_toml_duplicate() {
     Config::parse_inner(
         &[
             "check".to_owned(),
+            "--set=build.rustc=/does/not/exist".to_string(),
+            "--set=build.cargo=/does/not/exist".to_string(),
             "--config=/does/not/exist".to_owned(),
+            "--skip-stage0-validation".to_owned(),
             "--set=change-id=1".to_owned(),
             "--set=change-id=2".to_owned(),
         ],
@@ -192,7 +197,15 @@ fn profile_user_dist() {
             .and_then(|table: toml::Value| TomlConfig::deserialize(table))
             .unwrap()
     }
-    Config::parse_inner(&["check".to_owned()], get_toml);
+    Config::parse_inner(
+        &[
+            "check".to_owned(),
+            "--set=build.rustc=/does/not/exist".to_string(),
+            "--set=build.cargo=/does/not/exist".to_string(),
+            "--skip-stage0-validation".to_string(),
+        ],
+        get_toml,
+    );
 }
 
 #[test]
@@ -254,3 +267,34 @@ fn parse_change_id_with_unknown_field() {
     let change_id_wrapper: ChangeIdWrapper = toml::from_str(config).unwrap();
     assert_eq!(change_id_wrapper.inner, Some(3461));
 }
+
+#[test]
+fn order_of_clippy_rules() {
+    let args = vec![
+        "clippy".to_string(),
+        "--fix".to_string(),
+        "--allow-dirty".to_string(),
+        "--allow-staged".to_string(),
+        "-Aclippy:all".to_string(),
+        "-Wclippy::style".to_string(),
+        "-Aclippy::foo1".to_string(),
+        "-Aclippy::foo2".to_string(),
+    ];
+    let config = Config::parse(&args);
+
+    let actual = match &config.cmd {
+        crate::Subcommand::Clippy { allow, deny, warn, forbid, .. } => {
+            get_clippy_rules_in_order(&args, &allow, &deny, &warn, &forbid)
+        }
+        _ => panic!("invalid subcommand"),
+    };
+
+    let expected = vec![
+        "-Aclippy:all".to_string(),
+        "-Wclippy::style".to_string(),
+        "-Aclippy::foo1".to_string(),
+        "-Aclippy::foo2".to_string(),
+    ];
+
+    assert_eq!(expected, actual);
+}