Commit Graph

718 Commits

Author SHA1 Message Date
hdelc 1e8abe7da2 Make `Target::name` method pass by copy 2022-08-02 16:30:09 -04:00
hdelc 6b37a79581 Refactor `Display` impl for `Target` to `Target::name` method 2022-08-02 09:41:32 -04:00
Camille GILLOT 212a06ee69 Match on TraitItem exhaustively. 2022-08-01 21:39:59 +02:00
Camille GILLOT 110f0656cb Store associated item defaultness in impl_defaultness. 2022-08-01 21:38:16 +02:00
Matthias Krüger e6bb00fff5
Rollup merge of #100003 - nnethercote:improve-size-assertions, r=lqd
Improve size assertions.

- For any file with four or more size assertions, move them into a
  separate module (as is already done for `hir.rs`).
- Add some more for AST nodes and THIR nodes.
- Put the `hir.rs` ones in alphabetical order.

r? `@lqd`
2022-08-01 16:49:33 +02:00
Goldstein d9f28b7b70
fix ICE in Definitions::create_def 2022-08-01 16:15:55 +03:00
Nicholas Nethercote 9037ebba0c Improve size assertions.
- For any file with four or more size assertions, move them into a
  separate module (as is already done for `hir.rs`).
- Add some more for AST nodes and THIR nodes.
- Put the `hir.rs` ones in alphabetical order.
2022-08-01 09:15:05 +10:00
Jack Wrenn bc4a1dea41 Initial (incomplete) implementation of transmutability trait.
This initial implementation handles transmutations between types with specified layouts, except when references are involved.

Co-authored-by: Igor null <m1el.2027@gmail.com>
2022-07-27 17:33:56 +00:00
Camille GILLOT 10be0dd8df Replace LifetimeRes::Anonymous by LifetimeRes::Infer. 2022-07-26 19:00:31 +02:00
Camille GILLOT ab63591f00 Remove the distinction between LifetimeName::Implicit and LifetimeName::Underscore. 2022-07-26 19:00:31 +02:00
bors 6dbae3ad19 Auto merge of #97313 - cjgillot:ast-lifetimes-anon, r=petrochenkov
Resolve function lifetime elision on the AST

~Based on https://github.com/rust-lang/rust/pull/97720~

Lifetime elision for functions is purely syntactic in nature, so can be resolved on the AST.
This PR replicates the elision logic and diagnostics on the AST, and replaces HIR-based resolution by a `delay_span_bug`.

This refactor allows for more consistent diagnostics, which don't have to guess the original code from HIR.

r? `@petrochenkov`
2022-07-25 20:02:55 +00:00
Camille GILLOT 3c5048d2ec Report elision failures on the AST. 2022-07-25 19:19:23 +02:00
Michael Goulet 3eef023da0 Address more nits 2022-07-21 16:43:10 +00:00
Michael Goulet 99c32570bb Do if-expression obligation stuff less eagerly 2022-07-21 07:39:28 +00:00
Camille GILLOT bfd0435fd7 Introduce AnonymousLifetimeRib::Elided and use it for implied 'static. 2022-07-20 22:12:12 +02:00
Michael Woerister 88f6c6d8a0 Remove unused StableMap and StableSet types from rustc_data_structures 2022-07-20 13:11:39 +02:00
Michael Woerister b8138db0ff Use FxIndexMap instead of otherwise unused StableMap for WEAK_ITEMS_REFS. 2022-07-20 12:40:51 +02:00
Dylan DPC 24f0e1499e
Rollup merge of #99119 - TaKO8Ki:remove-string-matching-about-methods, r=cjgillot
Refactor: remove a string matching about methods

This patch remove a string matching about methods and adds some rustfix tests.
2022-07-15 15:53:38 +05:30
Takayuki Maeda 45b88aff10 simplify `suggest_deref_ref_or_into` 2022-07-15 14:29:15 +09:00
Dylan DPC e5a86d7358
Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillot
Implement `for<>` lifetime binder for closures

This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following:

```rust
let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) };
//       ^^^^^^^^^^^--- new!
```

cc ``@Aaron1011`` ``@cjgillot``
2022-07-14 14:14:21 +05:30
Maybe Waffle d2923b4007 Add back expr size checks 2022-07-12 21:00:13 +04:00
Maybe Waffle df4fee9841 Add an indirection for closures in `hir::ExprKind`
This helps bring `hir::Expr` size down, `Closure` was the biggest
variant, especially after `for<>` additions.
2022-07-12 21:00:13 +04:00
Maybe Waffle c2dbd62c7c Lower closure binders to hir & properly check them 2022-07-12 21:00:03 +04:00
Maybe Waffle f89ef3cf66 Comment out expr size check 2022-07-12 16:26:08 +04:00
Ding Xiang Fei 5374688e1d
add tests for async await 2022-07-11 23:20:39 +02:00
Ding Xiang Fei 1cd30e7b32
move else block into the `Local` struct 2022-07-11 23:20:37 +02:00
Ding Xiang Fei 6c529ded86
lower let-else in MIR instead 2022-07-11 23:20:36 +02:00
Dylan DPC 6497130baa
Rollup merge of #99043 - compiler-errors:derive-nit, r=cjgillot
Collapse some weirdly-wrapping derives

self-explanatory
2022-07-09 11:28:07 +05:30
Michael Goulet 69ac8a68af Collapse some weirdly-wrapping derives 2022-07-08 04:36:30 +00:00
Michael Goulet ff9fd36aa4 Implement IntoDiagnosticArg for hir::ConstContext 2022-07-08 03:47:31 +00:00
bors 1517f5de01 Auto merge of #99024 - matthiaskrgr:rollup-8ygpcpg, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #97917 (Implement ExitCodeExt for Windows)
 - #98844 (Reword comments and rename HIR visiting methods.)
 - #98979 (interpret: use AllocRange in UninitByteAccess)
 - #98986 (Fix missing word in comment)
 - #98994 (replace process exit with more detailed exit in src/bootstrap/*.rs)
 - #98995 (Add a test for #80471)
 - #99002 (suggest adding a derive for #[default] applied to variants)
 - #99004 (Add a test for #70408)
 - #99017 (Replace boolean argument for print_where_clause with an enum to make code more clear)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-07 20:55:34 +00:00
