Commit Graph

213056 Commits

Author SHA1 Message Date
Matthias Krüger
24e584b991
Rollup merge of #105694 - ouz-a:issue_105689, r=estebank
Don't create dummy if val has escaping bounds var

Skips creating/pushing obligations if val has escaping bounds vars.

Fixes #105689
2022-12-15 22:02:59 +01:00
Matthias Krüger
86cedb4062
Rollup merge of #105679 - estebank:suggest-clone, r=compiler-errors
Suggest constraining type parameter with `Clone`

Fix #34896.
2022-12-15 22:02:58 +01:00
Matthias Krüger
622f56065e
Rollup merge of #105674 - estebank:iterator-chains, r=oli-obk
Point at method chains on `E0271` errors

Follow up to #105332. Fix #33941. CC #9082.

r? `@oli-obk`
2022-12-15 22:02:58 +01:00
Matthias Krüger
863d1f653a
Rollup merge of #105481 - lqd:mono-stats, r=wesleywiser
Start improving monomorphization items stats

As described in [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/Compile-time.20case-study.3A.20AWS.20crates/near/314560832), some stats about monomorphization collection would be interesting to have, in a different form than `-Zprint-mono-items`: to have some visibility into the cost of the mono items, we'd like to know how many are instantiated and what is their estimated size.

That can be a proxy to analyze sources of slow compile times, although in the future, we'd also like to add more realistic stats from the actual backend's lowering.

This PR adds a new `-Z dump-mono-stats` flag which will output some stats in a `{crate_name}.mono-items.md` file (the flag optionally takes an output directory parameter, for easier use within a workspace than printing to stdout).

For example,

```rust
fn compute<T>(collection: Vec<T>) -> usize {
    collection.len() + 19 - 0 * 9 - 18 - 1 * 1 // random code to increase the function's size
}

fn main() {
    dbg!(compute(vec![0u8, 1, 2]));
    dbg!(compute(vec![0u64, 1, 2]));
    dbg!(compute(vec!["0", "1", "2", "3"]));
}
```

will output a file with this markdown table (abridged for readability), for a debug build:

| Item | Instantiation count | Estimated Cost Per Instantiation | Total Estimated Cost |
| --- | ---: | ---: | ---: |
| alloc::alloc::box_free | 3 | 122 | 366 |
| std::alloc::Global::alloc_impl | 1 | 284 | 284 |
| alloc::raw_vec::RawVec::<T, A>::current_memory | 3 | 82 | 246 |
| std::ptr::align_offset | 1 | 222 | 222 |
| std::slice::hack::into_vec | 3 | 67 | 201 |
| <std::vec::Vec<T, A> as std::ops::Drop>::drop | 3 | 66 | 198 |
| std::ptr::mut_ptr::<impl *mut T>::is_null | 4 | 47 | 188 |
| main | 1 | 163 | 163 |
| std::ptr::NonNull::<T>::new_unchecked | 4 | 37 | 148 |
...

<details>
<summary>Click for full output</summary>

