summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2021-02-05Rename `panic_fmt` lint to `non_fmt_panic`.Mara Bos-5/+6
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``
2020-12-25Rollup merge of #80274 - pierwill:lintlevelsource, r=petrochenkovDylan DPC-10/+12
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-22Auto merge of #78242 - Nadrieril:rename-overlapping_endpoints-lint, r=varkorbors-1/+1
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-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-11Move binder for dyn to each list itemJack Huey-3/+5
2020-12-08don't create owned values for comparison (clippy::cmp_owned)Matthias Krüger-3/+3
2020-12-03Only deny doc_keyword in std and set it as "allow" by defaultGuillaume Gomez-1/+1
2020-12-03Add lint pass for doc keywordGuillaume Gomez-1/+48
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-29`overlapping_range_endpoints` does not belong in the `unused` lint groupNadrieril-1/+0
2020-11-29Rename the `overlapping_patterns` lint to `overlapping_range_endpoints`Nadrieril-1/+2
2020-11-28Cleanup: shorter and faster codeAleksey Kladov-2/+2
2020-11-27Don't lint on redundant semicolons after item statementsAaron Hill-3/+18
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-26Fix new 'unnecessary trailing semicolon' warningsAaron Hill-2/+2
2020-11-24Move lev_distance to rustc_ast, make non-genericArlie Davis-2/+2
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-21More consistently use spaces after commas in lists in docsCarol (Nichols || Goulding)-1/+1
2020-11-21Auto merge of #77805 - JohnTitor:non-standard-char-sugg, r=Dylan-DPCbors-19/+35
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-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-09Rollup merge of #78710 - petrochenkov:macvisit, r=davidtwcoDylan DPC-8/+2
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-05Rename lint to non_autolinksGuillaume Gomez-2/+2
2020-11-05Rename automatic_links to url_improvementsGuillaume Gomez-3/+3
2020-11-05Add new lint for automatic_links improvementsGuillaume Gomez-1/+2
2020-11-04`u128` truncation and sign extension are not just interpreter relatedoli-3/+2
2020-11-03rustc_ast: `visit_mac` -> `visit_mac_call`Vadim Petrochenkov-1/+1
2020-11-03rustc_ast: Do not panic by default when visiting macro callsVadim Petrochenkov-7/+1
2020-11-03Rollup merge of #78663 - Aaron1011:fix/cap-future-compat, r=tmandryYuki Okushi-4/+5
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-02Treat trailing semicolon as a statement in macro callAaron Hill-0/+5
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-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-11-01Auto merge of #75534 - Aaron1011:feature/new-future-breakage, r=pnkfelixbors-5/+22
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 :smile: ). 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-10-30Implement rustc side of report-future-incompatAaron Hill-5/+22
2020-10-30Auto merge of #78182 - LeSeulArtichaut:ty-visitor-contolflow, r=lcnr,oli-obkbors-3/+9
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-30Fix some more clippy warningsJoshua Nelson-32/+22
2020-10-30Remove implicit `Continue` typeLeSeulArtichaut-1/+1
2020-10-30TypeVisitor: use `ControlFlow` in rustc_{infer,lint,trait_selection}LeSeulArtichaut-3/+9
2020-10-29Improve panic_fmt lint messages.Mara Bos-5/+5
(From the PR feedback.) Co-authored-by: Esteban Küber <esteban@kuber.com.ar>
2020-10-29Rollup merge of #78431 - Rustin-Liu:rustin-patch-lint, r=estebankJonas Schievink-1/+1
Prefer new associated numeric consts in float error messages Fix https://github.com/rust-lang/rust/issues/78382
2020-10-29Rollup merge of #78244 - workingjubilee:dogfood-fancy-ranges, r=varkorJonas Schievink-3/+5
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-28Dogfood {exclusive,half-open} ranges in compiler (nfc)Jubilee Young-3/+5
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-28Mark panic_fmt suggestion as machine applicable.Mara Bos-1/+1
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
2020-10-27Prefer new associated numeric consts in float error messagesRustin-Liu-1/+1
2020-10-26Fix doctestNathan Whitaker-0/+1
2020-10-26Write docs for lint / fix review nitNathan Whitaker-2/+20
2020-10-26Address review commentsNathan Whitaker-11/+8
2020-10-26Change to warn by default / fix typoNathan Whitaker-1/+1
2020-10-26Tweak diagnosticNathan Whitaker-4/+6
2020-10-26Address review commentsNathan Whitaker-49/+35
2020-10-26Uplift temporary-cstring-as-ptr into rustcNathan Whitaker-0/+105
2020-10-24Fix inconsistencies in handling of inert attributes on statementsAaron Hill-9/+33
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