Camille GILLOT 111df9e6ed Reword comments and rename HIR visiting methods. 2022-07-07 16:01:43 +02:00
Camille GILLOT 250c71b85d Make AST lowering a query. 2022-07-06 23:04:55 +02:00
Cameron Steffen ec82bc1996 Factor out hir::Node::Binding 2022-07-01 10:04:19 -05:00
bors 66c83ffca1 Auto merge of #98558 - nnethercote:smallvec-1.8.1, r=lqd
Update `smallvec` to 1.8.1.

This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.

r? `@lqd`
2022-06-29 09:11:29 +00:00
bors 5ffa8f67b7 Auto merge of #98222 - cjgillot:single-wf, r=michaelwoerister
Only keep a single query for well-formed checking

There are currently 3 queries to perform wf checks on different item-likes.  This complexity is not required.

This PR replaces the query by:
- one query per item;
- one query to invoke it for a whole module.

This allows to remove HIR `ParItemLikeVisitor`.
2022-06-28 03:44:33 +00:00
Nicholas Nethercote 7c40661ddb Update `smallvec` to 1.8.1.
This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.
2022-06-27 08:48:55 +10:00
bors 10f4ce324b Auto merge of #98279 - cjgillot:all-fresh-nofn, r=petrochenkov
Create elided lifetime parameters for function-like types

Split from https://github.com/rust-lang/rust/pull/97720

This PR refactor lifetime generic parameters in bare function types and parenthesized traits to introduce the additional required lifetimes as fresh parameters in a `for<>` bound.

This PR does the same to lifetimes appearing in closure signatures, and as-if introducing `for<>` bounds on closures (without the associated change in semantics).

r? `@petrochenkov`
2022-06-22 10:48:58 +00:00
Camille GILLOT 9ae2546907 Only keep a single well-formed query. 2022-06-21 23:56:17 +02:00
Camille GILLOT 7437136f0e Use CreateParameter mode for closures too. 2022-06-21 21:13:43 +02:00
Camille GILLOT 32af719b07 Always create parameters for functions-like types. 2022-06-21 21:13:41 +02:00
Camille GILLOT bc6a2c11ee Leave the responsibility to create `Fresh` lifetimes to lowering. 2022-06-19 22:32:43 +02:00
Matthias Krüger f351f347b8
Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-se
once cell renamings

This PR does the renamings proposed in https://github.com/rust-lang/rust/issues/74465#issuecomment-1153703128

- Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`
- Move/rename `lazy::{SyncOnceCell, SyncLazy}` to `sync::{OnceLock, LazyLock}`

(I used `Lazy...` instead of `...Lazy` as it seems to be more consistent, easier to pronounce, etc)

```@rustbot``` label +T-libs-api -T-libs
2022-06-19 00:17:13 +02:00
bors cdcc53b7dc Auto merge of #98153 - nnethercote:fix-MissingDoc-quadratic-behaviour, r=cjgillot
Fix `MissingDoc` quadratic behaviour

Best reviewed one commit at a time.

r? `@cjgillot`
2022-06-18 09:57:00 +00:00
bors 3a8b0144c8 Auto merge of #98106 - cjgillot:split-definitions, r=michaelwoerister
Split up `Definitions` and `ResolverAstLowering`.

Split off https://github.com/rust-lang/rust/pull/95573

r? `@michaelwoerister`
2022-06-17 10:00:11 +00:00
Maybe Waffle c1a2db3372 Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock` 2022-06-16 19:54:42 +04:00
Nicholas Nethercote c9e97251ad Remove unused `hir_id` arg from `visit_attribute`. 2022-06-16 09:52:04 +10:00
Yuki Okushi 87e373e82f
Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011
Make `ExprKind::Closure` a struct variant.

Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`.

r? ``@Aaron1011``
2022-06-15 19:37:14 +09:00
Camille GILLOT 34e4d72929 Separate `source_span` and `expn_that_defined` from `Definitions`. 2022-06-14 22:45:51 +02:00
Camille GILLOT 603746a35e Make ResolverAstLowering a struct. 2022-06-14 22:44:27 +02:00
klensy 4ea4e2e76d remove currently unused deps 2022-06-13 22:20:51 +03:00
Michael Goulet 5f7474e6dc Address comments 2022-06-11 16:38:48 -07:00
Michael Goulet 9c47afe9fa Handle empty where-clause better 2022-06-11 16:27:01 -07:00
Camille GILLOT 3039cfeb6a Make `ExprKind::Closure` a struct variant. 2022-06-12 00:16:27 +02:00
kyoto7250 3685a1e9d2 feat(fix): update some links 2022-06-11 23:19:58 +09:00
Michael Goulet 2ae1ec9119 Don't suggest adding let in certain if conditions 2022-06-07 21:02:58 -07:00
Dylan DPC a736acc804
Rollup merge of #97312 - cjgillot:no-path-in-scope, r=compiler-errors
Compute lifetimes in scope at diagnostic time

The set of available lifetimes is currently computed during lifetime resolution on HIR.  It is only used for one diagnostic.

In this PR, HIR lifetime resolution just reports whether elided lifetimes are well-defined at the place of use.  The diagnostic code is responsible for building a list of lifetime names if elision is not allowed.

This will allow to remove lifetime resolution on HIR eventually.
2022-06-06 14:34:55 +02:00
Matthias Krüger f2b3808920
Rollup merge of #97683 - cjgillot:no-apit-hrtb, r=nagisa
Fail gracefully when encountering an HRTB in APIT.

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

~The first commit will be merged as part of https://github.com/rust-lang/rust/pull/97415~
2022-06-06 08:37:00 +02:00
Camille GILLOT a07290047e Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
Camille GILLOT 623ea5f5d2 Make hir().get_generics and generics_of consistent. 2022-06-03 23:07:04 +02:00
Camille GILLOT bacd8adeda Fail gracefully when encountering an HRTB in APIT. 2022-06-03 22:50:14 +02:00
Camille GILLOT b1294e86bb Manipulate lifetimes by LocalDefId for region resolution. 2022-06-03 12:03:20 +02:00
Dylan DPC 5c041f98fa
Rollup merge of #97023 - cjgillot:uniform-anon, r=estebank
Diagnose anonymous lifetimes errors more uniformly between async and regular fns

Async fns and regular fns are desugared differently.  For the former, we create a generic parameter at HIR level.  For the latter, we just create an anonymous region for typeck.

I plan to migrate regular fns to the async fn desugaring.

Before that, this PR attempts to merge the diagnostics for both cases.

r? ```@estebank```
2022-06-02 11:13:22 +02:00
Yuki Okushi c7db4b08ff
Apply track_caller to closure on `expect_non_local()` 2022-05-31 23:57:13 +09:00
Oli Scherer 0e3d8d2b13 Default methods of traits are also AssocFn defs as they essentially desugar to a method in a new impl block 2022-05-30 08:52:25 +00:00
Camille GILLOT da175c743c Make lifetime errors more precise in the presence of `Fresh` lifetimes. 2022-05-29 12:16:09 +02:00
Michael Goulet b2a95cb582 Lifetime variance fixes for rustdoc 2022-05-22 14:22:40 -07:00
Ding Xiang Fei 6044fbe462
factor out the rvalue lifetime rule
remove region_scope_tree from RegionCtxt

Apply suggestions from code review

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2022-05-22 16:46:50 +08:00
Guillaume Gomez 54e36ef1b3
Rollup merge of #97223 - cjgillot:linear-hir-tree, r=jackh726
Remove quadratic behaviour from -Zunpretty=hir-tree.

Closes https://github.com/rust-lang/rust/issues/97115
2022-05-21 11:39:51 +02:00
bors 4f372b14de Auto merge of #97239 - jhpratt:remove-crate-vis, r=joshtriplett
Remove `crate` visibility modifier

FCP to remove this syntax is just about complete in #53120. Once it completes, this should be merged ASAP to avoid merge conflicts.

The first two commits remove usage of the feature in this repository, while the last removes the feature itself.
2022-05-21 06:38:49 +00:00
Jacob Pratt 49c82f31a8
Remove `crate` visibility usage in compiler 2022-05-20 20:04:54 -04:00
bors e6a4afc3af Auto merge of #95418 - cjgillot:more-disk, r=davidtwco
Cache more queries on disk

One of the principles of incremental compilation is to allow saving results on disk to avoid recomputing them.
This PR investigates persisting a lot of queries whose result are to be saved into metadata.
Some of the queries are cheap reads from HIR, but we may also want to get rid of these reads for incremental lowering.
2022-05-20 20:49:55 +00:00
Camille GILLOT cd90406090 Remove quadratic behaviour from -Zunpretty=hir-tree. 2022-05-20 19:34:31 +02:00
Eric Holk 7d1dbdf3de Update IfLet syntax 2022-05-19 16:32:06 -07:00
Eric Holk d08efdec1c Borrow guard patterns for the body of the guard 2022-05-19 16:23:28 -07:00
bors 07ae142d77 Auto merge of #96863 - SparrowLii:let, r=michaelwoerister
use `hir::Let` in `hir::Guard::IfLet`

This PR fixes the FIXME about using `hir::Let` in `hir::Guard::IfLet`
2022-05-18 17:48:46 +00:00
Miguel Guarniz f975d05116 rename visit item-like methods
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Miguel Guarniz 7e44078e9a update comments about visitor strategy
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Miguel Guarniz 93616dd539 remove ItemLikeVisitor and DeepVisitor
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13 11:46:06 -04:00
Camille GILLOT 9900ea352b Cache more queries on disk. 2022-05-13 08:06:48 +02:00
Camille GILLOT dde7bff574 Replace DefPathData::Misc by two appropriately-named variants. 2022-05-12 20:12:35 +02:00
lcnr 32b13ac928 review 2022-05-09 18:40:18 +02:00
SparrowLii 5251a80c0a use hir::Let in hir::Guard 2022-05-09 20:35:58 +08:00
bors ed3164baf0 Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot
Track if a where bound comes from a impl Trait desugar

With https://github.com/rust-lang/rust/pull/93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a `impl Trait` or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during AST->HIR lowering.

r? `@cjgillot`

cc `@estebank` (as the reviewer of #93803)
2022-05-08 14:10:12 +00:00
flip1995 dd1ff405e3
Track if a where bound comes from a impl Trait desugar
With #93803 `impl Trait` function arguments get desugared to hidden
where bounds. However, Clippy needs to know if a bound was originally a
impl Trait or an actual bound. This adds a field to the
`WhereBoundPredicate` struct to keep track of this information during
HIR lowering.
2022-05-07 17:10:30 +02:00
bors 574830f573 Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errors
Begin fixing all the broken doctests in `compiler/`

Begins to fix #95994.
All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are.
There are also a few that I marked `ignore` that could maybe be made to work but seem less important.
Each `ignore` has a rough "reason" for ignoring after it parentheses, with

- `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax"
- `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.
- `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR.
- `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup.

Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.

I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-07 06:30:29 +00:00
Wei Liu fcb385cfb1 Use matches! for YieldSource::is_await 2022-05-06 15:00:48 +00:00
Wei Liu 85e688e4c3 Fix comment for async closure variant 2022-05-06 14:59:40 +00:00
lcnr 209dd2cb0a generalize "incoherent impls" impl for custom types 2022-05-05 10:53:00 +02:00
bors 1b2e0b60cc Auto merge of #95380 - compiler-errors:unit-destructure-assign, r=nikomatsakis
Fix unit struct/enum variant in destructuring assignment

See https://github.com/rust-lang/rfcs/blob/master/text/2909-destructuring-assignment.md#guide-level-explanation, "including **unit** and tuple structs"

Fixes #94319
2022-05-03 22:29:58 +00:00
Elliot Roberts 7907385999 fix most compiler/ doctests 2022-05-02 17:40:30 -07:00
Scott McMurray e094ee5f10 Add `do yeet` expressions to allow experimentation in nightly
Using an obviously-placeholder syntax.  An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point.

But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
2022-04-30 17:40:27 -07:00
Cameron Steffen 61ba32b768 Update intravisit docs 2022-04-30 12:27:27 -05:00
Camille GILLOT 39c67b2133 Correct comment. 2022-04-30 13:55:17 +02:00
Camille GILLOT 74583852e8 Save colon span to suggest bounds. 2022-04-30 13:55:17 +02: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 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 f385f856cd Use LifetimeRes during lowering. 2022-04-27 22:00:15 +02:00
Camille GILLOT 38a4c2cc44 Update comment. 2022-04-27 21:59:47 +02:00
George 14a127be3e Add new diagnostic 2022-04-26 17:04:44 -04:00
Camille GILLOT 4bbe078d92 Drop vis in Item. 2022-04-23 09:59:24 +02:00
Camille GILLOT a6e3124d2c Drop vis in ImplItem. 2022-04-23 09:57:00 +02:00
Camille GILLOT 2827007d32 Drop vis from ForeignItem. 2022-04-23 09:56:37 +02:00
Camille GILLOT a62680d108 Drop vis in FieldDef. 2022-04-23 09:56:15 +02:00
Camille GILLOT 10d10efb21 Stop visiting visibility. 2022-04-23 09:53:45 +02:00
bors 27af517549 Auto merge of #96082 - michaelwoerister:less_impl_stable_hash_via_hash, r=compiler-errors
incr. comp.: Don't export impl_stable_hash_via_hash!() and warn about using it.

Fixes https://github.com/rust-lang/rust/issues/96013.
2022-04-20 03:51:09 +00: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
Michael Woerister c0be619724 incr. comp.: Don't export impl_stable_hash_via_hash!() and warn about using it. 2022-04-19 10:43:20 +02:00
bors 1ec2c136b3 Auto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov
Report undeclared lifetimes during late resolution.

First step in https://github.com/rust-lang/rust/pull/91557

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-17 12:56:19 +00: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
bors edba282770 Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
Refactor HIR item-like traversal (part 1)

Issue  #95004

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>

cc `@cjgillot`
2022-04-17 08:06:53 +00:00
bors 080d5452e1 Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisa
Implement sym operands for global_asm!

Tracking issue: #93333

This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are:
- At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`.
- At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails).
  - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`.
  - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to.
- The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression.
- At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details.
  - On Mach-O, all symbols have a leading underscore.
  - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall.
  - No mangling is needed on other platforms.

r? `@nagisa`
cc `@eddyb`
2022-04-16 04:46:01 +00:00
Dylan DPC bdbf0998f3
Rollup merge of #95194 - kckeiks:update-algo-in-find-use-placement, r=pnkfelix
remove find_use_placement

A more robust solution to finding where to place use suggestions was added in #94584.
The algorithm uses the AST to find the span for the suggestion so we pass this span
down to the HIR during lowering and use it instead of calling `find_use_placement`

Fixes #94941
2022-04-15 20:50:45 +02:00
Vadim Petrochenkov 5bee741a08 library: Move `CStr` to libcore, and `CString` to liballoc 2022-04-14 21:53:11 +03: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
bors f38c5c8e5d Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011
Remove NodeIdHashingMode.

r? `@ghost`
2022-04-13 11:27:17 +00:00
Dylan DPC d63a46ad28
Rollup merge of #95970 - WaffleLapkin:nicer_trait_suggestions, r=compiler-errors
Fix suggestions in case of `T:` bounds

This PR fixes a corner case in `suggest_constraining_type_params` that was causing incorrect suggestions.

For the following functions:
```rust
fn a<T:>(t: T) { [t, t]; }
fn b<T>(t: T) where T: { [t, t]; }
```

We previously suggested the following:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy:>(t: T) { [t, t]; }
  |       ++++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: + Copy { [t, t]; }
  |                        ++++++
```

