Commit Graph

212 Commits

Author SHA1 Message Date
bors 25f39fe802 Auto merge of #81135 - jyn514:no-backticks, r=flip1995
Fix formatting for removed lints

- Don't add backticks for the reason a lint was removed. This is almost
never a code block, and when it is the backticks should be in the reason
itself.
- Don't assume clippy is the only tool that needs to be checked for
backwards compatibility

I split this out of https://github.com/rust-lang/rust/pull/80527/ because it kept causing tests to fail, and it's a good change to have anyway.

r? `@flip1995`
2021-01-22 06:13:19 +00:00
Esteban Küber 707ce2b798 Account for labels when suggesting `loop` instead of `while true` 2021-01-21 21:41:46 -08:00
LeSeulArtichaut 50e1ae15e9 Use ty::{IntTy,UintTy,FloatTy} in rustc 2021-01-18 21:09:30 +01:00
Cameron Steffen 21fb586c0c Query for TypeckResults in LateContext::qpath_res
Actually fulfills the documented guarantees.
2021-01-18 13:38:14 -06:00
Cameron Steffen 63a1eeea23 Reset LateContext enclosing body in nested items
Prevents LateContext::maybe_typeck_results() from returning data in a
nested item without a body. Consequently, LateContext::qpath_res is less
likely to ICE when called in a nested item. Would have prevented
rust-lang/rust-clippy#4545, presumably.
2021-01-18 13:38:14 -06:00
Joshua Nelson 77b5ced3aa Fix formatting for removed lints
- Don't add backticks for the reason a lint was removed. This is almost
never a code block, and when it is the backticks should be in the reason
itself.
- Don't assume clippy is the only tool that needs to be checked for
backwards compatibility
2021-01-17 16:18:02 -05:00
bors 4253153db2 Auto merge of #80679 - jackh726:predicate-kind-take2, r=lcnr
Remove PredicateKind and instead only use Binder<PredicateAtom>

Originally brought up in https://github.com/rust-lang/rust/pull/76814#discussion_r546858171

r? `@lcnr`
2021-01-17 20:49:11 +00:00
Jack Huey 3dea68de1d Review changes 2021-01-16 18:56:37 -05:00
flip1995 5e3df4266a
More advanced unknown lint suggestion
This copies the unknown_lints code clippy uses for its
unknown_clippy_lints lint to rustc. The unknown_clippy_lints code is
more advanced, because it doesn't suggest renamed or removed lints and
correctly suggest lower casing lints.
2021-01-16 19:44:46 +01:00
Joshua Nelson 5053db7c00 Don't make tools responsible for checking unknown and renamed lints
Previously, clippy (and any other tool emitting lints) had to have their
own separate UNKNOWN_LINTS pass, because the compiler assumed any tool
lint could be valid. Now, as long as any lint starting with the tool
prefix exists, the compiler will warn when an unknown lint is present.
2021-01-15 16:08:28 -05:00
LingMan a56bffb4f9 Use Option::map_or instead of `.map(..).unwrap_or(..)` 2021-01-14 19:23:59 +01:00
Mark Rousskov c4a8d7f86a Introduce missing ABI lint on extern blocks 2021-01-13 07:49:16 -05:00
bors fc93e4719c Auto merge of #80960 - Dylan-DPC:rollup-89tri8x, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #78901 (diagnostics: Note capturing closures can't be coerced to fns)
 - #79588 (Provide more information for HRTB lifetime errors involving closures)
 - #80232 (Remove redundant def_id lookups)
 - #80662 (Added support for i386-unknown-linux-gnu and i486-unknown-linux-gnu)
 - #80736 (use Once instead of Mutex to manage capture resolution)
 - #80796 (Update to LLVM 11.0.1)
 - #80859 (Fix --pretty=expanded with --remap-path-prefix)
 - #80922 (Revert "Auto merge of #76896 - spastorino:codegen-inline-fns2)
 - #80924 (Fix rustdoc --test-builder argument parsing)
 - #80935 (Rename `rustc_middle::lint::LevelSource` to `LevelAndSource`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-13 04:29:45 +00:00
