about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/internal.rs
AgeCommit message (Collapse)AuthorLines
2025-08-20Instantiate higher-ranked binder with erased when checking IntoIterator ↵Michael Goulet-9/+14
predicate query instability
2025-08-15Extend `QueryStability` to handle `IntoIterator` implementationsSamuel Moelius-47/+85
Fix adjacent code Fix duplicate warning; merge test into `tests/ui-fulldeps/internal-lints` Use `rustc_middle::ty::FnSig::inputs` Address two review comments - https://github.com/rust-lang/rust/pull/139345#discussion_r2109006991 - https://github.com/rust-lang/rust/pull/139345#discussion_r2109058588 Use `Instance::try_resolve` Import `rustc_middle::ty::Ty` as `Ty` rather than `MiddleTy` Simplify predicate handling Add more `#[allow(rustc::potential_query_instability)]` following rebase Remove two `#[allow(rustc::potential_query_instability)]` following rebase Address review comment Update compiler/rustc_lint/src/internal.rs Co-authored-by: lcnr <rust@lcnr.de>
2025-08-11Propagate TraitImplHeader to hirCameron Steffen-2/+2
2025-08-11Extract ast TraitImplHeaderCameron Steffen-4/+4
2025-07-28use let chains in hir, lint, mirKivooeo-16/+15
2025-06-18Implement lint against direct uses of rustc_type_ir in compiler cratesRomain Perier-3/+28
This commit adds a lint to prevent the use of rustc_type_ir in random compiler crates, except for type system internals traits, which are explicitly allowed. Moreover, this fixes diagnostic_items() to include the CRATE_OWNER_ID, otherwise rustc_diagnostic_item attribute is ignored on the crate root.
2025-06-03Overhaul `UsePath`.Nicholas Nethercote-2/+5
`UsePath` contains a `SmallVec<[Res; 3]>`. This holds up to three `Res` results, one per namespace (type, value, or macro). `lower_import_res` takes a `PerNS<Option<Res<NodeId>>>` result and lowers it into the `SmallVec`. This is pretty weird. The input `PerNS` makes it clear which `Res` belongs to which namespace, but the `SmallVec` throws that information away. And code that operates on the `SmallVec` tends to use iteration (or even just grabbing the first entry!) without knowing which namespace the `Res` belongs to. Even weirder! Also, `SmallVec` is an overly flexible type to use here, because it can contain any number of elements (even though it's optimized for 3 in this case). This commit changes `UsePath` so it also contains a `PerNS<Option<Res<HirId>>>`. This type preserves more information and is more self-documenting. The commit also changes a lot of the use sites to access the result for a particular namespace. E.g. if you're looking up a trait, it will be in the `Res` for the type namespace if it's present; it's silly to look in the `Res` for the value namespace or macro namespace. Overall I find the new code much easier to understand. However, some use sites still iterate. These now use `present_items` because that filters out the `None` results. Also, `redundant_pub_crate.rs` gets a bigger change. A `UseKind:ListStem` item gets no `Res` results, which means the old `all` call in `is_not_macro_export` would succeed (because `all` succeeds on an empty iterator) and the `ListStem` would be ignored. This is what we want, but was more by luck than design. The new code detects `ListStem` explicitly. The commit generalizes the name of that function accordingly. Finally, the commit also removes the `use_path` arena, because `PerNS<Option<Res>>` impls `Copy` (unlike `SmallVec`) and it can be allocated in the arena shared by all `Copy` types.
2025-06-02Factor out repeated code into `is_mod_inherent`.Nicholas Nethercote-9/+8
2025-03-26Implement lint against using Interner and InferCtxtLike in random compiler ↵Michael Goulet-3/+36
crates
2025-03-26hir::-ify internal lintsMichael Goulet-39/+50
2025-03-18Move `hir::Item::ident` into `hir::ItemKind`.Nicholas Nethercote-3/+3
`hir::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Macro`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, Trait`, TraitAalis`. - It's always empty for these item kinds: `ForeignMod`, `GlobalAsm`, `Impl`. - For `Use`, it is non-empty for `UseKind::Single` and empty for `UseKind::{Glob,ListStem}`. All of this is quite non-obvious; the only documentation is a single comment saying "The name might be a dummy name in case of anonymous items". Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - A similar transformation makes sense for `ast::Item`, but this is already a big change. That can be done later. - Lots of assertions are added to item lowering to ensure that identifiers are empty/non-empty as expected. These will be removable when `ast::Item` is done later. - `ItemKind::Use` doesn't get an `Ident`, but `UseKind::Single` does. - `lower_use_tree` is significantly simpler. No more confusing `&mut Ident` to deal with. - `ItemKind::ident` is a new method, it returns an `Option<Ident>`. It's used with `unwrap` in a few places; sometimes it's hard to tell exactly which item kinds might occur. None of these unwraps fail on the test suite. It's conceivable that some might fail on alternative input. We can deal with those if/when they happen. - In `trait_path` the `find_map`/`if let` is replaced with a loop, and things end up much clearer that way. - `named_span` no longer checks for an empty name; instead the call site now checks for a missing identifier if necessary. - `maybe_inline_local` doesn't need the `glob` argument, it can be computed in-function from the `renamed` argument. - `arbitrary_source_item_ordering::check_mod` had a big `if` statement that was just getting the ident from the item kinds that had one. It could be mostly replaced by a single call to the new `ItemKind::ident` method. - `ItemKind` grows from 56 to 64 bytes, but `Item` stays the same size, and that's what matters, because `ItemKind` only occurs within `Item`.
2025-02-21Move methods from Map to TyCtxt, part 3.Nicholas Nethercote-2/+2
Continuing the work from #137162. Every method gains a `hir_` prefix.
2025-02-08Rustfmtbjorn3-20/+30
2025-01-29Eliminate PatKind::PathOli Scherer-6/+4
2025-01-23Split hir `TyKind` and `ConstArgKind` in two and update `hir::Visitor`Boxy-3/+3
2024-12-18Merge some patterns togetherOli Scherer-21/+5
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-17Remove `rustc::existing_doc_keyword` lint.Nicholas Nethercote-42/+2
`CheckAttrVisitor::check_doc_keyword` checks `#[doc(keyword = "..")]` attributes to ensure they are on an empty module, and that the value is a non-empty identifier. The `rustc::existing_doc_keyword` lint checks these attributes to ensure that the value is the name of a keyword. It's silly to have two different checking mechanisms for these attributes. This commit does the following. - Changes `check_doc_keyword` to check that the value is the name of a keyword (avoiding the need for the identifier check, which removes a dependency on `rustc_lexer`). - Removes the lint. - Updates tests accordingly. There is one hack: the `SelfTy` FIXME case used to used to be handled by disabling the lint, but now is handled with a special case in `is_doc_keyword`. That hack will go away if/when the FIXME is fixed. Co-Authored-By: Guillaume Gomez <guillaume1.gomez@gmail.com>
2024-12-03Rollup merge of #133545 - clubby789:symbol-intern-lit, r=jieyouxuMatthias Krüger-2/+33
Lint against Symbol::intern on a string literal Disabled in tests where this doesn't make much sense
2024-12-02remove outdated commentlcnr-11/+4
2024-11-28Implement lint against `Symbol::intern` on a string literalclubby789-2/+33
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-2/+3
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-10-26Auto merge of #132190 - matthiaskrgr:rollup-rsocfiz, r=matthiaskrgrbors-2/+2
Rollup of 3 pull requests Successful merges: - #131875 (Add WASM | WASI | Emscripten groups to triagebot.toml) - #132019 (Document `PartialEq` impl for `OnceLock`) - #132182 (Downgrade `untranslatable_diagnostic` and `diagnostic_outside_of_impl` to `allow`) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-26Downgrade `untranslatable_diagnostic` and `diagnostic_outside_of_impl` to ↵Jieyou Xu-2/+2
`allow` See <https://github.com/rust-lang/rust/issues/132181> for more context.
2024-10-19Unify syntax (all to @eval_always)blyxyas-2/+2
2024-10-19Remove module passes filteringblyxyas-2/+2
2024-10-19Do not run lints that cannot emitblyxyas-2/+4
Before this change, adding a lint was a difficult matter because it always had some overhead involved. This was because all lints would run, no matter their default level, or if the user had #![allow]ed them. This PR changes that
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-37/+25
2024-09-03Add an internal lint that warns when accessing untracked dataNadrieril-3/+21
2024-09-01Deny imports of rustc_type_ir::inherent outside of type ir + new trait solverMichael Goulet-2/+28
2024-08-10Refactor: `diagnostic_outside_of_impl`, `untranslatable_diagnostic`Pavel Grigorenko-60/+74
1. Decouple them. 2. Make logic around `diagnostic_outside_of_impl`'s early exits simpler. 3. Make `untranslatable_diagnostic` run one loop instead of two and not allocate an intermediate vec. 4. Overall, reduce the amount of code executed when the lints do not end up firing.
2024-08-10`untranslatable_diagnostic` lint: point at the untranslated thingPavel Grigorenko-10/+12
and not the function/method call
2024-07-29Reformat `use` declarations.Nicholas Nethercote-8/+12
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-18Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent`León Orell Valerian Liehr-1/+45
2024-07-02Instance::resolve -> Instance::try_resolve, and other nitsMichael Goulet-2/+2
2024-06-03Fix up comments.Nicholas Nethercote-7/+7
Wrap overly long ones, etc.
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_lint`.Nicholas Nethercote-0/+1
2024-03-11Allow multiple `impl Into<{D,Subd}iagMessage>` parameters in a function.Nicholas Nethercote-12/+5
The internal diagnostic lint currently only allows one, because that was all that occurred in practice. But rust-lang/rust-clippy/pull/12453 wants to introduce functions with more than one, and this limitation is getting in the way.
2024-03-11Rename diagnostic derive things.Nicholas Nethercote-2/+1
For increased consistency. - session_diagnostic_derive -> diagnostic_derive - session_subdiagnostic_derive -> subdiagnostic_derive - SubdiagnosticDeriveBuilder -> SubdiagnosticDerive
2024-03-11Rename `DecorateLint` as `LintDiagnostic`.Nicholas Nethercote-5/+5
To match `derive(LintDiagnostic)`.
2024-03-11Rename `AddToDiagnostic` as `Subdiagnostic`.Nicholas Nethercote-4/+4
To match `derive(Subdiagnostic)`. Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-7/+4
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-08Fix crash in late internal checkingyukang-4/+6
2024-03-06Rewrite the `untranslatable_diagnostic` lint.Nicholas Nethercote-43/+122
Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This commit changes it to check calls to any function with an `impl Into<{D,Subd}iagMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. The commit also adds `#[allow(rustc::untranslatable_diagnostic)`] attributes to places that need it that are caught by the improved lint. These places that might be easy to convert to translatable diagnostics. Finally, it also: - Expands and corrects some comments. - Does some minor formatting improvements. - Adds missing `DecorateLint` cases to `tests/ui-fulldeps/internal-lints/diagnostics.rs`.
2024-03-05Rename `SubdiagnosticMessage` as `SubdiagMessage`.Nicholas Nethercote-1/+1
2024-03-05Rename `DiagnosticMessage` as `DiagMessage`.Nicholas Nethercote-1/+1
2024-02-28Remove the `UntranslatableDiagnosticTrivial` lint.Nicholas Nethercote-82/+1
It's a specialized form of the `UntranslatableDiagnostic` lint that is deny-by-default. Now that `UntranslatableDiagnostic` has been changed from allow-by-default to deny-by-default, the trivial variant is no longer needed.
2024-02-10hir: Remove `hir::Map::{opt_parent_id,parent_id,get_parent,find_parent}`Vadim Petrochenkov-6/+5
2024-02-06Invert diagnostic lints.Nicholas Nethercote-2/+2
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-01-23Rename `LintContext::emit_spanned_lint` as `LintContext::emit_span_lint`.Nicholas Nethercote-13/+13