summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2024-07-11Account for `let foo = expr`; to suggest `const foo: Ty = expr;`Esteban Küber-5/+6
2024-07-08Rollup merge of #127431 - oli-obk:feed_item_attrs, r=compiler-errors许杰友 Jieyou Xu (Joe)-5/+13
Use field ident spans directly instead of the full field span in diagnostics on local fields This improves diagnostics and avoids having to store the `DefId`s of fields
2024-07-06Use field ident spans directly instead of the full field span in diagnostics ↵Oli Scherer-5/+13
on local fields
2024-07-06out_of_scope_macro_calls: Detect calls inside attributes more preciselyVadim Petrochenkov-2/+3
2024-06-28Change RTN to use .. againMichael Goulet-0/+1
2024-06-25resolve: Tweak some naming around import ambiguitiesVadim Petrochenkov-6/+8
2024-06-14delegation: Implement glob delegationVadim Petrochenkov-1/+13
2024-05-29Rollup merge of #125381 - estebank:issue-96799, r=petrochenkov许杰友 Jieyou Xu (Joe)-1/+3
Silence some resolve errors when there have been glob import errors When encountering `use foo::*;` where `foo` fails to be found, and we later encounter resolution errors, we silence those later errors. A single case of the above, for an *existing* import on a big codebase would otherwise have a huge number of knock-down spurious errors. Ideally, instead of a global flag to silence all subsequent resolve errors, we'd want to introduce an unnameable binding in the appropriate rib as a sentinel when there's a failed glob import, so when we encounter a resolve error we can search for that sentinel and if found, and only then, silence that error. The current approach is just a quick proof of concept to iterate over. Partially address #96799.
2024-05-28Silence some resolve errors when there have been glob import errorsEsteban Küber-1/+3
When encountering `use foo::*;` where `foo` fails to be found, and we later encounter resolution errors, we silence those later errors. A single case of the above, for an *existing* import on a big codebase would otherwise have a huge number of knock-down spurious errors. Ideally, instead of a global flag to silence all subsequent resolve errors, we'd want to introduce an unameable binding in the appropriate rib as a sentinel when there's a failed glob import, so when we encounter a resolve error we can search for that sentinel and if found, and only then, silence that error. The current approach is just a quick proof of concept to iterate over. Partially address #96799.
2024-05-21Rename buffer_lint_with_diagnostic to buffer_lintXiretza-1/+1
2024-05-21Convert uses of BuiltinLintDiag::Normal to custom variantsXiretza-3/+7
This ensures all diagnostic messages are created at diagnostic emission time, making them translatable.
2024-05-10Remove unused `derive(Clone)` on `MacroData`.Nicholas Nethercote-1/+0
2024-05-10Remove `#[macro_use] extern crate tracing` from `rustc_resolve`.Nicholas Nethercote-9/+5
Explicit imports are more standard nowadays and easier to read.
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