tidy: Run tidy style against markdown files.
This commit is contained in:
parent
e708cbd91c
commit
bb22eaf39e
@ -1,4 +1,3 @@
|
||||
|
||||
Lexical Region Resolution was removed in https://github.com/rust-lang/rust/pull/64790.
|
||||
|
||||
Rust now uses Non-lexical lifetimes. For more info, please see the [borrowck
|
||||
|
@ -378,7 +378,7 @@ C library default allocator<sup id="fnref:5" role="doc-noteref"><a
|
||||
href="#fn:5" class="footnote">5</a></sup> since version 1.32.0
|
||||
(2019-01-17)[39].
|
||||
|
||||
```ignore
|
||||
```rust,no_run
|
||||
fn main() {
|
||||
let mut x = Box::new([0; 1024]);
|
||||
|
||||
|
@ -62,7 +62,7 @@ warning: unused variable: `x`
|
||||
A 'deny' lint produces an error if you violate it. For example, this code
|
||||
runs into the `exceeding_bitshifts` lint.
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
fn main() {
|
||||
100u8 << 10;
|
||||
}
|
||||
@ -232,7 +232,7 @@ pub fn foo() {}
|
||||
This is the maximum level for all lints. So for example, if we take our
|
||||
code sample from the "deny" lint level above:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
fn main() {
|
||||
100u8 << 10;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ $ .\hello.exe # on Windows
|
||||
Note that we only ever pass `rustc` the *crate root*, not every file we wish
|
||||
to compile. For example, if we had a `main.rs` that looked like this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (needs-multiple-files)
|
||||
mod foo;
|
||||
|
||||
fn main() {
|
||||
@ -49,7 +49,7 @@ fn main() {
|
||||
|
||||
And a `foo.rs` that had this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
pub fn hello() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
@ -47,8 +47,7 @@ all type errors and name resolution errors with function bodies. Note that this
|
||||
work for anything outside a function body: since Rustdoc documents your types, it has to
|
||||
know what those types are! For example, this code will work regardless of the platform:
|
||||
|
||||
<!-- `ignore` because doc-tests are run with `rustc`, not `rustdoc` -->
|
||||
```ignore
|
||||
```rust,ignore (platform-specific)
|
||||
pub fn f() {
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
}
|
||||
@ -56,7 +55,7 @@ pub fn f() {
|
||||
|
||||
but this will not, because the unknown type is part of the function signature:
|
||||
|
||||
```ignore
|
||||
```rust,ignore (platform-specific)
|
||||
pub fn f() -> std::os::windows::ffi::EncodeWide<'static> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
@ -5,12 +5,13 @@ that examples within your documentation are up to date and working.
|
||||
|
||||
The basic idea is this:
|
||||
|
||||
```ignore
|
||||
```rust,no_run
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// let x = 5;
|
||||
/// ```
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
The triple backticks start and end code blocks. If this were in a file named `foo.rs`,
|
||||
@ -78,12 +79,13 @@ Sometimes, you need some setup code, or other things that would distract
|
||||
from your example, but are important to make the tests work. Consider
|
||||
an example block that looks like this:
|
||||
|
||||
```ignore
|
||||
```rust,no_run
|
||||
/// ```
|
||||
/// /// Some documentation.
|
||||
/// # fn foo() {} // this function will be hidden
|
||||
/// println!("Hello, World!");
|
||||
/// ```
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
It will render like this:
|
||||
@ -196,12 +198,13 @@ When writing an example, it is rarely useful to include a complete error
|
||||
handling, as it would add significant amounts of boilerplate code. Instead, you
|
||||
may want the following:
|
||||
|
||||
```ignore
|
||||
```rust,no_run
|
||||
/// ```
|
||||
/// use std::io;
|
||||
/// let mut input = String::new();
|
||||
/// io::stdin().read_line(&mut input)?;
|
||||
/// ```
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
The problem is that `?` returns a `Result<T, E>` and test functions don't
|
||||
@ -210,7 +213,7 @@ return anything, so this will give a mismatched types error.
|
||||
You can get around this limitation by manually adding a `main` that returns
|
||||
`Result<T, E>`, because `Result<T, E>` implements the `Termination` trait:
|
||||
|
||||
```ignore
|
||||
```rust,no_run
|
||||
/// A doc test using ?
|
||||
///
|
||||
/// ```
|
||||
@ -222,12 +225,13 @@ You can get around this limitation by manually adding a `main` that returns
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
Together with the `# ` from the section above, you arrive at a solution that
|
||||
appears to the reader as the initial idea but works with doc tests:
|
||||
|
||||
```ignore
|
||||
```rust,no_run
|
||||
/// ```
|
||||
/// use std::io;
|
||||
/// # fn main() -> io::Result<()> {
|
||||
@ -236,18 +240,20 @@ appears to the reader as the initial idea but works with doc tests:
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
As of version 1.34.0, one can also omit the `fn main()`, but you will have to
|
||||
disambiguate the error type:
|
||||
|
||||
```ignore
|
||||
```rust,no_run
|
||||
/// ```
|
||||
/// use std::io;
|
||||
/// let mut input = String::new();
|
||||
/// io::stdin().read_line(&mut input)?;
|
||||
/// # Ok::<(), io::Error>(())
|
||||
/// ```
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
This is an unfortunate consequence of the `?` operator adding an implicit
|
||||
@ -417,7 +423,7 @@ Another possible use of `#[cfg(doctest)]` is to test doctests that are included
|
||||
without including it in your main documentation. For example, you could write this into your
|
||||
`lib.rs` to test your README as part of your doctests:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![feature(external_doc)]
|
||||
|
||||
#[doc(include = "../README.md")]
|
||||
|
@ -51,7 +51,7 @@ use a different convention than the rest of the rustdocs. Lines should
|
||||
start with `//!` which indicate module-level or crate-level documentation.
|
||||
Here's a quick example of the difference:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
//! Fast and easy queue abstraction.
|
||||
//!
|
||||
//! Provides an abstraction over a queue. When the abstraction is used
|
||||
@ -64,8 +64,8 @@ Here's a quick example of the difference:
|
||||
/// This module makes it easy.
|
||||
pub mod easy {
|
||||
|
||||
/// Use the abstract function to do this specific thing.
|
||||
pub fn abstract() {}
|
||||
/// Use the abstraction function to do this specific thing.
|
||||
pub fn abstraction() {}
|
||||
|
||||
}
|
||||
```
|
||||
|
@ -3,10 +3,11 @@
|
||||
`rustdoc` provides lints to help you writing and testing your documentation. You
|
||||
can use them like any other lints by doing this:
|
||||
|
||||
```rust,ignore
|
||||
```rust
|
||||
#![allow(missing_docs)] // allows the lint, no diagnostics will be reported
|
||||
#![warn(missing_docs)] // warn if there are missing docs
|
||||
#![deny(missing_docs)] // error if there are missing docs
|
||||
# //! Crate docs.
|
||||
```
|
||||
|
||||
Here is the list of the lints provided by `rustdoc`:
|
||||
|
@ -32,8 +32,9 @@ Without this pass, these items will remain in the output.
|
||||
|
||||
When you write a doc comment like this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
/// This is a documentation comment.
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
There's a space between the `///` and that `T`. That spacing isn't intended
|
||||
@ -52,9 +53,10 @@ documentation string.
|
||||
|
||||
For example:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#[doc = "This is the first line."]
|
||||
#[doc = "This is the second line."]
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
Gets collapsed into a single doc string of
|
||||
@ -68,7 +70,7 @@ This is the second line.
|
||||
|
||||
This removes documentation for any non-public items, so for example:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
/// These are private docs.
|
||||
struct Private;
|
||||
|
||||
|
@ -7,9 +7,10 @@ The most basic function of `#[doc]` is to handle the actual documentation
|
||||
text. That is, `///` is syntax sugar for `#[doc]`. This means that these two
|
||||
are the same:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
/// This is a doc comment.
|
||||
#[doc = " This is a doc comment."]
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
(Note the leading space in the attribute version.)
|
||||
@ -18,16 +19,18 @@ In most cases, `///` is easier to use than `#[doc]`. One case where the latter i
|
||||
when generating documentation in macros; the `collapse-docs` pass will combine multiple
|
||||
`#[doc]` attributes into a single doc comment, letting you generate code like this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#[doc = "This is"]
|
||||
#[doc = " a "]
|
||||
#[doc = "doc comment"]
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
Which can feel more flexible. Note that this would generate this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#[doc = "This is\n a \ndoc comment"]
|
||||
# fn f() {}
|
||||
```
|
||||
|
||||
but given that docs are rendered via Markdown, it will remove these newlines.
|
||||
@ -45,7 +48,7 @@ These options control how the docs look at a crate level.
|
||||
|
||||
This form of the `doc` attribute lets you control the favicon of your docs.
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![doc(html_favicon_url = "https://example.com/favicon.ico")]
|
||||
```
|
||||
|
||||
@ -59,7 +62,7 @@ If you don't use this attribute, there will be no favicon.
|
||||
This form of the `doc` attribute lets you control the logo in the upper
|
||||
left hand side of the docs.
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![doc(html_logo_url = "https://example.com/logo.jpg")]
|
||||
```
|
||||
|
||||
@ -73,7 +76,7 @@ If you don't use this attribute, there will be no logo.
|
||||
This form of the `doc` attribute lets you control where the "run" buttons
|
||||
on your documentation examples make requests to.
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![doc(html_playground_url = "https://playground.example.com/")]
|
||||
```
|
||||
|
||||
@ -88,7 +91,7 @@ When a feature is unstable, an issue number for tracking the feature must be
|
||||
given. `rustdoc` uses this number, plus the base URL given here, to link to
|
||||
the tracking issue.
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![doc(issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
|
||||
```
|
||||
|
||||
@ -103,7 +106,7 @@ available. If that is not available, then it will use the `html_root_url`
|
||||
value in the extern crate if it is available. If that is not available, then
|
||||
the extern items will not be linked.
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![doc(html_root_url = "https://docs.rs/serde/1.0")]
|
||||
```
|
||||
|
||||
@ -112,7 +115,7 @@ the extern items will not be linked.
|
||||
By default, `rustdoc` will include the source code of your program, with links
|
||||
to it in the docs. But if you include this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![doc(html_no_source)]
|
||||
```
|
||||
|
||||
@ -123,7 +126,7 @@ it will not.
|
||||
By default, `rustdoc` will automatically add a line with `extern crate my_crate;` into each doctest.
|
||||
But if you include this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![doc(test(no_crate_inject))]
|
||||
```
|
||||
|
||||
@ -134,7 +137,7 @@ it will not.
|
||||
This form of the `doc` attribute allows you to add arbitrary attributes to all your doctests. For
|
||||
example, if you want your doctests to fail if they produce any warnings, you could add this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![doc(test(attr(deny(warnings))))]
|
||||
```
|
||||
|
||||
@ -148,7 +151,7 @@ they are documented.
|
||||
These attributes are used on `use` statements, and control where the documentation shows
|
||||
up. For example, consider this Rust code:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
pub use bar::Bar;
|
||||
|
||||
/// bar docs
|
||||
@ -156,6 +159,7 @@ pub mod bar {
|
||||
/// the docs for Bar
|
||||
pub struct Bar;
|
||||
}
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
The documentation will generate a "Re-exports" section, and say `pub use bar::Bar;`, where
|
||||
@ -163,9 +167,11 @@ The documentation will generate a "Re-exports" section, and say `pub use bar::Ba
|
||||
|
||||
If we change the `use` line like this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#[doc(inline)]
|
||||
pub use bar::Bar;
|
||||
# pub mod bar { pub struct Bar; }
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
Instead, `Bar` will appear in a `Structs` section, just like `Bar` was defined at the
|
||||
@ -173,7 +179,7 @@ top level, rather than `pub use`'d.
|
||||
|
||||
Let's change our original example, by making `bar` private:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
pub use bar::Bar;
|
||||
|
||||
/// bar docs
|
||||
@ -181,6 +187,7 @@ mod bar {
|
||||
/// the docs for Bar
|
||||
pub struct Bar;
|
||||
}
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
Here, because `bar` is not public, `Bar` wouldn't have its own page, so there's nowhere
|
||||
@ -188,7 +195,7 @@ to link to. `rustdoc` will inline these definitions, and so we end up in the sam
|
||||
as the `#[doc(inline)]` above; `Bar` is in a `Structs` section, as if it were defined at
|
||||
the top level. If we add the `no_inline` form of the attribute:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#[doc(no_inline)]
|
||||
pub use bar::Bar;
|
||||
|
||||
@ -197,6 +204,7 @@ mod bar {
|
||||
/// the docs for Bar
|
||||
pub struct Bar;
|
||||
}
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
Now we'll have a `Re-exports` line, and `Bar` will not link to anywhere.
|
||||
|
@ -15,7 +15,7 @@ named `__rustc_codegen_backend` with a signature of `fn() -> Box<dyn rustc_codeg
|
||||
See also the [`hotplug_codegen_backend`](https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/hotplug_codegen_backend) test
|
||||
for a full example.
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (partial-example)
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
|
||||
struct MyBackend;
|
||||
|
@ -16,8 +16,8 @@ by the `negative_impls` feature.)
|
||||
[`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
|
||||
[`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
|
||||
|
||||
```rust,ignore
|
||||
impl !Trait for Type
|
||||
```rust,ignore (partial-example)
|
||||
impl !Trait for Type {}
|
||||
```
|
||||
|
||||
Example:
|
||||
@ -80,7 +80,7 @@ where
|
||||
|
||||
Explicit impls may be either positive or negative. They take the form:
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (partial-example)
|
||||
impl<...> AutoTrait for StructName<..> { }
|
||||
impl<...> !AutoTrait for StructName<..> { }
|
||||
```
|
||||
@ -104,4 +104,3 @@ Auto traits cannot have any trait items, such as methods or associated types. Th
|
||||
## Supertraits
|
||||
|
||||
Auto traits cannot have supertraits. This is for soundness reasons, as the interaction of coinduction with implied bounds is difficult to reconcile.
|
||||
|
||||
|
@ -30,4 +30,3 @@ const WILL_PASS: i32 = 0;
|
||||
#[test_case]
|
||||
const WILL_FAIL: i32 = 4;
|
||||
```
|
||||
|
||||
|
@ -42,4 +42,3 @@ struct Bar<T: 'static> {
|
||||
x: T,
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -27,4 +27,3 @@ extern "rust-intrinsic" {
|
||||
```
|
||||
|
||||
As with any other FFI functions, these are always `unsafe` to call.
|
||||
|
||||
|
@ -15,8 +15,8 @@ For example, `Box` pointers require two lang items, one for allocation
|
||||
and one for deallocation. A freestanding program that uses the `Box`
|
||||
sugar for dynamic allocations via `malloc` and `free`:
|
||||
|
||||
```rust,ignore
|
||||
#![feature(lang_items, box_syntax, start, libc, core_intrinsics)]
|
||||
```rust,ignore (libc-is-finicky)
|
||||
#![feature(lang_items, box_syntax, start, libc, core_intrinsics, rustc_private)]
|
||||
#![no_std]
|
||||
use core::intrinsics;
|
||||
use core::panic::PanicInfo;
|
||||
@ -105,8 +105,8 @@ or overriding the default shim for the C `main` function with your own.
|
||||
The function marked `#[start]` is passed the command line parameters
|
||||
in the same format as C:
|
||||
|
||||
```rust,ignore
|
||||
#![feature(lang_items, core_intrinsics)]
|
||||
```rust,ignore (libc-is-finicky)
|
||||
#![feature(lang_items, core_intrinsics, rustc_private)]
|
||||
#![feature(start)]
|
||||
#![no_std]
|
||||
use core::intrinsics;
|
||||
@ -141,8 +141,8 @@ with `#![no_main]` and then create the appropriate symbol with the
|
||||
correct ABI and the correct name, which requires overriding the
|
||||
compiler's name mangling too:
|
||||
|
||||
```rust,ignore
|
||||
#![feature(lang_items, core_intrinsics)]
|
||||
```rust,ignore (libc-is-finicky)
|
||||
#![feature(lang_items, core_intrinsics, rustc_private)]
|
||||
#![feature(start)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
@ -19,9 +19,9 @@ const Π: f64 = 3.14f64;
|
||||
|
||||
## Changes to the language reference
|
||||
|
||||
> **<sup>Lexer:<sup>**
|
||||
> IDENTIFIER :
|
||||
> XID_start XID_continue<sup>\*</sup>
|
||||
> **<sup>Lexer:<sup>**\
|
||||
> IDENTIFIER :\
|
||||
> XID_start XID_continue<sup>\*</sup>\
|
||||
> | `_` XID_continue<sup>+</sup>
|
||||
|
||||
An identifier is any nonempty Unicode string of the following form:
|
||||
|
@ -11,7 +11,7 @@ a pattern, for example, `Some(A(0) | B(1 | 2))` becomes a valid pattern.
|
||||
|
||||
## Examples
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![feature(or_patterns)]
|
||||
|
||||
pub enum Foo {
|
||||
|
@ -38,7 +38,7 @@ additional checks for code style, safety, etc. Now let's write a plugin
|
||||
[`lint-plugin-test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs)
|
||||
that warns about any item named `lintme`.
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (requires-stage-2)
|
||||
#![feature(plugin_registrar)]
|
||||
#![feature(box_syntax, rustc_private)]
|
||||
|
||||
@ -77,7 +77,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
||||
|
||||
Then code like
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (requires-plugin)
|
||||
#![feature(plugin)]
|
||||
#![plugin(lint_plugin_test)]
|
||||
|
||||
|
@ -18,7 +18,7 @@ Options provided by `#[rustc_layout(...)]` are `debug`, `size`, `align`,
|
||||
|
||||
## Examples
|
||||
|
||||
```rust,ignore
|
||||
```rust,compile_fail
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[rustc_layout(abi, size)]
|
||||
|
@ -30,7 +30,7 @@ fn foo(_: dyn Any) {}
|
||||
|
||||
The RFC still forbids the following unsized expressions:
|
||||
|
||||
```rust,ignore
|
||||
```rust,compile_fail
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
use std::any::Any;
|
||||
@ -124,7 +124,7 @@ One of the objectives of this feature is to allow `Box<dyn FnOnce>`.
|
||||
|
||||
The RFC also describes an extension to the array literal syntax: `[e; dyn n]`. In the syntax, `n` isn't necessarily a constant expression. The array is dynamically allocated on the stack and has the type of `[T]`, instead of `[T; n]`.
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (not-yet-implemented)
|
||||
#![feature(unsized_locals)]
|
||||
|
||||
fn mergesort<T: Ord>(a: &mut [T]) {
|
||||
|
@ -8,7 +8,7 @@ The tracking issue for this feature is: [#42877]
|
||||
|
||||
This is a part of [RFC0401]. According to the RFC, there should be an implementation like this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (partial-example)
|
||||
impl<..., T, U: ?Sized> Unsized<(..., U)> for (..., T) where T: Unsized<U> {}
|
||||
```
|
||||
|
||||
|
@ -405,7 +405,7 @@ When required, options are specified as the final argument.
|
||||
|
||||
The following ABNF specifies the general syntax:
|
||||
|
||||
```ignore
|
||||
```text
|
||||
dir_spec := "in" / "out" / "lateout" / "inout" / "inlateout"
|
||||
reg_spec := <register class> / "<explicit register>"
|
||||
operand_expr := expr / "_" / expr "=>" expr / expr "=>" "_"
|
||||
|
@ -24,15 +24,15 @@ conventions of the assembler in your toolchain.
|
||||
|
||||
A simple usage looks like this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (requires-external-file)
|
||||
# #![feature(global_asm)]
|
||||
# you also need relevant target_arch cfgs
|
||||
# // you also need relevant target_arch cfgs
|
||||
global_asm!(include_str!("something_neato.s"));
|
||||
```
|
||||
|
||||
And a more complicated usage looks like this:
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
# #![feature(global_asm)]
|
||||
# #![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
|
||||
|
@ -10,7 +10,7 @@ For extremely low-level manipulations and performance reasons, one
|
||||
might wish to control the CPU directly. Rust supports using inline
|
||||
assembly to do this via the `llvm_asm!` macro.
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (pseudo-code)
|
||||
llvm_asm!(assembly template
|
||||
: output operands
|
||||
: input operands
|
||||
|
@ -9,7 +9,7 @@ most widely used part of the `test` crate are benchmark tests, which can test
|
||||
the performance of your code. Let's make our `src/lib.rs` look like this
|
||||
(comments elided):
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
@ -83,7 +83,7 @@ the benchmark is no longer benchmarking what one expects. For example, the
|
||||
compiler might recognize that some calculation has no external effects and
|
||||
remove it entirely.
|
||||
|
||||
```rust,ignore
|
||||
```rust,no_run
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
@ -16,7 +16,7 @@ macro on `Poll`, among other things.
|
||||
|
||||
Here's an example implementation of the trait:
|
||||
|
||||
```rust,ignore
|
||||
```rust,ignore (cannot-reimpl-Try)
|
||||
/// A distinct type to represent the `None` value of an `Option`.
|
||||
///
|
||||
/// This enables using the `?` operator on `Option`; it's rarely useful alone.
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
/// Error code markdown is restricted to 80 columns because they can be
|
||||
/// displayed on the console with --example.
|
||||
const ERROR_CODE_COLS: usize = 80;
|
||||
const COLS: usize = 100;
|
||||
|
||||
@ -55,9 +57,9 @@ enum LIUState {
|
||||
/// Lines of this form are allowed to be overlength, because Markdown
|
||||
/// offers no way to split a line in the middle of a URL, and the lengths
|
||||
/// of URLs to external references are beyond our control.
|
||||
fn line_is_url(columns: usize, line: &str) -> bool {
|
||||
// more basic check for error_codes.rs, to avoid complexity in implementing two state machines
|
||||
if columns == ERROR_CODE_COLS {
|
||||
fn line_is_url(is_error_code: bool, columns: usize, line: &str) -> bool {
|
||||
// more basic check for markdown, to avoid complexity in implementing two state machines
|
||||
if is_error_code {
|
||||
return line.starts_with('[') && line.contains("]:") && line.contains("http");
|
||||
}
|
||||
|
||||
@ -93,8 +95,13 @@ fn line_is_url(columns: usize, line: &str) -> bool {
|
||||
/// Returns `true` if `line` is allowed to be longer than the normal limit.
|
||||
/// Currently there is only one exception, for long URLs, but more
|
||||
/// may be added in the future.
|
||||
fn long_line_is_ok(max_columns: usize, line: &str) -> bool {
|
||||
if line_is_url(max_columns, line) {
|
||||
fn long_line_is_ok(extension: &str, is_error_code: bool, max_columns: usize, line: &str) -> bool {
|
||||
if extension != "md" || is_error_code {
|
||||
if line_is_url(is_error_code, max_columns, line) {
|
||||
return true;
|
||||
}
|
||||
} else if extension == "md" {
|
||||
// non-error code markdown is allowed to be any length
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -158,8 +165,36 @@ pub fn is_in(full_path: &Path, parent_folder_to_find: &str, folder_to_find: &str
|
||||
}
|
||||
}
|
||||
|
||||
fn skip_markdown_path(path: &Path) -> bool {
|
||||
// These aren't ready for tidy.
|
||||
const SKIP_MD: &[&str] = &[
|
||||
"src/doc/edition-guide",
|
||||
"src/doc/embedded-book",
|
||||
"src/doc/nomicon",
|
||||
"src/doc/reference",
|
||||
"src/doc/rust-by-example",
|
||||
"src/doc/rustc-dev-guide",
|
||||
];
|
||||
SKIP_MD.iter().any(|p| path.ends_with(p))
|
||||
}
|
||||
|
||||
fn is_unexplained_ignore(extension: &str, line: &str) -> bool {
|
||||
if !line.ends_with("```ignore") && !line.ends_with("```rust,ignore") {
|
||||
return false;
|
||||
}
|
||||
if extension == "md" && line.trim().starts_with("//") {
|
||||
// Markdown examples may include doc comments with ignore inside a
|
||||
// code block.
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn check(path: &Path, bad: &mut bool) {
|
||||
super::walk(path, &mut super::filter_dirs, &mut |entry, contents| {
|
||||
fn skip(path: &Path) -> bool {
|
||||
super::filter_dirs(path) || skip_markdown_path(path)
|
||||
}
|
||||
super::walk(path, &mut skip, &mut |entry, contents| {
|
||||
let file = entry.path();
|
||||
let filename = file.file_name().unwrap().to_string_lossy();
|
||||
let extensions = [".rs", ".py", ".js", ".sh", ".c", ".cpp", ".h", ".md", ".css"];
|
||||
@ -176,13 +211,6 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||
a.ends_with("src/doc/book")
|
||||
});
|
||||
|
||||
if filename.ends_with(".md")
|
||||
&& file.parent().unwrap().file_name().unwrap().to_string_lossy() != "error_codes"
|
||||
{
|
||||
// We don't want to check all ".md" files (almost of of them aren't compliant
|
||||
// currently), just the long error code explanation ones.
|
||||
return;
|
||||
}
|
||||
if is_style_file && !is_in(file, "src", "librustdoc") {
|
||||
// We only check CSS files in rustdoc.
|
||||
return;
|
||||
@ -192,11 +220,10 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||
tidy_error!(bad, "{}: empty file", file.display());
|
||||
}
|
||||
|
||||
let max_columns = if filename == "error_codes.rs" || filename.ends_with(".md") {
|
||||
ERROR_CODE_COLS
|
||||
} else {
|
||||
COLS
|
||||
};
|
||||
let extension = file.extension().unwrap().to_string_lossy();
|
||||
let is_error_code = extension == "md" && is_in(file, "src", "error_codes");
|
||||
|
||||
let max_columns = if is_error_code { ERROR_CODE_COLS } else { COLS };
|
||||
|
||||
let can_contain = contents.contains("// ignore-tidy-")
|
||||
|| contents.contains("# ignore-tidy-")
|
||||
@ -227,7 +254,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||
};
|
||||
if !under_rustfmt
|
||||
&& line.chars().count() > max_columns
|
||||
&& !long_line_is_ok(max_columns, line)
|
||||
&& !long_line_is_ok(&extension, is_error_code, max_columns, line)
|
||||
{
|
||||
suppressible_tidy_err!(
|
||||
err,
|
||||
@ -280,7 +307,7 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||
"copyright notices attributed to the Rust Project Developers are deprecated"
|
||||
);
|
||||
}
|
||||
if line.ends_with("```ignore") || line.ends_with("```rust,ignore") {
|
||||
if is_unexplained_ignore(&extension, line) {
|
||||
err(UNEXPLAINED_IGNORE_DOCTEST_INFO);
|
||||
}
|
||||
if filename.ends_with(".cpp") && line.contains("llvm_unreachable") {
|
||||
|
Loading…
Reference in New Issue
Block a user