-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Begin fixing all the broken doctests in compiler/
#96094
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @compiler-errors (or someone else) soon. Please see the contribution instructions for more information. |
r? @jyn514 |
Here are some of the
|
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.
Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run rg '```ignore (' . on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.
I don't think it's too important to clean these up, the categories you have seem fine 👍 no need to change existing tests.
I left suggestions for most of your HELP
comments :)
(internal) uses rustc_* code which would be difficult to make work with the testing setup.
In retrospect, I think I was wrong on the issue and this should work out of the box as long as it only uses crates that have previously been compiled (see also #95445). Maybe try running these and see if they work?
@@ -229,7 +229,7 @@ enum ImplTraitContext<'b, 'a> { | |||
/// them. This includes lifetimes bound since we entered this context. | |||
/// For example: | |||
/// | |||
/// ``` | |||
/// ```ignore HELP (how would you make a stub trait for this?) | |||
/// type A<'b> = impl for<'a> Trait<'a, Out = impl Sized + 'a>; |
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, good question - I got as far as
/// #![feature(type_alias_impl_trait)]
/// trait Trait<'a, Out> {}
/// impl<'a, T: Sized> Trait<'a, T> for i32 {}
/// type A<'b> = impl for<'a> Trait<'a, impl Sized + 'a>;
/// fn foo() -> A<'static> { 0_i32 }
and then wasn't sure how to fix
error[E0666]: nested `impl Trait` is not allowed
--> src/lib.rs:236:37
|
6 | type A<'b> = impl for<'a> Trait<'a, impl Sized + 'a>;
| -----------------------^^^^^^^^^^^^^^^-
| | |
| | nested `impl Trait` here
| outer `impl Trait`
error: non-defining opaque type use in defining scope
--> src/lib.rs:237:26
|
6 | type A<'b> = impl for<'a> Trait<'a, impl Sized + 'a>;
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
7 | fn foo() -> A<'static> { 0_i32 }
| ^^^^^
error: unconstrained opaque type
--> src/lib.rs:236:37
|
6 | type A<'b> = impl for<'a> Trait<'a, impl Sized + 'a>;
| ^^^^^^^^^^^^^^^
|
= note: `` must be used in combination with a concrete type within the same module
while keeping the original semantics.
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.
Should we ignore this one as just an "illustration" then? The original single line of code gets quite buried when we add all that. If we figure out how to make it compile we could just hide the extra lines, but it would still be harder to read the un-rendered source (is that at all a priority for us? I've been considering it moderately important as my vscode doesn't have built-in doc rendering unless I hover on an item which is tedious and doesn't work for everything, but if we expect most future readers to have rendering then I can see why we wouldn't bother with it.)
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 semi important to figure out what the comment is describing in the first place - it's unclear to me now even having read it several times and played around with the example, so it will almost certainly be unclear to whoever reads it next without that context. But I agree making it compile is probably not worth it.
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.
It's unclear to me, too. Igot all the way to
#![feature(type_alias_impl_trait)]
trait Trait<'a> { type Out: 'a;}
impl<'a> Trait<'a> for i32 { type Out = String;}
type A = impl for<'a> Trait<'a, Out = impl Sized + 'a>;
fn foo() -> A {
0_i32
}
which is just a bug that it ain't accepted.i'll openable issuefor it And try to figure out the details of what's going on with this field at the same time.
@@ -45,7 +45,8 @@ pub unsafe trait Pointer: Deref { | |||
/// case you'll need to manually figure out what the right type to pass to | |||
/// align_of is. | |||
/// | |||
/// ```rust | |||
/// ```ignore HELP (should we try to make this runnable? and why does this import not seem to work?) | |||
/// # use std::ops::Deref; |
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 import works fine for me (are you using --stage 0
? If so you need to cherry-pick #95993).
and this is a good question - I think using Self
instead of a concrete type here was intentional. Not sure the right approach.
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'll try that again. I might have somehow been looking at stale error messages (oops sorry).
I used --stage 1
for the entire thing. Which are the stages we would want to run in CI?
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.
CI always uses --stage 2. At some point I want to test that other stages work, but those will be tests of bootstrap itself, not that the doctests are correct.
/// | ||
/// f(1, 2); | ||
/// | ||
/// ```ignore HELP (is there a way to set TupleArgumentsFlag so that this compiles?) |
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 this is used for Fn*
traits. Not sure how to replicate in user code.
@@ -269,7 +269,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { | |||
/// | |||
/// Consider this silly example: | |||
/// | |||
/// ``` | |||
/// ```ignore HELP (is that @ intentional?) |
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.
@
is old syntax for "garbage-collected pointer": https://pcwalton.github.io/2013/06/02/removing-garbage-collection-from-the-rust-language.html. Not sure how to keep the same semantics - maybe Box<i32>
is close?
Thanks for all your help so far, @jyn514! I'm learning lots. I'll have the straightforward fixes done soon and then we'll just have the handful that need expert input :) |
Thank you for tackling this!
I highly recommend cherry-picking my fix for --stage 0 so the iteration time is faster. It was taking me about ~10 seconds to check each suggestion I made, I wouldn't have gone through them all one by one if it took me 10 minutes each time. |
Oh ok wow haha. I luckily only had to recompile everything <10 times by working in batches but that sounds like a way better approach. Oh and for the ones I marked |
This comment has been minimized.
This comment has been minimized.
89e1574
to
cd7734e
Compare
Alright, I fixed the
|
I think it's useful to have at least one example of what |
☔ The latest upstream changes (presumably #91557) made this pull request unmergeable. Please resolve the merge conflicts. |
cd7734e
to
b213ce6
Compare
I think I've done most of what I know how to do and incorporated all the feedback given so far (thanks for the help everyone!). |
I think merging as-is is fine too, no need to do everything at once. We can keep the tracking issue open until we figure out how to get rid of the |
@compiler-errors I think this is ready for review - I don't have bors permissions. |
Maybe squash? Some commits add\remove the same things. |
Right, thanks for the reminder. |
e5a054e
to
7907385
Compare
📌 Commit 7907385 has been approved by |
…iler-errors Begin fixing all the broken doctests in `compiler/` Begins to fix rust-lang#95994. All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are. There are also a few that I marked `ignore` that could maybe be made to work but seem less important. Each `ignore` has a rough "reason" for ignoring after it parentheses, with - `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax" - `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy. - `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR. - `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup. Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful. I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
…iler-errors Begin fixing all the broken doctests in `compiler/` Begins to fix rust-lang#95994. All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are. There are also a few that I marked `ignore` that could maybe be made to work but seem less important. Each `ignore` has a rough "reason" for ignoring after it parentheses, with - `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax" - `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy. - `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR. - `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup. Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful. I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
Apparently Can you fix these @Elliot-Roberts? Thanks! See: https://github.com/rust-lang-ci/rust/runs/6316344673?check_suite_focus=true |
Oh ok. I think I'll have to change a few older ignores too. Like this one from 5 years ago: rust/compiler/rustc_ast/src/ast.rs Lines 1479 to 1487 in 74cea9f
|
Wait never mind, rustdoc doesn't mind that one. So, given that the error message says
should I still mark everything that isn't valid rust as text, or should I keep the ones that rustdoc is OK with? |
Looks like there were just a couple unmatched braces in one file that were causing rustdoc to fail to parse for syntax highlighting 😅. |
@Elliot-Roberts: I think you should mark it as text, syntax highlighting may get messed up by stray tokens even if rustdoc doesn't get angry when parsing it, and yeah, that "this example is not tested" string is a bit misleading. ... though I have been less involved in this thread compared to e.g. @jyn514 who may have more of a opinion. |
We should use See also #96573 which tries to make this a little less confusing. |
ok hm. reading #96573 and learning that it's expected to be possible to run doctests marked with I'll start by just using text for everything that wouldn't Parse. I expect there will be some grey area for even that, though. |
Don't spend too much more time on this. If it passes CI and it looks vaguely right in the generated docs, it's fine :) no need to rewrite half your work. |
+1, don't waste too much time on it -- I can re-approve it as soon as you can locally confirm that the tests don't fail like they do in https://github.com/rust-lang-ci/rust/runs/6316344673?check_suite_focus=true |
Ok thanks for the reassurance :) @compiler-errors How do I test that locally? I have at least verified that rusdoc succeeds for everything in And I can still go make more of them text as now it's bothering me. I have free time today to work on it. |
Frankly.... I don't actually know. Anywho, let's try to merge this now.
Feel free to open a new PR and |
@bors r+ |
📌 Commit 647d0b6 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (574830f): comparison url. Summary: This benchmark run did not return any relevant results. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
Begins to fix #95994.
All of them pass now but 24 of them I've marked with
ignore HELP (<explanation>)
(asking for help) as I'm unsure how to get them to work / if we should leave them as they are.There are also a few that I marked
ignore
that could maybe be made to work but seem less important.Each
ignore
has a rough "reason" for ignoring after it parentheses, with(pseudo-rust)
meaning "mostly rust-like but contains foreign syntax"(illustrative)
a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.(not-rust)
stuff that isn't rust but benefits from the syntax highlighting, like MIR.(internal)
usesrustc_*
code which would be difficult to make work with the testing setup.Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run
rg '```ignore \(' .
on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool