diff options
| author | bors <bors@rust-lang.org> | 2022-05-07 06:30:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-07 06:30:29 +0000 |
| commit | 574830f5730f2cfc3abdb486428d33d541c0abee (patch) | |
| tree | 5ae5951d8ef6ed2b12910f8035fc457d5193308c /compiler/rustc_parse/src | |
| parent | 36aa7c143672af30bfcca01e5924b326f93fd922 (diff) | |
| parent | 647d0b6dd3008b2d9d3a57a914bd1487da9133cf (diff) | |
| download | rust-574830f5730f2cfc3abdb486428d33d541c0abee.tar.gz rust-574830f5730f2cfc3abdb486428d33d541c0abee.zip | |
Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errors
Begin fixing all the broken doctests in `compiler/`
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)` 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
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 22 |
3 files changed, 20 insertions, 19 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 358b01df3b9..2f90a7c54ab 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -371,9 +371,10 @@ impl<'a> Parser<'a> { } /// Matches the following grammar (per RFC 1559). - /// - /// meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ; - /// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ; + /// ```ebnf + /// meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ; + /// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ; + /// ``` pub fn parse_meta_item(&mut self) -> PResult<'a, ast::MetaItem> { let nt_meta = match self.token.kind { token::Interpolated(ref nt) => match **nt { diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 77a03428c16..0f940cffcc4 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -485,7 +485,7 @@ impl<'a> Parser<'a> { /// Parses an implementation item. /// - /// ``` + /// ```ignore (illustrative) /// impl<'a, T> TYPE { /* impl items */ } /// impl<'a, T> TRAIT for TYPE { /* impl items */ } /// impl<'a, T> !TRAIT for TYPE { /* impl items */ } @@ -493,7 +493,7 @@ impl<'a> Parser<'a> { /// ``` /// /// We actually parse slightly more relaxed grammar for better error reporting and recovery. - /// ``` + /// ```ebnf /// "impl" GENERICS "const"? "!"? TYPE "for"? (TYPE | "..") ("where" PREDICATES)? "{" BODY "}" /// "impl" GENERICS "const"? "!"? TYPE ("where" PREDICATES)? "{" BODY "}" /// ``` @@ -806,7 +806,7 @@ impl<'a> Parser<'a> { } /// Parses a `type` alias with the following grammar: - /// ``` + /// ```ebnf /// TypeAlias = "type" Ident Generics {":" GenericBounds}? {"=" Ty}? ";" ; /// ``` /// The `"type"` has already been eaten. @@ -930,7 +930,7 @@ impl<'a> Parser<'a> { /// /// # Examples /// - /// ``` + /// ```ignore (illustrative) /// extern crate foo; /// extern crate bar as foo; /// ``` @@ -1630,7 +1630,7 @@ impl<'a> Parser<'a> { /// Parses a declarative macro 2.0 definition. /// The `macro` keyword has already been parsed. - /// ``` + /// ```ebnf /// MacBody = "{" TOKEN_STREAM "}" ; /// MacParams = "(" TOKEN_STREAM ")" ; /// DeclMac = "macro" Ident MacParams? MacBody ; diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 9e771a8af1a..b0439a5987a 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -52,7 +52,7 @@ pub(super) enum RecoverQuestionMark { /// Signals whether parsing a type should recover `->`. /// /// More specifically, when parsing a function like: -/// ```rust +/// ```compile_fail /// fn foo() => u8 { 0 } /// fn bar(): u8 { 0 } /// ``` @@ -499,12 +499,12 @@ impl<'a> Parser<'a> { } /// Parses a function pointer type (`TyKind::BareFn`). - /// ``` - /// [unsafe] [extern "ABI"] fn (S) -> T - /// ^~~~~^ ^~~~^ ^~^ ^ - /// | | | | - /// | | | Return type - /// Function Style ABI Parameter types + /// ```ignore (illustrative) + /// [unsafe] [extern "ABI"] fn (S) -> T + /// // ^~~~~^ ^~~~^ ^~^ ^ + /// // | | | | + /// // | | | Return type + /// // Function Style ABI Parameter types /// ``` /// We actually parse `FnHeader FnDecl`, but we error on `const` and `async` qualifiers. fn parse_ty_bare_fn( @@ -707,7 +707,7 @@ impl<'a> Parser<'a> { } /// Parses a bound according to the grammar: - /// ``` + /// ```ebnf /// BOUND = TY_BOUND | LT_BOUND /// ``` fn parse_generic_bound(&mut self) -> PResult<'a, Result<GenericBound, Span>> { @@ -729,7 +729,7 @@ impl<'a> Parser<'a> { } /// Parses a lifetime ("outlives") bound, e.g. `'a`, according to: - /// ``` + /// ```ebnf /// LT_BOUND = LIFETIME /// ``` fn parse_generic_lt_bound( @@ -787,7 +787,7 @@ impl<'a> Parser<'a> { /// /// If no modifiers are present, this does not consume any tokens. /// - /// ``` + /// ```ebnf /// TY_BOUND_MODIFIERS = ["~const"] ["?"] /// ``` fn parse_ty_bound_modifiers(&mut self) -> PResult<'a, BoundModifiers> { @@ -807,7 +807,7 @@ impl<'a> Parser<'a> { } /// Parses a type bound according to: - /// ``` + /// ```ebnf /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) /// TY_BOUND_NOPAREN = [TY_BOUND_MODIFIERS] [for<LT_PARAM_DEFS>] SIMPLE_PATH /// ``` |
