about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
AgeCommit message (Collapse)AuthorLines
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-8/+12
2022-02-25Auto merge of #94290 - Mark-Simulacrum:bump-bootstrap, r=pietroalbinibors-1/+1
Bump bootstrap to 1.60 This bumps the bootstrap compiler to 1.60 and cleans up cfgs and Span's rustc_pass_by_value (enabled by the bootstrap bump).
2022-02-25Rollup merge of #93845 - compiler-errors:in-band-lifetimes, r=cjgillotMatthias Krüger-112/+27
Remove in band lifetimes As discussed in t-lang backlog bonanza, the `in_band_lifetimes` FCP closed in favor for the feature not being stabilized. This PR removes `#![feature(in_band_lifetimes)]` in its entirety. Let me know if this PR is too hasty, and if we should instead do something intermediate for deprecate the feature first. r? `@scottmcm` (or feel free to reassign, just saw your last comment on #44524) Closes #44524
2022-02-25Switch bootstrap cfgsMark Rousskov-1/+1
2022-02-24Remove LifetimeDefOriginMichael Goulet-33/+25
2022-02-24Remove in-band lifetimesMichael Goulet-79/+2
2022-02-25Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebankbors-41/+39
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-15/+22
2022-02-24resolve: Fix incorrect results of `opt_def_kind` query for some built-in macrosVadim Petrochenkov-1/+15
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-10/+17
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-3/+1
2022-02-23Replace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`.Eduard-Mihai Burtescu-29/+22
2022-02-23rustc_errors: add `downgrade_to_delayed_bug` to `Diagnostic` itself.Eduard-Mihai Burtescu-2/+2
2022-02-20Rollup merge of #94146 - est31:let_else, r=cjgillotMatthias Krüger-39/+20
Adopt let else in more places Continuation of #89933, #91018, #91481, #93046, #93590, #94011. I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
2022-02-19Adopt let else in more placesest31-39/+20
2022-02-18Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obkMatthias Krüger-5/+4
compiler: clippy::complexity fixes useless_format map_flatten useless_conversion needless_bool filter_next clone_on_copy needless_option_as_deref
2022-02-18Auto merge of #94088 - oli-obk:revert, r=jackh726bors-26/+8
Revert #91403 fixes #94004 r? `@pnkfelix` `@cjgillot`
2022-02-17Rollup merge of #94011 - est31:let_else, r=lcnrMatthias Krüger-8/+4
Even more let_else adoptions Continuation of #89933, #91018, #91481, #93046, #93590.
2022-02-17Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"Oli Scherer-26/+8
This reverts commit 3cfa4def7c87d571bd46d92fed608edf8fad236e, reversing changes made to 5d8767cb229b097fedb1dd4bd9420d463c37774f.
2022-02-16Adopt let_else in even more placesest31-8/+4
2022-02-15Rename `PtrKey` as `Interned` and improve it.Nicholas Nethercote-12/+14
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-14Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnrbors-18/+23
Make `Res::SelfTy` a struct variant and update docs I found pattern matching on a `(Option<DefId>, Option<(DefId, bool)>)` to not be super readable, additionally the doc comments on the types in a tuple variant aren't visible anywhere at use sites as far as I can tell (using rust analyzer + vscode) The docs incorrectly assumed that the `DefId` in `Option<(DefId, bool)>` would only ever be for an impl item and I also found the code examples to be somewhat unclear about which `DefId` was being talked about. r? `@lcnr` since you reviewed the last PR changing these docs
2022-02-12Auto merge of #91403 - cjgillot:inherit-async, r=oli-obkbors-8/+26
Inherit lifetimes for async fn instead of duplicating them. The current desugaring of `async fn foo<'a>(&usize) -> &u8` is equivalent to ```rust fn foo<'a, '0>(&'0 usize) -> foo<'static, 'static>::Opaque<'a, '0, '_>; type foo<'_a, '_0>::Opaque<'a, '0, '1> = impl Future<Output = &'1 u8>; ``` following the RPIT model. Duplicating all the inherited lifetime parameters and setting the inherited version to `'static` makes lowering more complex and causes issues like #61949. This PR removes the duplication of inherited lifetimes to directly use ```rust fn foo<'a, '0>(&'0 usize) -> foo<'a, '0>::Opaque<'_>; type foo<'a, '0>::Opaque<'1> = impl Future<Output = &'1 u8>; ``` following the TAIT model. Fixes https://github.com/rust-lang/rust/issues/61949
2022-02-12change to a struct variantEllen-18/+23
2022-02-12Inherit lifetimes for async fn instead of duplicating them.Camille GILLOT-8/+26
2022-02-11Rollup merge of #91607 - FabianWolff:issue-91560-const-span, r=jackh726Matthias Krüger-19/+19
Make `span_extend_to_prev_str()` more robust Fixes #91560. The logic in `span_extend_to_prev_str()` is currently quite brittle and fails if there is extra whitespace or something else in between, and it also should return an `Option` but doesn't currently.
2022-02-11Rollup merge of #93853 - steffahn:map_by_value, r=wesleywiserMatthias Krüger-18/+15
Make all `hir::Map` methods consistently by-value `hir::Map` only consists of a single reference (as part of the contained `TyCtxt`) anyways, so copying is literally zero overhead compared to passing a reference
2022-02-10Remove further usage of `&hir::Map`Frank Steffahn-18/+15
2022-02-09Use a slice for object_lifetime_defaults.Camille GILLOT-78/+71
2022-02-09Ensure that queries only return Copy types.Camille GILLOT-1/+7
2022-02-05resolve lifetimes for const generic defaultsMichael Goulet-1/+4
2022-02-03compiler: clippy::complexity fixesMatthias Krüger-5/+4
useless_format map_flatten useless_conversion needless_bool filter_next clone_on_copy needless_option_as_deref
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-02Detect `::` -> `:` typo in type argumentEsteban Kuber-1/+42
When writing `Vec<A:B>`, suggest `Vec<A::B>`.
2022-02-01add a rustc::query_stability lintlcnr-0/+1
2022-01-31Make `span_extend_to_prev_str()` more robustFabian Wolff-19/+19
2022-01-27Store def_id_to_hir_id as variant in hir_owner.Camille GILLOT-9/+1
If hir_owner is Owner(_), the LocalDefId is pointing to an owner, so the ItemLocalId is 0. If the HIR node does not exist, we store Phantom. Otherwise, we store the HirId associated to the LocalDefId.
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-2/+13
This eliminates one more late use of resolver
2022-01-23rustc_lint: Reuse the set of registered tools from resolverVadim Petrochenkov-3/+9
2022-01-21Rollup merge of #93046 - est31:let_else, r=davidtwcoMatthias Krüger-41/+38
Use let_else in even more places Followup of #89933, #91018, #91481.
2022-01-19Only suggest adding `!` to expressions that can be macro invocationEsteban Kuber-1/+14
2022-01-18Use let_else in even more placesest31-41/+38
2022-01-16Replace NestedVisitorMap with NestedFilterCameron Steffen-40/+5
2022-01-16rustc_metadata: Switch all decoder methods from vectors to iteratorsVadim Petrochenkov-10/+10
Also remove unnecessary `is_proc_macro_crate` checks from decoder
2022-01-15Reduce use of local_def_id_to_hir_id.Camille GILLOT-44/+36
2022-01-15Return a LocalDefId in get_parent_item.Camille GILLOT-5/+5
2022-01-15Auto merge of #92441 - cjgillot:resolve-trait-impl-item, r=matthewjasperbors-23/+89
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-12Ensure res and module are consistent with each other.Camille GILLOT-23/+13
The `record_used` parameter changes the result, so we must pass the same value for initial and module resolution.
2022-01-09Compute most of Public/Exported access level in rustc_resolveLamb-4/+256
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