Commit Graph

687 Commits

Author SHA1 Message Date
bors
879fb42596 Auto merge of #96431 - petrochenkov:parent, r=cjgillot
rustc: Panic by default in `DefIdTree::parent`

Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 14:03:20 +00:00
Vadim Petrochenkov
5b5964f569 rustc: Panic by default in DefIdTree::parent
Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.
2022-05-02 01:56:50 +03:00
bors
4dd8b420c0 Auto merge of #96521 - petrochenkov:docrules, r=notriddle,GuillaumeGomez
rustdoc: Resolve doc links referring to `macro_rules` items

cc https://github.com/rust-lang/rust/issues/81633

UPD: the fallback to considering *all* `macro_rules` in the crate for unresolved names is not removed in this PR, it will be removed separately and will be run through crater.
2022-05-01 20:28:10 +00:00
Vadim Petrochenkov
7841247ca9 resolve: Rename unusable_binding to ignore_binding 2022-05-01 18:02:37 +03:00
Vadim Petrochenkov
f0e0434feb resolve: Merge last_import_segment into Finalize 2022-05-01 18:02:35 +03:00
Vadim Petrochenkov
ffedcec4e8 resolve: Pass full Finalize in nearly all cases 2022-05-01 18:02:01 +03:00
Vadim Petrochenkov
900607f49a resolve: Turn enum Finalize into an optional struct 2022-05-01 17:42:22 +03:00
Vadim Petrochenkov
8b21421873 rustdoc: Track macro_rules scopes during early doc link resolution
This way links referring to `macro_rules` items are resolved correctly
2022-05-01 00:02:15 +03:00
Vadim Petrochenkov
044e45c595 rustdoc: Keep full ParentScope during early doc link resolution 2022-04-30 23:06:48 +03:00
Camille GILLOT
94449e6101 Store all generic bounds as where predicates. 2022-04-30 13:55:13 +02:00
Camille GILLOT
05b29f9a92 Inline WhereClause into Generics. 2022-04-30 13:51:49 +02:00
Camille GILLOT
71b4e2d852 Box HIR Generics and Impl. 2022-04-30 13:51:49 +02:00
bors
76d4862fdd Auto merge of #95776 - cjgillot:ast-lifetimes-static, r=petrochenkov
Enforce static lifetimes in consts during late resolution

This PR moves the handling of implicitly and explicitly static lifetimes in constants from HIR to the AST.
2022-04-30 07:52:18 +00:00
Esteban Kuber
bce5ab2c78 Use newtype enums instead of bool 2022-04-30 02:40:36 +00:00
Esteban Kuber
09f3ea1692 When encountering a binding that could be a const or unit variant, suggest the right path 2022-04-30 02:27:25 +00:00
Camille GILLOT
865d0fef2f Ban non-static lifetimes from AnonConst on AST.
The extra diagnostics come from the compiler no longer aborting before
typeck.
2022-04-30 00:28:42 +02:00
Dylan DPC
2003d833a5
Rollup merge of #96559 - cjgillot:elided-path-fn, r=petrochenkov
Use the correct lifetime binder for elided lifetimes in path.

Fixes https://github.com/rust-lang/rust/issues/96540
2022-04-29 23:54:41 +02:00
Camille GILLOT
6e349c7f07 Remove error variable. 2022-04-29 22:26:22 +02:00
Camille GILLOT
f66de50f8a Use the correct lifetime binder for elided lifetimes in path. 2022-04-29 18:51:21 +02:00
David Wood
73fa217bc1 errors: span_suggestion takes impl ToString
Change `span_suggestion` (and variants) to take `impl ToString` rather
than `String` for the suggested code, as this simplifies the
requirements on the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:05:20 +01:00
Camille GILLOT
a87ab48099 Ban non-static in const generics in AST. 2022-04-29 00:02:49 +02:00
bors
81799cd8fd Auto merge of #96495 - Dylan-DPC:rollup-9lm4tpp, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #96377 (make `fn() -> _ { .. }` suggestion MachineApplicable)
 - #96397 (Make EncodeWide implement FusedIterator)
 - #96421 (Less `NoDelim`)
 - #96432 (not need `Option` for `dbg_scope`)
 - #96466 (Better error messages when collecting into `[T; n]`)
 - #96471 (replace let else with `?`)
 - #96483 (Add missing `target_feature` to the list of well known cfg names)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-28 01:37:03 +00:00
Dylan DPC
4c628bbb1c
Rollup merge of #96471 - BoxyUwU:let_else_considered_harmful, r=lcnr
replace let else with `?`

r? `@oli-obk`
2022-04-28 02:40:36 +02:00
bors
c95346b8ac Auto merge of #91557 - cjgillot:ast-lifetimes-named, r=petrochenkov
Perform lifetime resolution on the AST for lowering

Lifetime resolution is currently implemented several times. Once during lowering in order to introduce in-band lifetimes, and once in the resolve_lifetimes query. However, due to the global nature of lifetime resolution and how it interferes with hygiene, it is better suited on the AST.

