Skip to content
Merged
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
22 changes: 8 additions & 14 deletions src/doc/rustc/src/lints/levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ level is capped via cap-lints.
## deny

A 'deny' lint produces an error if you violate it. For example, this code
runs into the `exceeding_bitshifts` lint.
runs into the `arithmetic_overflow` lint.

```rust,no_run
fn main() {
Expand All @@ -114,13 +114,13 @@ fn main() {

```bash
$ rustc main.rs
error: bitshift exceeds the type's number of bits
--> main.rs:2:13
error: this arithmetic operation will overflow
--> main.rs:2:5
|
2 | 100u8 << 10;
| ^^^^^^^^^^^
| ^^^^^^^^^^^ attempt to shift left by `10_i32`, which would overflow
|
= note: `#[deny(exceeding_bitshifts)]` on by default
= note: `#[deny(arithmetic_overflow)]` on by default
```

What's the difference between an error from a lint and a regular old error?
Expand Down Expand Up @@ -306,19 +306,13 @@ And we compile it, capping lints to warn:

```bash
$ rustc lib.rs --cap-lints warn
warning: bitshift exceeds the type's number of bits
warning: this arithmetic operation will overflow
--> lib.rs:2:5
|
2 | 100u8 << 10;
| ^^^^^^^^^^^
| ^^^^^^^^^^^ attempt to shift left by `10_i32`, which would overflow
|
= note: `#[warn(exceeding_bitshifts)]` on by default

warning: this expression will panic at run-time
--> lib.rs:2:5
|
2 | 100u8 << 10;
| ^^^^^^^^^^^ attempt to shift left with overflow
= note: `#[warn(arithmetic_overflow)]` on by default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When I run this locally it says deny and not warn. Does it say warn when you run locally?

Suggested change
= note: `#[warn(arithmetic_overflow)]` on by default
= note: `#[deny(arithmetic_overflow)]` on by default
my output
$ git diff
diff --git a/src/doc/rustc/src/lints/levels.md b/src/doc/rustc/src/lints/levels.md
index 5b23ac9e09c..2274b70c509 100644
--- a/src/doc/rustc/src/lints/levels.md
+++ b/src/doc/rustc/src/lints/levels.md
@@ -106,7 +106,7 @@ level is capped via cap-lints.
 A 'deny' lint produces an error if you violate it. For example, this code
 runs into the `exceeding_bitshifts` lint.

-```rust,no_run
+```rust
 fn main() {
     100u8 << 10;
 }
@@ -296,7 +296,7 @@ pub fn get_path() -> PathBuf {
 This is the maximum level for all lints. So for example, if we take our
 code sample from the "deny" lint level above:

-```rust,no_run
+```rust
 fn main() {
     100u8 << 10;
 }
$ ./x test src/doc/rustc -- src/lints/levels.md
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.06s
/home/martin/src/rust/build/x86_64-unknown-linux-gnu/ci-llvm/bin/llvm-strip does not exist; skipping copy
Building stage1 compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.21s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage1 lld-wrapper (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.08s
Building stage1 library artifacts (stage1 -> stage1, x86_64-unknown-linux-gnu)
    Finished `dist` profile [optimized + debuginfo] target(s) in 0.03s
Testing stage1 book rustc (x86_64-unknown-linux-gnu)
Building stage1 rustdoc_tool_binary (stage0 -> stage1, x86_64-unknown-linux-gnu)
    Finished `release` profile [optimized + debuginfo] target(s) in 0.13s
Command `/home/martin/src/rust/build/bootstrap/debug/rustdoc -Wrustdoc::invalid_codeblock_attributes -Znormalize-docs -Z unstable-options --test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md --test-args src/lints/levels.md` failed with exit code 101
Created at: src/bootstrap/src/core/builder/mod.rs:1524:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:3178:13

--- STDOUT vvv
running 12 tests
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Priority_of_lint_level_sources (line 370) - compile fail ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Priority_of_lint_level_sources (line 346) - compile fail ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::deny (line 109) ... FAILED
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Configuring_warning_levels::Capping_lints (line 299) ... FAILED
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Configuring_warning_levels::Via_an_attribute (line 263) ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Priority_of_lint_level_sources (line 400) ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::warn (line 76) ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::allow (line 21) ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Priority_of_lint_level_sources (line 423) ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Configuring_warning_levels::Via_an_attribute (line 271) ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Configuring_warning_levels::Via_an_attribute (line 282) ... ok
test /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::expect (line 45) ... ok

failures:

---- /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::deny (line 109) stdout ----
error: this arithmetic operation will overflow
   --> /home/martin/src/rust/src/doc/rustc/src/lints/levels.md:111:5
    |
111 |     100u8 << 10;
    |     ^^^^^^^^^^^ attempt to shift left by `10_i32`, which would overflow
    |
    = note: `#[deny(arithmetic_overflow)]` on by default

error: aborting due to 1 previous error

Couldn't compile the test.
---- /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Configuring_warning_levels::Capping_lints (line 299) stdout ----
error: this arithmetic operation will overflow
   --> /home/martin/src/rust/src/doc/rustc/src/lints/levels.md:301:5
    |
301 |     100u8 << 10;
    |     ^^^^^^^^^^^ attempt to shift left by `10_i32`, which would overflow
    |
    = note: `#[deny(arithmetic_overflow)]` on by default

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
    /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::Configuring_warning_levels::Capping_lints (line 299)
    /home/martin/src/rust/src/doc/rustc/src/lints/levels.md - Lint_Levels::deny (line 109)

test result: FAILED. 10 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.16s

--- STDERR vvv


Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:00:01

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this section is "Capping lints", the command above is rustc lib.rs --cap-lints warn

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, right, that flag is not passed when rustdoc runs the test, of course. This confirms it says warn:

echo 'fn main() { 100u8 << 10; }' | rustc --cap-lints warn -

All good then.

```

It now only warns, rather than errors. We can go further and allow all lints:
Expand Down
Loading