Dylan DPC 5b90fe1c30
Rollup merge of #80935 - pierwill:rustc_middle-levelandsource, r=petrochenkov
Rename `rustc_middle::lint::LevelSource` to `LevelAndSource`

This continues work in https://github.com/rust-lang/rust/pull/80274 to improve code readability.

This naming follows a pattern seen elsewhere in the compiler (e.g. [`rustc_middle::ty::TypeAndMut`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeAndMut.html)).
2021-01-13 03:20:27 +01:00
bors 150d1fee04 Auto merge of #79322 - jyn514:refactor-impl, r=estebank
Separate out a `hir::Impl` struct

This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.

See `rustc_save_analysis::dump_visitor::process_impl` or `rustdoc::clean::clean_impl` for a good example of how this makes `impl`s easier to work with.

r? `@petrochenkov` maybe?
2021-01-13 01:40:41 +00:00
Joshua Nelson a8ff647deb Separate out a `hir::Impl` struct
This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.
2021-01-12 20:32:33 -05:00
pierwill 2e3ab43f5c Rename `rustc_middle::lint::LevelSource` to `LevelAndSource` 2021-01-11 18:02:09 -08:00
jumbatm 4b740acea2 Add FIXME note about storing &'tcx str 2021-01-12 03:31:01 +10:00
jumbatm 7a46a4f219 Remove unnecessary allocation. 2021-01-12 03:31:01 +10:00
jumbatm 15c64a181b Use tcx.symbol_name to check for clashes. 2021-01-12 03:31:00 +10:00
bors c97f11af7b Auto merge of #79414 - sasurau4:feature/add-suggestion-for-pattern-in-fns-without-body, r=matthewjasper
Add suggestion for PATTERNS_IN_FNS_WITHOUT_BODY

## Overview

Fix #78927
2021-01-10 20:48:27 +00:00
Guillaume Gomez ff1f21a8fd
Rollup merge of #80628 - matthiaskrgr:match_ref_pats, r=varkor
reduce borrowing and (de)referencing around match patterns (clippy::match_ref_pats)
2021-01-03 17:09:11 +01:00
Matthias Krüger 8a90626a46 reduce borrowing and (de)referencing around match patterns (clippy::match_ref_pats) 2021-01-02 20:09:17 +01:00
Skynoodle 750c52af73 Add snake case lint note about keyword identifiers which cannot be raw 2021-01-02 15:46:41 +00:00
Skynoodle 91f436b456 Add suggestion to use raw identifiers when fixing snake-case lints 2021-01-01 18:38:30 +00:00
bors 923e3d2400 Auto merge of #80500 - jyn514:track-caller, r=nagisa
Add `#[track_caller]` to `bug!` and `register_renamed`

Before:

```
thread 'rustc' panicked at 'compiler/rustc_lint/src/context.rs:267:18: invalid lint renaming of broken_intra_doc_links to rustdoc::broken_intra_doc_links', compiler/rustc_middle/src/util/bug.rs:34:26
```

After:

```
thread 'rustc' panicked at 'src/librustdoc/core.rs:455:24: invalid lint renaming of broken_intra_doc_links to rustdoc::broken_intra_doc_links', compiler/rustc_middle/src/util/bug.rs:35:26
```

The reason I added it to `register_renamed` too is that any panic in
that function will be the caller's fault.
2020-12-31 03:17:50 +00:00
Mara Bos 9e8edc8c22
Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkov
Rename kw::Invalid -> kw::Empty

See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.

r? `@petrochenkov`
2020-12-30 20:56:58 +00:00
Joshua Nelson edeac1778c Rename kw::Invalid -> kw::Empty
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.
2020-12-30 09:50:02 -05:00
Joshua Nelson 56ea926b1c Add `#[track_caller]` to `bug!` and `register_renamed`
Before:

```
thread 'rustc' panicked at 'compiler/rustc_lint/src/context.rs:267:18: invalid lint renaming of broken_intra_doc_links to rustdoc::broken_intra_doc_links', compiler/rustc_middle/src/util/bug.rs:34:26
```

After:

