Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/attributes/mod.rs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prime example ^^

Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub(crate) enum AttributeOrder {
///
/// Attributes are processed from bottom to top, so this raises a warning/error on all the attributes
/// further above the lowest one:
/// ```
/// ```ignore (illustrative)
/// #[stable(since="1.0")] //~ WARNING duplicated attribute
/// #[stable(since="2.0")]
/// ```
Expand All @@ -252,7 +252,7 @@ pub(crate) enum AttributeOrder {
///
/// Attributes are processed from bottom to top, so this raises a warning/error on all the attributes
/// below the highest one:
/// ```
/// ```ignore (illustrative)
/// #[path="foo.rs"]
/// #[path="bar.rs"] //~ WARNING duplicated attribute
/// ```
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ impl Emitter for AnnotateSnippetEmitter {
fn translator(&self) -> &Translator {
&self.translator
}

fn supports_color(&self) -> bool {
false
}
}

fn annotation_level_for_level(level: Level) -> annotate_snippets::level::Level<'static> {
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,6 @@ pub trait Emitter {
true
}

/// Checks if we can use colors in the current output stream.
fn supports_color(&self) -> bool {
false
}
Comment on lines -206 to -209
Copy link
Member Author

@fmease fmease Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


fn source_map(&self) -> Option<&SourceMap>;

fn translator(&self) -> &Translator;
Expand Down
334 changes: 146 additions & 188 deletions src/librustdoc/doctest/make.rs

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions tests/rustdoc-ui/doctest/doctest-output-include-fail.stdout
Copy link
Member Author

@fmease fmease Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the parser recovers from a missing semicolon and returns Ok(_). As a result, we used to consider the doctest syntactically valid and thus applied all the usual preprocessing, most importantly adding #![allow(unused)].

Now that we consider it syntactically invalid (rightfully so!), it no longer enjoys this privilege. Hence the warning.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ LL | let x = 234 // no semicolon here! oh no!
LL | }
| - unexpected token

error: aborting due to 1 previous error
warning: unused variable: `x`
--> $DIR/doctest-output-include-fail.md:5:9
|
LL | let x = 234 // no semicolon here! oh no!
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

error: aborting due to 1 previous error; 1 warning emitted

Couldn't compile the test.

Expand All @@ -22,4 +30,3 @@ failures:

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

all doctests ran in $TIME; merged doctests compilation took $TIME
9 changes: 8 additions & 1 deletion tests/rustdoc-ui/doctest/no-capture-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ LL | Input: 123
LL ~ } }
|

error: aborting due to 1 previous error
error[E0601]: `main` function not found in crate `rust_out`
Copy link
Member Author

@fmease fmease Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this an unfortunate regression. As mentioned in my other review comment, this doctest no longer gets preprocessed (like adding a main if absent).

If you like to see this addressed, I can of course change it to not bail out on has_errors (but still set failed_to_parse to true) in order to forward has_main and so on correctly (the code might get a bit gnarly tho).

However in general (not necessarily in this specific case), wrapping invalid doctests in a function is always a trade-off (it may lead to better errors in some cases but to worse ones in others; and it may leak internal names in diagnostics like _doctest_main_tests_rustdoc_ui_doctest_comment_in_attr_134221_2_rs_11_0; see #142446 (comment) for context).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, due to the existence of error code checks like compile_fail,ENNNN I have to preserve some of the original behavior actually (namely continuing to preprocess certain syntactically invalid doctests (at the very least ones that have syntax errors that the parser recovered from)).

--> $DIR/nocapture-fail.rs:10:2
|
LL | }
| ^ consider adding a `main` function to `$DIR/nocapture-fail.rs`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0601`.
9 changes: 9 additions & 0 deletions tests/rustdoc-ui/doctest/recovered-syntax-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// issue: <https://github.com/rust-lang/rust/issues/147999>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[add description]

//@ compile-flags: --test
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ failure-status: 101

//! ```
//! #[derive(Clone)]
//! ```
22 changes: 22 additions & 0 deletions tests/rustdoc-ui/doctest/recovered-syntax-error.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

running 1 test
test $DIR/recovered-syntax-error.rs - (line 7) ... FAILED

failures:

---- $DIR/recovered-syntax-error.rs - (line 7) stdout ----
error: expected item after attributes
--> $DIR/recovered-syntax-error.rs:8:1
|
LL | #[derive(Clone)]
| ^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
$DIR/recovered-syntax-error.rs - (line 7)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

Loading