rust-marker / marker

An experimental linting interface for Rust. Let's make custom lints a reality
https://rust-marker.github.io/marker/
Other
144 stars 11 forks source link

[Bug]: `cargo uitest` fails with `[E0463]: can't find crate for std` #324

Closed tigerros closed 11 months ago

tigerros commented 12 months ago

Summary

I'm not positive that this is a bug, but running Marker on a different crate instead of testing does work, so I think something is wrong with the testing.

Reproducer

Windows 10

  1. git clone https://github.com/rust-marker/lint-crate-template.git
  2. cd lint-crate-template
  3. cargo uitest

Using the latest nightly toolchain and latest Marker dependencies (0.4.2) doesn't help.

Version

cargo-marker 0.4.2

Logs

Updating crates.io index
   Compiling proc-macro2 v1.0.70
   Compiling unicode-ident v1.0.12
   Compiling serde v1.0.193
   Compiling cfg-if v1.0.0
   Compiling once_cell v1.18.0
   Compiling lazy_static v1.4.0
   Compiling windows_x86_64_msvc v0.48.5
   Compiling windows_x86_64_msvc v0.42.2
   Compiling winapi v0.3.9
   Compiling unicode-width v0.1.11
   Compiling sharded-slab v0.1.7
   Compiling tracing-core v0.1.32
   Compiling thread_local v1.1.7
   Compiling pin-project-lite v0.2.13
   Compiling serde_json v1.0.108
   Compiling windows-targets v0.48.5
   Compiling semver v1.0.20
   Compiling cc v1.0.83
   Compiling libc v0.2.150
   Compiling windows-sys v0.48.0
   Compiling quote v1.0.33
   Compiling windows-targets v0.42.2
   Compiling syn v2.0.39
   Compiling tracing v0.1.40
   Compiling tracing-subscriber v0.3.18
   Compiling thiserror v1.0.50
   Compiling portable-atomic v1.5.1
   Compiling regex-syntax v0.8.2
   Compiling ryu v1.0.15
   Compiling eyre v0.6.9
   Compiling crossbeam-utils v0.8.16
   Compiling anyhow v1.0.75
   Compiling itoa v1.0.9
   Compiling camino v1.1.6
   Compiling tracing-error v0.2.0
   Compiling regex-automata v0.4.3
   Compiling backtrace v0.3.69
   Compiling windows-sys v0.45.0
   Compiling rustc-demangle v0.1.23
   Compiling encode_unicode v0.3.6
   Compiling indenter v0.3.3
   Compiling owo-colors v3.5.0
   Compiling console v0.15.7
   Compiling color-spantrace v0.2.1
   Compiling serde_derive v1.0.193
   Compiling thiserror-impl v1.0.50
   Compiling ansi_term v0.12.1
   Compiling yansi-term v0.1.2
   Compiling is-terminal v0.4.9
   Compiling pad v0.1.6
   Compiling number_prefix v0.4.0
   Compiling log v0.4.20
   Compiling memchr v2.6.4
   Compiling fastrand v2.0.1
   Compiling indicatif v0.17.7
   Compiling prettydiff v0.6.4
   Compiling tempfile v3.8.1
   Compiling colored v2.0.4
   Compiling annotate-snippets v0.9.2
   Compiling bstr v1.8.0
   Compiling crossbeam-channel v0.5.8
   Compiling regex v1.10.2
   Compiling color-eyre v0.6.2
   Compiling levenshtein v1.0.5
   Compiling comma v1.0.0
   Compiling marker_api v0.4.2
   Compiling marker_utils v0.4.2
   Compiling cargo-platform v0.1.5
   Compiling rustc_version v0.4.0
   Compiling cargo_metadata v0.15.4
   Compiling rustfix v0.6.1
   Compiling ui_test v0.21.2
   Compiling marker_uitest v0.4.2
   Compiling lint-crate-template v0.1.0 (C:\Users\aurel\source\repos\lint-crate-template)
    Finished test [unoptimized + debuginfo] target(s) in 22.29s
     Running tests\uitest.rs (target\debug\deps\uitest-ab45871b164387e1.exe)
marker_rustc_driver 0.4.2 (c753799 2023-11-25)

FAILED TEST: tests\ui\hello_marker.rs
command: "C:\\Users\\aurel\\.rustup\\toolchains\\nightly-2023-11-16-x86_64-pc-windows-msvc\\bin\\marker_rustc_driver.exe" "--error-format=json" "-Aunused" "--out-dir" "\\\\?\\C:\\Users\\aurel\\source\\repos\\lint-crate-template\\target\\ui_test\\tests\\ui" "tests\\ui\\hello_marker.rs" "--edition" "2021"

error: actual output differed from expected
Execute `cargo test -- -- --bless` to update `tests\ui\hello_marker.stderr` to the actual output
--- tests\ui\hello_marker.stderr
+++ <stderr output>
-warning: hello, main (From Marker)
+error[E0463]: can't find crate for `std`
~ --> $DIR/hello_marker.rs:5:1
   |