```
thread 'rustc' panicked at 'src/librustdoc/core.rs:455:24: invalid lint renaming of broken_intra_doc_links to rustdoc::broken_intra_doc_links', compiler/rustc_middle/src/util/bug.rs:35:26
```

The reason I added it to `register_renamed` too is that any panic in
that function will be the caller's fault.
2020-12-29 23:18:11 -05:00
Aaron Hill c857cbeb06
Lint on redundant trailing semicolon after item
We now lint on code like this:

```rust
fn main() {
    fn foo() {};
    struct Bar {};
}
```

Previously, this caused warnings in Cargo, so it was disabled.
2020-12-29 16:30:02 -05:00
Bastian Kauschke 06cc9c26da stabilize min_const_generics 2020-12-26 18:24:10 +01:00
Dylan DPC b295b8e67b
Rollup merge of #80274 - pierwill:lintlevelsource, r=petrochenkov
Rename rustc_middle::lint::LintSource

Rename [`rustc_middle::lint::LintSource`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/enum.LintSource.html) to `rustc_middle::lint::LintLevelSource`.

This enum represents the source of a *lint level*, not a lint. This should improve code readability.

Update: Also documents `rustc_middle::lint::LevelSource` to clarify.
2020-12-25 03:39:36 +01:00
bors 75e1acb63a Auto merge of #78242 - Nadrieril:rename-overlapping_endpoints-lint, r=varkor
Rename `overlapping_patterns` lint

As discussed in https://github.com/rust-lang/rust/issues/65477. I also tweaked a few things along the way.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-12-22 10:32:03 +00:00
pierwill d3900d3775 Document rustc_middle::lint::LevelSource
This is to clarify the difference between `LevelSource`
and `LintLevelSource`.

Appease x.py fmt.
2020-12-21 15:03:00 -08:00
pierwill aec3575aa7 Rename rustc_middle::lint::LintSource
Rename rustc_middle::lint::LintSource to rustc_middle::lint::LintLevelSource.
2020-12-21 14:30:50 -08:00
Daiki Ihara acbebd81d4 add suggest for PatternsInWithoutBody 2020-12-21 21:40:47 +09:00
Camelid d00ca11202 Add 'consider using' message to overflowing_literals
Ironically, the overflowing_literals handler for binary or hex already
had this message! You would think it would be the other way around :)
2020-12-12 14:59:35 -08:00
Jack Huey ed80815bf2 Move binder for dyn to each list item 2020-12-11 15:02:46 -05:00
Tomasz Miąsko 8fc246251f Types with a hidden niche are not known to be non-null 2020-12-10 00:00:00 +00:00
Matthias Krüger c37e19843a don't create owned values for comparison (clippy::cmp_owned) 2020-12-08 20:27:48 +01:00
Guillaume Gomez 50eb3a89f8 Only deny doc_keyword in std and set it as "allow" by default 2020-12-03 16:48:17 +01:00
Guillaume Gomez 56c64f871e Add lint pass for doc keyword 2020-12-03 10:42:15 +01:00
bors eb4860c7e1 Auto merge of #78864 - Mark-Simulacrum:warn-on-forbids, r=pnkfelix
Use true previous lint level when detecting overriden forbids

Previously, cap-lints was ignored when checking the previous forbid level, which
meant that it was a hard error to do so. This is different from the normal
behavior of lints, which are silenced by cap-lints; if the forbid would not take
effect regardless, there is not much point in complaining about the fact that we
are reducing its level.

It might be considered a bug that even `--cap-lints deny` would suffice to
silence the error on overriding forbid, depending on if one cares about failing
the build or precisely forbid being set. But setting cap-lints to deny is quite
odd and not really done in practice, so we don't try to handle it specially.

