Commit Graph

1223 Commits

Author SHA1 Message Date
Michael Goulet
eff2cb7760 Rename some region-specific stuff 2023-02-16 03:39:59 +00:00
Matthias Krüger
0400c68517 use chars instead of strings where applicable 2023-02-15 22:54:57 +01:00
bors
2d14db321b Auto merge of #108006 - cjgillot:def-impl, r=oli-obk
Avoid accessing HIR when it can be avoided

Experiment to see if it helps some incremental cases.

Will be rebased once https://github.com/rust-lang/rust/pull/107942 gets merged.

r? `@ghost`
2023-02-15 16:14:10 +00:00
Camille GILLOT
03dff82d59 Add of_trait to DefKind::Impl. 2023-02-14 19:55:44 +00:00
Oli Scherer
43a5cc383d Separate the lifetime of the session and the arena in the resolver 2023-02-14 10:01:25 +00:00
Vadim Petrochenkov
efbf6547cf resolve: Fix doc links referring to other crates when documenting proc macro crates directly 2023-02-13 00:51:29 +04:00
Vadim Petrochenkov
fd73d01c98 rustc_resolve: Remove Resolver::clone_output
And remove `Clone` impls and `Lrc`s that are no longer necessary
2023-02-13 00:10:15 +04:00
Vadim Petrochenkov
9080b79f2b rustdoc: Eliminate remaining uses of resolver 2023-02-13 00:10:15 +04:00
bors
5b45024487 Auto merge of #94857 - petrochenkov:doclink2, r=oli-obk
Resolve documentation links in rustc and store the results in metadata

This PR implements MCP https://github.com/rust-lang/compiler-team/issues/584.

Doc links are now resolved in rustc and stored into metadata, so rustdoc simply retrieves them through a query (local or extern),

Code that is no longer used is removed, and some code that no longer needs to be public is privatized.
The removed code includes resolver cloning, so this PR fixes https://github.com/rust-lang/rust/issues/83761.
2023-02-11 12:10:16 +00:00
bors
d1ac43a9b9 Auto merge of #107652 - estebank:re_error, r=oli-obk
Introduce `ReError`

CC #69314

r? `@nagisa`
2023-02-10 10:10:12 +00:00
Vadim Petrochenkov
da4ce6b41e Skip doc link resolution for some crate types and non-exported items 2023-02-10 09:35:14 +04:00
Vadim Petrochenkov
3b0866272a Stop resolving doc links on mod items twice 2023-02-10 09:34:13 +04:00
Vadim Petrochenkov
b62b82aef4 Resolve documentation links in rustc and store the results in metadata
This commit implements MCP https://github.com/rust-lang/compiler-team/issues/584

It also removes code that is no longer used, and that includes code cloning resolver, so issue #83761 is fixed.
2023-02-10 09:34:13 +04:00
Esteban Küber
30cf7a3f51 Introduce ReError
CC #69314
2023-02-09 10:26:49 +00:00
Matthias Krüger
a3637032db unused-lifetimes: don't warn about lifetimes originating from expanded code
previously, we would warn like this:

````
warning: lifetime parameter `'s` never used
 --> /tmp/unusedlif/code.rs:6:62
  |
5 | #[derive(Clone)]
  |          - help: elide the unused lifetime
6 | struct ShimMethod4<T: Trait2 + 'static>(pub &'static dyn for<'s> Fn(&'s mut T::As));
  |                                                              ^^
  |
  = note: requested on the command line with `-W unused-lifetimes`
````

Fixes #104432
2023-02-03 21:18:34 +01:00
Maybe Waffle
9fe8ae792e Rename rust_2015 => is_rust_2015 2023-02-02 08:17:13 +00:00
Guillaume Gomez
fe44f3bdd0
Rollup merge of #107508 - WaffleLapkin:uneq'15, r=oli-obk
`Edition` micro refactor

