Commit Graph

218 Commits

Author SHA1 Message Date
Deadbeef
1d260067f1 fix documentation 2022-07-13 04:49:32 +00:00
Deadbeef
944c0e23b8 check non_exhaustive attr and private fields for transparent types 2022-07-12 10:20:55 +00:00
Dylan DPC
c815fef795
Rollup merge of #98507 - xFrednet:rfc-2383-manual-expectation-magic, r=wesleywiser
Finishing touches for `#[expect]` (RFC 2383)

This PR adds documentation and some functionality to rustc's lint passes, to manually fulfill expectations. This is needed for some lints in Clippy. Hopefully, it should be one of the last things before we can move forward with stabilizing this feature.

As part of this PR, I've also updated `clippy::duplicate_mod` to showcase how this new functionality can be used and to ensure that it works correctly.

---

changelog: [`duplicate_mod`]: Fixed lint attribute interaction

r? `@wesleywiser`

cc: https://github.com/rust-lang/rust/issues/97660, https://github.com/rust-lang/rust/issues/85549

And I guess that's it. Here have a magical unicorn 🦄
2022-07-07 18:06:50 +05:30
xFrednet
c8b4873cf9
Add function to manually fulfill lint expectations (RFC 2383) 2022-07-06 22:01:39 +02:00
xFrednet
6c6388cd6c
Document, that some lint have to be expected on the crate level (RFC 2383)
Examples: NON_ASCII_IDENTS, UNCOMMON_CODEPOINTS, CONFUSABLE_IDENTS, MIXED_SCRIPT_CONFUSABLES
2022-07-06 22:01:39 +02:00
bors
6a10920564 Auto merge of #97235 - nbdd0121:unwind, r=Amanieu
Fix FFI-unwind unsoundness with mixed panic mode

