Commit Graph

718 Commits

Author SHA1 Message Date
KaDiWa 9bc69925cb
compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
Matthias Krüger 660795eee5
Rollup merge of #105441 - nnethercote:rm-UnsafetyState, r=lcnr
Remove `UnsafetyState`

r? `@lcnr`
2022-12-08 12:57:33 +01:00
Matthias Krüger fbfc5ada02
Rollup merge of #105423 - oli-obk:symbols, r=jackh726
Use `Symbol` for the crate name instead of `String`/`str`

It always got converted to a symbol anyway
2022-12-08 12:57:32 +01:00
Nicholas Nethercote 9af48e5ab6 Fix a typo. 2022-12-08 15:53:31 +11:00
Oli Scherer d30848b30a Use `Symbol` for the crate name instead of `String`/`str` 2022-12-07 20:30:02 +00:00
Matthias Krüger 967085ecdf
Rollup merge of #105250 - Swatinem:async-rm-resumety, r=oli-obk
Replace usage of `ResumeTy` in async lowering with `Context`

Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces the raw pointer in `ResumeTy` and the `get_context` fn that pulls the correct lifetimes out of thin air.

fixes https://github.com/rust-lang/rust/issues/104828 and https://github.com/rust-lang/rust/pull/104321#issuecomment-1336363077

r? `@oli-obk`
2022-12-06 16:54:54 +01:00
bors 9db224fc90 Auto merge of #105175 - michaelwoerister:add-stable-ord-trait, r=nagisa
Add StableOrd trait as proposed in MCP 533.

The `StableOrd` trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order.

See https://github.com/rust-lang/compiler-team/issues/533 for more information.
2022-12-06 09:21:49 +00:00
Arpad Borsos cf031a3355
Replace usage of `ResumeTy` in async lowering with `Context`
Replaces using `ResumeTy` / `get_context` in favor of using `&'static mut Context<'_>`.

Usage of the `'static` lifetime here is technically "cheating", and replaces
the raw pointer in `ResumeTy` and the `get_context` fn that pulls the
correct lifetimes out of thin air.
2022-12-06 10:16:23 +01:00
Matthias Krüger 1a2f79b82c
Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514
Remove useless borrows and derefs

