Commit Graph

564 Commits

Author SHA1 Message Date
bors
b321742c6c Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnr
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-14 12:26:43 +00:00
bors
3cfa4def7c Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk
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-12 21:42:10 +00:00
Ellen
e81e09a24e change to a struct variant 2022-02-12 11:23:53 +00:00
Camille GILLOT
a4da6308b7 Inherit lifetimes for async fn instead of duplicating them. 2022-02-12 01:26:11 +01:00
Matthias Krüger
b7c48b4691
Rollup merge of #91607 - FabianWolff:issue-91560-const-span, r=jackh726
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-11 21:48:43 +01:00
Matthias Krüger
ddba967855
Rollup merge of #93853 - steffahn:map_by_value, r=wesleywiser
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-11 07:48:06 +01:00
Frank Steffahn
7eff2feb62 Remove further usage of &hir::Map 2022-02-10 13:04:59 +01:00
Camille GILLOT
e52131efad Use a slice for object_lifetime_defaults. 2022-02-09 20:11:01 +01:00
Camille GILLOT
6c2ee885e6 Ensure that queries only return Copy types. 2022-02-09 20:07:38 +01:00
Michael Goulet
bcf98841d4 resolve lifetimes for const generic defaults 2022-02-05 01:30:14 -08:00
bors
7cd14d2f56 Auto merge of #93312 - pierwill:map-all-local-trait-impls, r=cjgillot
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-02 15:36:12 +00:00
Esteban Kuber
b26ad8d10f Detect :: -> : typo in type argument
When writing `Vec<A:B>`, suggest `Vec<A::B>`.
2022-02-02 01:19:24 +00:00
lcnr
a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
Fabian Wolff
69803f7888 Make span_extend_to_prev_str() more robust 2022-01-31 19:28:15 +01:00
Camille GILLOT
a0bcce4884
Store def_id_to_hir_id as variant in hir_owner.
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-27 10:46:40 -03:00
pierwill
f5fe6cd277 Return an indexmap in all_local_trait_impls query
The data structure previously used here required Ord.
As part of #90317, we do not want DefId to implement Ord.
2022-01-25 17:44:45 -06:00
Vadim Petrochenkov
00ba815a58 rustdoc: Pre-calculate traits that are in scope for doc links
This eliminates one more late use of resolver
2022-01-25 21:45:21 +08:00
Vadim Petrochenkov
51b2338611 rustc_lint: Reuse the set of registered tools from resolver 2022-01-23 18:51:51 +08:00
Matthias Krüger
ab19d4a515
Rollup merge of #93046 - est31:let_else, r=davidtwco
Use let_else in even more places

Followup of #89933, #91018, #91481.
2022-01-21 22:03:17 +01:00
Esteban Kuber
017747fa5a Only suggest adding ! to expressions that can be macro invocation 2022-01-19 18:00:10 +00:00
est31
b2dd1377c7 Use let_else in even more places 2022-01-18 21:37:57 +01:00
Cameron Steffen
45db716902 Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
Vadim Petrochenkov
4549b13571 rustc_metadata: Switch all decoder methods from vectors to iterators
Also remove unnecessary `is_proc_macro_crate` checks from decoder
2022-01-16 14:14:39 +08:00
Camille GILLOT
67727aa7c3 Reduce use of local_def_id_to_hir_id. 2022-01-15 21:26:25 +01:00
Camille GILLOT
60064726ae Return a LocalDefId in get_parent_item. 2022-01-15 21:26:20 +01:00
bors
ec4bcaac45 Auto merge of #92441 - cjgillot:resolve-trait-impl-item, r=matthewjasper
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-15 14:43:45 +00:00
Camille GILLOT
7b285925c8 Ensure res and module are consistent with each other.
The `record_used` parameter changes the result, so we must pass the same
value for initial and module resolution.
2022-01-12 20:04:06 +01:00
Lamb
3a77bb86ff Compute most of Public/Exported access level in rustc_resolve
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-09 21:33:14 +00:00
bors
f7bb8e3677 Auto merge of #92690 - matthiaskrgr:rollup-rw0oz05, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #92055 (Add release notes for 1.58)
 - #92490 (Move crate drop-down to search results page)
 - #92510 (Don't resolve blocks in foreign functions)
 - #92573 (expand: Refactor InvocationCollector visitor for better code reuse)
 - #92608 (rustdoc: Introduce a resolver cache for sharing data between early doc link resolution and later passes)
 - #92657 (Implemented const casts of raw pointers)
 - #92671 (Make `Atomic*::from_mut` return `&mut Atomic*`)
 - #92673 (Remove useless collapse toggle on "all items" page)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-09 12:43:37 +00:00
Matthias Krüger
464a0813d1
Rollup merge of #92510 - inquisitivecrystal:foreign-block, r=cjgillot
Don't resolve blocks in foreign functions