UB maybe introduced when an FFI exception happens in a `C-unwind` foreign function and it propagates through a crate compiled with `-C panic=unwind` into a crate compiled with `-C panic=abort` (#96926).

To prevent this unsoundness from happening, we will disallow a crate compiled with `-C panic=unwind` to be linked into `panic-abort` *if* it contains a call to `C-unwind` foreign function or function pointer. If no such call exists, then we continue to allow such mixed panic mode linking because it's sound (and stable). In fact we still need the ability to do mixed panic mode linking for std, because we only compile std once with `-C panic=unwind` and link it regardless panic strategy.

For libraries that wish to remain compile-once-and-linkable-to-both-panic-runtimes, a `ffi_unwind_calls` lint is added (gated under `c_unwind` feature gate) to flag any FFI unwind calls that will cause the linkable panic runtime be restricted.

In summary:
```rust
#![warn(ffi_unwind_calls)]

mod foo {
    #[no_mangle]
    pub extern "C-unwind" fn foo() {}
}

extern "C-unwind" {
    fn foo();
}

fn main() {
    // Call to Rust function is fine regardless ABI.
    foo::foo();
    // Call to foreign function, will cause the crate to be unlinkable to panic-abort if compiled with `-Cpanic=unwind`.
    unsafe { foo(); }
    //~^ WARNING call to foreign function with FFI-unwind ABI
    let ptr: extern "C-unwind" fn() = foo::foo;
    // Call to function pointer, will cause the crate to be unlinkable to panic-abort if compiled with `-Cpanic=unwind`.
    ptr();
    //~^ WARNING call to function pointer with FFI-unwind ABI
}
```

Fix #96926

`@rustbot` label: T-compiler F-c_unwind
2022-07-02 14:06:27 +00:00
Ralf Jung
dc2cc10941 make const_err show up in future breakage reports 2022-06-25 10:30:47 -04:00
Michael Goulet
41cb5e9439
Rollup merge of #98283 - TaKO8Ki:point-at-private-fields-in-struct-literal, r=compiler-errors
Point at private fields in struct literal

closes #95872
2022-06-23 14:39:08 -07:00
Takayuki Maeda
eb86daa138 add "was" to pluralize macro and use it 2022-06-22 14:56:40 +09:00
bors
aaf100597c Auto merge of #97652 - RalfJung:cenum_impl_drop_cast, r=nagisa
make cenum_impl_drop_cast deny-by-default

Also make it show up as future breakage diagnostic.

In https://github.com/rust-lang/rust/pull/96862 we are proposing to change behavior of those drops *again*, so this looks like a good opportunity to increase our pressure on getting them out of the ecosystem. Looking at the [tracking issue](https://github.com/rust-lang/rust/issues/73333), so far nobody spoke up in favor of this (accidental) feature.

Cc https://github.com/rust-lang/rust/issues/73333 `@oli-obk`
2022-06-18 00:02:52 +00:00
xFrednet
8527a3d369
Support lint expectations for --force-warn lints (RFC 2383) 2022-06-16 08:16:43 +02:00
Gary Guo
6ef2033884 Fix FFI-unwind unsoundness with mixed panic mode 2022-06-08 21:32:41 +01:00
bjorn3
62a4f91a5a Use serde_json for json error messages 2022-06-03 16:46:19 +00:00
Ralf Jung
f6b41e346b fix lint doctests 2022-06-02 09:41:13 -04:00
Ralf Jung
0faef0a96e make cenum_impl_drop_cast deny-by-default and show up as future breakage diagnostic 2022-06-02 09:06:29 -04:00
est31
cd251fb48e Fix typo 2022-05-23 14:07:40 +02:00
Camille GILLOT
563916d698 Lint single-use-lifetimes on the AST. 2022-05-20 12:26:37 +02:00
est31
015e2ae769 Allow the unused_macro_rules lint for now
This makes the transition easier as e.g. allow directives
won't fire the unknown lint warning once it is turned to
warn by default in the future. This is especially
important compared to other lints in the unused group
because the _ prefix trick doesn't exist for macro rules,
so allowing is the only option (either of unused_macro_rules,
or of the entire unused group, but that is not as informative
to readers). Allowing the lint also makes it possible to work
on possible heuristics for disabling the macro in specific
cases.
2022-05-14 12:31:14 +02:00
bors
0cd939e36c Auto merge of #96150 - est31:unused_macro_rules, r=petrochenkov
Implement a lint to warn about unused macro rules

This implements a new lint to warn about unused macro rules (arms/matchers), similar to the `unused_macros` lint added by #41907 that warns about entire macros.

```rust
macro_rules! unused_empty {
    (hello) => { println!("Hello, world!") };
    () => { println!("empty") }; //~ ERROR: 1st rule of macro `unused_empty` is never used
}

fn main() {
    unused_empty!(hello);
}
```

Builds upon #96149 and #96156.

Fixes #73576
2022-05-12 00:08:08 +00:00
bors
8a2fe75d0e Auto merge of #95960 - jhpratt:remove-rustc_deprecated, r=compiler-errors
Remove `#[rustc_deprecated]`

This removes `#[rustc_deprecated]` and introduces diagnostics to help users to the right direction (that being `#[deprecated]`). All uses of `#[rustc_deprecated]` have been converted. CI is expected to fail initially; this requires #95958, which includes converting `stdarch`.

I plan on following up in a short while (maybe a bootstrap cycle?) removing the diagnostics, as they're only intended to be short-term.
2022-05-09 04:47:30 +00:00
bors
574830f573 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
2022-05-07 06:30:29 +00:00
bors
9a251644fa Auto merge of #96268 - jackh726:remove-mutable_borrow_reservation_conflict-lint, r=nikomatsakis
Remove mutable_borrow_reservation_conflict lint and allow the code pattern

This was the only breaking issue with the NLL stabilization PR. Lang team decided to go ahead and allow this.

r? `@nikomatsakis`
Closes #59159
Closes #56254
2022-05-06 12:32:44 +00:00
est31
3d43be3ad3 Add unused_macro_rules lint definition
Not fired yet.
2022-05-04 02:40:49 +02:00
Elliot Roberts
7907385999 fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
Jeremy Fitzhardinge
0529a13b5d Plumb through rustc_lint_defs::Level as enum rather than string. 2022-04-27 10:04:25 -07:00
Jack Huey
2300401fb0 Remove mutable_borrow_reservation_conflict lint 2022-04-20 22:10:46 -04:00
bors
27af517549 Auto merge of #96082 - michaelwoerister:less_impl_stable_hash_via_hash, r=compiler-errors
incr. comp.: Don't export impl_stable_hash_via_hash!() and warn about using it.

Fixes https://github.com/rust-lang/rust/issues/96013.
2022-04-20 03:51:09 +00:00
Dylan DPC
5f10d1312d
Rollup merge of #96086 - jsgf:remove-extern-location, r=davidtwco
Remove `--extern-location` and all associated code

`--extern-location` was an experiment to investigate the best way to
generate useful diagnostics for unused dependency warnings by enabling a
build system to identify the corresponding build config.

While I did successfully use this, I've since been convinced the
alternative `--json unused-externs` mechanism is the way to go, and
there's no point in having two mechanisms with basically the same
functionality.

This effectively reverts https://github.com/rust-lang/rust/pull/72603
2022-04-19 14:43:17 +02:00
Michael Woerister
c0be619724 incr. comp.: Don't export impl_stable_hash_via_hash!() and warn about using it. 2022-04-19 10:43:20 +02:00
Camille GILLOT
a9e13fa553 Lint elided lifetimes in path on the AST. 2022-04-17 11:03:34 +02:00
Jeremy Fitzhardinge
1be1157d75 Remove --extern-location and all associated code
`--extern-location` was an experiment to investigate the best way to
generate useful diagnostics for unused dependency warnings by enabling a
build system to identify the corresponding build config.

While I did successfully use this, I've since been convinced the
alternative `--json unused-externs` mechanism is the way to go, and
there's no point in having two mechanisms with basically the same
functionality.

This effectively reverts https://github.com/rust-lang/rust/pull/72603
2022-04-15 11:19:06 -07:00
Ralf Jung
1a6c2ff4fd make unaligned_reference warning visible in future compat report 2022-04-14 22:15:56 -04:00
Jacob Pratt
bfdf234fae
Update error code docs 2022-04-14 21:19:46 -04:00
Jacob Pratt
e46f8b23dd
Error on #[rustc_deprecated] 2022-04-14 21:19:44 -04:00
Ralf Jung
e30d6d9096 make unaligned_references lint deny-by-default 2022-04-14 21:16:42 -04:00
niluxv
98a4834237 Split fuzzy_provenance_casts into lossy and fuzzy, feature gate and test it
* split `fuzzy_provenance_casts` into a ptr2int and a int2ptr lint
* feature gate both lints
* update documentation to be more realistic short term
* add tests for these lints
2022-04-08 17:41:28 +02:00
Aria Beingessner
1040cab53b WIP PROOF-OF-CONCEPT: Make the compiler complain about all int<->ptr casts.
ALL

OF

THEM
2022-04-08 17:40:33 +02:00
David Wood
c45f29595d span: move MultiSpan
`MultiSpan` contains labels, which are more complicated with the
introduction of diagnostic translation and will use types from
`rustc_errors` - however, `rustc_errors` depends on `rustc_span` so
`rustc_span` cannot use types like `DiagnosticMessage` without
dependency cycles. Introduce a new `rustc_error_messages` crate that can
contain `DiagnosticMessage` and `MultiSpan`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:00 +01:00
Yuri Astrakhan
5160f8f843 Spellchecking compiler comments
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-30 15:14:15 -04:00
codehorseman
01dbfb3eb2 resolve the conflict in compiler/rustc_session/src/parse.rs
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-16 20:12:30 +08:00
Matthias Krüger
183262d8d3
Rollup merge of #94958 - est31:pluralize, r=oli-obk
Support other types of pluralization in pluralize macro
2022-03-15 17:15:55 +01:00
est31
3bf9124f14 Support other types of pluralization in pluralize macro 2022-03-15 15:37:49 +01:00
Matthias Krüger
6548a368c8
Rollup merge of #94670 - xFrednet:rfc-2383-expect-impl-after-party, r=flip1995,wesleywiser
Improve `expect` impl and handle `#[expect(unfulfilled_lint_expectations)]` (RFC 2383)

This PR updates unstable `ExpectationIds` in stashed diagnostics and adds some asserts to ensure that the stored expectations are really empty in the end. Additionally, it handles the `#[expect(unfulfilled_lint_expectations)]` case.

According to the [Errors and lints docs](https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-levels) the `error` level should only be used _"when the compiler detects a problem that makes it unable to compile the program"_. As this isn't the case with `#[expect(unfulfilled_lint_expectations)]` I decided to only create a warning. To avoid adding a new lint only for this case, I simply emit a `unfulfilled_lint_expectations` diagnostic with an additional note.

---

r? `@wesleywiser` I'm requesting a review from you since you reviewed the previous PR https://github.com/rust-lang/rust/pull/87835. You are welcome to reassign it if you're busy 🙃

rfc: [RFC-2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html)

tracking issue: https://github.com/rust-lang/rust/issues/85549

cc: `@flip1995` In case you're also interested in this :)
2022-03-14 17:24:58 +01:00
Dylan DPC
1ed2a94fd2
Rollup merge of #94274 - djkoloski:unknown_unstable_lints, r=tmandry
Treat unstable lints as unknown

This change causes unstable lints to be ignored if the `unknown_lints`
lint is allowed. To achieve this, it also changes lints to apply as soon
as they are processed. Previously, lints in the same set were processed
as a batch and then all simultaneously applied.

Implementation of https://github.com/rust-lang/compiler-team/issues/469
2022-03-10 23:12:57 +01:00
T-O-R-U-S
72a25d05bf Use implicit capture syntax in format_args
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
2022-03-10 10:23:40 -05:00
David Koloski
fa10d90b99 Fix docs, fix incorrect lint source in note 2022-03-08 19:09:32 +00:00
David Koloski
1593ce8609 Fill out documentation for new lint 2022-03-08 19:09:30 +00:00
David Koloski
2677eca237 Switch the primary diagnostic to unknown_lints
This also affects the `non_exhaustive_omitted_patterns` and
`must_not_suspend` lints as they are not stable. This also changes the
diagnostic level to pull from `unknown_lints` instead of always being
allow or deny.
2022-03-08 19:07:29 +00:00
David Koloski
8852752078 Treat unstable lints as unknown
This change causes unstable lints to be ignored if the `unknown_lints`
lint is allowed. To achieve this, it also changes lints to apply as soon
as they are processed. Previously, lints in the same set were processed
as a batch and then all simultaneously applied.

Implementation of https://github.com/rust-lang/compiler-team/issues/469
2022-03-08 19:06:40 +00:00
xFrednet
165b5583e5
Fix typos in LintExpectationId docs 2022-03-07 18:08:31 +01:00