about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/levels.rs
AgeCommit message (Collapse)AuthorLines
2021-10-08remove unwrap_or! macroklensy-2/+4
2021-09-02Rename walk_crate.Camille GILLOT-1/+1
2021-09-02Stop using walk_crate.Camille GILLOT-1/+1
2021-08-28Treat macros as HIR itemsinquisitivecrystal-3/+0
2021-08-21Remove `Session.used_attrs` and move logic to `CheckAttrVisitor`Aaron Hill-2/+0
Instead of updating global state to mark attributes as used, we now explicitly emit a warning when an attribute is used in an unsupported position. As a side effect, we are to emit more detailed warning messages (instead of just a generic "unused" message). `Session.check_name` is removed, since its only purpose was to mark the attribute as used. All of the callers are modified to use `Attribute.has_name` Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed used' attribute is implemented by simply not performing any checks in `CheckAttrVisitor` for a particular attribute. We no longer emit unused attribute warnings for the `#[rustc_dummy]` attribute - it's an internal attribute used for tests, so it doesn't mark sense to treat it as 'unused'. With this commit, a large source of global untracked state is removed.
2021-08-01Auto merge of #87449 - matthiaskrgr:clippyy_v2, r=nagisabors-1/+1
more clippy::complexity fixes (also a couple of clippy::perf fixes)
2021-07-25clippy::flat_map_identityMatthias Krüger-1/+1
2021-07-25Merge the BTreeMap in hir::Crate.Camille GILLOT-2/+2
2021-07-17Make `--force-warns` a normal lint level optioninquisitivecrystal-19/+5
2021-07-08Rollup merge of #86639 - eholk:lint-tool, r=petrochenkovYuki Okushi-30/+34
Support lint tool names in rustc command line options When rustc is running without a lint tool such as clippy enabled, options for lints such as `clippy::foo` are meant to be ignored. This was already working for those specified by attrs, such as `#![allow(clippy::foo)]`, but this did not work for command line arguments like `-A clippy::foo`. This PR fixes that issue. Note that we discovered this issue while discussing https://github.com/rust-lang/cargo/issues/5034. Fixes #86628.
2021-07-07Cleanup: unify lint name checkingEric Holk-3/+4
This change merges `check_lint_and_tool_name` into `check_lint_name` in order to avoid having two very similar functions. Also adds the `.stderr` file back for the test case, since apparently it is still needed.
2021-07-06Unify lint tool and lint name checkingEric Holk-29/+32
This shares a little more code between checking command line and attribute lint specifications.
2021-06-29Encode CommandLine in the index only.Camille GILLOT-2/+2
2021-06-29Use a newtype_index instead of a u32.Camille GILLOT-8/+8
2021-06-26Make ForceWarn a lint level.Camille GILLOT-15/+16
2021-06-02Force warn on lint groups as wellRyan Levick-3/+8
2021-06-01Fix issues and add testRyan Levick-1/+1
2021-05-28Initial support for force-warnsRyan Levick-0/+9
2021-05-12Use () for lint_levels.Camille GILLOT-5/+3
2021-04-17Do not ignore path segments in the middle in ↵hyd-dev-43/+38
`#[allow]`/`#[warn]`/`#[deny]`/`#[forbid]` attributes
2021-04-05Fix bug where rustc_lint would not apply renamed tool lintsJoshua Nelson-3/+4
2021-03-27Remove (lots of) dead codeJoshua Nelson-4/+0
Found with https://github.com/est31/warnalyzer. Dubious changes: - Is anyone else using rustc_apfloat? I feel weird completely deleting x87 support. - Maybe some of the dead code in rustc_data_structures, in case someone wants to use it in the future? - Don't change rustc_serialize I plan to scrap most of the json module in the near future (see https://github.com/rust-lang/compiler-team/issues/418) and fixing the tests needed more work than I expected. TODO: check if any of the comments on the deleted code should be kept.
2021-03-18Rollup merge of #83216 - jyn514:register-tool, r=petrochenkovDylan DPC-9/+37
Allow registering tool lints with `register_tool` Previously, there was no way to add a custom tool prefix, even if the tool itself had registered a lint: ```rust #![feature(register_tool)] #![register_tool(xyz)] #![warn(xyz::my_lint)] ``` ``` $ rustc unknown-lint.rs --crate-type lib error[E0710]: an unknown tool name found in scoped lint: `xyz::my_lint` --> unknown-lint.rs:3:9 | 3 | #![warn(xyz::my_lint)] | ^^^ ``` This allows opting-in to lints from other tools using `register_tool`. cc https://github.com/rust-lang/rust/issues/66079#issuecomment-788589193, ``@chorman0773`` r? ``@petrochenkov``
2021-03-16Allow registering tool lints with `register_tool`Joshua Nelson-9/+37
Previously, there was no way to add a custom tool prefix, even if the tool itself had registered a lint: ``` #![feature(register_tool)] #![register_tool(xyz)] #![warn(xyz::my_lint)] ``` ``` $ rustc unknown-lint.rs --crate-type lib error[E0710]: an unknown tool name found in scoped lint: `xyz::my_lint` --> unknown-lint.rs:3:9 | 3 | #![warn(xyz::my_lint)] | ^^^ ``` This allows opting-in to lints from other tools using `register_tool`.
2021-03-16ast/hir: Rename field-related structuresVadim Petrochenkov-2/+2
StructField -> FieldDef ("field definition") Field -> ExprField ("expression field", not "field expression") FieldPat -> PatField ("pattern field", not "field pattern") Also rename visiting and other methods working on them.
2021-03-09Remove hir::Crate::attrs.Camille GILLOT-1/+1
2021-03-09Access attrs directly from HirId in rustc_lint::levels.Camille GILLOT-11/+12
2021-02-28Apply lint restrictions from renamed lintsJoshua Nelson-8/+25
Previously, if you denied the old name of a renamed lint, it would warn about using the new name, but otherwise do nothing. Now, it will behave the same as if you'd used the new name.
2021-02-15Only store a LocalDefId in hir::MacroDef.Camille GILLOT-1/+1
2021-02-15Only store a LocalDefId in hir::ForeignItem.Camille GILLOT-1/+1
2021-02-15Only store a LocalDefId in hir::ImplItem.Camille GILLOT-1/+1
2021-02-15Only store a LocalDefId in hir::TraitItem.Camille GILLOT-1/+1
2021-02-15Only store a LocalDefId in hir::Item.Camille GILLOT-1/+1
Items are guaranteed to be HIR owner.
2021-02-02introduce future-compatibility warning for forbidden lint groupsNiko Matsakis-28/+73
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-01-17Fix formatting for removed lintsJoshua Nelson-2/+1
- 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-15Don't make tools responsible for checking unknown and renamed lintsJoshua Nelson-0/+5
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-11Rename `rustc_middle::lint::LevelSource` to `LevelAndSource`pierwill-3/+3
2020-12-21Document rustc_middle::lint::LevelSourcepierwill-1/+3
This is to clarify the difference between `LevelSource` and `LintLevelSource`. Appease x.py fmt.
2020-12-21Rename rustc_middle::lint::LintSourcepierwill-10/+10
Rename rustc_middle::lint::LintSource to rustc_middle::lint::LintLevelSource.
2020-12-02Auto merge of #78864 - Mark-Simulacrum:warn-on-forbids, r=pnkfelixbors-49/+21
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-11-14Use true previous lint level when detecting overriden forbidsMark Rousskov-49/+21
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-13Reserve space in advanceDániel Buga-0/+2
2020-11-02Fix ICE when a future-incompat-report has its command-line level cappedAaron Hill-4/+5
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-10-24Fix inconsistencies in handling of inert attributes on statementsAaron Hill-0/+7
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-04Prevent forbid from being ignored if overriden at the same level.Felix S. Klock II-4/+43
That is, this changes `#[forbid(foo)] #[allow(foo)]` from allowing foo to forbidding foo.
2020-08-30mv compiler to compiler/mark-0/+576