Commit graph

161818 commits

Author SHA1 Message Date
Matthias Krüger
1cb57e2d2b
Rollup merge of #92992 - kornelski:backtraceopt, r=Mark-Simulacrum
Help optimize out backtraces when disabled

The comment in `rust_backtrace_env` says:

>    // If the `backtrace` feature of this crate isn't enabled quickly return
>   // `None` so this can be constant propagated all over the place to turn
>  // optimize away callers.

but this optimization has regressed, because the only caller of this function had an alternative path that unconditionally (and pointlessly) asked for a full backtrace, so the disabled state couldn't propagate.

I've added a getter for the full format that respects the feature flag, so that the caller will now be able to really optimize out the disabled backtrace path. I've also made `rust_backtrace_env` trivially inlineable when backtraces are disabled.
2022-01-20 17:10:40 +01:00
Matthias Krüger
ed3bf67db7
Rollup merge of #92861 - jsha:mobile-column-flex, r=GuillaumeGomez
Rustdoc mobile: put out-of-band info on its own line

Before this, the item name and the stability, source link, and "collapse
all docs" would compete for room on a single line, resulting in awkward
wrapping behavior on mobile. This gives a separate line for that
out-of-band information. It also removes the "copy path" icon on mobile
to make a little more room.

Demo: https://rustdoc.crud.net/jsha/mobile-column-flex/std/string/struct.String.html

r? `@GuillaumeGomez`
2022-01-20 17:10:39 +01:00
Matthias Krüger
5c10dbd85f
Rollup merge of #92704 - 5225225:std_mem_transmute_ref_t_mut_t, r=michaelwoerister
Change lint message to be stronger for &T -> &mut T transmute

The old message implied that it's only UB if you use the reference to mutate, which (as far as I know) is not true. As in, the following program has UB, and a &T -> &mut T transmute is effectively an `unreachable_unchecked`.

```rust
fn main() {
    #[allow(mutable_transmutes)]
    unsafe {
        let _ = std::mem::transmute::<&i32, &mut i32>(&0);
    }
}
```

In the future, it might be a good idea to use the edition system to make this a hard error, since I don't think it is *ever* defined behaviour? Unless we rule that `&UnsafeCell<i32> -> &mut i32` is fine. (That, and you always could just use `.get()`, so you're not losing anything)
2022-01-20 17:10:37 +01:00
Matthias Krüger
1839829f0a
Rollup merge of #92680 - camelid:assoc-item-cleanup, r=petrochenkov
intra-doc: Use the impl's assoc item where possible

Before, the trait's associated item would be used. Now, the impl's
associated item is used. The only exception is for impls that use
default values for associated items set by the trait. In that case,
the trait's associated item is still used.

As an example of the old and new behavior, take this code:

    trait MyTrait {
        type AssocTy;
    }

    impl MyTrait for String {
        type AssocTy = u8;
    }

Before, when resolving a link to `String::AssocTy`,
`resolve_associated_trait_item` would return the associated item for
`MyTrait::AssocTy`. Now, it would return the associated item for
`<String as MyTrait>::AssocTy`, as it claims in its docs.

r? `@petrochenkov`
2022-01-20 17:10:36 +01:00
Matthias Krüger
db1253f1d2
Rollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwU
improve `_` constants in item signature handling

removing the "type" from the error messages does slightly worsen the error messages for types, but figuring out whether the placeholder is for a type or a constant and correctly dealing with that seemed fairly difficult to me so I took the easy way out  Imo the error message is still clear enough.

r? `@BoxyUwU` cc `@estebank`
2022-01-20 17:10:35 +01:00
Matthias Krüger
413f490677
Rollup merge of #92183 - tmandry:issue-74256, r=estebank
Point at correct argument when async fn output type lifetime disagrees with signature

Fixes most of #74256.

## Problems fixed

This PR fixes a couple of related problems in the error reporting code.

### Highlighting the wrong argument

First, the error reporting code was looking at the desugared return type of an `async fn` to decide which parameter to highlight. For example, a function like

```rust
async fn async_fn(self: &Struct, f: &u32) -> &u32
{ f }
```

