Commit Graph

4407 Commits

Author SHA1 Message Date
bors
18be2728bd Auto merge of #115131 - frank-king:feature/unnamed-fields-lite, r=petrochenkov
Parse unnamed fields and anonymous structs or unions (no-recovery)

It is part of #114782 which implements #49804. Only parse anonymous structs or unions in struct field definition positions.

r? `@petrochenkov`
2023-08-24 12:52:35 +00:00
bors
9bd60a60ce Auto merge of #115078 - camelid:tydef-to-alias, r=aDotInTheVoid,GuillaumeGomez
rustdoc: Rename typedef to type alias

This matches the name used by the [Rust Reference][1], which is also what
people usually call these items.

[1]: https://doc.rust-lang.org/reference/items/type-aliases.html

r? `@GuillaumeGomez`
2023-08-24 04:13:28 +00:00
Frank King
868706d9b5 Parse unnamed fields and anonymous structs or unions
Anonymous structs or unions are only allowed in struct field
definitions.

Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
2023-08-24 11:17:54 +08:00
Noah Lev
912d11d4d1 Fix rustdoc-json tests 2023-08-23 11:52:49 -07:00
Guillaume Gomez
5cbc00fb7e
Rollup merge of #115135 - GuillaumeGomez:no-html-source-flag, r=notriddle
Rustdoc: Add unstable --no-html-source flag

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

This is the equivalent of `#![doc(no_html_source)]` but on the command-line. It disables the generation of the source pages (and of the links pointing to them as well).

The motivation behind this is to enable to reduce documentation size when generating it in some locations without enforcing this to end users or adding a new feature to enable/disable the crate attribute.

r? `@notriddle`
2023-08-23 17:46:35 +02:00
Guillaume Gomez
c9dbff2f42
Rollup merge of #115102 - Urgau:invalid_ref_casting-book-note, r=est31
Improve note for the `invalid_reference_casting` lint

This PR add link to the book interior mutability chapter, https://doc.rust-lang.org/book/ch15-05-interior-mutability.html; this is done to guide peoples to a place with many useful information and context.

*Note that this isn't the first occurrence of a link to the book in [tests outputs](https://github.com/search?q=repo%3Arust-lang%2Frust+book+path%3A%2F%5Etests%5C%2Fui%5C%2F%2F&type=code).*

r? `@est31`
2023-08-23 17:46:34 +02:00
Guillaume Gomez
73ccfc5683 Update run-make/issue-88756-default-output test 2023-08-23 16:33:07 +02:00
Guillaume Gomez
d3f35e96c1 Add test for --no-html-source flag 2023-08-23 15:54:04 +02:00
bors
97fff1f2ed Auto merge of #114790 - taiki-e:asm-maybe-uninit, r=Amanieu
Allow MaybeUninit in input and output of inline assembly

**Motivation:**

