-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix injected errors when running doctests on a crate named after a keyword #79775
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
src/test/rustdoc/doctest-keyword.rs
Outdated
#![crate_name = "mod"] | ||
//! ``` | ||
//! // NOTE: requires that the literal string 'mod' appears in the doctest for | ||
//! // the bug to appear | ||
//! assert_eq!(1, 1); | ||
//! ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to test this. Currently the test does nothing because it isn't running rustdoc with --test
; if I add // compile-flags: --test
it errors regardless of the fix because the aux metadata isn't built:
running 1 test
test src/test/rustdoc/doctest-keyword.rs - (line 3) ... FAILED
failures:
---- src/test/rustdoc/doctest-keyword.rs - (line 3) stdout ----
error[E0463]: can't find crate for `mod`
--> src/test/rustdoc/doctest-keyword.rs:4:1
|
4 | extern crate r#mod;
| ^^^^^^^^^^^^^^^^^^^ can't find crate
I can't seem to find any other tests for this? @GuillaumeGomez do you have ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use aux-build
to achieve that I think, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not sure how. Normally aux-build
looks in the auxiliary
directory, so I tried using // aux-build:../doctest-keyword.rs
to trick it into building the current file. But it still seems to be breaking :/
running 6 tests
iiiiiF
failures:
---- [rustdoc] rustdoc/doctest-keyword.rs stdout ----
executing "/home/joshua/rustc/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/joshua/rustc/src/test/rustdoc/auxiliary/../doctest-keyword.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "-C" "prefer-dynamic" "--out-dir" "/home/joshua/rustc/build/x86_64-unknown-linux-gnu/test/rustdoc/doctest-keyword/auxiliary" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/home/joshua/rustc/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--test" "--crate-type" "dylib" "-L" "/home/joshua/rustc/build/x86_64-unknown-linux-gnu/test/rustdoc/doctest-keyword/auxiliary"
------stdout------------------------------
------stderr------------------------------
------------------------------------------
executing "/home/joshua/rustc/build/x86_64-unknown-linux-gnu/stage1/bin/rustdoc" "-L" "/home/joshua/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/joshua/rustc/build/x86_64-unknown-linux-gnu/test/rustdoc/doctest-keyword/auxiliary" "-o" "/home/joshua/rustc/build/x86_64-unknown-linux-gnu/test/rustdoc/doctest-keyword" "/home/joshua/rustc/src/test/rustdoc/doctest-keyword.rs" "--test"
------stdout------------------------------
running 1 test
test src/test/rustdoc/doctest-keyword.rs - (line 7) ... FAILED
failures:
---- src/test/rustdoc/doctest-keyword.rs - (line 7) stdout ----
error[E0463]: can't find crate for `mod`
--> src/test/rustdoc/doctest-keyword.rs:8:1
|
4 | extern crate r#mod;
| ^^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
Couldn't compile the test.
failures:
src/test/rustdoc/doctest-keyword.rs - (line 7)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s
I did confirm that the aux file exists, but it doesn't seem to be picking up on it for some reason.
$ file /home/joshua/rustc/build/x86_64-unknown-linux-gnu/test/rustdoc/doctest-keyword/auxiliary/mod
/home/joshua/rustc/build/x86_64-unknown-linux-gnu/test/rustdoc/doctest-keyword/auxiliary/mod: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=df3038c014cbf237c458cb19f7571c62aa8b96f9, not stripped
@Mark-Simulacrum do you have ideas maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here might come from the .rs
file generated by rustdoc containing the test. Not sure how we link it then...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GuillaumeGomez shouldn't the generated .rs file be using the same -L aux dir that rustdoc will used normally? Or is it being ignored? That seems like a bug we should fix.
Here's how cargo does it for reference:
Running `rustc --crate-name mod --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=efd9726c342fe75e -C extra-filename=-efd9726c342fe75e --out-dir /home/joshua/test-rustdoc/doctest/target/debug/deps -C incremental=/home/joshua/test-rustdoc/doctest/target/debug/incremental -L dependency=/home/joshua/test-rustdoc/doctest/target/debug/deps -C link-arg=-fuse-ld=lld`
Finished test [unoptimized + debuginfo] target(s) in 0.05s
Doc-tests mod
Running `rustdoc --edition=2018 --crate-type lib --test /home/joshua/test-rustdoc/doctest/src/lib.rs --crate-name mod -L dependency=/home/joshua/test-rustdoc/doctest/target/debug/deps -L dependency=/home/joshua/test-rustdoc/doctest/target/debug/deps --extern mod=/home/joshua/test-rustdoc/doctest/target/debug/deps/libmod-efd9726c342fe75e.rlib -C embed-bitcode=no`
It's passing --extern mod=/home/joshua/test-rustdoc/doctest/target/debug/deps/libmod-efd9726c342fe75e.rlib
where compiletest only passes -L
- maybe that's the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's unlikely this will regress, since someone would have to change it intentionally. Do you think it makes sense to add the fix before figuring out how to test it?
@JohnCSimon this is waiting on review, not me. ping @GuillaumeGomez do you have ideas for how to test this? If not, are you ok with merging the fix even without tests? |
This isn't a bug with high priority, so I'd prefer to add the test alongside it if possible. We can take a look together if the aux-build isn't working for you if you want? |
If you can take a look, I'd appreciate it. I don't know how to do this. |
Sure! Taking a look then. ;) |
Ok, so the problem here with the test is that we need the file to be compiled first to then be used as dependency, which cannot be done currently unfortunately in the rustdoc test suites... Example: // name this file "foo.rs"
/// ```
/// let x = foo::foo();
/// ```
pub fn foo() {} If you run
We need So if you're fine with it @jyn514, please just remove the test and we'll r+ it. |
Thanks! r=me once CI is green. |
This comment has been minimized.
This comment has been minimized.
Oh, well, after all that it turns out it gets tested anyway because we hard-code the generated code in a test lol |
Nice surprise haha! |
This comment has been minimized.
This comment has been minimized.
…yword Unfortunately, this can't currently be tested. The problem is that we need the file to be compiled first to then be used as dependency, which cannot be done currently unfortunately in the rustdoc test suites. Example: ```rust // name this file "foo.rs" /// ``` /// let x = foo::foo(); /// ``` pub fn foo() {} ``` If you run `rustdoc --test foo.rs`, you'll get: ``` running 1 test test foo.rs - foo (line 1) ... FAILED failures: ---- foo.rs - foo (line 1) stdout ---- error[E0463]: can't find crate for `foo` --> foo.rs:0:1 | 2 | extern crate foo; | ^^^^^^^^^^^^^^^^^ can't find crate ``` If a test were possible, it would look something like ````rust #![crate_name = "mod"] #![crate_type = "lib"] //! ``` //! // NOTE: requires that the literal string 'mod' appears in the doctest for //! // the bug to appear //! assert_eq!(1, 1); //! ``` ````
Seems like it's ready to go. Thanks! @bors: r+ |
📌 Commit 02ffe9e has been approved by |
Fix injected errors when running doctests on a crate named after a keyword Closes rust-lang#79771
Rollup of 10 pull requests Successful merges: - rust-lang#79775 (Fix injected errors when running doctests on a crate named after a keyword) - rust-lang#81012 (Stabilize the partition_point feature) - rust-lang#81479 (Allow casting mut array ref to mut ptr) - rust-lang#81506 (HWAddressSanitizer support) - rust-lang#81741 (Increment `self.index` before calling `Iterator::self.a.__iterator_ge…) - rust-lang#81850 (use RWlock when accessing os::env) - rust-lang#81911 (GAT/const_generics: Allow with_opt_const_param to return GAT param def_id) - rust-lang#82022 (Push a `char` instead of a `str` with len one into a String) - rust-lang#82023 (Remove unnecessary lint allow attrs on example) - rust-lang#82030 (Use `Iterator::all` instead of open-coding it) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Closes #79771