Note that neither `T: Copy:` not `where T: + Copy` is a correct bound.

With this commit the suggestions are correct:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy>(t: T) { [t, t]; }
  |         ++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: Copy { [t, t]; }
  |                        ++++
```

r? `@compiler-errors`

I've tried fixing #95898 here too, but got too confused with how `suggest_traits_to_import` works and what it does 😅
2022-04-12 23:17:00 +02:00
Camille GILLOT 443333dc1f Remove NodeIdHashingMode. 2022-04-12 19:59:32 +02:00
Maybe Waffle de2edb226b Fix wrong suggestions for `T:`
This commit fixes a corner case in `suggest_constraining_type_params`
that was causing incorrect suggestions.

For the following functions:
```rust
fn a<T:>(t: T) { [t, t]; }
fn b<T>(t: T) where T: { [t, t]; }
```
We previously suggested the following:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy:>(t: T) { [t, t]; }
  |       ++++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: + Copy { [t, t]; }
  |                        ++++++
```
Note that neither `T: Copy:` not `where T: + Copy` is a correct bound.

With this commit the suggestions are correct:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy>(t: T) { [t, t]; }
  |         ++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: Copy { [t, t]; }
  |                        ++++
```
2022-04-12 11:29:23 +04:00
Camille GILLOT db03a2deb0 Avoid accessing HIR from MIR queries. 2022-04-10 13:08:36 +02:00
Miguel Guarniz 88108bd5d9 add comment about restriction of Target::from_def_kind 2022-04-09 16:03:16 -04:00
Camille GILLOT f89d64d7aa Use def_key in `tcx.item_name` when possible. 2022-04-09 10:54:43 +02:00
Miguel Guarniz d2840d237c add mapping from DefKind to Target and remove more ItemLikeVisitor impls
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-04-08 12:00:23 -04:00
Michael Goulet 17f5c4d255 Fix unit struct/enum variant in destructuring assignment 2022-04-06 19:28:27 -07:00
David Wood c45f29595d span: move `MultiSpan`
`MultiSpan` contains labels, which are more complicated with the
introduction of diagnostic translation and will use types from
`rustc_errors` - however, `rustc_errors` depends on `rustc_span` so
`rustc_span` cannot use types like `DiagnosticMessage` without
dependency cycles. Introduce a new `rustc_error_messages` crate that can
contain `DiagnosticMessage` and `MultiSpan`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:00 +01:00
Fausto 8c2353b6c1 remove find_use_placement
A more robust solution to finding where to place use suggestions was added.
The algorithm uses the AST to find the span for the suggestion so we pass this span
down to the HIR during lowering and use it.

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-03-31 17:20:03 -04:00
Camille GILLOT c10a1cebe7 Store next_disambiguator in Definitions. 2022-03-31 13:34:54 +02:00
bors a40c595695 Auto merge of #95436 - cjgillot:static-mut, r=oli-obk
Remember mutability in `DefKind::Static`.

This allows to compute the `BodyOwnerKind` from `DefKind` only, and
removes a direct dependency of some MIR queries onto HIR.

As a side effect, it also simplifies metadata, since we don't need 4
flavours of `EntryKind::*Static` any more.
2022-03-30 22:09:56 +00:00
bors 3e7514670d Auto merge of #94963 - lcnr:inherent-impls-std, r=oli-obk,m-ou-se
allow arbitrary inherent impls for builtin types in core

Part of https://github.com/rust-lang/compiler-team/issues/487. Slightly adjusted after some talks with `@m-ou-se` about the requirements of `t-libs-api`.

This adds a crate attribute `#![rustc_coherence_is_core]` which allows arbitrary impls for builtin types in core.