r? ``@oli-obk``
2023-01-31 23:38:53 +01:00
Maybe Waffle
03158f40d2 Don't do .edition().rust_*() 2023-01-31 10:09:23 +00:00
Maybe Waffle
fd5774a4d7 Use Edition methods a bit more 2023-01-31 10:09:22 +00:00
Maybe Waffle
fd649a3cc5 Replace enum ==s with matches where it makes sense 2023-01-30 12:26:26 +00:00
Andy Russell
8b12d5f42f
suggest qualifying bare associated constants 2023-01-25 08:58:27 -05:00
bors
940d00f2f6 Auto merge of #107185 - compiler-errors:rollup-wkomjma, r=compiler-errors
Rollup of 8 pull requests

Successful merges:

 - #103418 (Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` to future-incompat report)
 - #106113 (llvm-wrapper: adapt for LLVM API change)
 - #106144 (Improve the documentation of `black_box`)
 - #106578 (Label closure captures/generator locals that make opaque types recursive)
 - #106749 (Update cc to 1.0.77)
 - #106935 (Fix `SingleUseLifetime` ICE)
 - #107015 (Re-enable building rust-analyzer on riscv64)
 - #107029 (Add new bootstrap members to triagebot.toml)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-22 06:53:36 +00:00
Michael Goulet
8a830cf182
Rollup merge of #106935 - TaKO8Ki:fix-104440, r=cjgillot
Fix `SingleUseLifetime` ICE

Fixes #104440
cc: ``@matthiaskrgr``
2023-01-21 23:21:00 -05:00
bors
85da15c016 Auto merge of #107133 - pnkfelix:revert-pr-84022-for-issue-106337, r=Mark-Simulacrum
Revert "Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error"

This reverts commit 7d82cadd97 aka PR #84022

I am doing this to buy us some time with respect to issue #106337 w.r.t. the 1.67 release.
2023-01-22 03:58:52 +00:00
bors
005fc0f00f Auto merge of #106977 - michaelwoerister:unord_id_collections, r=oli-obk
Use UnordMap and UnordSet for id collections (DefIdMap, LocalDefIdMap, etc)

This PR changes the `rustc_data_structures::define_id_collections!` macro to use `UnordMap` and `UnordSet` instead of `FxHashMap` and `FxHashSet`. This should account for a large portion of hash-maps being used in places where they can cause trouble.

The changes required are moderate but non-zero:
- In some places the collections are extracted into sorted vecs.
- There are a few instances where for-loops have been changed to extends.

~~Let's see what the performance impact is. With a bit more refactoring, we might be able to get rid of some of the additional sorting -- but the change set is already big enough. Unless there's a performance impact, I'd like to do further changes in subsequent PRs.~~