This PR implements a first draft of lifetime resolution on the AST. For now, we specifically target named lifetimes and everything we need to remove lifetime resolution from lowering. Some diagnostics have already been ported, and sometimes made more precise using available hygiene information. Follow-up PRs will address in particular the resolution of anonymous lifetimes on the AST.

We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes.

r? `@petrochenkov`
2022-04-27 23:13:28 +00:00
Camille GILLOT
21b6d23890 Collect extra lifetime parameters during late resolution. 2022-04-27 22:03:26 +02:00
Camille GILLOT
f385f856cd Use LifetimeRes during lowering. 2022-04-27 22:00:15 +02:00
Camille GILLOT
69985f0175 Do not resolve elided lifetimes in path twice. 2022-04-27 21:59:47 +02:00
Ellen
f697955c1e tut tut tut 2022-04-27 08:51:33 +01:00
bors
7417110cef Auto merge of #96246 - SparrowLii:bound_contxet, r=compiler-errors
Add `BoundKind` in `visit_param_bounds` to check questions in bounds

From the FIXME in the impl of `AstValidator`. Better bound checks by adding `BoundCtxt` type parameter to `visit_param_bound`

cc `@ecstatic-morse`
2022-04-25 10:46:58 +00:00
Camille GILLOT
9861bc8d52 Compute has_pub_restricted in the resolver. 2022-04-23 23:03:18 +02:00
Camille GILLOT
423a712a16 Fix lints. 2022-04-23 23:01:19 +02:00
Camille GILLOT
4bbe078d92 Drop vis in Item. 2022-04-23 09:59:24 +02:00
Camille GILLOT
10d10efb21 Stop visiting visibility. 2022-04-23 09:53:45 +02:00
Nixon Enraght-Moony
8fa20e01a5 Remove redundant format!s 2022-04-21 16:46:20 +01:00
SparrowLii
38bd4fbdbd rename to BoundKind and add comments 2022-04-21 10:09:32 +08:00
SparrowLii
4375b36117 Add BoundCtxt in visit_param_bounds to check questions in bounds 2022-04-20 19:06:32 +08:00
Dylan DPC
9fad214593
Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Stop using CRATE_DEF_INDEX outside of metadata encoding.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.  We should not manipulate raw `DefIndex` outside of metadata encoding.
2022-04-19 14:43:21 +02:00
Camille GILLOT
07ee031763 Stop using CRATE_DEF_INDEX.
`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.
2022-04-17 12:14:42 +02:00
Camille GILLOT
a9e13fa553 Lint elided lifetimes in path on the AST. 2022-04-17 11:03:34 +02:00
Camille GILLOT
fc9f25531a Report undeclared lifetimes on AST. 2022-04-17 11:03:34 +02:00
Camille GILLOT
4cfceeabdc Remove is_in_fn_syntax. 2022-04-17 11:03:33 +02:00
Camille GILLOT
e47f66dc0d Visit generics inside visit_fn. 2022-04-17 11:03:33 +02:00
Camille GILLOT
aa2b5ef635 Count number of lifetime parameters in a separate pass. 2022-04-17 11:03:33 +02:00
Dylan DPC
0a8acac7a3
Rollup merge of #95887 - petrochenkov:doclink5, r=cjgillot
resolve: Create dummy bindings for all unresolved imports

Apparently such bindings weren't previously created for all unresolved imports, causing issues like https://github.com/rust-lang/rust/issues/95879.
In this PR I'm trying to create such dummy bindings in a more centralized way by calling `import_dummy_binding` once for all imports in `finalize_imports`.

Fixes https://github.com/rust-lang/rust/issues/95879.
2022-04-16 14:25:55 +02:00
Amanieu d'Antras
dc345d8bff Reimplement lowering of sym operands for asm! so that it also works with global_asm! 2022-04-14 15:32:03 +01:00
Dylan DPC
91813a7175
Rollup merge of #95918 - compiler-errors:issue-95878, r=cjgillot
Delay a bug when we see SelfCtor in ref pattern

Fixes #95878
2022-04-12 23:16:59 +02:00
Dylan DPC
2743c13de0
Rollup merge of #95405 - cjgillot:probe, r=petrochenkov
Move name resolution logic to a dedicated file

The code resolution logic from an Ident is scattered between several files.

The first commits creates `rustc_resolve::probe` module to hold the different mutually recursive functions together. Just a move, no code change.
The following commits attempt to make the logic a bit more readable.

The two fields `last_import_segment` and `unusable_binding` are replaced by function parameters.
In order to manage the fallout, `maybe_` variants of the function are added, dedicated to speculative resolution.

r? `@petrochenkov`
2022-04-12 23:16:56 +02:00
Vadim Petrochenkov
276b946010 Handle unusable_binding more compactly. 2022-04-12 22:07:15 +02:00
Camille GILLOT
b796d92da3 Fix imports. 2022-04-12 19:55:47 +02:00
Camille GILLOT
abbd0b85b2 Move diagnostic methods to the dedicated module. 2022-04-12 19:54:09 +02:00