summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/lib.rs
AgeCommit message (Collapse)AuthorLines
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-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.
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-10-13Format all the let chains in compilerMichael Goulet-2/+4
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+2
2023-10-05Rename `Resolver::active_features`.Nicholas Nethercote-8/+3
For the reasons described in the previous commit.
2023-09-13resolve: determined binding after parent module macro expandbohan-0/+13
2023-09-11Rollup merge of #115744 - fmease:fix-e0401, r=compiler-errorsMatthias Krüger-2/+2
Improve diagnostic for generic params from outer items (E0401) Generalize the wording of E0401 to talk about *outer items* instead of *outer functions* since the current phrasing is outdated. The outer item can be a function, constant, trait, ADT or impl block (see the new UI test for the more exotic examples). Further, don't suggest introducing generic parameters to constant items unless the feature `generic_const_items` is enabled. Lastly, make E0401 translatable while we're at it. Fixes #115720.
2023-09-10Generalize E0401León Orell Valerian Liehr-2/+2
2023-09-09Use `FreezeLock` for `CStore`John Kåre Alsaker-3/+3
2023-09-01Auto merge of #113126 - Bryanskiy:delete_old, r=petrochenkovbors-4/+0
Replace old private-in-public diagnostic with type privacy lints Next part of RFC https://github.com/rust-lang/rust/issues/48054. r? `@petrochenkov`
2023-08-24Auto merge of #113408 - petrochenkov:bindintern2, r=cjgillotbors-23/+85
resolve: Stop creating `NameBinding`s on every use, create them once per definition instead `NameBinding` values are supposed to be unique, use referential equality, and be created once for every name declaration. Before this PR many `NameBinding`s were created on name use, rather than on name declaration, because it's sufficiently cheap, and comparisons are not actually used in practice for some binding kinds. This PR makes `NameBinding`s consistently unique and created on name declaration. There are two special cases - for extern prelude names creating `NameBinding` requires loading the corresponding crate, which is expensive, so such bindings are created lazily on first use, but they still keep the uniqueness by being reused on further uses. - for legacy derive helpers (helper attributes written before derives that introduce them) the declaration and the use is basically the same thing (that's one of the reasons why they are deprecated), so they are still created on use, but we can still maybe do a bit better in a way that I described in FIXME in the last commit.
2023-08-24resolve: Make bindings for derive helper attributes uniqueVadim Petrochenkov-1/+1
instead of creating them every time such attribute is used
2023-08-24resolve: Make bindings for crate roots uniqueVadim Petrochenkov-2/+22
instead of creating a new every time `crate` or `$crate` is used
2023-08-24resolve: Pre-intern tool module bindingsVadim Petrochenkov-0/+9
2023-08-24resolve: Make bindings from extern prelude uniqueVadim Petrochenkov-11/+29
instead of creating a new every time a name from extern prelude is accessed
2023-08-24resolve: Pre-intern builtin name bindingsVadim Petrochenkov-9/+24
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-1/+1
Removes two pieces of mutable state. Follow up to #114622.
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-08-02Replace old private-in-public diagnostic with type privacy lintsBryanskiy-4/+0
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-2/+2
2023-07-29fix(resolve): update the ambiguity glob binding as warning recursivelybohan-2/+24
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-1/+4
2023-07-05resolve: Add comments explaining use of `Interned`Vadim Petrochenkov-0/+4
2023-07-05resolve: Use `Interned` for `Module`Vadim Petrochenkov-41/+41
2023-07-05resolve: Use `Interned` for `Import`Vadim Petrochenkov-17/+16
2023-07-05resolve: Use `Interned` for `NameBinding`Vadim Petrochenkov-41/+34
2023-07-01fix(resolve): skip assertion judgment when `NonModule` is dummybohan-1/+1
2023-06-29resolve: Remove artificial import ambiguity errorsVadim Petrochenkov-4/+2