about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-2/+4
2022-02-25Switch bootstrap cfgsMark Rousskov-1/+1
2022-02-25Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebankbors-4/+4
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission". That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have: * `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`) * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called (though note that this isn't a real guarantee until after completing the work on #69426) * `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.) * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()` This PR is a companion to other ongoing work, namely: * #69426 and it's ongoing implementation: #93222 the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes * #93244 would make the choices of API changes (esp. naming) in this PR fit better overall In order to be able to let `.emit()` return anything trustable, several changes had to be made: * `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail) * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()` * `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early) * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`) * since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>, we have to make `.emit()` idempotent wrt the guarantees it returns * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission * `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic) * the APIs were already mostly identical, allowing for low-effort porting to this new setup * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259) * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective) * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same) This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each. r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`
2022-02-24resolve/metadata: Stop encoding macros as reexportsVadim Petrochenkov-4/+0
2022-02-24resolve: Fix incorrect results of `opt_def_kind` query for some built-in macrosVadim Petrochenkov-0/+8
Previously it always returned `MacroKind::Bang` while some of those macros are actually attributes and derives
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-2/+2
2022-02-23Replace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`.Eduard-Mihai Burtescu-3/+3
2022-02-19Adopt let else in more placesest31-4/+3
2022-02-15Rename `PtrKey` as `Interned` and improve it.Nicholas Nethercote-6/+8
In particular, there's now more protection against incorrect usage, because you can only create one via `Interned::new_unchecked`, which makes it more obvious that you must be careful. There are also some tests.
2022-02-12change to a struct variantEllen-3/+3
2022-02-02Auto merge of #93312 - pierwill:map-all-local-trait-impls, r=cjgillotbors-2/+2
Return an indexmap in `all_local_trait_impls` query The data structure previously used here required that `DefId` be `Ord`. As part of #90317, we do not want `DefId` to implement `Ord`.
2022-02-01add a rustc::query_stability lintlcnr-0/+1
2022-01-25Return an indexmap in `all_local_trait_impls` querypierwill-2/+2
The data structure previously used here required Ord. As part of #90317, we do not want DefId to implement Ord.
2022-01-25rustdoc: Pre-calculate traits that are in scope for doc linksVadim Petrochenkov-1/+12
This eliminates one more late use of resolver
2022-01-23rustc_lint: Reuse the set of registered tools from resolverVadim Petrochenkov-2/+4
2022-01-16rustc_metadata: Switch all decoder methods from vectors to iteratorsVadim Petrochenkov-1/+0
Also remove unnecessary `is_proc_macro_crate` checks from decoder
2022-01-15Auto merge of #92441 - cjgillot:resolve-trait-impl-item, r=matthewjasperbors-0/+8
Link impl items to corresponding trait items in late resolver. Hygienically linking trait impl items to declarations in the trait can be done directly by the late resolver. In fact, it is already done to diagnose unknown items. This PR uses this resolution work and stores the `DefId` of the trait item in the HIR. This avoids having to do this resolution manually later. r? `@matthewjasper` Related to #90639. The added `trait_item_id` field can be moved to `ImplItemRef` to be used directly by your PR.
2022-01-09Compute most of Public/Exported access level in rustc_resolveLamb-0/+13
Mak DefId to AccessLevel map in resolve for export hir_id to accesslevel in resolve and applied in privacy using local def id removing tracing probes making function not recursive and adding comments Move most of Exported/Public res to rustc_resolve moving public/export res to resolve fix missing stability attributes in core, std and alloc move code to access_levels.rs return for some kinds instead of going through them Export correctness, macro changes, comments add comment for import binding add comment for import binding renmae to access level visitor, remove comments, move fn as closure, remove new_key fmt fix rebase fix rebase fmt fmt fix: move macro def to rustc_resolve fix: reachable AccessLevel for enum variants fmt fix: missing stability attributes for other architectures allow unreachable pub in rustfmt fix: missing impl access level + renaming export to reexport Missing impl access level was found thanks to a test in clippy
2022-01-09rustc_middle: Rename `Export` to `ModChild` and add some commentsVadim Petrochenkov-6/+6
Also rename `module_exports`/`export_map` to `module_reexports`/`reexport_map` for clarity.
2022-01-08Simplify error reporting.Camille GILLOT-0/+8
2022-01-06rustc_metadata: Make attribute decoding slightly faster and stricterVadim Petrochenkov-1/+1
Rename `CStore::item_attrs` -> `CStore::item_attrs_untracked` top follow conventions
2022-01-05ast: Always keep a `NodeId` in `ast::Crate`Vadim Petrochenkov-4/+3
This makes it more uniform with other expanded nodes
2021-12-21resolve: Minor miscellaneous cleanups from #89059Vadim Petrochenkov-20/+14
2021-12-19Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obkbors-1/+1
Remove `SymbolStr` This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-1/+1
2021-12-14Stabilize iter::zip.PFPoitras-1/+0
2021-12-02Rollup merge of #91394 - Mark-Simulacrum:bump-stage0, r=pietroalbiniMatthias Krüger-1/+0
Bump stage0 compiler r? `@pietroalbini` (or anyone else)
2021-12-01Improve suggestion for extern crate self error messageMichael-1/+3
2021-12-01Fix bad `NodeId` limit checking.Nicholas Nethercote-6/+3
`Resolver::next_node_id` converts a `u32` to a `usize` (which is possibly bigger), does a checked add, and then converts the result back to a `u32`. The `usize` conversion completely subverts the checked add! This commit removes the conversion to/from `usize`.
2021-11-30Apply cfg-bootstrap switchMark Rousskov-1/+0
2021-11-15Stabilize format_args_captureJosh Triplett-1/+1
Works as expected, and there are widespread reports of success with it, as well as interest in it.
2021-11-11Shorten Span of unused macro lintsMarcel Hellwig-1/+1
The span has been recuded to the actual ident, instead of linting the *whole* macro.
2021-11-03fix messageTakayuki Maeda-1/+1
2021-11-03add a suggestion about undeclared `alloc` moduleTakayuki Maeda-9/+19
2021-10-28Revert "Add rustc lint, warning when iterating over hashmaps"Mark Rousskov-1/+0
2021-10-25Edit error messages for rustc_resolve::AmbiguityKind variantspierwill-10/+8
Emit description of the ambiguity as a note. Co-authored-by: Noah Lev <camelidcamel@gmail.com> Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2021-10-24Rollup merge of #89558 - lcnr:query-stable-lint, r=estebankMatthias Krüger-0/+1
Add rustc lint, warning when iterating over hashmaps r? rust-lang/wg-incr-comp
2021-10-21Revert "Auto merge of #89100 - petrochenkov:localbind, r=cjgillot"Mark Rousskov-56/+138
This reverts commit 6162529a01473bbb2427fa27354cbafc3c514eee.
2021-10-20Auto merge of #89100 - petrochenkov:localbind, r=cjgillotbors-138/+56
resolve: Use `NameBinding` for local variables and generic parameters `NameBinding` is a structure used for representing any name introduction (an item, or import, or even a built-in). Except that local variables and generic parameters weren't represented as `NameBinding`s, for this reason they requires separate paths in name resolution code in several places. This PR introduces `NameBinding`s for local variables as well and simplifies all the code working with them leaving only the `NameBinding` paths.
2021-10-19Auto merge of #89933 - est31:let_else, r=michaelwoeristerbors-0/+1
Adopt let_else across the compiler This performs a substitution of code following the pattern: ``` let <id> = if let <pat> = ... { identity } else { ... : ! }; ``` To simplify it to: ``` let <pat> = ... { identity } else { ... : ! }; ``` By adopting the `let_else` feature (cc #87335). The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet. Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-18Auto merge of #89124 - cjgillot:owner-info, r=michaelwoeristerbors-43/+10
Index and hash HIR as part of lowering Part of https://github.com/rust-lang/rust/pull/88186 ~Based on https://github.com/rust-lang/rust/pull/88880 (see merge commit).~ Once HIR is lowered, it is later indexed by the `index_hir` query and hashed for `crate_hash`. This PR moves those post-processing steps to lowering itself. As a side objective, the HIR crate data structure is refactored as an `IndexVec<LocalDefId, Option<OwnerInfo<'hir>>>` where `OwnerInfo` stores all the relevant information for an HIR owner. r? `@michaelwoerister` cc `@petrochenkov`
2021-10-18resolve: Use `NameBinding` for local variables and generic parametersVadim Petrochenkov-138/+56
2021-10-16Adopt let_else across the compilerest31-0/+1
This performs a substitution of code following the pattern: let <id> = if let <pat> = ... { identity } else { ... : ! }; To simplify it to: let <pat> = ... { identity } else { ... : ! }; By adopting the let_else feature.
2021-10-15allow `potential_query_instability` everywherelcnr-0/+1
2021-10-13suggestion for typoed crate or moduleTakayuki Maeda-1/+16
avoid suggesting the same name sort candidates fix a message use `opt_def_id` instead of `def_id` move `find_similarly_named_module_or_crate` to rustc_resolve/src/diagnostics.rs
2021-10-09Forbid hashing HIR outside of indexing.Camille GILLOT-39/+6
2021-10-09Store lowering outputs per owner.Camille GILLOT-4/+4
2021-10-03Move rustc_middle::middle::cstore to rustc_session.Camille GILLOT-1/+1
2021-10-02resolve: Avoid comparing modules by optional def-idVadim Petrochenkov-7/+12
It makes all block modules identical during comparison
2021-10-02resolve: Cache module loading for all foreign modulesVadim Petrochenkov-3/+21
It was previously cached for modules loaded from `fn get_module`, but not for modules loaded from `fn build_reduced_graph_for_external_crate_res`. This also makes all foreign modules use their real parent, span and expansion instead of possibly a parent/span/expansion of their reexport. An ICE happening on attempt to decode expansions for foreign enums and traits is avoided. Also local enums and traits are now added to the module map.