Although it is an error for a foreign function to have a block, it is still possible at the level of the AST. #74204 made AST lowering skip over blocks belonging to foreign functions, since they're invalid. However, resolve still treated these blocks normally, resulting in a mismatch between the HIR and resolve, which could cause an ICE under certain circumstances. This PR changes resolve to skip over blocks belonging to foreign functions, as AST lowering does.

Fixes #91370.

r? ``@cjgillot``
2022-01-09 13:38:30 +01:00
Vadim Petrochenkov
4b03fd910c rustc_middle: Rename Export to ModChild and add some comments
Also rename `module_exports`/`export_map` to `module_reexports`/`reexport_map` for clarity.
2022-01-09 09:22:07 +08:00
Vadim Petrochenkov
3051f6e9c4 rustc_metadata: Rename item_children(_untracked) to module_children(_untracked)
And `each_child_of_item` to `for_each_module_child`
2022-01-09 09:22:06 +08:00
Camille GILLOT
554aceba49 Simplify error reporting. 2022-01-08 20:45:59 +01:00
Camille GILLOT
1be6e2d6e9 Link impl items to corresponding trait items in late resolver. 2022-01-08 20:45:59 +01:00
Vadim Petrochenkov
4c6120c386 rustc_metadata: Make attribute decoding slightly faster and stricter
Rename `CStore::item_attrs` -> `CStore::item_attrs_untracked` top follow conventions
2022-01-06 12:13:41 +08:00
inquisitivecrystal
486585242e Do not resolve blocks in foreign functions 2022-01-05 15:22:22 -08:00
Vadim Petrochenkov
55595c5616 ast: Always keep a NodeId in ast::Crate
This makes it more uniform with other expanded nodes
2022-01-05 17:09:37 +08:00
Matthias Krüger
0335b7bca9
Rollup merge of #92402 - pr2502:while-let-typo, r=oli-obk
Suggest while let x = y when encountering while x = y

Extends #75931 to also detect where the `let` might be missing from `while let` expressions.
2022-01-03 14:44:18 +01:00
ametisf
874cd08e23 Suggest while let x = y when encountering while x = y
Extends #75931 to also detect where the `let` might be missing from `while let` expressions.
2021-12-29 13:23:19 +01:00
Matthias Krüger
f044c6c86c
Rollup merge of #92237 - compiler-errors:issue-92100, r=cjgillot
Visit expressions in-order when resolving pattern bindings

[edited:] Visit the pattern's sub-expressions before defining any bindings.

Otherwise, we might get into a case where a Lit/Range expression in a pattern has a qpath pointing to a Ident pattern that is defined after it, causing an ICE when lowering to HIR. I have a more detailed explanation in the issue linked.

Fixes #92100
2021-12-29 10:17:10 +01:00
Matthias Krüger
98c61b673e
Rollup merge of #92333 - compiler-errors:elided-lifetime-spans, r=cjgillot
Tighten span when suggesting lifetime on path

This is kind of a hack.

Really the issue here is that we want to suggest the segment's span if the path resolves to something defined outside of the macro, and the macro's span if it resolves to something defined within.. I'll look into seeing if we can do something like that.

Fixes #92324

r? `@cjgillot`
2021-12-28 13:59:25 +01:00
Michael Goulet
e37d012a06 Tighten span when suggesting lifetime on path 2021-12-27 23:34:52 -08:00
Matthias Krüger
a11414d62e
Rollup merge of #92161 - petrochenkov:misclean, r=cjgillot
resolve: Minor miscellaneous cleanups from #89059

`@bors` rollup=always
2021-12-27 21:42:27 +01:00
Michael Goulet
b1529a680a Visit patterns' literal expressions before binding new idents 2021-12-27 12:20:13 -08:00
Vadim Petrochenkov
337ced2ef0 rustc_metadata: Merge get_ctor_def_id and get_ctor_kind
Also avoid decoding the whole `ty::AssocItem` to get a `has_self` flag
2021-12-22 11:05:54 +08:00
Vadim Petrochenkov
1324100800 resolve: Minor miscellaneous cleanups from #89059 2021-12-21 20:26:41 +08:00
Matthias Krüger
790950a530
Rollup merge of #91770 - TaKO8Ki:suggest-adding-cfg-test, r=joshtriplett
Suggest adding a `#[cfg(test)]` to to a test module

closes #88138
2021-12-21 08:33:39 +01:00
bors
a41a6925ba Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
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-19 09:31:37 +00:00
Vadim Petrochenkov
0d61852cc5 hir: Do not introduce dummy type names for extern blocks in def paths
Use a separate nameless `DefPathData` variant instead
2021-12-18 16:30:17 +08:00
Takayuki Maeda
6f8ad6d83a suggest adding a #[cfg(test)] to test modules
remove a empty line

import `module_to_string`

use `contains("test")`

show a suggestion in case module starts_with/ends_with "test"

replace `parent` with `containing`
2021-12-16 11:48:58 +09:00