about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2021-02-15Only store a LocalDefId in hir::Item.Camille GILLOT-31/+26
Items are guaranteed to be HIR owner.
2021-02-15Use ItemId as a strongly typed index.Camille GILLOT-1/+1
2021-02-14Formatting.Mara Bos-8/+2
2021-02-14Suggest correct replacement for panic![123].Mara Bos-15/+33
Before this change, the suggestion was `std::panic::panic_any(123]`, changing the opening brace but not the closing one.
2021-02-14Improve suggestion for panic!(format!(..)).Mara Bos-1/+30
2021-02-14Fix span in non_fmt_panic for panic!(some_macro!()).Mara Bos-4/+15
2021-02-13Improve error and help messagesCamelid-4/+4
2021-02-10Auto merge of #79804 - tmiasko:improper-ctypes-no-niche, r=pnkfelixbors-1/+7
Types with a hidden niche are not known to be non-null Fixes #79787.
2021-02-10Rollup merge of #81913 - osa1:rename_unop_variants, r=matthewjasperYuki Okushi-1/+1
Rename HIR UnOp variants This renames the variants in HIR UnOp from enum UnOp { UnDeref, UnNot, UnNeg, } to enum UnOp { Deref, Not, Neg, } Motivations: - This is more consistent with the rest of the code base where most enum variants don't have a prefix. - These variants are never used without the `UnOp` prefix so the extra `Un` prefix doesn't help with readability. E.g. we don't have any `UnDeref`s in the code, we only have `UnOp::UnDeref`. - MIR `UnOp` type variants don't have a prefix so this is more consistent with MIR types. - "un" prefix reads like "inverse" or "reverse", so as a beginner in rustc code base when I see "UnDeref" what comes to my mind is something like `&*` instead of just `*`.
2021-02-09Rename HIR UnOp variantsÖmer Sinan Ağacan-1/+1
This renames the variants in HIR UnOp from enum UnOp { UnDeref, UnNot, UnNeg, } to enum UnOp { Deref, Not, Neg, } Motivations: - This is more consistent with the rest of the code base where most enum variants don't have a prefix. - These variants are never used without the `UnOp` prefix so the extra `Un` prefix doesn't help with readability. E.g. we don't have any `UnDeref`s in the code, we only have `UnOp::UnDeref`. - MIR `UnOp` type variants don't have a prefix so this is more consistent with MIR types. - "un" prefix reads like "inverse" or "reverse", so as a beginner in rustc code base when I see "UnDeref" what comes to my mind is something like "&*" instead of just "*".
2021-02-09Rollup merge of #72209 - Nemo157:lint-no-mangle-in-unsafe-code, r=nikomatsakisDylan DPC-0/+46
Add checking for no_mangle to unsafe_code lint fixes #72188 r? `@estebank`
2021-02-07Add `--extern-loc` to augment unused crate dependency diagnosticsJeremy Fitzhardinge-2/+29
This allows a build system to indicate a location in its own dependency specification files (eg Cargo's `Cargo.toml`) which can be reported along side any unused crate dependency. This supports several types of location: - 'json' - provide some json-structured data, which is included in the json diagnostics in a `tool_metadata` field - 'raw' - emit the provided string into the output. This also appears as a json string in `tool_metadata`. If no `--extern-location` is explicitly provided then a default json entry of the form `"tool_metadata":{"name":<cratename>,"path":<cratepath>}` is emitted.
2021-02-07expand/resolve: Turn `#[derive]` into a regular macro attributeVadim Petrochenkov-0/+3
2021-02-04Rollup merge of #81645 - m-ou-se:panic-lint, r=estebank,flip1995Mara Bos-158/+200
Add lint for `panic!(123)` which is not accepted in Rust 2021. This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}",` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines. ![image](https://user-images.githubusercontent.com/783247/106520928-675ea680-64d5-11eb-81f7-d8fa48b93a0b.png) This is part of #80162. r? ```@estebank```
2021-02-04Rollup merge of #81556 - nikomatsakis:forbidden-lint-groups-lint, r=pnkfelixMara Bos-28/+88
introduce future-compatibility warning for forbidden lint groups We used to ignore `forbid(group)` scenarios completely. This changed in #78864, but that led to a number of regressions (#80988, #81218). This PR introduces a future compatibility warning for the case where a group is forbidden but then an individual lint within that group is allowed. We now issue a FCW when we see the "allow", but permit it to take effect. r? ``@Mark-Simulacrum``
2021-02-03Add lint for `panic!(123)` which is not accepted in Rust 2021.Mara Bos-158/+200
This extends the `panic_fmt` lint to warn for all cases where the first argument cannot be interpreted as a format string, as will happen in Rust 2021. It suggests to add `"{}", ` to format the message as a string. In the case of `std::panic!()`, it also suggests the recently stabilized `std::panic::panic_any()` function as an alternative. It renames the lint to `non_fmt_panic` to match the lint naming guidelines.
2021-02-03Really fix early lints inside an async desugaringJethro Beekman-4/+4
2021-02-02introduce future-compatibility warning for forbidden lint groupsNiko Matsakis-28/+88
We used to ignore `forbid(group)` scenarios completely. This changed in #78864, but that led to a number of regressions (#80988, #81218). This PR introduces a future compatibility warning for the case where a group is forbidden but then an individual lint within that group is allowed. We now issue a FCW when we see the "allow", but permit it to take effect.
2021-02-02Auto merge of #81541 - Aaron1011:early-lint-async-fn, r=petrochenkovbors-0/+16
Fix early lints inside an async desugaring Fixes #81531 When we buffer an early lint for a macro invocation, we need to determine which NodeId to take the lint level from. Currently, we use the NodeId of the closest def parent. However, if the macro invocation is inside the desugared closure from an `async fn` or async closure, that NodeId does not actually exist in the AST. This commit uses the parent of a desugared closure when computing `lint_node_id`, which is something that actually exists in the AST (an `async fn` or async closure).
2021-02-02Fix early lints inside an async desugaringAaron Hill-0/+16
Fixes #81531 When we buffer an early lint for a macro invocation, we need to determine which NodeId to take the lint level from. Currently, we use the `NodeId` of the closest def parent. However, if the macro invocation is inside the desugared closure from an `async fn` or async closure, that `NodeId` does not actually exist in the AST. This commit explicitly calls `check_lint` for the `NodeId`s of closures desugared from async expressions, ensuring that we do not miss any buffered lints.
2021-02-02Auto merge of #81405 - bugadani:ast, r=cjgillotbors-11/+10
Box the biggest ast::ItemKind variants This PR is a different approach on https://github.com/rust-lang/rust/pull/81400, aiming to save memory in humongous ASTs. The three affected item kind enums are: - `ast::ItemKind` (208 -> 112 bytes) - `ast::AssocItemKind` (176 -> 72 bytes) - `ast::ForeignItemKind` (176 -> 72 bytes)
2021-02-01Rollup merge of #81529 - estebank:case_lints, r=davidtwcoJonas Schievink-1/+18
Fix invalid camel case suggestion involving unicode idents Follow up to #77805.
2021-02-01Auto merge of #80851 - m-ou-se:panic-2021, r=petrochenkovbors-9/+14
Implement Rust 2021 panic This implements the Rust 2021 versions of `panic!()`. See https://github.com/rust-lang/rust/issues/80162 and https://github.com/rust-lang/rfcs/pull/3007. It does so by replacing `{std, core}::panic!()` by a bulitin macro that expands to either `$crate::panic::panic_2015!(..)` or `$crate::panic::panic_2021!(..)` depending on the edition of the caller. This does not yet make std's panic an alias for core's panic on Rust 2021 as the RFC proposes. That will be a separate change: https://github.com/rust-lang/rust/pull/80879/commits/c5273bdfb266c35e8eab9413aa8d58d27fdbe114 That change is blocked on figuring out what to do with https://github.com/rust-lang/rust/issues/80846 first.
2021-02-01Box the biggest ast::ItemKind variantsDániel Buga-11/+10
2021-01-31Rollup merge of #81568 - osa1:remove_old_fixme, r=jonas-schievinkJonas Schievink-2/+0
Fix an old FIXME in redundant paren lint Referenced bug was fixed a while ago
2021-01-30review commentsEsteban Küber-1/+12
2021-01-30Fix an old FIXME in redundant paren lintÖmer Sinan Ağacan-2/+0
Referenced bug was fixed a while ago
2021-01-30Auto merge of #81453 - jumbatm:clashing-extern-decl-perf, r=nagisabors-4/+4
clashing_extern_declarations: Use symbol interning to avoid string alloc. Use symbol interning as a hack to avoid allocating a string for every symbol name we store in the seen set. This hopefully addresses the minor perf regression described in https://github.com/rust-lang/rust/pull/80009#issuecomment-763526902. r? `@nagisa`
2021-01-29Fix invalid camel case suggestion involving unicode identsEsteban Küber-1/+7
Follow up to #77805.
2021-01-29Rollup merge of #81176 - camsteffen:qpath-res, r=oli-obkYuki Okushi-0/+12
Improve safety of `LateContext::qpath_res` This is my first rustc code change, inspired by hacking on clippy! The first change is to clear cached `TypeckResults` from `LateContext` when visiting a nested item. I took a hint from [here](https://github.com/rust-lang/rust/blob/5e91c4ecc09312d8b63d250a432b0f3ef83f1df7/compiler/rustc_privacy/src/lib.rs#L1300). Clippy has a `qpath_res` util function to avoid a possible ICE in `LateContext::qpath_res`. But the docs of `LateContext::qpath_res` promise no ICE. So this updates the `LateContext` method to keep its promises, and removes the util function. Related: rust-lang/rust-clippy#4545 CC ````````````@eddyb```````````` since you've done related work CC ````````````@flip1995```````````` FYI
2021-01-28Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakisYuki Okushi-23/+37
Refractor a few more types to `rustc_type_ir` In the continuation of #79169, ~~blocked on that PR~~. This PR: - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance` - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler. ~~I will split up that commit to make this easier to review and to have a better commit history.~~ EDIT: done, I split the PR in commits of 200-ish lines each r? `````@nikomatsakis````` cc `````@jackh726`````
2021-01-28Use symbol interning to avoid string alloc.jumbatm-4/+4
2021-01-25Implement new panic!() behaviour for Rust 2021.Mara Bos-9/+14
2021-01-23Rollup merge of #81275 - jyn514:time-render, r=wesleywiserJonas Schievink-11/+3
Fix <unknown> queries and add more timing info to render_html Closes https://github.com/rust-lang/rust/issues/81251. ## Fix `<unknown>` queries This happened because `alloc_query_strings` was never called. ## Add more timing info to render_html This still has some issues I'm not sure how to work out: - `create_renderer` and `renderer_after_krate` aren't shown by default. I want something like `verbose_generic_activity_with_arg`, but it doesn't exist. I'm also not sure how to show activities that aren't on by default - I tried `-Z self-profile -Z self-profile-args=all`, but it didn't show up. r? `@wesleywiser`
2021-01-22Remove special casing of rustdoc in rustc_lintJoshua Nelson-11/+3
This is no longer necessary now that rustdoc doesn't run everybody_loops.
2021-01-22Rollup merge of #81236 - estebank:everybody-loop-now, r=oli-obkMara Bos-3/+9
Gracefully handle loop labels missing leading `'` in different positions Fix #81192. * Account for labels when suggesting `loop` instead of `while true` * Suggest `'a` when given `a` only when appropriate * Add loop head span to hir * Tweak error for invalid `break expr` * Add more misspelled label tests * Avoid emitting redundant "unused label" lint * Parse loop labels missing a leading `'` Each commit can be reviewed in isolation.
2021-01-22Auto merge of #81135 - jyn514:no-backticks, r=flip1995bors-3/+2
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-21Account for labels when suggesting `loop` instead of `while true`Esteban Küber-3/+9
2021-01-18Use ty::{IntTy,UintTy,FloatTy} in rustcLeSeulArtichaut-23/+37
2021-01-18Query for TypeckResults in LateContext::qpath_resCameron Steffen-0/+8
Actually fulfills the documented guarantees.
2021-01-18Reset LateContext enclosing body in nested itemsCameron Steffen-0/+4
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-17Fix formatting for removed lintsJoshua Nelson-3/+2
- 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-17Auto merge of #80679 - jackh726:predicate-kind-take2, r=lcnrbors-10/+10
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-16Review changesJack Huey-10/+10
2021-01-16More advanced unknown lint suggestionflip1995-5/+11
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-15Don't make tools responsible for checking unknown and renamed lintsJoshua Nelson-14/+30
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-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-4/+3
2021-01-13Introduce missing ABI lint on extern blocksMark Rousskov-0/+4
2021-01-13Auto merge of #80960 - Dylan-DPC:rollup-89tri8x, r=Dylan-DPCbors-3/+3
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-13Rollup merge of #80935 - pierwill:rustc_middle-levelandsource, r=petrochenkovDylan DPC-3/+3
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)).