summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
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)).
2021-01-13Auto merge of #79322 - jyn514:refactor-impl, r=estebankbors-1/+1
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-12Separate out a `hir::Impl` structJoshua Nelson-1/+1
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-11Rename `rustc_middle::lint::LevelSource` to `LevelAndSource`pierwill-3/+3
2021-01-12Add FIXME note about storing &'tcx strjumbatm-0/+5
2021-01-12Remove unnecessary allocation.jumbatm-4/+4
2021-01-12Use tcx.symbol_name to check for clashes.jumbatm-7/+9
2021-01-10Auto merge of #79414 - ↵bors-0/+3
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-03Rollup merge of #80628 - matthiaskrgr:match_ref_pats, r=varkorGuillaume Gomez-7/+7
reduce borrowing and (de)referencing around match patterns (clippy::match_ref_pats)
2021-01-02reduce borrowing and (de)referencing around match patterns ↵Matthias Krüger-7/+7
(clippy::match_ref_pats)
2021-01-02Add snake case lint note about keyword identifiers which cannot be rawSkynoodle-0/+1
2021-01-01Add suggestion to use raw identifiers when fixing snake-case lintsSkynoodle-2/+16
2020-12-31Auto merge of #80500 - jyn514:track-caller, r=nagisabors-0/+1
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-30Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkovMara Bos-2/+2
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`