about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/internal.rs
AgeCommit message (Collapse)AuthorLines
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-1/+1
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-1/+1
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-10-16tweak pass description and fix lint fail post-rebaseArthur Lafrance-1/+1
2023-10-16debug Span::ctxt() call detectionArthur Lafrance-17/+6
2023-10-16basic lint v2 implementedArthur Lafrance-2/+43
2023-10-13Format all the let chains in compilerMichael Goulet-50/+49
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-12/+12
2023-05-24Use `is_some_and`/`is_ok_and` in less obvious spotsMaybe Waffle-3/+2
2023-05-06Check arguments length in trivial diagnostic lintclubby789-2/+4
2023-04-25Add deny lint to prevent untranslatable diagnostics using static stringsclubby789-1/+79
2023-04-10Fix typos in compilerDaniPopes-3/+3
2023-03-21Use local key in providersMichael Goulet-1/+1
2023-03-09Document tool lintsclubby789-0/+30
2023-02-16remove bound_type_of query; make type_of return EarlyBinder; change type_of ↵Kyle Matsuda-1/+1
in metadata
2023-02-16change usages of type_of to bound_type_ofKyle Matsuda-1/+1
2023-01-15remove redundant clonesMatthias Krüger-2/+2
2023-01-09refactor: cleanupRejyr-2/+0
2023-01-09migrate: `internal.rs`Rejyr-76/+35
2023-01-04get_parent and find_parentMichael Goulet-1/+1
2023-01-04rename get_parent_node to parent_idMichael Goulet-1/+1
2022-12-01rustc_hir: Relax lifetime requirements on `Visitor::visit_path`Vadim Petrochenkov-1/+1
2022-11-28Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.Nicholas Nethercote-2/+2
We already use a mix of `Literal` and `Lit`. The latter is better because it is shorter without causing any ambiguity.
2022-11-23Separate lifetime ident from resolution in HIR.Camille GILLOT-5/+1
2022-10-23Migrate all diagnosticsNilstrieb-18/+18
2022-10-01Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebankbors-100/+105
Move lint level source explanation to the bottom So, uhhhhh r? `@estebank` ## User-facing change "note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic: ```diff - = note: `#[warn(unsupported_calling_conventions)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678> + = note: `#[warn(unsupported_calling_conventions)]` on by default ``` Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO. ## Developer-facing change `struct_span_lint` and similar methods have a different signature. Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)` After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>` The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion. Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere. ## Subtle problem By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings... I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate. ## P.S. I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
2022-10-01Refactor rustc lint APIMaybe Waffle-100/+105
2022-09-29Shrink `hir::def::Res`.Nicholas Nethercote-1/+1
`Res::SelfTy` currently has two `Option`s. When the second one is `Some` the first one is never consulted. So we can split it into two variants, `Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res` from 24 bytes to 12. This then shrinks `hir::Path` and `hir::PathSegment`, which are the HIR types that take up the most space.
2022-09-21FIX - adopt new Diagnostic naming in newly migrated modulesJhonny Bill Mena-1/+1
FIX - ambiguous Diagnostic link in docs UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic [Gardening] FIX - formatting via `x fmt` FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way DELETE - unneeded allow attributes in Handler method FIX - broken test FIX - Rebase conflict UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21UPDATE - rename SessionSubdiagnostic macro to SubdiagnosticJhonny Bill Mena-1/+1
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21UPDATE - rename DiagnosticHandler macro to DiagnosticJhonny Bill Mena-2/+2
2022-09-21UPDATE - rename AddSubdiagnostic trait to AddToDiagnosticJhonny Bill Mena-1/+1
2022-09-21UPDATE - rename DiagnosticHandler trait to IntoDiagnosticJhonny Bill Mena-2/+2
2022-09-05Auto merge of #101261 - TaKO8Ki:separate-receiver-from-arguments-in-hir, ↵bors-1/+1
r=cjgillot Separate the receiver from arguments in HIR Related to #100232 cc `@cjgillot`
2022-09-05separate the receiver from arguments in HIRTakayuki Maeda-1/+1
2022-09-05Make `hir::PathSegment::res` non-optional.Nicholas Nethercote-2/+1
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+0
by module
2022-08-31lint: avoid linting diag functions with diag lintsDavid Wood-3/+9
Functions annotated with `#[rustc_lint_diagnostics]` are used by the diagnostic migration lints to know when to lint, but functions that are annotated with this attribute shouldn't themselves be linted. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-27lint: add bad opt access internal lintDavid Wood-0/+35
Some command-line options accessible through `sess.opts` are best accessed through wrapper functions on `Session`, `TyCtxt` or otherwise, rather than through field access on the option struct in the `Session`. Adds a new lint which triggers on those options that should be accessed through a wrapper function so that this is prohibited. Options are annotated with a new attribute `rustc_lint_opt_deny_field_access` which can specify the error message (i.e. "use this other function instead") to be emitted. A simpler alternative would be to simply rename the options in the option type so that it is clear they should not be used, however this doesn't prevent uses, just discourages them. Another alternative would be to make the option fields private, and adding accessor functions on the option types, however the wrapper functions sometimes rely on additional state from `Session` or `TyCtxt` which wouldn't be available in an function on the option type, so the accessor would simply make the field available and its use would be discouraged too. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-27session: disable internal lints for rustdocDavid Wood-14/+0
If an internal lint uses `typeck_results` or similar queries then that can result in rustdoc checking code that it shouldn't (e.g. from other platforms) and emit compilation errors. Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05errors: introduce `DecorateLint`David Wood-1/+1
Add a new trait to be generated by diagnostic derives which uses a `LintDiagnosticBuilder`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30lint: port translation migration diagnosticsDavid Wood-3/+2
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30lint: port non-existant doc keyword diagnosticsDavid Wood-7/+4
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30lint: port impl `LintPass` by hand diagnosticsDavid Wood-2/+2
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30lint: port ty diagnosticsDavid Wood-11/+12
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30lint: port query instability diagnosticsDavid Wood-6/+3
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30lint: port default hash types diagnosticsDavid Wood-8/+5
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27lint: fix condition in diagnostic lintsDavid Wood-3/+6
Unfortunately, the diagnostic lints are very broken and trigger much more often than they should. Correct the conditional which checks if the function call being made is to a diagnostic function so that it returns in every intended case. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-14Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obkDylan DPC-31/+107
lint: add diagnostic translation migration lints Introduce allow-by-default lints for checking whether diagnostics are written in `SessionDiagnostic` or `AddSubdiagnostic` impls and whether diagnostics are translatable. These lints can be denied for modules once they are fully migrated to impls and translation. These lints are intended to be temporary - once all diagnostics have been changed then we can just change the APIs we have and that will enforce these constraints thereafter. r? `````@oli-obk`````
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-4/+4
2022-06-10lint: add diagnostic translation migration lintsDavid Wood-31/+107
Introduce allow-by-default lints for checking whether diagnostics are written in `SessionDiagnostic`/`AddSubdiagnostic` impls and whether diagnostics are translatable. These lints can be denied for modules once they are fully migrated to impls and translation. Signed-off-by: David Wood <david.wood@huawei.com>