Commit Graph

3841 Commits

Author SHA1 Message Date
bors c5afe0a61e Auto merge of #117513 - matthiaskrgr:rollup-jvl6y84, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #117394 (use global cache when computing proof trees)
 - #117495 (Clarify `Unsize` documentation)
 - #117509 (Remove support for alias `-Z symbol-mangling-version`)
 - #117512 (Expand mem::offset_of! docs)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-02 14:46:23 +00:00
Matthias Krüger 67b51879e3
Rollup merge of #117509 - Zalathar:zsymbol, r=petrochenkov
Remove support for alias `-Z symbol-mangling-version`

(This is very similar to the removal of `-Z instrument-coverage` in #117111.)

`-C symbol-mangling-version` was stabilized back in rustc 1.59.0 (2022-02-24) via #90128, with the old unstable flag kept around (with a warning) as an alias to ease migration.
2023-11-02 15:31:21 +01:00
Matthias Krüger 9575625835
Rollup merge of #117495 - compiler-errors:unsize-docs, r=lcnr
Clarify `Unsize` documentation

The documentation erroneously says that:

```rust
/// - Types implementing a trait `Trait` also implement `Unsize<dyn Trait>`.
/// - Structs `Foo<..., T, ...>` implement `Unsize<Foo<..., U, ...>>` if all of these conditions
///   are met:
///   - `T: Unsize<U>`.
///   - Only the last field of `Foo` has a type involving `T`.
///   - `Bar<T>: Unsize<Bar<U>>`, where `Bar<T>` stands for the actual type of that last field.
```

Specifically, `T: Unsize<U>` is not required to hold -- only the final field must implement `FinalField<T>: Unsize<FinalField<U>>`. This can be demonstrated by the test I added.

---

Second commit fleshes out the documentation a lot more.
2023-11-02 15:31:21 +01:00
bors b800c30352 Auto merge of #117466 - compiler-errors:alias-bound, r=aliemjay
Don't check for alias bounds in liveness when aliases have escaping bound vars

I actually have no idea how we *should* be treating aliases with escaping bound vars here... but the simplest behavior is just doing what we used to do before.

r? aliemjay

Fixes #117455
2023-11-02 12:47:14 +00:00
Michael Goulet 4d5d763e05 Don't check for alias bounds in liveness when aliases have escaping bound vars 2023-11-02 10:25:57 +00:00
bors 62270fb4d6 Auto merge of #117204 - nnethercote:rustc_ast_passes, r=compiler-errors
Minor improvements to `rustc_ast_passes`

Some improvements I found while looking at this code.

r? `@compiler-errors`
2023-11-02 10:08:53 +00:00
Zalathar a9e1e43b56 Add UI tests for values accepted by `-C symbol-mangling-version` 2023-11-02 18:20:42 +11:00
Matthias Krüger 2b2360abb1
Rollup merge of #117298 - clubby789:fn-missing-params, r=petrochenkov
Recover from missing param list in function definitions

Addresses the other issue mentioned in #108109
2023-11-01 21:40:05 +01:00
Michael Goulet 6af30ec720 Remove a false statement from Unsize docs, add a test 2023-11-01 20:16:11 +00:00
bors b0a07595b5 Auto merge of #117289 - estebank:issue-72298, r=cjgillot
Account for `ref` and `mut` in the wrong place for pattern ident renaming

If the user writes `S { ref field: name }` instead of `S { field: ref name }`, we suggest the correct code.

Fix #72298.
2023-11-01 18:39:01 +00:00
clubby789 ca1bcb6466 Recover from missing param list in function definitions 2023-11-01 14:48:20 +00:00
bors 146dafa262 Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiser
Support enum variants in offset_of!

This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like

```rust
offset_of!(Type, field.Variant.field)
```

Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful.

[RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant)
Tracking Issue #106655.
2023-11-01 14:17:56 +00:00
bors 7fc6365570 Auto merge of #116692 - Nadrieril:half-open-ranges, r=cjgillot
Match usize/isize exhaustively with half-open ranges

The long-awaited finale to the saga of [exhaustiveness checking for integers](https://github.com/rust-lang/rust/pull/50912)!

```rust
match 0usize {
    0.. => {} // exhaustive!
}
match 0usize {
    0..usize::MAX => {} // helpful error message!
}
```

Features:
- Half-open ranges behave as expected for `usize`/`isize`;
- Trying to use `0..usize::MAX` will tell you that `usize::MAX..` is missing and explain why. No more unhelpful "`_` is missing";
- Everything else stays the same.

This should unblock https://github.com/rust-lang/rust/issues/37854.

Review-wise:
- I recommend looking commit-by-commit;
- This regresses perf because of the added complexity in `IntRange`; hopefully not too much;
- I measured each `#[inline]`, they all help a bit with the perf regression (tho I don't get why);
- I did not touch MIR building; I expect there's an easy PR there that would skip unnecessary comparisons when the range is half-open.
2023-11-01 03:17:19 +00:00
George Bateman e742f809f6
Update based on wesleywiser review 2023-10-31 23:41:40 +00:00
George Bateman d995bd61e7
Enums in offset_of: update based on est31, scottmcm & llogiq review 2023-10-31 23:26:02 +00:00
George Bateman e936416a8d
Support enum variants in offset_of! 2023-10-31 23:25:54 +00:00
bors 045f158d7b Auto merge of #117444 - matthiaskrgr:rollup-43s0spc, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #116267 (Some codegen cleanups around SIMD checks)
 - #116712 (When encountering unclosed delimiters during lexing, check for diff markers)
 - #117416 (Also consider TAIT to be uncomputable if the MIR body is tainted)
 - #117421 (coverage: Replace impossible `coverage::Error` with assertions)
 - #117438 (Do not ICE on constant evaluation failure in GVN.)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-31 12:55:06 +00:00
Matthias Krüger f623530742
Rollup merge of #117438 - cjgillot:deterministic-error, r=oli-obk
Do not ICE on constant evaluation failure in GVN.

Fixes https://github.com/rust-lang/rust/issues/117362
2023-10-31 12:55:10 +01:00
Matthias Krüger 8daa317a4b
Rollup merge of #117416 - compiler-errors:tait-in-bad-body, r=oli-obk
Also consider TAIT to be uncomputable if the MIR body is tainted

Not totally sure if this is the best solution. We could, alternatively, look at the hir typeck results and try to take a type from there instead of just falling back to type error, inferring `u8` instead of `{type error}`. Not certain it really matters, though.

Happy to iterate on this.

Fixes #117413

r? ``@oli-obk`` cc ``@Nadrieril``
2023-10-31 12:55:09 +01:00
Matthias Krüger 7035c3d718
Rollup merge of #116712 - estebank:issue-116252, r=petrochenkov
When encountering unclosed delimiters during lexing, check for diff markers

Fix #116252.
2023-10-31 12:55:09 +01:00
Camille GILLOT 5b7cc9d704 Do not ICE on constant evaluation failure in GVN. 2023-10-31 10:44:28 +00:00
bors 22b27120b9 Auto merge of #117377 - dtolnay:deprecatedsince, r=cjgillot
Store #[deprecated] attribute's `since` value in parsed form

This PR implements the first followup bullet listed in https://github.com/rust-lang/rust/pull/117148#issue-1960240108.

We centralize error handling to the attribute parsing code in `compiler/rustc_attr/src/builtin.rs`, and thereby remove some awkward error codepaths from later phases of compilation that had to make sense of these #\[deprecated\] attributes, namely `compiler/rustc_passes/src/stability.rs` and `compiler/rustc_middle/src/middle/stability.rs`.
2023-10-31 10:42:24 +00:00
David Tolnay c52367276d
Preserve deprecation attribute even if 'since' version is missing 2023-10-30 15:48:46 -07:00
bors a395214a3a Auto merge of #116405 - estebank:issue-103155, r=davidtwco
Detect object safety errors when assoc type is missing

When an associated type with GATs isn't specified in a `dyn Trait`, emit an object safety error instead of only complaining about the missing associated type, as it will lead the user down a path of three different errors before letting them know that what they were trying to do is impossible to begin with.

Fix #103155.
2023-10-30 22:47:48 +00:00
Esteban Küber b8a8ba9c91 Sort errors 2023-10-30 22:19:17 +00:00
Esteban Küber 8c5577283c Add test 2023-10-30 22:12:07 +00:00
Esteban Küber 17a6ae2df3 Detect object safety errors when assoc type is missing
When an associated type with GATs isn't specified in a `dyn Trait`, emit
an object safety error instead of only complaining about the missing
associated type, as it will lead the user down a path of three different
errors before letting them know that what they were trying to do is
impossible to begin with.

Fix #103155.
2023-10-30 22:12:07 +00:00
Nicholas Nethercote 5b391b01ce Test the multispan case in `tests.ui/bounds-lifetime.rs`. 2023-10-31 08:01:02 +11:00
bors 31bc7e2c47 Auto merge of #117415 - matthiaskrgr:rollup-jr2p1t2, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #116862 (Detect when trait is implemented for type and suggest importing it)
 - #117389 (Some diagnostics improvements of `gen` blocks)
 - #117396 (Don't treat closures/coroutine types as part of the public API)
 - #117398 (Correctly handle nested or-patterns in exhaustiveness)
 - #117403 (Poison check_well_formed if method receivers are invalid to prevent typeck from running on it)
 - #117411 (Improve some diagnostics around `?Trait` bounds)
 - #117414 (Don't normalize to an un-revealed opaque when we hit the recursion limit)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-10-30 20:50:14 +00:00
Michael Goulet 48491c182b Also consider TAIT to be uncomputable if the MIR body is tainted 2023-10-30 20:16:22 +00:00
Matthias Krüger c5aec96440
Rollup merge of #117414 - compiler-errors:tait-forevert, r=oli-obk
Don't normalize to an un-revealed opaque when we hit the recursion limit

Currently, we will normalize `Opaque := Option<&Opaque>` to something like `Option<&Option<&Option<&...Opaque>>>`, hitting a limit and bottoming out in an unnormalized opaque after the recursion limit gets hit.

Unfortunately, during `layout_of`, we'll simply recurse and try again if the type normalizes to something different than the type:
e6e931dda5/compiler/rustc_ty_utils/src/layout.rs (L58-L60)

That means then we'll try to normalize `Option<&Option<&Option<&...Opaque>>>` again, substituting `Opaque` into itself even deeper. Eventually this will get to the point that we're just stack-overflowing on a really deep type before even hitting an opaque again.

To fix this, we just bottom out into `ty::Error` instead of the unrevealed opaque type.

Fixes #117412

r? `@oli-obk`
2023-10-30 21:03:40 +01:00
Matthias Krüger 3e95c6ab03
Rollup merge of #117411 - oli-obk:query_merge_immobile_game, r=compiler-errors,Nilstrieb
Improve some diagnostics around `?Trait` bounds

* uses better spans
* clarifies a message that was only talking about generic params, but applies to `dyn ?Trait` and `impl ?Trait` as well
2023-10-30 21:03:39 +01:00
Matthias Krüger 24c6b6c803
Rollup merge of #117403 - oli-obk:the_gift_that_keeps_on_giving_116849, r=compiler-errors
Poison check_well_formed if method receivers are invalid to prevent typeck from running on it

fixes #117379

Though if some code invokes typeck without having first invoked `check_well_formed` then we'll encounter this ICE again. This can happen in const and const fn bodies if they are evaluated due to other `check_well_formed` checks or similar
2023-10-30 21:03:39 +01:00
Matthias Krüger 342483ccc6
Rollup merge of #117398 - Nadrieril:fix-117378, r=compiler-errors
Correctly handle nested or-patterns in exhaustiveness

I had assumed nested or-patterns were flattened, and they mostly are but not always.

Fixes https://github.com/rust-lang/rust/issues/117378
2023-10-30 21:03:38 +01:00
Matthias Krüger e648f479d8
Rollup merge of #117396 - oli-obk:privacy_visitor_types, r=compiler-errors
Don't treat closures/coroutine types as part of the public API

Fixes a regression from https://github.com/rust-lang/rust/pull/117076

r? `@compiler-errors`
2023-10-30 21:03:38 +01:00
Matthias Krüger 86259e79e4
Rollup merge of #117389 - oli-obk:gen_fn, r=compiler-errors
Some diagnostics improvements of `gen` blocks

These are leftovers from https://github.com/rust-lang/rust/pull/116447
2023-10-30 21:03:37 +01:00
Michael Goulet c91f60e22f Don't super-fold types when we hit the recursion limit 2023-10-30 19:24:15 +00:00
Oli Scherer 455cf5a4f6 Improve some diagnostics around `?Trait` bounds 2023-10-30 17:47:07 +00:00
Esteban Küber 162443b32e Detect when trait is implemented for type and suggest importing it
Fix #57457.
2023-10-30 17:00:44 +00:00
Guillaume Gomez 9e4ab9f111
Rollup merge of #117395 - gurry:117380-wrong-parent-sugg, r=Nilstrieb
Fix missing leading space in suggestion

For a local pattern with no space between `let` and `(` e.g.:
```rust
  let(_a) = 3;
```
we were previously suggesting this illegal code:
```rust
  let_a = 3;
```
After this change the suggestion will instead be:
```rust
  let _a = 3;
```
Fixes #117380
2023-10-30 17:33:19 +01:00
Guillaume Gomez 02d32d2bc2
Rollup merge of #117390 - chenyukang:yukang-fix-117284-unused-macro, r=estebank
Fix unused variables lint issue for args in macro

Fixes #117284
r? ````@estebank````
2023-10-30 17:33:18 +01:00
Guillaume Gomez 784f04b367
Rollup merge of #117370 - nicholasbishop:bishop-better-c-variadic-errors, r=oli-obk
C-variadic error improvements

A couple improvements for c-variadic errors:

1. Fix the bad-c-variadic error being emitted multiple times. If a function incorrectly contains multiple `...` args, and is also not foreign or `unsafe extern "C"`, only emit the latter error once rather than once per `...`.

2. Explicitly reject `const` C-variadic functions. Trying to use C-variadics in a const function would previously fail with an error like "destructor of `VaListImpl<'_>` cannot be evaluated at compile-time". Add an explicit check for const C-variadics to provide a clearer error: "functions cannot be both `const` and C-variadic". This also addresses one of the concerns in https://github.com/rust-lang/rust/issues/44930: "Ensure that even when this gets stabilized for regular functions, it is still rejected on const fn."
2023-10-30 17:33:17 +01:00
Guillaume Gomez 95de91b5ce
Rollup merge of #117132 - estebank:issue-80194, r=petrochenkov
On object safety error, mention new enum as alternative

When we encounter a `dyn Trait` that isn't object safe, look for its implementors. If there's one, mention using it directly If there are less than 9, mention the possibility of creating a new enum and using that instead.

Fix #80194.
2023-10-30 17:33:15 +01:00
Oli Scherer 224ddf8fd9 Only run panic tests on targets that can unwind 2023-10-30 16:32:53 +00:00
Oli Scherer ff3a818554 Poison check_well_formed if method receivers are invalid to prevent typeck from running on it 2023-10-30 16:11:52 +00:00
Nicholas Bishop f91b5ceaf2 Explicitly reject const C-variadic functions
Trying to use C-variadics in a const function would previously fail with
an error like "destructor of `VaListImpl<'_>` cannot be evaluated at
compile-time".

Add an explicit check for const C-variadics to provide a clearer error:
"functions cannot be both `const` and C-variadic".
2023-10-30 10:38:25 -04:00
Nadrieril d5e836cf0c Correctly handle nested or-patterns in column-wise analyses 2023-10-30 15:31:00 +01:00
Nicholas Bishop 8508e65895 Fix bad-c-variadic error being emitted multiple times
If a function incorrectly contains multiple `...` args, and is also not
foreign or `unsafe extern "C"`, only emit the latter error once.
2023-10-30 10:29:11 -04:00
Oli Scherer 8d03e1394f Don't treat closures/coroutines as part of the public API 2023-10-30 13:46:44 +00:00
Oli Scherer 972ee01b69 Add regression test 2023-10-30 13:38:54 +00:00