As part of the work to remove UBs from crossbeam's AtomicCell, I'm writing a library to implement atomic operations on MaybeUnint using inline assembly ([atomic-maybe-uninit](https://github.com/taiki-e/atomic-maybe-uninit), https://github.com/crossbeam-rs/crossbeam/pull/1015).

However, currently, MaybeUnint cannot be used in input&output of inline assembly, so when processing MaybeUninit, values must be [passed through memory](https://github.com/taiki-e/atomic-maybe-uninit/blob/main/src/arch/aarch64.rs#L121-L122). It is inefficient and microbenchmarks have [actually shown significant performance degradation](https://github.com/crossbeam-rs/crossbeam/pull/1015#issuecomment-1676549870).

It would be nice if we could allow MaybeUninit in input and output of inline assembly.

---

This PR changed the type check in rustc_hir_analysis to allow `MaybeUnint<int | float | ptr | fn ptr | simd vector>` in input and output of inline assembly and added a simple test.

To be honest, I'm not sure that this is the correct way to do it, because this is like doing transmute to integers/floats/etc from MaybeUninit on the compiler side. EDIT: [this seems fine](https://rust-lang.zulipchat.com/#narrow/stream/216763-project-inline-asm/topic/MaybeUninit.20in.20asm!/near/384662900)

r? `@Amanieu`
cc `@thomcc` (because you [had previously proposed this](https://rust-lang.zulipchat.com/#narrow/stream/216763-project-inline-asm/topic/MaybeUninit.20in.20asm!))
2023-08-23 13:40:41 +00:00
Taiki Endo
03fd2d4379 Allow MaybeUninit in input and output of inline assembly 2023-08-23 21:57:18 +09:00
Urgau
aa7730003e Improve note for the invalid_reference_casting lint
Add link to the book interior mutability chapter,
https://doc.rust-lang.org/book/ch15-05-interior-mutability.html.
2023-08-23 11:27:33 +02:00
Dylan DPC
0a78123b55
Rollup merge of #115114 - tmiasko:115052, r=compiler-errors
Contents of reachable statics is reachable

Fixes #115052.
2023-08-23 05:35:18 +00:00
Dylan DPC
7257e9c2de
Rollup merge of #115100 - Urgau:invalid_ref_casting-ptr-writes, r=est31
Add support for `ptr::write`s for the `invalid_reference_casting` lint

This PR adds support for `ptr::write` and others for the `invalid_reference_casting` lint.

Detecting instances where instead of using the deref (`*`) operator to assign someone uses `ptr::write`, `ptr::write_unaligned` or `ptr::write_volatile`.

```rust
let data_len = 5u64;

std::ptr::write(
    std::mem::transmute::<*const u64, *mut u64>(&data_len),
    new_data_len,
);
```

r? ``@est31``
2023-08-23 05:35:17 +00:00
Dylan DPC
391cbdaa7c
Rollup merge of #115096 - kadiwa4:no_memcpy_padding, r=cjgillot
Add regression test for not `memcpy`ing padding bytes

Closes #56297

See this comparison: https://rust.godbolt.org/z/jjzfonfcE

I don't have any experience with codegen tests, I hope this is correct
2023-08-23 05:35:17 +00:00
bors
c6f5495591 Auto merge of #115070 - notriddle:notriddle/utf8-redundant-explicit-links, r=GuillaumeGomez,ChAoSUnItY
rustdoc: use unicode-aware checks for redundant explicit link fastpath

Fixes #115064
Fixes #115062
Fixes #115116
2023-08-23 00:02:50 +00:00
bors
c469197b19 Auto merge of #115005 - compiler-errors:passes, r=cjgillot
Don't do intra-pass validation on MIR shims

Fixes #114375

In the test that was committed, we end up generating the drop shim for `struct Foo` that looks like:

```
fn std::ptr::drop_in_place(_1: *mut Foo) -> () {
    let mut _0: ();

    bb0: {
        goto -> bb5;
    }

    bb1: {
        return;
    }

    bb2 (cleanup): {
        resume;
    }

    bb3: {
        goto -> bb1;
    }

    bb4 (cleanup): {
        drop(((*_1).0: foo::WrapperWithDrop<()>)) -> [return: bb2, unwind terminate];
    }

    bb5: {
        drop(((*_1).0: foo::WrapperWithDrop<()>)) -> [return: bb3, unwind: bb2];
    }
}
```

In `bb4` and `bb5`, we assert that `(*_1).0` has type `WrapperWithDrop<()>`. However, In a user-facing param env, the type is actually `WrapperWithDrop<Tait>`. These types are not equal in a user-facing param-env (and can't be made equal even if we use `DefiningAnchor::Bubble`, since it's a non-local TAIT).
2023-08-22 22:04:49 +00:00
bors
154ae32a55 Auto merge of #114643 - dpaoliello:inlinedebuginfo, r=wesleywiser
Use the same DISubprogram for each instance of the same inlined function within a caller

# Issue Details:
The call to `panic` within a function like `Option::unwrap` is translated to LLVM as a `tail call` (as it will never return), when multiple calls to the same function like this is inlined LLVM will notice the common `tail call` block (i.e., loading the same panic string + location info and then calling `panic`) and merge them together.

When merging these instructions together, LLVM will also attempt to merge the debug locations as well, but this fails (i.e., debug info is dropped) as Rust emits a new `DISubprogram` at each inline site thus LLVM doesn't recognize that these are actually the same function and so thinks that there isn't a common debug location.

As an example of this when building for x86_64 Windows (note the lack of `.cv_loc` before the call to `panic`, thus it will be attributed to the same line at the `addq` instruction):

```
	.cv_loc	0 1 23 0                        # src\lib.rs:23:0
	addq	$40, %rsp
	retq
	leaq	.Lalloc_f570dea0a53168780ce9a91e67646421(%rip), %rcx
	leaq	.Lalloc_629ace53b7e5b76aaa810d549cc84ea3(%rip), %r8
	movl	$43, %edx
	callq	_ZN4core9panicking5panic17h12e60b9063f6dee8E
	int3
```

# Fix Details:
Cache the `DISubprogram` emitted for each inlined function instance within a caller so that this can be reused if that instance is encountered again, this also requires caching the `DILexicalBlock` and `DIVariable` objects to avoid creating duplicates.

After this change the above assembly now looks like:

```
	.cv_loc	0 1 23 0                        # src\lib.rs:23:0
	addq	$40, %rsp
	retq
	.cv_inline_site_id 5 within 0 inlined_at 1 0 0
	.cv_inline_site_id 6 within 5 inlined_at 1 12 0
	.cv_loc	6 2 935 0                       # library\core\src\option.rs:935:0
	leaq	.Lalloc_5f55955de67e57c79064b537689facea(%rip), %rcx
	leaq	.Lalloc_e741d4de8cb5801e1fd7a6c6795c1559(%rip), %r8
	movl	$43, %edx
	callq	_ZN4core9panicking5panic17hde1558f32d5b1c04E
	int3
```
2023-08-22 20:15:29 +00:00
Michael Goulet
0e84d42a9e
Rollup merge of #115077 - estebank:issue-115019, r=compiler-errors
Do not emit invalid suggestion in E0191 when spans overlap

Fix #115019.
2023-08-22 09:00:49 -07:00
Michael Goulet
e9897c3a71
Rollup merge of #115011 - compiler-errors:warn-on-elided-assoc-ct-lt, r=cjgillot
Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)

Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since #97313. This is not correct behavior (see #38831).

I originally opened #114716 to fix this, but given the time that has passed, the crater results seem pretty bad: https://github.com/rust-lang/rust/pull/114716#issuecomment-1682091952

This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
2023-08-22 09:00:49 -07:00
Esteban Küber
b86285af16 Do not emit invalid suggestion in E0191 when spans overlap
Fix #115019.
2023-08-22 15:51:12 +00:00
Urgau
7ee77b5d1b Add support for ptr::write for the invalid_reference_casting lint 2023-08-22 15:47:29 +02:00
kadiwa
265c1b5d50
add regression test for not memcpying padding bytes 2023-08-22 15:10:56 +02:00
mojave2
d2744175ac
unknown unstable lint command line
fix ##113702

fix #113702

unknown unstable lint command lint

improve impelementation
2023-08-22 18:58:39 +08:00
bors
795ade084a Auto merge of #113365 - dima74:diralik/add-deprecated-suggestions, r=workingjubilee
Add `suggestion` for some `#[deprecated]` items

Consider code:
```rust
fn main() {
    let _ = ["a", "b"].connect(" ");
}
```

Currently it shows deprecated warning:
```rust
warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join
 --> src/main.rs:2:24
  |
2 |     let _ = ["a", "b"].connect(" ");
  |                        ^^^^^^^
  |
  = note: `#[warn(deprecated)]` on by default
```

This PR adds `suggestion` for `connect` and some other deprecated items, so the warning will be changed to this:
```rust
warning: use of deprecated method `std::slice::<impl [T]>::connect`: renamed to join
 --> src/main.rs:2:24
  |
2 |     let _ = ["a", "b"].connect(" ");
  |                        ^^^^^^^
  |
  = note: `#[warn(deprecated)]` on by default
help: replace the use of the deprecated method
  |
2 |     let _ = ["a", "b"].join(" ");
  |                        ^^^^
```
2023-08-22 00:02:50 +00:00
Tomasz Miąsko
0383131f7f Contents of reachable statics is reachable 2023-08-22 00:00:00 +00:00
Noah Lev
4d9ac5df59 Fix test 2023-08-21 16:20:00 -07:00
Michael Howell
3df9b4d65d rustdoc: use unicode-aware checks for redundant explicit link fastpath
Fixes #115064
2023-08-21 14:25:26 -07:00
Esteban Küber
bf766cd31b Add test for #115019 2023-08-21 19:59:27 +00:00
Noah Lev
ea9e442222 rustdoc: Rename "Type Definition" to "Type Alias"
This matches the name used by the Rust Reference [1], which is also what
people usually call these items.

[1]: https://doc.rust-lang.org/reference/items/type-aliases.html
2023-08-21 12:53:39 -07:00
bors
fe5f591257 Auto merge of #115039 - jackh726:impl_compare_add_alias_obligations, r=aliemjay
Add projection obligations when comparing impl too

Fixes #115033

In the test, when we ask for WF obligations of `DatasetIter<'a, ArrayBase<D>>`, we get back two important obligations: `[<D as Data>::Elem -> ?1, ?1: 'a]`. If we don't add the projection obligation, `?1` remains unconstrained.

An alternative solution would be to use unnormalized obligations, where we only have one relevant obligation: `<D as Data>::Elem: 'a`. This would leave no inference vars unconstrained.
2023-08-21 13:10:15 +00:00
Dmitry Murzin
07b57f9a7a
Add suggestion for some #[deprecated] items 2023-08-21 12:51:51 +03:00
bors
5e9d3d8a03 Auto merge of #106561 - GuillaumeGomez:warning-block, r=rustdoc
Add warning block support in rustdoc

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

You can test it [here](https://rustdoc.crud.net/imperio/warning-block/foo/struct.Foo.html). It currently looks like this:

![image](https://user-images.githubusercontent.com/3050060/211413494-e1cf04e4-c081-4a9d-97db-27329405cfa7.png)

So a few things to note:

 * Since it's a new add and it's changing the UI, we'll need to go through an FCP.
 * Does the UI looks good?
 * Is the way picked to add a warning block ok for everyone? The discussion on the issue seemed to be in favour of this solution but it doesn't hurt to double-check.

cc `@rust-lang/rustdoc`
2023-08-21 09:26:02 +00:00
bors
8a562f9671 Auto merge of #115023 - GuillaumeGomez:migrate-gui-test-color-35, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

r? `@notriddle`
2023-08-21 01:45:40 +00:00
Jack Huey
31032ecb15 Add projection obligations when comparing impl too 2023-08-20 21:13:52 -04:00
Ralf Jung
ac3bca24b7 interpret: have assert_* intrinsics call the panic machinery instead of a direct abort 2023-08-20 15:52:40 +02:00
Guillaume Gomez
f2f999e7b2 Migrate GUI colors test to original CSS color format 2023-08-20 14:44:36 +02:00
bors
ff55fa3026 Auto merge of #113124 - nbdd0121:eh_frame, r=cjgillot
Add MIR validation for unwind out from nounwind functions + fixes to make validation pass

`@Nilstrieb`  This is the MIR validation you asked in https://github.com/rust-lang/rust/pull/112403#discussion_r1222739722.

Two passes need to be fixed to get the validation to pass:
* `RemoveNoopLandingPads` currently unconditionally introduce a resume block (even there is none to begin with!), changed to not do that
* Generator state transform introduces a `assert` which may unwind, and its drop elaboration also introduces many new `UnwindAction`s, so in this case run the AbortUnwindingCalls after the transformation.

I believe this PR should also fix Rust-for-Linux/linux#1016, cc `@ojeda`

r? `@Nilstrieb`
2023-08-20 09:58:52 +00:00
bors
b6ab01a713 Auto merge of #115018 - matthiaskrgr:rollup-pxj0qdb, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #114834 (Avoid side-effects from `try_coerce` when suggesting borrowing LHS of cast)
 - #114968 (Fix UB in `std::sys::os::getenv()`)
 - #114976 (Ignore unexpected incr-comp session dirs)
 - #114999 (Migrate GUI colors test to original CSS color format)
 - #115000 (custom_mir: change Call() terminator syntax to something more readable)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-20 08:11:08 +00:00
Matthias Krüger
2bca4b5913
Rollup merge of #115000 - RalfJung:custom-mir-call, r=compiler-errors,JakobDegen
custom_mir: change Call() terminator syntax to something more readable

I find our current syntax very hard to read -- I cannot even remember the order of arguments, and having the "next block" *before* the actual function call is very counter-intuitive IMO. So I suggest we use `Call(ret_val = function(v), next_block)` instead.

r? `@JakobDegen`
2023-08-20 08:34:05 +02:00
Matthias Krüger
4542711a69
Rollup merge of #114999 - GuillaumeGomez:migrate-gui-test-color-34, r=notriddle
Migrate GUI colors test to original CSS color format

Follow-up of https://github.com/rust-lang/rust/pull/111459.

This test needed more cleanup: first I removed duplication by using a function, then I merge similar rules which had the same values.

r? `@notriddle`
2023-08-20 08:34:04 +02:00
Matthias Krüger
33771dfaf0
Rollup merge of #114834 - compiler-errors:try_coerce-side-effects, r=lcnr
Avoid side-effects from `try_coerce` when suggesting borrowing LHS of cast

The name `try_coerce` is a bit misleading -- it has side-effects, so when it's used in diagnostics code, it sometimes causes spurious obligations to be registered which cause other errors to occur that really make no sense in context.

Addendum: let's just rename `try_coerce` to `coerce` -- the `try_` part doesn't really add much, imo.
2023-08-20 08:34:03 +02:00
bors
39e0749329 Auto merge of #114914 - compiler-errors:deduce-tait-in-future-output, r=lcnr
Normalize return type of `deduce_future_output_from_obligations`

Fixes #114909
Also confirmed to fix #114727 manually

Now that we have weak/lazy type aliases, we need to normalize those in future signatures to ensure that `replace_opaque_types_with_inference_vars` actually sees TAITs behind them. This isn't needed in the new solver, but added a test to make sure it doesn't regress there either.

r? types cc `@oli-obk` (who's gone, worst case can delay this PR until he's back)
2023-08-20 06:24:44 +00:00
bors
484cb4e78d Auto merge of #114332 - nbdd0121:riscv, r=compiler-errors
Fix ABI flags in RISC-V/LoongArch ELF file generated by rustc

Fix #114153

It turns out the current way to set these flags are completely wrong. In LLVM the target ABI is used instead of target features to determine these flags.

Not sure how to write a test though. Or maybe a test isn't necessary because this affects only those touching target json?

r? `@Nilstrieb`
2023-08-20 04:38:08 +00:00
bors
82c5732b9a Auto merge of #113966 - lu-zero:relocation-model-in-cfg, r=bjorn3
Add the relocation_model to the cfg

This way is possible to write inline assembly code aware of it.
2023-08-20 02:48:33 +00:00
bors
9c699a40cc Auto merge of #113167 - ChAoSUnItY:redundant_explicit_link, r=GuillaumeGomez
rustdoc: Add lint `redundant_explicit_links`

Closes #87799.
- Lint warns by default
- Reworks link parser to cache original link's display text

r? `@jyn514`
2023-08-20 01:04:22 +00:00
Michael Goulet
fad7d220fd Warn on elided lifetimes in associated constants 2023-08-20 00:21:47 +00:00
Matthias Krüger
03455c8895
Rollup merge of #114934 - lcnr:generalize-substs-relate, r=compiler-errors
instantiate response: no unnecessary new universe

this previously was a off-by-one error.

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/55

r? ````@compiler-errors````
2023-08-20 00:28:31 +02:00
Michael Goulet
822caa8b80 Avoid side-effects from try_coerce when suggesting borrowing LHS of cast 2023-08-19 22:12:51 +00:00
Ralf Jung
7a6346660e custom_mir: change Call() terminator syntax to something more readable 2023-08-19 22:41:33 +02:00
Michael Goulet
acd3542b8d Don't do intra-pass validation on MIR shims 2023-08-19 18:47:08 +00:00