desugars to

```rust
async fn async_fn<'a, 'b>(self: &'a Struct, f: &'b u32)
-> impl Future<Output = &'a u32> + 'a + 'b
{ f }
```

Since `f: &'b u32` is returned but the output type is `&'a u32`, the error would occur when checking that `'a: 'b`.

The reporting code would look to see if the "offending" lifetime `'b` was included in the return type, and because the code was looking at the desugared future type, it was included. So it defaulted to reporting that the source of the other lifetime `'a` (the `self` type) was the problem, when it was really the type of `f`. (Note that if it had chosen instead to look at `'a` first, it too would have been included in the output type, and it would have arbitrarily reported the error (correctly this time) on the type of `f`.)

Looking at the actual future type isn't useful for this reason; it captures all input lifetimes. Using the written return type for `async fn` solves this problem and results in less confusing error messages for the user.

This isn't a perfect fix, unfortunately; writing the "manually desugared" form of the above function still results in the wrong parameter being highlighted. Looking at the output type of every `impl Future` return type doesn't feel like a very principled approach, though it might work. The problem would remain for function signatures that look like the desugared one above but use different traits. There may be deeper changes required to pinpoint which part of each type is conflicting.

### Lying about await point capture causing lifetime conflicts

The second issue fixed by this PR is the unnecessary complexity in `try_report_anon_anon_conflict`. It turns out that the root cause I suggested in https://github.com/rust-lang/rust/issues/76547#issuecomment-692863608 wasn't really the root cause. Adding special handling to report that a variable was captured over an await point only made the error messages less correct and pointed to a problem other than the one that actually occurred.

Given the above discussion, it's easy to see why: `async fn`s capture all input lifetimes in their return type, so holding an argument across an await point should never cause a lifetime conflict! Removing the special handling simplified the code and improved the error messages (though they still aren't very good!)

## Future work

* Fix error reporting on the "desugared" form of this code
* Get the `suggest_adding_lifetime_params` suggestion firing on these examples
  * cc #42703, I think

r? `@estebank`
2022-01-20 17:10:34 +01:00
Matthias Krüger
405cf20442
Rollup merge of #91694 - euclio:stability-improvements, r=GuillaumeGomez
rustdoc: decouple stability and const-stability

This PR tweaks the stability rendering code to consider stability and const-stability separately. This fixes two issues:

- Stabilities that match the enclosing item are now always omitted, even if the item has const-stability as well (#90552)
- Const-stable unstable functions will now have their (const-) stability rendered.

Fixes #90552.
2022-01-20 17:10:33 +01:00
Matthias Krüger
02379e917b
Rollup merge of #91606 - joshtriplett:stabilize-print-link-args, r=pnkfelix
Stabilize `-Z print-link-args` as `--print link-args`

We have stable options for adding linker arguments; we should have a
stable option to help debug linker arguments.

Add documentation for the new option. In the documentation, make it clear that
the *exact* format of the output is not a stable guarantee.
2022-01-20 17:10:32 +01:00
Matthias Krüger
d188287a54
Rollup merge of #89764 - tmiasko:uninhabited-enums, r=wesleywiser
Fix variant index / discriminant confusion in uninhabited enum branching

Fix confusion between variant index and variant discriminant. The pass
incorrectly assumed that for `Variants::Single` variant index is the same as
variant discriminant.

r? `@wesleywiser`
2022-01-20 17:10:31 +01:00
Matthias Krüger
98cb33894c
Rollup merge of #89747 - Amanieu:maybeuninit_bytes, r=m-ou-se
Add MaybeUninit::(slice_)as_bytes(_mut)

This adds methods to convert between `MaybeUninit<T>` and a slice of `MaybeUninit<u8>`. This is safe since `MaybeUninit<u8>` can correctly handle padding bytes in any `T`.

These methods are added:
```rust
impl<T> MaybeUninit<T> {
	pub fn as_bytes(&self) -> &[MaybeUninit<u8>];
	pub fn as_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>];
	pub fn slice_as_bytes(this: &[MaybeUninit<T>]) -> &[MaybeUninit<u8>];
	pub fn slice_as_bytes_mut(this: &mut [MaybeUninit<T>]) -> &mut [MaybeUninit<u8>];
}
```
2022-01-20 17:10:30 +01:00
Hans Kratz
0a6c9adc4a
Fix compilation for a few tier 2 targets 2022-01-20 16:35:16 +01:00
Oli Scherer
8d0d023964
Simplify use of map_or 2022-01-20 15:41:00 +01:00
Rémy Rakic
820fd05e29 Update thorin-dwp to deduplicate object 2022-01-20 15:09:05 +01:00
lcnr
c29b637875 update comments 2022-01-20 14:50:35 +01:00
Jakob Degen
4de76184aa Remove unnecessary unsafe code in Arc deferred initialization examples. 2022-01-20 06:21:51 -05:00
Laurențiu Nicola
3b100458c1 ⬆️ rust-analyzer 2022-01-20 12:14:08 +02:00
Jakob Degen
7bc47cfd92 Correct docs in Arc and Rc.
A number of trait implementations incorrectly claimed to be zero cost.
2022-01-20 04:54:03 -05:00
David Tolnay
3136c5f752
Update stabilization version of impl Not for ! 2022-01-19 23:30:55 -08:00
bors
74fbbefea8 Auto merge of #92138 - AngelicosPhosphoros:try_smarter_vec_from_iter_48994_2, r=Mark-Simulacrum
Improve capacity estimation in Vec::from_iter

Iterates on the attempt made in #53086.

Closes #48994
2022-01-20 06:50:14 +00:00
Artem Kryvokrysenko
4e17170c54 rustdoc: auto create output directory when "--output-format json"
This PR allows rustdoc to automatically create output directory in case
it does not exist (when run with `--output-format json`).

This fixes rustdoc crash:

````
$ rustdoc --output-format json -Z unstable-options src/main.rs
error: couldn't generate documentation: No such file or directory (os error 2)
  |
  = note: failed to create or modify "doc/main.json"

error: aborting due to previous error
````

With this fix behavior of `rustdoc --output-format json` becomes consistent
with `rustdoc --output-format html` (which already auto-creates output
directory if it's missing)
2022-01-19 22:28:07 -08:00
Jacob Hoffman-Andrews
152e888905 Rustdoc mobile: put out-of-band on its own line
Before this, the item name and the stability, source link, and "collapse
all docs" would compete for room on a single line, resulting in awkward
wrapping behavior on mobile. This gives a separate line for that
out-of-band information. It also removes the "copy path" icon on mobile
to make a little more room.

Also, switch to flex-wrap: wrap, so anytime there's not enough room for
`source`, it gets bumped to the next line.
2022-01-19 20:52:09 -08:00
David Tolnay
dcb0721a29
Support --bless for pp-exact pretty printer tests 2022-01-19 20:15:08 -08:00
Esteban Kuber
7356e28abb Tweak expr.await desugaring Span
Fix #93074
2022-01-20 04:09:46 +00:00
Michael Goulet
b7e4433974 Foreign types are trivially drop
- Also rename a trivial_const_drop to match style of other functions in
  the util module.
- Also add a test for `const Drop` that doesn't depend on a `~const`
  bound.
- Also comment a bit why we remove the const bound during dropck impl
  check.
2022-01-19 20:07:04 -08:00
David Tolnay
21c1571e79
Deduplicate branches of print_break implementation 2022-01-19 19:04:36 -08:00
David Tolnay
51eeb82d9d
Inline print_newline function 2022-01-19 19:04:35 -08:00
David Tolnay
224536f4fe
Inline indent function 2022-01-19 19:04:35 -08:00
David Tolnay
9e794d7de3
Eliminate offset number from Fits frames
PrintStackElems with pbreak=PrintStackBreak::Fits always carried a
meaningless value offset=0. We can combine the two types PrintStackElem
+ PrintStackBreak into one PrintFrame enum that stores offset only for
Broken frames.
2022-01-19 19:04:34 -08:00
David Tolnay
65dd67096e
Touch up print_string 2022-01-19 19:04:33 -08:00
David Tolnay
d5f15a8c18
Replace all single character variable names 2022-01-19 19:04:32 -08:00
David Tolnay
ea23a1fac7
Combine advance_left matches 2022-01-19 19:04:31 -08:00
David Tolnay
ae75ba692a
Inline print into advance_left 2022-01-19 19:04:30 -08:00
David Tolnay
d2eb46cfec
Simplify advance_left 2022-01-19 19:03:53 -08:00
David Tolnay
351011ec3f
Simplify left_total tracking 2022-01-19 19:02:56 -08:00
David Tolnay
d981c5b354
Eliminate a token clone from advance_left 2022-01-19 19:02:25 -08:00
David Tolnay
d81740ed2a
Grow scan_stack in the conventional direction
The pretty printer algorithm involves 2 VecDeques: a ring-buffer of
tokens and a deque of ring-buffer indices. Confusingly, those two deques
were being grown in opposite directions for no good reason. Ring-buffer
pushes would go on the "back" of the ring-buffer (i.e. higher indices)
while scan_stack pushes would go on the "front" (i.e. lower indices).
This commit flips the scan_stack accesses to grow the scan_stack and
ring-buffer in the same direction, where push does the same
operation as a Vec push i.e. inserting on the high-index end.
2022-01-19 18:32:18 -08:00
David Tolnay
eec6016ec3
Delete unused Display for pretty printer Token 2022-01-19 18:31:36 -08: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
bors
237949b6c8 Auto merge of #93085 - matthiaskrgr:rollup-mgpu2ju, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #92316 (mangling_v0: Skip extern blocks during mangling)
 - #92630 (Change PhantomData type for `BuildHasherDefault` (and more))
 - #92800 (Add manifest docs fallback.)
 - #93005 (Move back templates into html folder)
 - #93065 (Pretty printer algorithm revamp step 2)
 - #93077 (remove `List::is_noop`)

Failed merges:

 - #93068 (Fix spacing for `·` between stability and source)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-01-19 22:34:55 +00:00
Aaron Hill
c8941d3e48
Store a Symbol instead of an Ident in AssocItem
This is the same idea as #92533, but for `AssocItem` instead
of `VariantDef`/`FieldDef`.

With this change, we no longer have any uses of
`#[stable_hasher(project(...))]`
2022-01-19 17:13:21 -05:00
Tyler Mandry
698631e16c Simplify error reporting code, remove await point wording 2022-01-19 21:33:57 +00:00
Tyler Mandry
5c15ad7fca NiceRegionError: Use written return type for async fn 2022-01-19 21:33:57 +00:00
Tyler Mandry
6487845884 Properly account for binders in get_impl_future_output_ty 2022-01-19 21:33:57 +00:00
Amanieu d'Antras
5c96dcf961 Add MaybeUninit::as_bytes 2022-01-19 21:27:29 +00:00
Martin Nordholts
ab239cc749 src/test/rustdoc-json: Check for struct_fields in variant_tuple_struct.rs
The presence of `struct_field`s is being checked for already in
`variant_struct.rs`. We should also check for them in `variant_tuple_struct.rs`.
2022-01-19 22:10:26 +01:00
Michael Goulet
8547f5732c never is trivially const-drop, and add test 2022-01-19 12:59:28 -08:00
Jacob Hoffman-Andrews
801ac0e24f Fix scroll offset when jumping to internal id 2022-01-19 12:45:16 -08:00
pierwill
8d27c28e39 ⬆ chalk to 0.76.0 2022-01-19 13:44:43 -06:00
Caio
f491a9f601 Add tests to ensure that let_chains works with if_let_guard 2022-01-19 16:23:44 -03:00
pierwill
7f16d0ed54 Remove ordering traits from rustc_borrowck::constraints::OutlivesConstraint
In two cases where this ordering was used, I've replaced the sorting
to use a key that does not include DefId. I'm not sure this is correct
in terms of our goals from #90317, or otherwise.
2022-01-19 13:12:26 -06:00