about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2024-05-10Remove unnecessary `allow` attribute.Nicholas Nethercote-6/+7
The `#[allow(rustdoc:private_intra_doc_links)]` isn't necessary. Also sort them, as is done in other files like `compiler/rustc_errors/src/lib.rs`.
2024-04-26Rollup merge of #124391 - nnethercote:builtin_macros-cleanups, r=fee1-deadJacob Pratt-2/+2
`rustc_builtin_macros` cleanups Some improvements I found while looking over this code. r? ``@fee1-dead``
2024-04-26Introduce `DeriveResolution`.Nicholas Nethercote-2/+2
Making this a proper struct, and giving its fields names, makes things easier to understand.
2024-04-23delegation: Support async, const, extern "ABI" and C-variadic functionsVadim Petrochenkov-10/+6
Also allow `impl Trait` in delegated functions. The delegation item will refer to the original opaque type from the callee, fresh opaque type won't be created.
2024-04-17consistency rename: language item -> lang itemRalf Jung-1/+1
2024-04-11Silence unused_imports lint for redundant importsMichael Goulet-1/+1
2024-03-28remove `def_id_to_node_id` in ast loweringbohan-1/+0
2024-03-20store segment and module in `UnresolvedImportError`bohan-0/+13
2024-03-14fixes #121331surechen-2/+5
2024-03-07Rollup merge of #121089 - oli-obk:create_def_feed, r=petrochenkovGuillaume Gomez-22/+45
Remove `feed_local_def_id` best reviewed commit by commit Basically I returned `TyCtxtFeed` from `create_def` and then preserved that in the local caches based on https://github.com/rust-lang/rust/pull/121084 r? ````@petrochenkov````
2024-03-06avoid overlapping privacy suggestion for single nested importsbohan-0/+2
2024-03-05Remove a use of feed_local_crate and make it fail if used within queriesOli Scherer-7/+11
2024-03-05Prevent feeding `CRATE_DEF_ID` queries outside the resolverOli Scherer-2/+5
2024-03-05Get rid of `feed_local_def_id`Oli Scherer-1/+1
2024-03-05Eliminate all non-CRATE_DEF_ID uses of `feed_def_id`Oli Scherer-4/+5
2024-03-05Preserve the `Feed` in local tablesOli Scherer-9/+23
2024-03-05Bubble up the TyCtxtFeedOli Scherer-4/+5
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-2/+2
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-18resolve: Scale back unloading of speculatively loaded cratesVadim Petrochenkov-1/+0
2024-02-18By tracking import use types to check whether it is scope uses or the other ↵surechen-12/+39
situations like module-relative uses, we can do more accurate redundant import checking. fixes #117448 For example unnecessary imports in std::prelude that can be eliminated: ```rust use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly use std::option::Option::None; //~ WARNING the item `None` is imported redundantly ```
2024-02-14Move all the heavy lifting from `TyCtxtAt::create_def` into `TyCtxt::create_def`Oli Scherer-1/+1
2024-02-12Lowering field access for anonymous adtsFrank King-0/+6
2024-02-09Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwcoMatthias Krüger-0/+2
Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. r? ````@davidtwco````
2024-02-08Rollup merge of #119592 - petrochenkov:unload, r=compiler-errorsMatthias Krüger-0/+1
resolve: Unload speculatively resolved crates before freezing cstore Name resolution sometimes loads additional crates to improve diagnostics (e.g. suggest imports). Not all of these diagnostics result in errors, sometimes they are just warnings, like in #117772. If additional crates loaded speculatively stay and gets listed by things like `query crates` then they may produce further errors like duplicated lang items, because lang items from speculatively loaded crates are as good as from non-speculatively loaded crates. They can probably do things like adding unintended impls from speculatively loaded crates to method resolution as well. The extra crates will also get into the crate's metadata as legitimate dependencies. In this PR I remove the speculative crates from cstore when name resolution is finished and cstore is frozen. This is better than e.g. filtering away speculative crates in `query crates` because things like `DefId`s referring to these crates and leaking to later compilation stages can produce ICEs much easier, allowing to detect them. The unloading could potentially be skipped if any errors were reported (to allow using `DefId`s from speculatively loaded crates for recovery), but I didn't do it in this PR because I haven't seen such cases of recovery. We can reconsider later if any relevant ICEs are reported. Unblocks https://github.com/rust-lang/rust/pull/117772.
2024-02-06Rollup merge of #119939 - clubby789:static-const-generic-note, r=compiler-errorsMatthias Krüger-1/+5
Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items Fixes #109596 Fixes #119936
2024-02-06resolve: Unload speculatively resolved crates before freezing cstoreVadim Petrochenkov-0/+1
2024-02-06Invert diagnostic lints.Nicholas Nethercote-0/+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-29Stop using `String` for error codes.Nicholas Nethercote-2/+2
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-25Remove unused featuresclubby789-2/+0
2024-01-22Rollup merge of #119369 - bvanjoi:fix-119301, r=petrochenkovMatthias Krüger-0/+5
exclude unexported macro bindings from extern crate Fixes #119301 Macros that aren't exported from an external crate should not be defined. r? ``@petrochenkov``
2024-01-21exclude unexported macro bindings from extern cratebohan-0/+5
2024-01-19Pack the u128 in LitKind::IntJosh Stone-1/+1
2024-01-17Auto merge of #119922 - nnethercote:fix-Diag-code-is_lint, r=oli-obkbors-1/+1
Rework how diagnostic lints are stored. `Diagnostic::code` has the type `DiagnosticId`, which has `Error` and `Lint` variants. Plus `Diagnostic::is_lint` is a bool, which should be redundant w.r.t. `Diagnostic::code`. Seems simple. Except it's possible for a lint to have an error code, in which case its `code` field is recorded as `Error`, and `is_lint` is required to indicate that it's a lint. This is what happens with `derive(LintDiagnostic)` lints. Which means those lints don't have a lint name or a `has_future_breakage` field because those are stored in the `DiagnosticId::Lint`. It's all a bit messy and confused and seems unintentional. This commit: - removes `DiagnosticId`; - changes `Diagnostic::code` to `Option<String>`, which means both errors and lints can straightforwardly have an error code; - changes `Diagnostic::is_lint` to `Option<IsLint>`, where `IsLint` is a new type containing a lint name and a `has_future_breakage` bool, so all lints can have those, error code or not. r? `@oli-obk`
2024-01-15Auto merge of #119610 - Nadrieril:never_pattern_bindings, r=compiler-errorsbors-0/+2
never patterns: Check bindings wrt never patterns Never patterns: - Shouldn't contain bindings since they never match anything; - Don't count when checking that or-patterns have consistent bindings. r? `@compiler-errors`
2024-01-14Add note to resolve error about generics from inside static/constclubby789-1/+5
2024-01-14Rework how diagnostic lints are stored.Nicholas Nethercote-1/+1
`Diagnostic::code` has the type `DiagnosticId`, which has `Error` and `Lint` variants. Plus `Diagnostic::is_lint` is a bool, which should be redundant w.r.t. `Diagnostic::code`. Seems simple. Except it's possible for a lint to have an error code, in which case its `code` field is recorded as `Error`, and `is_lint` is required to indicate that it's a lint. This is what happens with `derive(LintDiagnostic)` lints. Which means those lints don't have a lint name or a `has_future_breakage` field because those are stored in the `DiagnosticId::Lint`. It's all a bit messy and confused and seems unintentional. This commit: - removes `DiagnosticId`; - changes `Diagnostic::code` to `Option<String>`, which means both errors and lints can straightforwardly have an error code; - changes `Diagnostic::is_lint` to `Option<IsLint>`, where `IsLint` is a new type containing a lint name and a `has_future_breakage` bool, so all lints can have those, error code or not.
2024-01-13store the segment name when resolution failsbohan-3/+12
2024-01-12Delegation implementation: step 1Bryanskiy-0/+5
2024-01-09Check bindings around never patternsNadrieril-0/+2
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-2/+2
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-20resolve: Eagerly feed closure visibilitiesVadim Petrochenkov-4/+1
Also factor out all tcx-dependent operations performed for every created definition into `TyCtxt::create_def`
2023-12-18Replace some instances of FxHashMap/FxHashSet with stable alternatives ↵Michael Woerister-2/+2
(mostly in rustc_hir and rustc_ast_lowering) Part of https://github.com/rust-lang/compiler-team/issues/533
2023-12-18resolve: Replace visibility table in resolver outputs with query feedingVadim Petrochenkov-8/+9
Also feed missing visibilities for import stems and trait impl items, which were previously evaluated lazily.
2023-12-03rustc: Harmonize `DefKind` and `DefPathData`Vadim Petrochenkov-2/+2
`DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-11-28resolve: Feed the `def_kind` query immediately on `DefId` creationVadim Petrochenkov-5/+4
2023-11-27Address unused tuple struct fields in the compilerJake Goulding-1/+1
2023-11-25Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, ↵Michael Goulet-5/+2
r=compiler-errors Reduce fluent boilerplate Best reviewed one commit at a time. r? `@davidtwco`
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-2/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-3/+1
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-25resolve: Avoid clones of `MacroData`Vadim Petrochenkov-5/+13
And move declarative macro compilation to an earlier point in def collector, which is required for #118188.