This also unifies the code paths for nested and same-level scopes. However, the
special case for CLI lint flags is left in place (introduced by #70918) to fix
the regression noted in #70819. That means that CLI flags do not lint on forbid
being overridden by a non-forbid level. It is unclear whether this is a bug or a
desirable feature, but it is certainly inconsistent. CLI flags are a
sufficiently different "type" of place though that this is deemed out of scope
for this commit.

r? `@pnkfelix` perhaps?

cc #77713 -- not marking as "Fixes" because of the lack of proper unused attribute handling in this PR
2020-12-02 02:07:45 +00:00
Nadrieril 5687c16279 `overlapping_range_endpoints` does not belong in the `unused` lint group 2020-11-29 21:29:19 +00:00
Nadrieril d1a50ffb7c Rename the `overlapping_patterns` lint to `overlapping_range_endpoints` 2020-11-29 21:29:19 +00:00
Aleksey Kladov 30d331ffb6 Cleanup: shorter and faster code 2020-11-28 17:47:34 +03:00
Aaron Hill 772292fa51
Don't lint on redundant semicolons after item statements
This preserves the current lint behavior for now.

Linting after item statements currently prevents the compiler from bootstrapping.
Fixing this is blocked on fixing this upstream in Cargo, and bumping the Cargo
submodule.
2020-11-27 09:37:49 -05:00
Aaron Hill 6f91c32da6
Fix new 'unnecessary trailing semicolon' warnings 2020-11-26 17:08:36 -05:00
Arlie Davis 5481c1bd6d Move lev_distance to rustc_ast, make non-generic
rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST
would not have any dependency its lexer, for minimizing unnecessarily
design-time dependencies. Breaking this dependency would also have practical
benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast.

This commit does not remove the rustc_ast --> rustc_lexer dependency,
but it does remove one of the sources of this dependency, which is the
code that handles fuzzy matching between symbol names for making suggestions
in diagnostics. Since that code depends only on Symbol, it is easy to move
it to rustc_span. It might even be best to move it to a separate crate,
since other tools such as Cargo use the same algorithm, and have simply
contain a duplicate of the code.

This changes the signature of find_best_match_for_name so that it is no
longer generic over its input. I checked the optimized binaries, and this
function was duplicated at nearly every call site, because most call sites
used short-lived iterator chains, generic over Map and such. But there's
no good reason for a function like this to be generic, since all it does
is immediately convert the generic input (the Iterator impl) to a concrete
Vec<Symbol>. This has all of the costs of generics (duplicated method bodies)
with no benefit.

Changing find_best_match_for_name to be non-generic removed about 10KB of
code from the optimized binary. I know it's a drop in the bucket, but we have
to start reducing binary size, and beginning to tame over-use of generics
is part of that.
2020-11-24 16:12:23 -08:00
Carol (Nichols || Goulding) ae17d7d455
More consistently use spaces after commas in lists in docs 2020-11-21 14:43:34 -05:00
bors 539402cb0b Auto merge of #77805 - JohnTitor:non-standard-char-sugg, r=Dylan-DPC
lint: Do not provide suggestions for non standard characters

Fixes #77273

Only provide suggestions if the case-fixed result is different than the original.
2020-11-21 13:11:35 +00:00
Mark Rousskov 64efcbe0e9 Use true previous lint level when detecting overriden forbids
Previously, cap-lints was ignored when checking the previous forbid level, which
meant that it was a hard error to do so. This is different from the normal
behavior of lints, which are silenced by cap-lints; if the forbid would not take
effect regardless, there is not much point in complaining about the fact that we
are reducing its level.

It might be considered a bug that even `--cap-lints deny` would suffice to
silence the error on overriding forbid, depending on if one cares about failing
the build or precisely forbid being set. But setting cap-lints to deny is quite
odd and not really done in practice, so we don't try to handle it specially.

This also unifies the code paths for nested and same-level scopes. However, the
special case for CLI lint flags is left in place (introduced by #70918) to fix
the regression noted in #70819. That means that CLI flags do not lint on forbid
being overridden by a non-forbid level. It is unclear whether this is a bug or a
desirable feature, but it is certainly inconsistent. CLI flags are a
sufficiently different "type" of place though that this is deemed out of scope
for this commit.
2020-11-14 15:56:07 -05:00
Dylan DPC 8ebca242bc
Rollup merge of #78710 - petrochenkov:macvisit, r=davidtwco
rustc_ast: Do not panic by default when visiting macro calls

Panicking by default made sense when we didn't have HIR or MIR and everything worked on AST, but now all AST visitors run early and majority of them have to deal with macro calls, often by ignoring them.

The second commit renames `visit_mac` to `visit_mac_call`, the corresponding structures were renamed earlier in https://github.com/rust-lang/rust/pull/69589.
2020-11-09 19:06:55 +01:00
Guillaume Gomez 9d114506c6 Rename lint to non_autolinks 2020-11-05 10:22:08 +01:00
Guillaume Gomez 60caf51b0d Rename automatic_links to url_improvements 2020-11-05 10:22:08 +01:00
Guillaume Gomez 2980367030 Add new lint for automatic_links improvements 2020-11-05 10:22:08 +01:00
oli abacaf2aef `u128` truncation and sign extension are not just interpreter related 2020-11-04 13:41:58 +00:00
Vadim Petrochenkov 90fafc8c8f rustc_ast: `visit_mac` -> `visit_mac_call` 2020-11-03 23:39:51 +03:00
Vadim Petrochenkov 3237b3886c rustc_ast: Do not panic by default when visiting macro calls 2020-11-03 20:38:20 +03:00
Yuki Okushi 8894c903cb
Rollup merge of #78663 - Aaron1011:fix/cap-future-compat, r=tmandry
Fix ICE when a future-incompat-report has its command-line level capped

Fixes #78660

With PR https://github.com/rust-lang/rust/pull/75534 merged, we now run
more lint-related code for future-incompat-report, even when their final
level is Allow. Some lint-related code was not expecting `Level::Allow`,
and had an explicit panic.

This PR explicitly tracks the lint level set on the command line before
`--cap-lints` is applied. This is used to emit a more precise error
note (e.g. we don't say that `-W lint-name` was specified on the
command line just because a lint was capped to Warn). As a result, we
can now correctly emit a note that `-A` was used if we got
`Level::Allow` from the command line (before the cap is applied).
2020-11-03 15:27:16 +09:00
Aaron Hill e78e9d4a06
Treat trailing semicolon as a statement in macro call
See https://github.com/rust-lang/rust/issues/61733#issuecomment-716188981

We now preserve the trailing semicolon in a macro invocation, even if
the macro expands to nothing. As a result, the following code no longer
compiles:

```rust
macro_rules! empty {
    () => { }
}

fn foo() -> bool { //~ ERROR mismatched
    { true } //~ ERROR mismatched
    empty!();
}
```

Previously, `{ true }` would be considered the trailing expression, even
though there's a semicolon in `empty!();`

This makes macro expansion more token-based.
2020-11-02 13:03:13 -05:00
Aaron Hill 6c1f15fa81
Fix ICE when a future-incompat-report has its command-line level capped
Fixes #78660

With PR https://github.com/rust-lang/rust/pull/75534 merged, we now run
more lint-related code for future-incompat-report, even when their final
level is Allow. Some lint-related code was not expecting `Level::Allow`,
and had an explicit panic.

This PR explicitly tracks the lint level set on the command line before
`--cap-lints` is applied. This is used to emit a more precise error
note (e.g. we don't say that `-W lint-name` was specified on the
command line just because a lint was capped to Warn). As a result, we
can now correctly emit a note that `-A` was used if we got
`Level::Allow` from the command line (before the cap is applied).
2020-11-02 01:43:25 -05:00
bors b202532608 Auto merge of #75534 - Aaron1011:feature/new-future-breakage, r=pnkfelix
Implement rustc side of report-future-incompat

cc https://github.com/rust-lang/rust/issues/71249

This is an alternative to `@pnkfelix's` initial implementation in https://github.com/pnkfelix/rust/commits/prototype-rustc-side-of-report-future-incompat (mainly because I started working before seeing that branch 😄 ).

My approach outputs the entire original `Diagnostic`, in a way that is compatible with incremental compilation. This is not yet integrated with compiletest, but can be used manually by passing `-Z emit-future-incompat-report` to `rustc`.

Several changes are made to support this feature:
* The `librustc_session/lint` module is moved to a new crate `librustc_lint_defs` (name bikesheddable). This allows accessing lint definitions from `librustc_errors`.
* The `Lint` struct is extended with an `Option<FutureBreakage>`. When present, it indicates that we should display a lint in the future-compat report. `FutureBreakage` contains additional information that we may want to display in the report (currently, a `date` field indicating when the crate will stop compiling).
* A new variant `rustc_error::Level::Allow` is added. This is used when constructing a diagnostic for a future-breakage lint that is marked as allowed (via `#[allow]` or `--cap-lints`). This allows us to capture any future-breakage diagnostics in one place, while still discarding them before they are passed to the `Emitter`.
* `DiagnosticId::Lint` is extended with a `has_future_breakage` field, indicating whether or not the `Lint` has future breakage information (and should therefore show up in the report).
* `Session` is given access to the `LintStore` via a new `SessionLintStore` trait (since `librustc_session` cannot directly reference `LintStore` without a cyclic dependency). We use this to turn a string `DiagnosticId::Lint` back into a `Lint`, to retrieve the `FutureBreakage` data.

Currently, `FutureBreakage.date` is always set to `None`. However, this could potentially be interpreted by Cargo in the future.

I've enabled the future-breakage report for the `ARRAY_INTO_ITER` lint, which can be used to test out this PR. The intent is to use the field to allow Cargo to determine the date of future breakage (as described in [RFC 2834](https://github.com/rust-lang/rfcs/blob/master/text/2834-cargo-report-future-incompat.md)) without needing to parse the diagnostic itself.

cc `@pnkfelix`
2020-11-01 16:52:28 +00:00
Aaron Hill 23018a55d9
Implement rustc side of report-future-incompat 2020-10-30 20:02:14 -04:00
bors 0d033dee3e Auto merge of #78182 - LeSeulArtichaut:ty-visitor-contolflow, r=lcnr,oli-obk
TypeVisitor: use `std::ops::ControlFlow` instead of `bool`

Implements MCP rust-lang/compiler-team#374.

Blocked on FCP in rust-lang/compiler-team#374.
r? `@lcnr` cc `@jonas-schievink`
2020-10-30 22:53:55 +00:00
Joshua Nelson bfecb18771 Fix some more clippy warnings 2020-10-30 10:12:56 -04:00
LeSeulArtichaut 9433eb83fe Remove implicit `Continue` type 2020-10-30 12:27:47 +01:00
LeSeulArtichaut 4fe735b320 TypeVisitor: use `ControlFlow` in rustc_{infer,lint,trait_selection} 2020-10-30 12:27:34 +01:00
Mara Bos 9743f67684 Improve panic_fmt lint messages.
(From the PR feedback.)

Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
2020-10-29 19:44:06 +01:00
Jonas Schievink 31cfe63fb9
Rollup merge of #78431 - Rustin-Liu:rustin-patch-lint, r=estebank
Prefer new associated numeric consts in float error messages

Fix https://github.com/rust-lang/rust/issues/78382
2020-10-29 17:05:21 +01:00
Jonas Schievink 9867e54bea
Rollup merge of #78244 - workingjubilee:dogfood-fancy-ranges, r=varkor
Dogfood {exclusive,half-open} ranges in compiler (nfc)

In particular, this allows us to write more explicit matches that
avoid the pitfalls of using a fully general fall-through case, yet
remain fairly ergonomic. Less logic is in guard cases, more is in
the actual exhaustive case analysis.

No functional changes.
2020-10-29 17:05:11 +01:00
Jubilee Young 0e88db7db4 Dogfood {exclusive,half-open} ranges in compiler (nfc)
In particular, this allows us to write more explicit matches that
avoid the pitfalls of using a fully general fall-through case, yet
remain fairly ergonomic. Less logic is in guard cases, more is in
the actual exhaustive case analysis.

No functional changes.
2020-10-28 20:09:20 -07:00
Mara Bos 5cefc3ce41 Mark panic_fmt suggestion as machine applicable.
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2020-10-28 11:00:28 +01:00
Rustin-Liu 650e3cb176 Prefer new associated numeric consts in float error messages 2020-10-27 14:14:08 +08:00
Nathan Whitaker 6ba127d3f0 Fix doctest 2020-10-26 18:19:49 -04:00
Nathan Whitaker 576eb2a30c Write docs for lint / fix review nit 2020-10-26 18:19:48 -04:00
Nathan Whitaker 1bcd2452fe Address review comments 2020-10-26 18:19:48 -04:00
Nathan Whitaker 737bfeffd2 Change to warn by default / fix typo 2020-10-26 18:19:48 -04:00
Nathan Whitaker 5643a0662a Tweak diagnostic 2020-10-26 18:19:47 -04:00
Nathan Whitaker 8b65df06ce Address review comments 2020-10-26 18:19:47 -04:00
Nathan Whitaker 8cf1b0e1ad Uplift temporary-cstring-as-ptr into rustc 2020-10-26 18:19:40 -04:00
Aaron Hill ac384ac2db
Fix inconsistencies in handling of inert attributes on statements
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306
2020-10-24 11:55:48 -04:00
Yuki Okushi 59ae7957b0
Rollup merge of #78155 - est31:rustc_lint_types_refactor, r=davidtwco
Fix two small issues in compiler/rustc_lint/src/types.rs

Two small improvements of `compiler/rustc_lint/src/types.rs`
2020-10-22 09:45:38 +09:00
Mara Bos 190c3ad64e Improve panic_fmt error messages for invalid format strings too. 2020-10-20 22:59:53 +02:00
Mara Bos 6b44662669 Parse the format string for the panic_fmt lint for better warnings. 2020-10-20 22:25:42 +02:00
est31 00d23cf220 Make {u,}int_range functions a bit nicer
.into() guarantees safety of the conversion.
Furthermore, the minimum value of all uints is known to be 0.
2020-10-20 19:36:44 +02:00
est31 c647735f40 rustc_lint: remove unused to_string
In this instance, we can just pass a &str slice
and save an allocation.
2020-10-20 19:30:09 +02:00
Yuki Okushi 378ca5e640
Rollup merge of #77931 - aticu:fix_60336, r=petrochenkov
Fix false positive for `unused_parens` lint

Fixes #60336
2020-10-20 12:11:06 +09:00
Mara Bos 0f193d1a62 Small cleanups in assert!() and panic_fmt lint.
(From the PR feedback.)

Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
2020-10-19 21:14:05 +02:00
Mara Bos d3b41497fe Also apply panic_fmt lint suggestions to debug_assert!(). 2020-10-19 00:45:07 +02:00
Mara Bos 9615d27ab7 Don't see `{{}}` as placeholder in panic_fmt lint. 2020-10-19 00:05:19 +02:00
Mara Bos b8a8b681b8 Formatting. 2020-10-18 23:25:57 +02:00
Mara Bos ded269fa10 Improve panic_fmt message for panic!("{}") with a fmt placeholder. 2020-10-18 23:25:06 +02:00
Mara Bos f228efc3f5 Make panic_fmt lint work properly for assert!(expr, msg) too. 2020-10-18 22:29:40 +02:00
Mara Bos da66a501f6 Specialize panic_fmt lint for the {core,std}::panic!() macros.
It now only reacts to expansion of those macros, and suggests
inserting `"{}", ` in the right place.
2020-10-18 22:26:36 +02:00
Mara Bos a46679098f Add lint to warn about braces in a panic message. 2020-10-18 22:24:15 +02:00
bors e0ef0fc392 Auto merge of #78779 - LeSeulArtichaut:ty-visitor-return, r=oli-obk
Introduce `TypeVisitor::BreakTy`

Implements MCP rust-lang/compiler-team#383.
r? `@ghost`
cc `@lcnr` `@oli-obk`

~~Blocked on FCP in rust-lang/compiler-team#383.~~
2020-11-17 12:24:34 +00:00
Bastian Kauschke 2bf93bd852 compiler: fold by value 2020-11-16 22:34:57 +01:00
LeSeulArtichaut 07b37cf791 Use `TypeVisitor::BreakTy` in `ProhibitOpaqueTypes` 2020-11-14 22:16:16 +01:00
LeSeulArtichaut 65cdc21f06 Set the default `BreakTy` to `!` 2020-11-14 21:46:39 +01:00