For other library crates impls for builtin types should be avoided if possible. We do have to allow the existing stable impls however. To prevent us from accidentally adding more of these in the future, there is a second attribute `#[rustc_allow_incoherent_impl]` which has to be added to **all impl items**. This only supports impls for builtin types but can easily be extended to additional types in a future PR.

This implementation does not check for overlaps in these impls. Perfectly checking that requires us to check the coherence of these incoherent impls in every crate, as two distinct dependencies may add overlapping methods. It should be easy enough to detect if it goes wrong and the attribute is only intended for use inside of std.

The first two commits are mostly unrelated cleanups.
2022-03-30 12:28:50 +00:00
lcnr afbecc0f68 remove now unnecessary lang items 2022-03-30 11:23:58 +02:00
Dylan DPC 03b3993ae8
Rollup merge of #95461 - nyurik:spelling, r=lcnr
Spellchecking some comments

This PR attempts to clean up some minor spelling mistakes in comments
2022-03-30 09:10:07 +02:00
Yuri Astrakhan a9cc3f6564 Spellchecking compiler code
Address some spelling mistakes in strings, private function names, and function params.
2022-03-30 01:42:10 -04:00
Yuri Astrakhan 7e8201ae0a Spellchecking some comments
This PR attempts to clean up some minor spelling mistakes in comments
2022-03-30 01:39:38 -04:00
Camille GILLOT 21a554caf6 Remember mutability in `DefKind::Static`.
This allows to compute the `BodyOwnerKind` from `DefKind` only, and
removes a direct dependency of some MIR queries onto HIR.

As a side effect, it also simplifies metadata, since we don't need 4
flavours of `EntryKind::*Static` any more.
2022-03-29 18:50:52 +02:00
Deadbeef 1f3ee7f32e
Rename `~const Drop` to `~const Destruct` 2022-03-21 17:04:03 +11:00
Deadbeef 4df2a28aee
Add `Destructible` for replacing `~const Drop` 2022-03-21 17:04:02 +11:00
Scott McMurray 1338a45d98 Give more details in `Display` for `hir::Target`
Made because I was making a code change and got a very confusing "should be applied to a method, not a method" error.

```
error[E0718]: `into_try_type` language item must be applied to a method
   --> library\core\src\ops\try_trait.rs:352:32
    |
352 |     #[cfg_attr(not(bootstrap), lang = "into_try_type")]
    |                                ^^^^^^^^^^^^^^^^^^^^^^ attribute should be applied to a method, not a method
```
2022-03-19 02:03:37 -07:00
Camille GILLOT d3b7ea6c9e Identify anonymous lifetimes by their DefId in HIR. 2022-03-12 14:18:56 +01:00
lcnr b8135fd5c8 add `#[rustc_pass_by_value]` to more types 2022-03-08 15:39:52 +01:00
cuishuang eb2b9441e7 compiler: fix some typos 2022-03-01 20:02:47 +08:00
Michael Goulet bb548a918a Remove in-band lifetimes 2022-02-24 18:50:33 -08:00
Vadim Petrochenkov 17b1afdbb2 resolve: Fix incorrect results of `opt_def_kind` query for some built-in macros
Previously it always returned `MacroKind::Bang` while some of those macros are actually attributes and derives
2022-02-24 22:54:36 +03:00
bors 8ebec97e09 Auto merge of #93438 - spastorino:node_id_to_hir_id_refactor, r=oli-obk
Node id to hir id refactor

Related to #89278

r? `@oli-obk`
2022-02-24 01:26:57 +00:00
Matthias Krüger 8bb6051317
Rollup merge of #94137 - aDotInTheVoid:abi-enum, r=CraftSpider
rustdoc-json: Better Header Type

- Make ABI an enum, instead of being stringly typed
- Replace Qualifier HashSet with 3 bools
- Merge ABI field into header, as they always occor together

r? ``@CraftSpider``