-5 | / fn main() {
+6 |     println!("Hello, World!");
~6 | |     println!("Hello, World!");^^^^^^^

-warning: 1 warning emitted
+error: requires `sized` lang_item

+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0463`.

full stderr:
error[E0463]: can't find crate for `std`

error: cannot find macro `println` in this scope
 --> tests\ui\hello_marker.rs:6:5
  |
6 |     println!("Hello, World!");
  |     ^^^^^^^

error: requires `sized` lang_item

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0463`.

full stdout:

FAILURES:
    tests\ui\hello_marker.rs

test result: FAIL. 1 failed;

Error: tests failed

Location:
    C:\Users\aurel\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ui_test-0.21.2\src\lib.rs:388:13
error: test failed, to rerun pass `--test uitest`

Caused by:
  process didn't exit successfully: `C:\Users\aurel\source\repos\lint-crate-template\target\debug\deps\uitest-ab45871b164387e1.exe` (exit code: 1)
xFrednet commented 11 months ago

Thank you for the report! Have you been able to run Marker on a normal crate, or does that also happen there?

tigerros commented 11 months ago

Thank you for the report! Have you been able to run Marker on a normal crate, or does that also happen there?

Running cargo marker on a crate that uses the same lint crate works, if that's what you mean.

xFrednet commented 11 months ago

Yes, that's what I meant. Then it seems to be a problem with the configuration of Marker's testing framework :thinking:

I'm not quite sure what could cause it, but that's what debugging is for. Since it works on my Linux machine and the CI of that crate, I'm guessing that it has something to do with windows.

@tigerros, would you mind running two tests for me?

  1. Add the "rust-std" component in the component list of the rust-toolchain.toml file of the lint crate, and run the tests again?
  2. And could you enable more debugging information, via the following environment variables MARKER_ERROR_TRACE=1 MARKER_LOG=info?

That would be super helpful!

tigerros commented 11 months ago

I'm pretty sure I enabled logging in the first log... Anyway, same issue.

Log ``` Updating crates.io index Compiling proc-macro2 v1.0.70 Compiling unicode-ident v1.0.12 Compiling cfg-if v1.0.0 Compiling serde v1.0.193 Compiling lazy_static v1.4.0 Compiling once_cell v1.18.0 Compiling windows_x86_64_msvc v0.48.5 Compiling winapi v0.3.9 Compiling windows_x86_64_msvc v0.42.2 Compiling unicode-width v0.1.11 Compiling sharded-slab v0.1.7 Compiling serde_json v1.0.108 Compiling tracing-core v0.1.32 Compiling thread_local v1.1.7 Compiling windows-targets v0.48.5 Compiling libc v0.2.150 Compiling semver v1.0.20 Compiling pin-project-lite v0.2.13 Compiling cc v1.0.83 Compiling tracing v0.1.40 Compiling windows-sys v0.48.0 Compiling windows-targets v0.42.2 Compiling quote v1.0.33 Compiling tracing-subscriber v0.3.18 Compiling syn v2.0.39 Compiling portable-atomic v1.5.1 Compiling ryu v1.0.15 Compiling itoa v1.0.9 Compiling thiserror v1.0.50 Compiling crossbeam-utils v0.8.16 Compiling anyhow v1.0.75 Compiling regex-syntax v0.8.2 Compiling camino v1.1.6 Compiling eyre v0.6.9 Compiling windows-sys v0.45.0 Compiling rustc-demangle v0.1.23 Compiling tracing-error v0.2.0 Compiling encode_unicode v0.3.6 Compiling indenter v0.3.3 Compiling backtrace v0.3.69 Compiling owo-colors v3.5.0 Compiling yansi-term v0.1.2 Compiling regex-automata v0.4.3 Compiling console v0.15.7 Compiling color-spantrace v0.2.1 Compiling ansi_term v0.12.1 Compiling is-terminal v0.4.9 Compiling pad v0.1.6 Compiling serde_derive v1.0.193 Compiling thiserror-impl v1.0.50 Compiling memchr v2.6.4 Compiling number_prefix v0.4.0 Compiling log v0.4.20 Compiling fastrand v2.0.1 Compiling indicatif v0.17.7 Compiling prettydiff v0.6.4 Compiling tempfile v3.8.1 Compiling crossbeam-channel v0.5.8 Compiling colored v2.0.4 Compiling color-eyre v0.6.2 Compiling regex v1.10.2 Compiling bstr v1.8.0 Compiling annotate-snippets v0.9.2 Compiling levenshtein v1.0.5 Compiling comma v1.0.0 Compiling marker_api v0.4.2 Compiling marker_utils v0.4.2 Compiling cargo-platform v0.1.5 Compiling rustc_version v0.4.0 Compiling rustfix v0.6.1 Compiling cargo_metadata v0.15.4 Compiling ui_test v0.21.2 Compiling marker_uitest v0.4.2 Compiling lint-crate-template v0.1.0 (C:\Users\aurel\source\repos\lint-crate-template) Finished test [unoptimized + debuginfo] target(s) in 18.56s Running tests\uitest.rs (target\debug\deps\uitest-ab45871b164387e1.exe) marker_rustc_driver 0.4.2 (c753799 2023-11-25) FAILED TEST: tests\ui\hello_marker.rs command: "C:\\Users\\aurel\\.rustup\\toolchains\\nightly-2023-11-16-x86_64-pc-windows-msvc\\bin\\marker_rustc_driver.exe" "--error-format=json" "-Aunused" "--out-dir" "\\\\?\\C:\\Users\\aurel\\source\\repos\\lint-crate-template\\target\\ui_test\\tests\\ui" "tests\\ui\\hello_marker.rs" "--edition" "2021" error: actual output differed from expected Execute `cargo test -- -- --bless` to update `tests\ui\hello_marker.stderr` to the actual output --- tests\ui\hello_marker.stderr +++ -warning: hello, main (From Marker) +error[E0463]: can't find crate for `std` ~ --> $DIR/hello_marker.rs:5:1 | -5 | / fn main() { +6 | println!("Hello, World!"); ~6 | | println!("Hello, World!");^^^^^^^ -warning: 1 warning emitted +error: requires `sized` lang_item +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0463`. full stderr: error[E0463]: can't find crate for `std` error: cannot find macro `println` in this scope --> tests\ui\hello_marker.rs:6:5 | 6 | println!("Hello, World!"); | ^^^^^^^ error: requires `sized` lang_item error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0463`. full stdout: FAILURES: tests\ui\hello_marker.rs test result: FAIL. 1 failed; Error: tests failed Location: C:\Users\aurel\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ui_test-0.21.2\src\lib.rs:388:13 error: test failed, to rerun pass `--test uitest` Caused by: process didn't exit successfully: `C:\Users\aurel\source\repos\lint-crate-template\target\debug\deps\uitest-ab45871b164387e1.exe` (exit code: 1) ```
Veetaha commented 11 months ago

@xFrednet I believe I already saw this issue when debugging something unrelated long ago, but didn't think it would be reproducable outside of my debugging setup. The core problem is with custom handling of --sysroot parameter in the driver here: https://github.com/rust-marker/marker/blob/e1dfde8dc49373c1459d27af12bc690d5909f6e2/marker_rustc_driver/src/lib.rs#L309-L353

I don't remember the conditions under which the problem reproduces, and I'm not sure that's windows specific. Some combination of RUSTUP_TOOLCHAIN and rust-toolchain or +{toolchain} plus the CARGO env vars in the test process causes this. The behavior that is implemented in that referenced function differs from real rustc's behavior. At that moment I wondered why that function event exists in the first place, and why not to forward processing of that parameter to RunCompiler, but didn't go further.

xFrednet commented 11 months ago

I had the feeling this code will come back to bite me. This way of getting the sysroot was taken from Clippy, with some refactorings for readability. I never use the --sysroot flag and don't know why it requires special handling in tools.

Some months back, there was a PR in rustc to move this special handling code into rustc https://github.com/rust-lang/rust/pull/103660. I've created https://github.com/rust-marker/marker/issues/48 to migrate Marker as well, but haven't gotten too it yet, since I assumed it worked fine as is.

Checking Clippy's driver code, it looks like there is still some code to forward the sysroot flag, but it's definitely cleaner than the old setup: https://github.com/rust-lang/rust-clippy/blob/8b0bf6423dfaf5545014db85fcba7bc745beed4c/src/driver.rs#L191-L200

Edit: I just looked it up, apparently the flag was added for cross compilation: https://github.com/rust-lang/cargo/issues/2312 It might be used for other things as well, but that seems to be the origin.

xFrednet commented 11 months ago

@tigerros We've created a release candidate for v0.4.3, which might fix the bug. Would you mind testing it on your machine?

This is the install script for the release candidate. You might have to specify v0.4.3-rc in the lint crate template, instead of the v0.4 version which is the default. If this fixes the bug, we'll do a proper v0.4.3 release.

curl.exe -fsSL https://raw.githubusercontent.com/rust-marker/marker/v0.4.3-rc/scripts/release/install.ps1 | powershell -command -
xFrednet commented 11 months ago

I think I figured out another problem... When I released v0.4.1 I accidentally did that from the master branch, which updated the used nightly toolchain. This update never made it to the master of the lint crate template. I'll fix that! Let's hope that fixes everything

Edit: The upside of this mess, is that I learned to never release hotfix versions from the master branch again

xFrednet commented 11 months ago

Okay, now everything should be back in order. Sorry :sweat_smile:

tigerros commented 11 months ago

@xFrednet It works. And yes, it's necessary to specify 0.4.3-rc for the marker deps in the template. Thanks!

xFrednet commented 11 months ago

Perfect, thank you!