Performance does not seem to be negatively affected ([perf-run here](https://github.com/rust-lang/rust/pull/106977#issuecomment-1396776699)).

Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).

r? `@ghost`
2023-01-21 14:18:17 +00:00
Felix S. Klock II
5fa1347331 Revert "Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error"
This reverts commit 7d82cadd97.

I am doing this to buy us some time with respect to issue #106337 w.r.t. the
1.67 release.
2023-01-20 17:13:55 -05:00
Michael Howell
c07a722847 diagnostics: remvoe unnecessary use of source_map.start_point 2023-01-20 14:53:34 -07:00
Michael Howell
dca160a06a diagnostics: use module_path to check crate import instead of strings 2023-01-20 14:53:34 -07:00
Michael Howell
e237690a28 diagnostics: add }; only if { was added too 2023-01-20 14:53:33 -07:00
Michael Howell
e9d8d238ef diagnostics: suggest changing s@self::{macro}@::macro for exported
Fixes #99695
2023-01-20 14:52:24 -07:00
Michael Woerister
c3d2573120 Use UnordMap instead of FxHashMap in define_id_collections!(). 2023-01-19 10:40:47 +01:00
Matthias Krüger
68f12338af
Rollup merge of #104505 - WaffleLapkin:no-double-spaces-in-comments, r=jackh726
Remove double spaces after dots in comments

Most of the comments do not have double spaces, so I assume these are typos.
2023-01-17 20:21:25 +01:00
Maybe Waffle
6a28fb42a8 Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
Michael Goulet
21725774a2 note -> help 2023-01-17 03:09:49 +00:00
Michael Goulet
716ea5f19c Fix use suggestion span 2023-01-17 03:06:38 +00:00
Takayuki Maeda
fe96c11aba fix #104440 2023-01-16 21:06:34 +09:00
Michael Goulet
566202b975 Only suggest adding type param if path being resolved was a type 2023-01-15 16:33:08 +00:00
Matthias Krüger
f7093826a4
Rollup merge of #106813 - oli-obk:sess_cleanup, r=GuillaumeGomez,petrochenkov
Remove redundant session field

There was already a session available in the resolver, so we access that session.
2023-01-13 19:16:45 +01:00
Oli Scherer
4aca7beab0 Remove redundant session field 2023-01-13 16:01:27 +00:00
Michael Goulet
bf0623e363 Don't suggest dyn as parameter to add 2023-01-12 22:04:30 +00:00
Michael Goulet
950b47fb96 Render missing generics suggestion verbosely 2023-01-12 22:04:30 +00:00
Esteban Küber
41e66d9025 review comments: Tweak output
* Account for `struct S(pub(super)Ty);` in suggestion
* Suggest changing field visibility in E0603 too
2023-01-11 21:36:02 +00:00
Esteban Küber
eb835093a3 review comment 2023-01-11 21:35:42 +00:00
Esteban Küber
ad13d9fbbe Suggest making private tuple struct field public
Fix #52144.
2023-01-11 21:35:42 +00:00
Albert Larsan
40ba0e84d5
Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
Yuki Okushi
684a3717cb
Rollup merge of #106175 - compiler-errors:bad-import-sugg, r=oli-obk
Fix bad import suggestion with nested `use` tree

Fixes #105566
Fixes #105373

Ideally, we'd find some way to turn these into structured suggestions -- perhaps on a separate line as a different `use` statement, but I have no idea how to access the span for the whole `use` from this point in the import resolution code.
2023-01-10 08:05:34 +09:00
Michael Goulet
1d66a675bb review comment 2023-01-09 18:07:34 +00:00
Matthias Krüger
0c8d11b97c
Rollup merge of #105859 - compiler-errors:hr-lifetime-add, r=davidtwco
Point out span where we could introduce higher-ranked lifetime

Somewhat addresses #105422, but not really. We don't have that much useful information here since we're still in resolution :^(

Maybe this suggestion isn't worth it. If the reviewer has an idea how we can get a more succinct binder information for a structured suggestion, it would be appreciated.
2023-01-07 20:43:21 +01:00
Michael Goulet
7690fe3bc6 Simplify some iterator combinators 2023-01-04 00:48:07 +00:00
Matthias Krüger
c610aeb592
Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, r=compiler-errors
Rename `Rptr` to `Ref` in AST and HIR

The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-29 13:16:04 +01:00
Nilstrieb
9067e4417e Rename Rptr to Ref in AST and HIR
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already
as well.
2022-12-28 18:52:36 +01:00
Esteban Küber
7e84273b7f Make resolve suggestion more generic 2022-12-27 12:16:25 -08:00
Esteban Küber
0c0685bb68 review comments: make suggestion more accurate 2022-12-27 09:25:00 -08:00
Michael Goulet
050bc95ce2 Fix some totally useless suggestions 2022-12-27 07:17:22 +00:00
Michael Goulet
d2404d6dca Dont clobber as .. rename in import suggestion 2022-12-27 07:05:45 +00:00
Michael Goulet
9e2536b938 Note alternative import candidates in nested use tree 2022-12-27 05:09:43 +00:00
Michael Goulet
564435f20a Suppress suggestions for nested use tree 2022-12-27 05:09:43 +00:00
Esteban Küber
c9381fc334 Detect likely . -> .. typo in method calls
Fix #65015.
2022-12-26 18:27:40 -08:00
Matthias Krüger
2cace6aa5d
Rollup merge of #105769 - lyming2007:issue-105177-fix, r=eholk
add function to tell the identical errors for ambiguity_errors

if 2 errors of the kind and ident and span of the ident, b1, b2 and misc1 misc2 are the same we call these 2 ambiguity errors identical
prevent identical ambiguity error from pushing into vector of ambiguity_errors this will fix #105177
2022-12-22 11:03:50 +01:00
Eric Holk
f20f86ec4e
Change comment to doc comment 2022-12-21 17:28:42 -08:00
Yiming Lei
bd12d151ee add function to tell if the current ambiguity error matches a previous one in ambiguity_errors
if 2 errors of the kind and ident and span of the ident, b1, b2 and misc1 misc2 are the same
then these 2 ambiguity errors matched
prevent identical ambiguity error from pushing into vector of ambiguity_errors
this will fix #105177
2022-12-19 08:38:05 -08:00
Matthias Krüger
ebe3563764
Rollup merge of #105873 - matthiaskrgr:clippy_fmt, r=Nilstrieb
use &str / String literals instead of format!()
2022-12-18 23:03:07 +01:00
Matthias Krüger
221e71e7a1
Rollup merge of #105869 - matthiaskrgr:clone_on_copy, r=compiler-errors
don't clone Copy types
2022-12-18 23:03:07 +01:00
Matthias Krüger
a108d55ce6 don't restuct references just to reborrow 2022-12-18 17:04:32 +01:00
Matthias Krüger
3af7df91fc use &str / String literals instead of format!() 2022-12-18 16:17:46 +01:00
Matthias Krüger
fec9e9ecf1 don't clone Copy types 2022-12-18 14:25:55 +01:00
Michael Goulet
5cccb36cfb higher-ranked lifetime message 2022-12-18 03:04:26 +00:00
Matthias Krüger
6dbaf86672
Rollup merge of #104864 - chenyukang:yukang/fix-104700-binding, r=estebank
Account for item-local in inner scope for E0425

Fixes #104700
2022-12-13 01:17:08 +01:00
Oli Scherer
75ff5c7dd3 Fold Definitions into the untracked data 2022-12-09 14:59:39 +00:00
Oli Scherer
1c1d3570ee Move the untracked cstore and source_span into a struct 2022-12-09 14:53:24 +00:00
Oli Scherer
2cd36f2c89 Generate crate loaders on the fly 2022-12-09 14:53:23 +00:00
Oli Scherer
4b08fbaea8 ResolverTree does not require access to the crate loader, only the store 2022-12-09 14:50:09 +00:00
Oli Scherer
d30848b30a Use Symbol for the crate name instead of String/str 2022-12-07 20:30:02 +00:00
Yuki Okushi
fa7d3ec630
Rollup merge of #105289 - Rageking8:fix-dupe-word-typos, r=cjgillot
Fix dupe word typos
2022-12-06 12:48:52 +09:00
Matthias Krüger
4ebbb20dad
Rollup merge of #105230 - cjgillot:issue-104312, r=petrochenkov
Skip recording resolution for duplicated generic params.

Turns out the fix was simpler than I thought.

Fixes https://github.com/rust-lang/rust/issues/104312
2022-12-05 20:43:44 +01:00
Rageking8
58110572fb fix dupe word typos 2022-12-05 16:42:36 +08:00
Matthias Krüger
7dbd1603b8
Rollup merge of #101975 - chenyukang:fix-101749, r=compiler-errors
Suggest to use . instead of :: when accessing a method of an object

Fixes #101749
Fixes #101542
2022-12-04 16:25:32 +01:00
Camille GILLOT
b1514108e2 Skip recording resolution for duplicated generic params. 2022-12-03 22:40:30 +00:00
yukang
fb004e9a95 fix #101749, use . instead of :: when accessing a method of an object 2022-12-03 22:41:12 +08:00
yukang
795b2afd20 fix #105069, Add AmbiguityError for inconsistent resolution for an import 2022-12-03 22:28:35 +08:00
Vadim Petrochenkov
b32a4edb20 rustc_ast_lowering: Stop lowering imports into multiple items
Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-01 18:51:20 +03:00
Rageking8
c95dceb63a clean up pr 104954 2022-11-29 10:41:21 +08:00
Matthias Krüger
412f05c9e8
Rollup merge of #104954 - vincenzopalazzo:macros/prinf, r=estebank
make simple check of prinf function

Fixes https://github.com/rust-lang/rust/issues/92898

With this commit we start to make some simple
check when the name resolution fails, and
we generate some helper messages in case the
name is a C name like in the case of the `printf`
and suggest the correct rust method.

`@rustbot` r? `@pnkfelix`

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-11-28 17:25:48 +01:00
Nicholas Nethercote
a60e337c88 Rename NestedMetaItem::[Ll]iteral as NestedMetaItem::[Ll]it.
We already use a mix of `Literal` and `Lit`. The latter is better
because it is shorter without causing any ambiguity.
2022-11-28 15:18:53 +11:00
Matthias Krüger
86304f5149
Rollup merge of #104976 - WaffleLapkin:move_comments, r=cjgillot
Prefer doc comments over `//`-comments in compiler

Doc comments are generally nicer: they show up in the documentation, they are shown in IDEs when you hover other mentions of items, etc. Thus it makes sense to use them instead of `//`-comments.
2022-11-27 22:14:08 +01:00
bors
454784afba Auto merge of #104048 - cjgillot:split-lifetime, r=compiler-errors
Separate lifetime ident from lifetime resolution in HIR

Drive-by: change how suggested generic args are computed.
Fixes https://github.com/rust-lang/rust/issues/103815

I recommend reviewing commit-by-commit.
2022-11-27 14:30:19 +00:00
Maybe Waffle
1d42936b18 Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
Vincenzo Palazzo
ee6f18ef59
make simple check of prinf function.
With this commit we start to make some simple
check when the name resolution fails, and
we generate some helper message in case the
name is a C name like in the case of the `printf`
and suggest the correct rust method.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-11-27 11:50:02 +01:00
bors
f8a2e491eb Auto merge of #104730 - petrochenkov:modchild5, r=cjgillot
rustc_metadata: Switch module children decoding to an iterator

Previously https://github.com/rust-lang/rust/pull/103578, https://github.com/rust-lang/rust/pull/103524 and previous PRs simplified it as much as possible.

A couple of cleanup commits is also added.
r? `@cjgillot`
2022-11-26 05:41:34 +00:00
yukang
68ea51602a fix the crossing function issue 2022-11-25 15:25:04 +08:00
bors
41e0363055 Auto merge of #104602 - petrochenkov:effvisperf5, r=oli-obk
privacy: Fix more (potential) issues with effective visibilities

Continuation of https://github.com/rust-lang/rust/pull/103965.
See individual commits for more detailed description of the changes.

The shortcuts removed in 4eb63f618e and c7c7d16727 could actually be correct (or correct after some tweaks), but they used global reasoning like "we can skip this update because if the code compiles then some other update should do the same thing eventually".
I have some expertise in this area, but I still have doubt whether such global reasoning was correct or not, especially in presence of all possible exotic cases with imports.
After this PR all table changes should be "locally correct" after every update, even if it may be overcautious.
If similar optimizations are introduced again they will need detailed comments explaining why it's legal to do what they do and providing proofs.

Fixes https://github.com/rust-lang/rust/issues/104249.
Fixes https://github.com/rust-lang/rust/issues/104539.
2022-11-25 06:14:42 +00:00
yukang
7cd4b673d0 fix #104700, account for item-local in inner scope for E0425 2022-11-25 13:19:21 +08:00
Matthias Krüger
0e4eb0da33
Rollup merge of #104747 - petrochenkov:ctorfields, r=cjgillot
resolve: Don't use constructor def ids in the map for field names

Also do some minor cleanup to insertion of those field names.

Addresses a FIXME left in https://github.com/rust-lang/rust/pull/103578.
2022-11-24 21:34:53 +01:00
Camille GILLOT
5f5e7a8eec Record in HIR whether lifetime elision was succesful. 2022-11-24 17:48:27 +00:00
bors
5dfb4b0afa Auto merge of #104321 - Swatinem:async-gen, r=oli-obk
Avoid `GenFuture` shim when compiling async constructs

Previously, async constructs would be lowered to "normal" generators, with an additional `from_generator` / `GenFuture` shim in between to convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that async constructs will *directly* implement `Future` without the need to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation detail in stack traces and debuginfo, but it can in theory also help the optimizer as there is less abstractions to see through.

---

Given this demo code:

```rust
pub async fn a(arg: u32) -> Backtrace {
    let bt = b().await;
    let _arg = arg;
    bt
}

pub async fn b() -> Backtrace {
    Backtrace::force_capture()
}
```

I would get the following with the latest stable compiler (on Windows):

```
   4: async_codegen:🅱️:async_fn$0
             at .\src\lib.rs:10
   5: core::future::from_generator::impl$1::poll<enum2$<async_codegen:🅱️:async_fn_env$0> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
   6: async_codegen:🅰️:async_fn$0
             at .\src\lib.rs:4
   7: core::future::from_generator::impl$1::poll<enum2$<async_codegen:🅰️:async_fn_env$0> >
             at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91
```

whereas now I get a much cleaner stack trace:

```
   3: async_codegen:🅱️:async_fn$0
             at .\src\lib.rs:10
   4: async_codegen:🅰️:async_fn$0
             at .\src\lib.rs:4
```
2022-11-24 17:14:42 +00:00
Arpad Borsos
9f36f988ad
Avoid GenFuture shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
2022-11-24 10:04:27 +01:00
Vadim Petrochenkov
47cd844468 effective visibility: Stop recalculating current private visibility
It becomes relatively expensive if done often and shows up during perf profiling.
2022-11-24 01:30:58 +03:00
Vadim Petrochenkov
7e76d94a22 effective visibility: Always add table entries for nodes used as parents
Previously if the parent was not in the table, and there was nothing to inherit from, the child's private visibility was used, but that's not correct - the parent may have a larger visibility so we should set it to at least the parent's private visibility.
That parent's private visibility is also inserted into the table for caching, so it's not recalculated later if used again.
2022-11-24 01:28:41 +03:00
Vadim Petrochenkov
a45a302be5 effective visibility: Fix private visibility calculation for modules
Optimizations removed in the previous commit required this function to behave incorrectly, but now those optimizations are gone so we can fix the bug.

Fixes https://github.com/rust-lang/rust/issues/104249
2022-11-24 00:03:51 +03:00
Vadim Petrochenkov
f0843b89d1 effective visibility: Remove questionable optimizations
First, they require eagerly calculating private visibility (current normal module), which is somewhat expensive.
Private visibilities are also lost once calculated, instead of being cached in the table.

Second, I cannot prove that the optimizations are correct.
Maybe they can be partially reinstated in the future in cases when it's cheap and provably correct to do them.
They will also probably be merged into `fn update` in that case.

Partially fixes https://github.com/rust-lang/rust/issues/104249
Fixes https://github.com/rust-lang/rust/issues/104539
2022-11-24 00:03:51 +03:00