``@rustbot`` modify labels: +A-rustdoc-json +T-rustdoc
2022-02-23 12:26:41 +01:00
Camille GILLOT 04d5f41c97
Make node_id_to_hir_id owner-local. 2022-02-20 10:17:27 -03:00
est31 2ef8af6619 Adopt let else in more places 2022-02-19 17:27:43 +01:00
Nixon Enraght-Moony aa601574a5 rustdoc-json: Better Header Type
- Make ABI an enum, instead of being stringly typed
- Replace Qualifier HashSet with 3 bools
- Merge ABI field into header, as they always occor together
2022-02-18 23:31:33 +00:00
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
Ellen 5e0e7ff068 trailing whitespace 2022-02-12 11:48:58 +00:00
Ellen 9130af2e4d change docs on `Res::SelfTy` 2022-02-12 11:23:53 +00:00
Ellen e81e09a24e change to a struct variant 2022-02-12 11:23:53 +00:00
Deadbeef 6d6314f878
Rebased and improved errors 2022-02-12 19:24:42 +11:00
Deadbeef f7f0f843b7
Improve error messages even more 2022-02-12 19:24:08 +11:00
Matthias Krüger de0feb30bd
Rollup merge of #93910 - rosehuds:master, r=cjgillot
fix mention of moved function in `rustc_hir` docs

The function was moved from `Crate` to `Map` in db9fea508a but these docs weren't updated
2022-02-11 21:48:52 +01:00
Rose Hudson 45dc8ebb7c fix mention of moved function in `rustc_hir` docs
the function was moved from `Crate` to `Map` in db9fea508a but the
docs weren't updated
2022-02-11 15:38:31 +00: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
Matthias Krüger 8611e292e4
Rollup merge of #93443 - spastorino:add-stable-hash-impl-doc, r=cjgillot
Add comment on stable_hash_impl for OwnerNodes

r? `@cjgillot`

cc `@oli-obk`

`@bors` rollup=always
2022-02-11 07:48:03 +01:00
Frank Steffahn 89ac81a6e6 Make all hir::Map methods consistently by-value
(hir::Map only consists of a single reference anyways)
2022-02-10 11:54:06 +01:00
Yuki Okushi e5ac08779b
Rollup merge of #93746 - cjgillot:nodefii, r=nikomatsakis
Remove defaultness from ImplItem.

This information is not really used anywhere, except HIR pretty-printing. This makes ImplItem and TraitItem more similar.
2022-02-09 14:12:22 +09:00
bors 25b21a1d16 Auto merge of #93179 - Urgau:unreachable-2021, r=m-ou-se,oli-obk
Fix invalid special casing of the unreachable! macro

This pull-request fix an invalid special casing of the `unreachable!` macro in the same way the `panic!` macro was solved, by adding two new internal only macros `unreachable_2015` and `unreachable_2021` edition dependent and turn `unreachable!` into a built-in macro that do dispatching. This logic is stolen from the `panic!` macro.

~~This pull-request also adds an internal feature `format_args_capture_non_literal` that allows capturing arguments from formatted string that expanded from macros. The original RFC #2795 mentioned this as a future possibility. This feature is [required](https://github.com/rust-lang/rust/issues/92137#issuecomment-1018630522) because of concatenation that needs to be done inside the macro:~~
```rust
$crate::concat!("internal error: entered unreachable code: ", $fmt)
```

**In summary** the new behavior for the `unreachable!` macro with this pr is:

Edition 2021:
```rust
let x = 5;
unreachable!("x is {x}");
```
```
internal error: entered unreachable code: x is 5
```

Edition <= 2018:
```rust
let x = 5;
unreachable!("x is {x}");
```
```
internal error: entered unreachable code: x is {x}
```