They are nothing more than noise.
<sub>These are not all of them, but my clippy started crashing (stack overflow), so rip :(</sub>
2022-12-03 17:37:42 +01:00
Matthias Krüger c89bff29e5
Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot
Keep track of the start of the argument block of a closure

This removes a call to `tcx.sess.source_map()` from [compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs](https://github.com/rust-lang/rust/compare/master...SarthakSingh31:issue-97417-1?expand=1#diff-8406bbc0d0b43d84c91b1933305df896ecdba0d1f9269e6744f13d87a2ab268a) as required by #97417.

VsCode automatically applied `rustfmt` to the files I edited under `src/tools`. I can undo that if its a problem.

r? `@cjgillot`
2022-12-03 17:37:41 +01:00
Michael Woerister 3a58309798 Add StableOrd trait as proposed in MCP 533.
The StableOrd trait can be used to mark types as having a stable
sort order across compilation sessions. Collections that sort their
items in a stable way can safely implement HashStable by
hashing items in sort order.
2022-12-02 15:19:30 +01:00
Maybe Waffle f2b97a8bfe Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
Vadim Petrochenkov 1f259ae679 rustc_hir: Change representation of import paths to support multiple resolutions 2022-12-01 18:51:05 +03:00
Vadim Petrochenkov 6cd4dd3091 rustc_hir: Relax lifetime requirements on `Visitor::visit_path` 2022-12-01 17:04:02 +03:00
Camille GILLOT 731c002b27 Only allow feeding a value to newly created definitions. 2022-11-29 18:43:00 +00:00
Sarthak Singh 8f705e2425 Keep track of the start of the argument block of a closure 2022-11-28 14:09:00 +05:30
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 1eb62b1235 Auto merge of #104983 - matthiaskrgr:rollup-018sk73, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #95836 (Use `rust_out{exe_suffix}` for doctests)
 - #104882 (notify lcnr on changes to `ObligationCtxt`)
 - #104892 (Explain how to get the discriminant out of a `#[repr(T)] enum` with payload)
 - #104917 (Allow non-org members to label `requires-debug-assertions`)
 - #104931 (Pretty-print generators with their `generator_kind`)
 - #104934 (Remove redundant `all` in cfg)
 - #104944 (Support unit tests for jsondoclint)
 - #104946 (rustdoc: improve popover focus handling JS)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-27 17:10:58 +00:00
Matthias Krüger 6e6c42c61c
Rollup merge of #104931 - Swatinem:async-pretty, r=eholk
Pretty-print generators with their `generator_kind`

After removing `GenFuture`, I special-cased async generators to pretty-print as `impl Future<Output = X>` mainly to avoid too much diagnostics changes originally.

This now reverses that change so that async fn/blocks are pretty-printed as `[$async-type@$source-position]` in various diagnostics, and updates the tests that this touches.
2022-11-27 16:03: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
Arpad Borsos c96d888bdf
Pretty-print generators with their `generator_kind`
After removing `GenFuture`, I special-cased async generators to pretty-print as `impl Future<Output = X>` mainly to avoid too much diagnostics changes originally.

This now reverses that change so that async fn/blocks are pretty-printed as `[$movability `async` $something@$source-position]` in various diagnostics, and updates the tests that this touches.
2022-11-26 20:42:50 +01:00
Guillaume Gomez a2e485c25c
Rollup merge of #104786 - WaffleLapkin:amp-mut-help, r=compiler-errors
Use the power of adding helper function to simplify code w/ `Mutability`

r? `@compiler-errors`
2022-11-26 17:47:23 +01:00
Camille GILLOT 5de9c84140 Fix rustc_pass_by_value. 2022-11-24 17:49:42 +00:00
Camille GILLOT 1c737d6997 Use kw::Empty for elided lifetimes in path. 2022-11-24 17:48:59 +00: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
bors 341d8b8a2c Auto merge of #103808 - cjgillot:vec-cache, r=TaKO8Ki
Use an IndexVec to cache queries with index-like key

Revival of an old idea. Let's see if it has more effect.

r? `@ghost`
2022-11-24 06:32:23 +00:00
Maybe Waffle 6486ba94a3 `random::<Improve<Mutability>>()` 2022-11-23 20:39:16 +00:00
Camille GILLOT fb7d25e978 Separate lifetime ident from resolution in HIR. 2022-11-23 19:33:06 +00:00
The 8472 a9128d8927 fix tests, update size asserts 2022-11-22 23:12:26 +01:00
Vadim Petrochenkov 7a5376d23c Unreserve braced enum variants in value namespace 2022-11-21 22:40:06 +03:00
bors e07425d55b Auto merge of #98914 - fee1-dead-contrib:min-deref-patterns, r=compiler-errors
Minimal implementation of implicit deref patterns for Strings

cc `@compiler-errors` `@BoxyUwU` https://github.com/rust-lang/lang-team/issues/88 #87121

~~I forgot to add a feature gate, will do so in a minute~~ Done
2022-11-20 07:16:42 +00:00
Matthias Krüger c571b2a964
Rollup merge of #104593 - compiler-errors:rpitit-object-safety-spans, r=fee1-dead
Improve spans for RPITIT object-safety errors

No reason why we can't point at the `impl Trait` that causes the object-safety violation.

Also [drive-by: Add is_async fn to hir::IsAsync](c4165f3a96), which touches clippy too.
2022-11-19 15:35:23 +01:00
Michael Goulet c4165f3a96 drive-by: Add is_async fn to hir::IsAsync 2022-11-19 02:22:24 +00:00
bors ff0ffda6b3 Auto merge of #104591 - Manishearth:rollup-b3ser4e, r=Manishearth
Rollup of 8 pull requests

Successful merges:

 - #102977 (remove HRTB from `[T]::is_sorted_by{,_key}`)
 - #103378 (Fix mod_inv termination for the last iteration)
 - #103456 (`unchecked_{shl|shr}` should use `u32` as the RHS)
 - #103701 (Simplify some pointer method implementations)
 - #104047 (Diagnostics `icu4x` based list formatting.)
 - #104338 (Enforce that `dyn*` coercions are actually pointer-sized)
 - #104498 (Edit docs for `rustc_errors::Handler::stash_diagnostic`)
 - #104556 (rustdoc: use `code-header` class to format enum variants)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-18 23:20:53 +00:00
Michael Goulet da3c5397a6 Enforce that dyn* casts are actually pointer-sized 2022-11-18 18:23:48 +00:00
Philipp Krones 4e65f5ea82
Add variant_name function to `LangItem`
Clippy has an internal lint that checks for the usage of hardcoded def
paths and suggests to replace them with a lang or diagnostic item, if
possible. This was implemented with a hack, by getting all the variants
of the `LangItem` enum and then index into it with the position of the
`LangItem` in the `items` list. This is no longer possible, because the
`items` list can't be accessed anymore.
2022-11-17 20:06:25 +01:00
Deadbeef b2cb42d6a7 Minimal implementation of implicit deref patterns 2022-11-17 12:46:43 +00:00
Camille GILLOT 9d20aca983 Store a LocalDefId in hir::Variant & hir::Field. 2022-11-13 14:06:51 +00:00
Camille GILLOT 607d0c2a14 Store a LocalDefId in hir::AnonConst. 2022-11-13 14:06:11 +00:00
Camille GILLOT 18482f7b23 Store a LocalDefId in hir::GenericParam. 2022-11-13 14:05:30 +00:00
Camille GILLOT 290f0781b4 Store LocalDefId in hir::Closure. 2022-11-13 14:04:02 +00:00
Oli Scherer 44d1936d00 Some tracing and comment cleanups 2022-11-04 17:10:07 +00:00
Santiago Pastorino ba18f16e81
Add visit_fn_ret_ty to hir intravisit 2022-11-03 10:41:22 -03:00
Samuel Moelius e604327286 Reorder `walk_` functions in intravisit.rs 2022-11-01 19:02:45 -04:00
Camille GILLOT 07f1948043 Implement Idx for OwnerId. 2022-11-01 17:02:51 +00:00
Dylan DPC 43634675f6
Rollup merge of #103061 - Amanieu:rewrite_alloc_error_handler, r=bjorn3
Rewrite implementation of `#[alloc_error_handler]`

The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called.

This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-11-01 14:12:25 +05:30
Yuki Okushi 2125181b7d
Rollup merge of #103692 - smoelius:walk_generic_arg, r=fee1-dead
Add `walk_generic_arg`

Could this please be added?

I could use it for a Clippy lint.
2022-11-01 12:03:41 +09:00