| Item | Instantiation count | Estimated Cost Per Instantiation | Total Estimated Cost |
| --- | ---: | ---: | ---: |
| alloc::alloc::box_free | 3 | 122 | 366 |
| std::alloc::Global::alloc_impl | 1 | 284 | 284 |
| alloc::raw_vec::RawVec::<T, A>::current_memory | 3 | 82 | 246 |
| std::ptr::align_offset | 1 | 222 | 222 |
| std::slice::hack::into_vec | 3 | 67 | 201 |
| <std::vec::Vec<T, A> as std::ops::Drop>::drop | 3 | 66 | 198 |
| std::ptr::mut_ptr::<impl *mut T>::is_null | 4 | 47 | 188 |
| main | 1 | 163 | 163 |
| std::ptr::NonNull::<T>::new_unchecked | 4 | 37 | 148 |
| std::boxed::Box::<T, A>::into_unique | 3 | 48 | 144 |
| std::boxed::Box::<T, A>::leak | 3 | 39 | 117 |
| std::alloc::Layout::array::inner | 1 | 107 | 107 |
| std::ptr::align_offset::mod_inv | 1 | 103 | 103 |
| std::boxed::Box::<T, A>::into_raw_with_allocator | 3 | 31 | 93 |
| std::fmt::Arguments::<'a>::new_v1 | 1 | 80 | 80 |
| <alloc::raw_vec::RawVec<T, A> as std::ops::Drop>::drop | 3 | 26 | 78 |
| alloc::raw_vec::RawVec::<T, A>::from_raw_parts_in | 3 | 26 | 78 |
| alloc::alloc::exchange_malloc | 1 | 75 | 75 |
| std::ptr::const_ptr::<impl *const T>::is_null | 1 | 75 | 75 |
| std::ptr::const_ptr::<impl *const T>::is_aligned_to | 1 | 64 | 64 |
| compute | 3 | 20 | 60 |
| std::ptr::const_ptr::<impl *const T>::align_offset | 1 | 55 | 55 |
| std::ptr::read | 1 | 52 | 52 |
| <std::alloc::Global as std::alloc::Allocator>::deallocate | 1 | 50 | 50 |
| std::ptr::mut_ptr::<impl *mut T>::guaranteed_eq | 1 | 48 | 48 |
| std::fmt::ArgumentV1::<'a>::new_display | 2 | 22 | 44 |
| std::ptr::Alignment::new_unchecked | 1 | 42 | 42 |
| core::fmt::num::<impl std::fmt::Debug for usize>::fmt | 1 | 40 | 40 |
| std::result::Result::<T, E>::unwrap_unchecked | 1 | 37 | 37 |
| std::cmp::Ord::min | 1 | 32 | 32 |
| std::cmp::impls::<impl std::cmp::Ord for usize>::cmp | 1 | 31 | 31 |
| std::intrinsics::is_aligned_and_not_null | 1 | 27 | 27 |
| std::rt::lang_start | 1 | 27 | 27 |
| std::ptr::NonNull::<T>::new | 1 | 24 | 24 |
| std::fmt::ArgumentV1::<'a>::new_debug | 1 | 22 | 22 |
| std::fmt::Arguments::<'a>::new_v1_formatted | 1 | 19 | 19 |
| std::rt::lang_start::{closure#0} | 1 | 17 | 17 |
| std::sys_common::backtrace::__rust_begin_short_backtrace | 1 | 16 | 16 |
| std::slice::<impl [T]>::into_vec | 3 | 5 | 15 |
| <std::ptr::NonNull<T> as std::convert::From<std::ptr::Unique<T>>>::from | 1 | 14 | 14 |
| <&T as std::fmt::Debug>::fmt | 1 | 12 | 12 |
| <&T as std::fmt::Display>::fmt | 1 | 12 | 12 |
| std::vec::Vec::<T, A>::len | 3 | 2 | 6 |
| <T as std::convert::Into<U>>::into | 1 | 5 | 5 |
| <T as std::convert::From<T>>::from | 1 | 2 | 2 |
| <() as std::process::Termination>::report | 1 | 2 | 2 |
| std::hint::unreachable_unchecked | 1 | 2 | 2 |
| core::fmt::UnsafeArg::new | 1 | 1 | 1 |

</details>

Since we discussed it together, r? `@wesleywiser.`
2022-12-15 22:02:57 +01:00
bors
ec56537c43 Auto merge of #105356 - JakobDegen:more-custom-mir, r=oli-obk
Custom MIR: Many more improvements

Commits are each atomic changes, best reviewed one at a time, with the exception that the last commit includes all the documentation.

### First commit

Unsafetyck was not correctly disabled before for `dialect = "built"` custom MIR. This is fixed and a regression test is added.

### Second commit

Implements `Discriminant`, `SetDiscriminant`, and `SwitchInt`.

### Third commit

Implements indexing, field, and variant projections.

### Fourth commit

Documents the previous commits and everything else.

There is some amount of weirdness here due to having to beat Rust syntax into cooperating with MIR concepts, but it hopefully should not be too much. All of it is documented.

r? `@oli-obk`
2022-12-15 19:59:48 +00:00
Esteban Küber
2492235c32 Consider lifetimes when comparing assoc types in method chain
Do not say "Type changed to X here" when the only difference is caused
by lifetimes.
2022-12-15 11:47:40 -08:00
Esteban Küber
3b938f73f3 Trim paths in E0599 2022-12-15 11:47:40 -08:00
Nilstrieb
651e41c14c Move TypeckResults to seperate module 2022-12-15 20:45:35 +01:00
Nilstrieb
153419b78f Small cleanup in parameterized 2022-12-15 20:41:07 +01:00
Ezra Shaw
fded03ee2d
docs: rewrite E0158 error-code docs for clarity 2022-12-16 08:36:40 +13:00
Michael Howell
88aaaa6135 rustdoc: remove unused CSS .sub-settings
Obsoleted when 9625ed8be7 changed the DOM.
2022-12-15 12:27:32 -07:00
Esteban Küber
4d4d4786f9 Shorten trimmed display of closures
When `with_forced_trimmed_paths` is used, only print filename and start
of the closure's span, to reduce their verbosity.
2022-12-15 11:13:44 -08:00
Esteban Küber
30ae261c42 Use with_forced_trimmed_paths more 2022-12-15 11:13:44 -08:00
Esteban Küber
294944dfec Point at method chains on E0271 errors 2022-12-15 11:13:44 -08:00
Michael Howell
f28a8ca1dc rustdoc: simplify CSS for codeblock tooltips
Instead of making its parts `display: none` and then changing it on hover,
just make the pseudo-element itself on hover.
2022-12-15 12:05:27 -07:00
Gary Guo
7574c98371 Fix new_return_no_self with recursive bounds 2022-12-15 18:56:13 +00:00
Guillaume Gomez
8ae479a02b Migrate Jump to def links background to CSS variable 2022-12-15 19:49:48 +01:00
Esteban Küber
e1b340195a Suggest #[derive(Clone)] 2022-12-15 10:27:05 -08:00
Esteban Küber
f19488064a Suggest constraining type parameter with Clone
Fix #34896.
2022-12-15 10:15:41 -08:00
bors
4954a7ef5c Auto merge of #104616 - RalfJung:ctfe-alignment, r=oli-obk,RalfJung
always check alignment during CTFE

We originally disabled alignment checks because they got in the way -- there are some things we do with the interpreter during CTFE which does not correspond to actually running user-written code, but is purely administrative, and we didn't want alignment checks there, so we just disabled them entirely. But with `-Zextra-const-ub-checks` we anyway had to figure out how to disable those alignment checks while doing checks in regular code. So now it is easy to enable CTFE alignment checking by default. Let's see what the perf consequences of that are.

r? `@oli-obk`
2022-12-15 17:04:25 +00:00
Oli Scherer
2d89027fac Make the test actually emit the future incompat lint 2022-12-15 16:54:00 +00:00
Ralf Jung
5a06b1e67c simplify alignment_check_failed a bit 2022-12-15 16:48:30 +00:00
Oli Scherer
2b2170384d Fix docs 2022-12-15 16:48:29 +00:00
Oli Scherer
b05c790fd6 Reuse the ctfe error emitting logic for the future incompat lint 2022-12-15 16:48:24 +00:00
Oli Scherer
dec05e9c73 Factor decorate closure out into a method 2022-12-15 16:25:50 +00:00
Oli Scherer
98dc76a374 Always report alignment failures in future incompat summaries 2022-12-15 16:24:11 +00:00
bors
3905f51230 Auto merge of #10073 - xFrednet:changelog-1-66, r=Alexendoo
Changelog 1.66

It's really nice to see a changelog with so many suggestion fixes and improvements. Not much else to say. This should be merged with the coming release on 2022-12-15. For the reviewer, please review it and approve it if it looks good. The merge should wait until the release :)

---

changelog: none

<!-- changelog_checked -->
2022-12-15 16:12:12 +00:00
Oli Scherer
d9d92ed7da Move alignment failure error reporting to machine 2022-12-15 16:07:35 +00:00
Oli Scherer
d66824dbc4 Make alignment checks a future incompat lint 2022-12-15 16:07:28 +00:00
Oli Scherer
ed71e32e14 Always pass alignment and handle checking lazily 2022-12-15 15:51:43 +00:00
Ralf Jung
a575828431 adjust tests 2022-12-15 15:50:15 +00:00
Ralf Jung
fa83763491 always check alignment during CTFE 2022-12-15 15:36:11 +00:00
Deadbeef
a8b9e00518 fix tidy and add rpitit test 2022-12-15 14:18:15 +00:00
bors
984eab57f7 Auto merge of #105746 - matthiaskrgr:rollup-sz3grbv, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #104592 (Ensure async trait impls are async (or otherwise return an opaque type))
 - #105623 (Fix `-Z print-type-sizes` for generators with discriminant field ordered first)
 - #105627 (Auto traits in `dyn Trait + Auto` are suggestable)
 - #105633 (Make `report_projection_error` more `Term` agnostic)
 - #105683 (Various cleanups to dest prop)
 - #105692 (Add regression test for #104678)
 - #105707 (rustdoc: remove unnecessary CSS `kbd { cursor: default }`)
 - #105715 (Do not mention long types in E0599 label)
 - #105722 (more clippy::complexity fixes)
 - #105724 (rustdoc: remove no-op CSS `.scrape-example .src-line-numbers { margin: 0 }`)
 - #105730 (rustdoc: remove no-op CSS `.item-info:before { color }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-15 14:04:24 +00:00
Hannes Körber
9671dd239d doc: Fix a few small issues
* A few typos around generic types (`;` vs `,`)
* Use inline code formatting for code fragments
* One instance of wrong wording
2022-12-15 14:05:03 +01:00
bors
f43e4f30d8 Auto merge of #9927 - xFrednet:0000-rustc-tool-macro-update, r=matthiaskrgr
Cleanup `rustc_tool_util` and add a convenient macro for `build.rs`

changelog: none
<!-- changelog_checked -->

If possible, I'd like to have a new release for this, maybe `v0.3.0` to use the changes in another project. Then we can also remove the `path = "./rustc_tools_util"` from `Cargo.toml`. I'd be happy to help with the release on crates.io if you'd like the help :)

r? `@matthiaskrgr`
2022-12-15 12:04:30 +00:00
xFrednet
004b885c0a
rustc_tools_util: changelog and 0.3.0 release 2022-12-15 13:01:02 +01:00
Matthias Krüger
2650b7bd34
Rollup merge of #105730 - notriddle:notriddle/item-info-before, r=GuillaumeGomez
rustdoc: remove no-op CSS `.item-info:before { color }`

No content is set, so this pseudo-element does not exist. The CSS was obsoleted by 73d0f7c7b6.
2022-12-15 12:46:05 +01:00
Matthias Krüger
99a1bfc221
Rollup merge of #105724 - notriddle:notriddle/scrape-example-src-line-numbers, r=GuillaumeGomez
rustdoc: remove no-op CSS `.scrape-example .src-line-numbers { margin: 0 }`

This is the default CSS for `<pre>` tags in `.code-wrapper` anyway, so this line does nothing.
2022-12-15 12:46:05 +01:00
Matthias Krüger
c0862f30bd
Rollup merge of #105722 - matthiaskrgr:compl2, r=compiler-errors
more clippy::complexity fixes

r? ```@compiler-errors```
2022-12-15 12:46:04 +01:00
Matthias Krüger
cb9bcafe0d
Rollup merge of #105715 - estebank:unsatisfied-bounds-label, r=compiler-errors
Do not mention long types in E0599 label

The type is already mentioned in the main message and the list of unmet bounds.
2022-12-15 12:46:04 +01:00
Matthias Krüger
a6337d3fe5
Rollup merge of #105707 - notriddle:notriddle/kbd-cursor, r=jhpratt,GuillaumeGomez
rustdoc: remove unnecessary CSS `kbd { cursor: default }`

Added along with theme picker changes in https://github.com/rust-lang/rust/pull/47686/files#diff-7dc22a0530802d77c2f2ec9e834024a5657b6eab4055520fca46edc99a544413R1144, but no reason seems to have been given at the time for why this particular rule was added.

Removing this rule results in `<kbd>` elements getting an I-bar, while the rule causes them to use the "default" arrow, but since selecting the text in these elements works fine, the I-bar is not misleading.
2022-12-15 12:46:03 +01:00
Matthias Krüger
8111cc4610
Rollup merge of #105692 - JohnTitor:issue-104678, r=compiler-errors
Add regression test for #104678

Closes #104678
r? `````@compiler-errors`````

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-12-15 12:46:03 +01:00
Matthias Krüger
6cdc83b64e
Rollup merge of #105683 - JakobDegen:dest-prop-storage, r=tmiasko
Various cleanups to dest prop

This makes fixing the issues identified in #105577 easier. A couple changes

 - Use an enum with names instead of a bool
 - Only call `remove_candidates_if` from one place instead of two. Doing it from two places is far too fragile, since any divergence in the behavior between those callsites is likely to be unsound.
 - Remove `is_constant`. Right now we only merge locals, so this doesn't do anything, and the logic would be wrong if it did.

r? `@tmiasko`
2022-12-15 12:46:02 +01:00
Matthias Krüger
78cf8cc02e
Rollup merge of #105633 - compiler-errors:term-agnostic, r=oli-obk
Make `report_projection_error` more `Term` agnostic

Fixes #105632
2022-12-15 12:46:01 +01:00
Matthias Krüger
a2c9f2a5e0
Rollup merge of #105627 - compiler-errors:dyn-auto-suggestable, r=davidtwco
Auto traits in `dyn Trait + Auto` are suggestable

Not  sure why I had made the `IsSuggestableVisitor` have that rule to not consider `dyn Trait + Auto` to be suggestable.

It's possible that this was done because of the fact that we don't print the right parentheses for `&(dyn Trait + Auto)`, but that's a problem with printing these types in general that we probably have tracked somewhere else...
2022-12-15 12:46:01 +01:00
Matthias Krüger
5d24760245
Rollup merge of #105623 - compiler-errors:generator-type-size-fix, r=Nilstrieb
Fix `-Z print-type-sizes` for generators with discriminant field ordered first

Fixes #105589
Fixes #105591
2022-12-15 12:46:00 +01:00
Matthias Krüger
c00eac3558
Rollup merge of #104592 - ComputerDruid:async_check, r=compiler-errors
Ensure async trait impls are async (or otherwise return an opaque type)

As a workaround for the full `#[refine]` semantics not being implemented
yet, forbit returning a concrete future type like `Box<dyn Future>` or a
manually implemented Future.

`-> impl Future` is still permitted; while that can also cause
accidental refinement, that's behind a different feature gate
(`return_position_impl_trait_in_trait`) and that problem exists
regardless of whether the trait method is async, so will have to be
solved more generally.

Fixes https://github.com/rust-lang/rust/issues/102745
2022-12-15 12:46:00 +01:00
Deadbeef
5da1a04278 Allow impl ~const Trait opaque types 2022-12-15 11:26:15 +00:00
bors
397b66e77b Auto merge of #105285 - compiler-errors:conflicting-param-env-2, r=estebank
Highlight conflicting param-env candidates, again

Un-reverts #98794 (i.e. reverts #99290).

The previous time I attempted to land this PR, it was because of an incremental issue (#99233). The repro instructions in the issue is no longer manifest the ICE -- I think it's because this ambiguity code was refactored (I think by `@lcnr)` to no longer store the ambiguities in the fulfillment error, but instead recompute them on the fly.

The main motivation for trying to re-land this is that it fixes #105131 by highlighting the root-cause of the issue, which is conflicting param-env candidates:

```
error[E0283]: type annotations needed: cannot satisfy `Self: Gen<'source>`
   |
note: multiple `impl`s or `where` clauses satisfying `Self: Gen<'source>` found
  --> $DIR/conflicting-bounds.rs:3:1
   |
LL | pub trait Gen<'source> {
   | ^^^^^^^^^^^^^^^^^^^^^^
...
LL |         Self: for<'s> Gen<'s, Output = T>;
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0283`.
```

Fixes #105131.
Fixes (again) #98786
2022-12-15 11:11:49 +00:00