Also note that the change in this PR are **insta-stable** and **breaking changes** but this a considered as being a [bug](https://github.com/rust-lang/rust/issues/92137#issuecomment-998441613).
If someone could start a perf run and then a crater run this would be appreciated.

Fixes https://github.com/rust-lang/rust/issues/92137
2022-02-07 00:26:52 +00:00
Camille GILLOT 710662c8ac Remove defaultness from ImplItem. 2022-02-03 18:56:08 +01:00
bors 1ea4851715 Auto merge of #93285 - JulianKnodt:const_eq_2, r=oli-obk
Continue work on associated const equality

This actually implements some more complex logic for assigning associated consts to values.
Inside of projection candidates, it now defers to a separate function for either consts or
types. To reduce amount of code, projections are now generic over T, where T is either a Type or
a Const. I can add some comments back later, but this was the fastest way to implement it.

It also now finds the correct type of consts in type_of.

---

The current main TODO is finding the const of the def id for the LeafDef.

Right now it works if the function isn't called, but once you use the trait impl with the bound it fails inside projection.
I was hoping to get some help in getting the `&'tcx ty::Const<'tcx>`, in addition to a bunch of other `todo!()`s which I think may not be hit.

r? `@oli-obk`

Updates #92827
2022-02-01 23:18:01 +00:00
kadmin 78fb74a600 Fix w/ comments 2022-02-01 20:19:54 +00:00
Loïc BRANSTETT a4b93eb188 Take in account the unreachable! macro in the non_fmt_panic lint 2022-01-31 17:09:31 +01:00
Santiago Pastorino 5f7b989275
Add comment on stable_hash_impl for OwnerNodes 2022-01-28 18:06:53 -03: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
Camille GILLOT 80132c3ce4
Store hir_id_to_def_id in OwnerInfo. 2022-01-25 15:05:19 -03:00
Matthias Krüger 9d7c8edd6c
Rollup merge of #92828 - Amanieu:unwind-abort, r=dtolnay
Print a helpful message if unwinding aborts when it reaches a nounwind function

This is implemented by routing `TerminatorKind::Abort` back through the panic handler, but with a special flag in the `PanicInfo` which indicates that the panic handler should *not* attempt to unwind the stack and should instead abort immediately.

This is useful for the planned change in https://github.com/rust-lang/lang-team/issues/97 which would make `Drop` impls `nounwind` by default.

### Code

```rust
#![feature(c_unwind)]

fn panic() {
    panic!()
}

extern "C" fn nounwind() {
    panic();
}

fn main() {
    nounwind();
}
```

### Before

```
$ ./test
thread 'main' panicked at 'explicit panic', test.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Illegal instruction (core dumped)
```

### After

```
$ ./test
thread 'main' panicked at 'explicit panic', test.rs:4:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'panic in a function that cannot unwind', test.rs:7:1
stack backtrace:
   0:     0x556f8f86ec9b - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdccefe11a6ac4396
   1:     0x556f8f88ac6c - core::fmt::write::he152b28c41466ebb
   2:     0x556f8f85d6e2 - std::io::Write::write_fmt::h0c261480ab86f3d3
   3:     0x556f8f8654fa - std::panicking::default_hook::{{closure}}::h5d7346f3ff7f6c1b
   4:     0x556f8f86512b - std::panicking::default_hook::hd85803a1376cac7f
   5:     0x556f8f865a91 - std::panicking::rust_panic_with_hook::h4dc1c5a3036257ac
   6:     0x556f8f86f079 - std::panicking::begin_panic_handler::{{closure}}::hdda1d83c7a9d34d2
   7:     0x556f8f86edc4 - std::sys_common::backtrace::__rust_end_short_backtrace::h5b70ed0cce71e95f
   8:     0x556f8f865592 - rust_begin_unwind
   9:     0x556f8f85a764 - core::panicking::panic_no_unwind::h2606ab3d78c87899
  10:     0x556f8f85b910 - test::nounwind::hade6c7ee65050347
  11:     0x556f8f85b936 - test::main::hdc6e02cb36343525
  12:     0x556f8f85b7e3 - core::ops::function::FnOnce::call_once::h4d02663acfc7597f
  13:     0x556f8f85b739 - std::sys_common::backtrace::__rust_begin_short_backtrace::h071d40135adb0101
  14:     0x556f8f85c149 - std::rt::lang_start::{{closure}}::h70dbfbf38b685e93
  15:     0x556f8f85c791 - std::rt::lang_start_internal::h798f1c0268d525aa
  16:     0x556f8f85c131 - std::rt::lang_start::h476a7ee0a0bb663f
  17:     0x556f8f85b963 - main
  18:     0x7f64c0822b25 - __libc_start_main
  19:     0x556f8f85ae8e - _start
  20:                0x0 - <unknown>
thread panicked while panicking. aborting.
Aborted (core dumped)
```
2022-01-22 15:32:49 +01:00
Cameron Steffen b11733534d Remove a span from hir::ExprKind::MethodCall 2022-01-21 07:48:10 -06:00
bors 523be2e05d Auto merge of #93138 - matthiaskrgr:rollup-m8akifd, r=matthiaskrgr
Rollup of 17 pull requests

Successful merges:

 - #91032 (Introduce drop range tracking to generator interior analysis)
 - #92856 (Exclude "test" from doc_auto_cfg)
 - #92860 (Fix errors on blanket impls by ignoring the children of generated impls)
 - #93038 (Fix star handling in block doc comments)
 - #93061 (Only suggest adding `!` to expressions that can be macro invocation)
 - #93067 (rustdoc mobile: fix scroll offset when jumping to internal id)
 - #93086 (Add tests to ensure that `let_chains` works with `if_let_guard`)
 - #93087 (Fix src/test/run-make/raw-dylib-alt-calling-convention)
 - #93091 (⬆ chalk to 0.76.0)
 - #93094 (src/test/rustdoc-json: Check for `struct_field`s in `variant_tuple_struct.rs`)
 - #93098 (Show a more informative panic message when `DefPathHash` does not exist)
 - #93099 (rustdoc: auto create output directory when "--output-format json")
 - #93102 (Pretty printer algorithm revamp step 3)
 - #93104 (Support --bless for pp-exact pretty printer tests)
 - #93114 (update comment for `ensure_monomorphic_enough`)
 - #93128 (Add script to prevent point releases with same number as existing ones)
 - #93136 (Backport the 1.58.1 release notes to master)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-21 03:04:43 +00:00
Aaron Hill 70d36a05bc
Show a more informative panic message when `DefPathHash` does not exist
This should hopefully make it easier to debug incremental compilation
bugs like #93096 without affecting performance.
2022-01-19 17:36:44 -05:00
Tyler Mandry 5c15ad7fca NiceRegionError: Use written return type for async fn 2022-01-19 21:33:57 +00:00
bors 7bc7be860f Auto merge of #87648 - JulianKnodt:const_eq_constrain, r=oli-obk
allow eq constraints on associated constants

Updates #70256

(cc `@varkor,` `@Centril)`
2022-01-18 09:58:39 +00:00
kadmin 67f56671d0 Use Term in ProjectionPredicate
ProjectionPredicate should be able to handle both associated types and consts so this adds the
first step of that. It mainly just pipes types all the way down, not entirely sure how to handle
consts, but hopefully that'll come with time.
2022-01-17 17:44:56 +00:00
kadmin 0765999622 add eq constraints on associated constants 2022-01-17 17:20:57 +00:00
bors ee5d8d37ba Auto merge of #90986 - camsteffen:nested-filter, r=cjgillot
Replace `NestedVisitorMap` with generic `NestedFilter`

This is an attempt to make the `intravisit::Visitor` API simpler and "more const" with regard to nested visiting.

With this change, `intravisit::Visitor` does not visit nested things by default, unless you specify `type NestedFilter = nested_filter::OnlyBodies` (or `All`). `nested_visit_map` returns `Self::Map` instead of `NestedVisitorMap<Self::Map>`. It panics by default (unreachable if `type NestedFilter` is omitted).

One somewhat trixty thing here is that `nested_filter::{OnlyBodies, All}` live in `rustc_middle` so that they may have `type Map = map::Map` and so that `impl Visitor`s never need to specify `type Map` - it has a default of `Self::NestedFilter::Map`.
2022-01-17 14:50:50 +00:00
bors a34c079752 Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes #70173.
Closes #92794.
Closes #87612.
Closes #82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
2022-01-17 09:40:29 +00:00
Amanieu d'Antras fe9dc6e62a Change TerminatorKind::Abort to call the panic handler instead of
aborting immediately.

The panic handler is called with a special flag which forces it to abort
after calling the panic hook.
2022-01-17 00:39:34 +00:00
Cameron Steffen 45db716902 Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
Camille GILLOT 8617ff0f0b Add inline. 2022-01-15 21:26:25 +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
Ellen 61c07a9a23 reviews ish 2022-01-14 13:45:07 +00:00
Ellen 73945fd620 fix bug 2022-01-14 00:27:12 +00:00
Tomasz Miąsko 000b36c505 Remove deprecated LLVM-style inline assembly 2022-01-12 18:51:31 +01:00
Matthias Krüger 6719e3eb18
Rollup merge of #92702 - ehuss:clean-lang_items-extract, r=petrochenkov
Clean up lang_items::extract

Noted in https://github.com/rust-lang/rust/pull/87739#pullrequestreview-740497194,
lang_items::extract no longer needs to take a closure.
2022-01-10 11:03:11 +01:00
Eric Huss 2b7572092c Clean up lang_items::extract
Noted in https://github.com/rust-lang/rust/pull/87739#pullrequestreview-740497194,
lang_items::extract no longer needs to take a closure.
2022-01-09 13:41:04 -08:00
bors 092e1c9d23 Auto merge of #92534 - Aaron1011:hash-hir, r=petrochenkov
Hash `Ident` spans in all HIR structures

This PR removes all of the `#[stable_hasher(project(name))]`
attributes used in HIR structs. While these attributes are not known
to be causing any issues in practice, we need to hash these in
order for the incremental system to work correctly -
a query could be otherwise be incorrectly marked green
when a change occures in one of the `Span`s that it uses.
2022-01-09 16:03:41 +00:00
Camille GILLOT 1be6e2d6e9 Link impl items to corresponding trait items in late resolver. 2022-01-08 20:45:59 +01:00
Matthias Krüger ac7a867715
Rollup merge of #91907 - lcnr:const-arg-infer, r=BoxyUwU
Allow `_` as the length of array types and repeat expressions

r? `@BoxyUwU` cc `@varkor`
2022-01-04 21:23:06 +01:00
Aaron Hill 467b72607d
Hash `Ident` spans in all HIR structures
This PR removes all of the `#[stable_hasher(project(name))]`
attributes used in HIR structs. While these attributes are not known
to be causing any issues in practice, we need to hash these in
order for the incremental system to work correctly -
a query could be otherwise be incorrectly marked green
when a change occures in one of the `Span`s that it uses.
2022-01-03 15:52:38 -05:00
Aaron Hill da3f196a4e
Remove special-cased stable hashing for HIR module
All other 'containers' (e.g. `impl` blocks) hashed their contents
in the normal, order-dependent way. However, `Mod` was hashing
its contents in a (sort-of) order-independent way. However, the
exact order is exposed to consumers through `Mod.item_ids`,
and through query results like `hir_module_items`. Therefore,
stable hashing needs to take the order of items into account,
to avoid fingerprint ICEs.

Unforuntately, I was unable to directly build a reproducer
for the ICE, due to the behavior of `Fingerprint::combine_commutative`.
This operation swaps the upper and lower `u64` when constructing the
result, which makes the function non-associative. Since we start
the hashing of module items by combining `Fingerprint::ZERO` with
the first item, it's difficult to actually build an example where
changing the order of module items leaves the final hash unchanged.

However, this appears to have been hit in practice in #92218
While we're not able to reproduce it, the fact that proc-macros
are involved (which can give an entire module the same span, preventing
any span-related invalidations) makes me confident that the root
cause of that issue is our method of hashing module items.

This PR removes all of the special handling for `Mod`, instead deriving
a `HashStable` implementation. This makes `Mod` consistent with other
'contains' like `Impl`, which hash their contents through the typical
derive of `HashStable`.
2021-12-24 12:38:29 -05:00
lcnr e3f5cc6c38 implement `generic_arg_infer` for array lengths 2021-12-23 10:09:35 +01:00
pierwill 8df9248591 Remove `PartialOrd` and `Ord` from `LocalDefId`
Implement `Ord`, `PartialOrd` for SpanData
2021-12-22 10:50:57 -06: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
bors dde825db46 Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa
Implement let-else type annotations natively

Tracking issue: #87335

Fixes #89688, fixes #89807, edit: fixes  #89960 as well

As explained in https://github.com/rust-lang/rust/issues/89688#issuecomment-940405082, the previous desugaring moved the let-else scrutinee into a dummy variable, which meant if you wanted to refer to it again in the else block, it had moved.

This introduces a new hir type, ~~`hir::LetExpr`~~ `hir::Let`, which takes over all the fields of `hir::ExprKind::Let(...)` and adds an optional type annotation. The `hir::Let` is then treated like a `hir::Local` when type checking a function body, specifically:

* `GatherLocalsVisitor` overrides a new `Visitor::visit_let_expr` and does pretty much exactly what it does for `visit_local`, assigning a local type to the `hir::Let` ~~(they could be deduplicated but they are right next to each other, so at least we know they're the same)~~
* It reuses the code in `check_decl_local` to typecheck the `hir::Let`, simply returning 'bool' for the expression type after doing that.

* ~~`FnCtxt::check_expr_let` passes this local type in to `demand_scrutinee_type`, and then imitates check_decl_local's pattern checking~~
* ~~`demand_scrutinee_type` (the blindest change for me, please give this extra scrutiny) uses this local type instead of of creating a new one~~
    * ~~Just realised the `check_expr_with_needs` was passing NoExpectation further down, need to pass the type there too. And apparently this Expectation API already exists.~~

Some other misc notes:

* ~~Is the clippy code supposed to be autoformatted? I tried not to give huge diffs but maybe some rustfmt changes simply haven't hit it yet.~~
* in `rustc_ast_lowering/src/block.rs`, I noticed some existing `self.alias_attrs()` calls in `LoweringContext::lower_stmts` seem to be copying attributes from the lowered locals/etc to the statements. Is that right? I'm new at this, I don't know.
2021-12-17 22:12:34 +00:00
Matthias Krüger 6b00227666
Rollup merge of #91888 - BoxyUwU:generic_arg_infer_aaaa, r=lcnr
Handle unordered const/ty generics for object lifetime defaults

*feel like I should have a PR description but cant think of what to put here*

r? ```@lcnr```
2021-12-15 08:36:23 +01:00