Stream: t-compiler/rust-analyzer

Topic: PSA: `cargo xtask codegen` is no more


matklad (Mar 08 2021 at 18:52, on Zulip):

cargo test now not only complains that the generated files are out of date, but actually updates them.

Jeremy Kolb (Mar 08 2021 at 19:00, on Zulip):

with an argument or automagically?

matklad (Mar 08 2021 at 19:05, on Zulip):

automaticaly

matklad (Mar 08 2021 at 19:16, on Zulip):

In other news: I accidentally deleted code model: https://github.com/rust-analyzer/rust-analyzer/pull/7923/files#diff-944d99df715f999866d3a80e35878b60657395e2472b1715edd6dbbb43aa0663

Chetan Khilosiya (Mar 11 2021 at 18:53, on Zulip):

for doctest in assists, the cargo test updates generated.rs file only if the test is not present.
If the generated test is present and we modify the doc then it will not update that test.
cargo xtask codegen used to do that.

matklad (Mar 12 2021 at 10:48, on Zulip):

Hm, this seem to work for me?

13:47:42|~/projects/rust-analyzer|master✓
λ git diff
diff --git a/crates/ide_assists/src/handlers/flip_comma.rs b/crates/ide_assists/src/handlers/flip_comma.rs
index 7f5e75d34..c19c992d1 100644
--- a/crates/ide_assists/src/handlers/flip_comma.rs
+++ b/crates/ide_assists/src/handlers/flip_comma.rs
@@ -8,13 +8,13 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
 //
 // ```
 // fn main() {
-//     ((1, 2),$0 (3, 4));
+//     ((1, 2),$0 (3, 92));
 // }
 // ```
 // ->
 // ```
 // fn main() {
-//     ((3, 4), (1, 2));
+//     ((3, 92), (1, 2));
 // }
 // ```
 pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {

13:47:55|~/projects/rust-analyzer|master⚡*
λ cargo t -p xtask
    Finished test [unoptimized] target(s) in 0.02s
     Running target/debug/deps/xtask-6e8e853982ebb953

running 11 tests
test tidy::generate_lint_completions ... ignored
test tidy::check_code_formatting ... ok
test tidy::check_merge_commits ... ok
test tidy::check_lsp_extensions_docs ... ok
test tidy::generate_parser_tests ... ok
test tidy::check_licenses ... ok
test tidy::cargo_files_are_tidy ... ok
test tidy::generate_assists_tests ... FAILED
test tidy::generate_grammar ... ok
test tidy::rust_files_are_tidy ... ok
test tidy::smoke_test_generate_documentation ... ok

failures:

---- tidy::generate_assists_tests stdout ----

error: crates/ide_assists/src/tests/generated.rs was not up-to-date, updating

thread 'tidy::generate_assists_tests' panicked at 'called `Result::unwrap()` on an `Err` value: some file were not up to date', xtask/src/tidy.rs:22:39
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    tidy::generate_assists_tests

test result: FAILED. 9 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 1.70s

error: test failed, to rerun pass '-p xtask --bin xtask'

13:47:59|~/projects/rust-analyzer|master⚡*
λ git diff
diff --git a/crates/ide_assists/src/handlers/flip_comma.rs b/crates/ide_assists/src/handlers/flip_comma.rs
index 7f5e75d34..c19c992d1 100644
--- a/crates/ide_assists/src/handlers/flip_comma.rs
+++ b/crates/ide_assists/src/handlers/flip_comma.rs
@@ -8,13 +8,13 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
 //
 // ```
 // fn main() {
-//     ((1, 2),$0 (3, 4));
+//     ((1, 2),$0 (3, 92));
 // }
 // ```
 // ->
 // ```
 // fn main() {
-//     ((3, 4), (1, 2));
+//     ((3, 92), (1, 2));
 // }
 // ```
 pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs
index 304b5798f..b7bc139c0 100644
--- a/crates/ide_assists/src/tests/generated.rs
+++ b/crates/ide_assists/src/tests/generated.rs
@@ -388,12 +388,12 @@ fn doctest_flip_comma() {
         "flip_comma",
         r#####"
 fn main() {
-    ((1, 2),$0 (3, 4));
+    ((1, 2),$0 (3, 92));
 }
 "#####,
         r#####"
 fn main() {
-    ((3, 4), (1, 2));
+    ((3, 92), (1, 2));
 }
 "#####,
     )
Chetan Khilosiya (Mar 12 2021 at 13:42, on Zulip):

If I updated the doctest then the cargo test is failing. below is the output
failures:

---- tidy::generate_assists_tests stdout ----

error: crates/ide_assists/src/tests/generated.rs was not up-to-date, updating

thread 'tidy::generate_assists_tests' panicked at 'called Result::unwrap() on an Err value: some file were not up to date', xtask/src/tidy.rs:22:39
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

failures:
tidy::generate_assists_tests

diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs
index 5cfc4110f..54d43fd26 100644
--- a/crates/ide_assists/src/tests/generated.rs
+++ b/crates/ide_assists/src/tests/generated.rs
@@ -700,6 +700,7 @@ impl MyStruct {
p$0ub fn len(&self) -> usize {
self.data.len()
}
+
}
"#####,
r#####"
@@ -711,6 +712,7 @@ impl MyStruct {
pub fn is_empty(&self) -> bool {
self.len() == 0
}
+
}
"#####,
)

I am not sure its problem or issue in my doctest.

Lukas Wirth (Mar 12 2021 at 13:43, on Zulip):

I think it is supposed to fail but it will still update the files

Chetan Khilosiya (Mar 12 2021 at 13:47, on Zulip):

yes it updates the generated file. I thought it will pass after updating file.

Chetan Khilosiya (Mar 12 2021 at 13:54, on Zulip):

I think it's not an issue then. :)

Last update: Jul 29 2021 at 20:45UTC