Commit Graph

29631 Commits

Author SHA1 Message Date
Nicholas Nethercote
222c22356b Minimize pub usage in hygiene.rs.
And remove dead functions revealed by this.
2023-11-02 17:23:26 +11:00
Nicholas Nethercote
16e9713e60 Tweak use items. 2023-11-02 17:23:26 +11:00
Nicholas Nethercote
1bcb6006ba Fix some comments.
The comment just below the first one describes how the `impl !Send for
FatalError` makes it impossible to `panic!(FatalError)`.

And the second one should be `panic_any` instead of `panic!`.
2023-11-02 17:22:44 +11:00
Nicholas Nethercote
d76661bf25 Explain the () argument to ErrorGuaranteed. 2023-11-02 17:07:07 +11:00
Nadrieril
3760d919d8 Cleanup check_match code paths 2023-11-02 03:19:19 +01:00
Nadrieril
fcd24fbd3c Factor out pointing at ADT definition 2023-11-02 03:19:19 +01:00
Nadrieril
c19856929d Always do all the pattern checks 2023-11-02 03:19:19 +01:00
Nadrieril
d95f6a9532 Tweak diagnostic for consistency 2023-11-02 03:19:19 +01:00
Nadrieril
380c56c6b3 Check pattern error while lowering 2023-11-02 03:19:18 +01:00
Nadrieril
1f9a2f73e1 Uncomplicate check_let_chain 2023-11-02 03:19:18 +01:00
Nadrieril
fedee8d524 Reorder 2023-11-02 03:19:18 +01:00
Matthias Krüger
4e437be044
Rollup merge of #117441 - cjgillot:diag-noassert, r=oli-obk,RalfJung
Do not assert in op_to_const.

`op_to_const` is used in `try_destructure_mir_constant_for_diagnostics`, which may encounter invalid constants created by optimizations and debugging.

r? ``@oli-obk``

Fixes https://github.com/rust-lang/rust/issues/117368
2023-11-01 21:40:06 +01:00
Matthias Krüger
3087b63d1f
Rollup merge of #117373 - saethlin:avoid-ice-lint, r=compiler-errors
Avoid the path trimming ICE lint in error reporting

Types or really anything in MIR should never be formatted without path trimming disabled, because its formatting often tries to construct trimmed paths. In this case, the lint turns a nice error report into an irrelevant ICE.
2023-11-01 21:40:05 +01: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
Camille GILLOT
f512f91258 Comment for_diagnostics flag. 2023-11-01 19:01:55 +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
Camille GILLOT
224e29030a Specify diagnostic path. 2023-11-01 18:36:38 +00:00
Camille GILLOT
3a55c283d0 Rename hook. 2023-11-01 16:49:18 +00:00
Camille GILLOT
c2f49e9edf Do not assert in op_to_const. 2023-11-01 16:49:18 +00:00
bors
f3457dbf84 Auto merge of #117307 - taiki-e:espidf-atomic-64, r=Amanieu
Set max_atomic_width for riscv32*-esp-espidf to 32

Fixes #117305

> Since riscv32 does not have 64-bit atomic instructions, I do not believe there is any way to fix this problem other than setting max_atomic_width of these targets to 32.

This is a breaking change because Atomic\*64 will become unavailable, but all affected targets are tier 3, and the current Atomic*64 violates the standard library's API contract and can cause problems with code that rely on the standard library's atomic types being lock-free.

r? `@Amanieu`
cc `@ivmarkov` `@MabezDev`
2023-11-01 16:39:22 +00:00
Ben Kimock
88f0688530 Avoid the path trimming ICE lint in error reporting 2023-11-01 10:54:07 -04: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
Matthias Krüger
515fdbf687
Rollup merge of #117475 - nnethercote:rm-create_session, r=oli-obk
Inline and remove `create_session`.

Currently the parts of session initialization that happen within `rustc_interface` are split between `run_compiler` and `create_session`. This split isn't necessary and obscures what's happening.

This commit merges the two functions. I think a single longer function is much clearer than splitting this code across two functions in different modules, especially when `create_session` has 13 parameters, and is misnamed (it also creates the codegen backend). The net result is 43 fewer lines of code.

r? ``@oli-obk``
2023-11-01 11:29:42 +01:00
Matthias Krüger
6c893e6673
Rollup merge of #117401 - chenyukang:yukang-cleanup-hir-typeck-suggestions, r=compiler-errors
Refactor: move suggestion functions from demand to suggestions

follow-up from
https://github.com/rust-lang/rust/pull/116841#discussion_r1370506700
2023-11-01 11:29:42 +01:00
Matthias Krüger
6bbe22c966
Rollup merge of #117397 - compiler-errors:dont-emit-good-path-on-panic, r=TaKO8Ki
Don't emit delayed good-path bugs on panic

This should fix #117381, cc ``@RalfJung``

As opposed to delayed bugs, delayed *good path* bugs really don't make sense to show on panics.
2023-11-01 11:29:41 +01: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
Nicholas Nethercote
587af91045 Inline and remove create_session.
Currently the parts of session initialization that happen within
`rustc_interface` are split between `run_compiler` and `create_session`.
This split isn't necessary and obscures what's happening.

This commit merges the two functions. I think a single longer function
is much clearer than splitting this code across two functions in
different modules, especially when `create_session` has 13 parameters,
and is misnamed (it also creates the codegen backend). The net result is
43 fewer lines of code.
2023-11-01 13:46:15 +11:00
bors
98f5ebbe2e Auto merge of #113970 - cjgillot:assume-all-the-things, r=nikic
Replace switch to unreachable by assume statements

`UnreachablePropagation` currently keeps some switch terminators alive in order to ensure codegen can infer the inequalities on the discriminants.

This PR proposes to encode those inequalities as `Assume` statements.

This allows to simplify MIR further by removing some useless terminators.
2023-11-01 01:10:31 +00:00
George Bateman
e742f809f6
Update based on wesleywiser review 2023-10-31 23:41:40 +00:00
George Bateman
9d6ce61376
Update MIR tests for offset_of 2023-10-31 23:26:02 +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
Matthias Krüger
86d69f9987
Rollup merge of #117439 - lcnr:prepopulate-earlier, r=compiler-errors
prepopulate opaque ty storage before using it

doesn't have any significant impact rn afaict, as we freely define new opaque types during MIR typeck.

It will be relevant with #117278 and once we stop allowing the definition of new opaques in MIR typeck

r? `@compiler-errors`
2023-10-31 19:03:22 +01:00
Matthias Krüger
290daf9318
Rollup merge of #117417 - celinval:smir-visitor, r=oli-obk
Add a stable MIR visitor

This change also adds a few utility functions as well and extend most `mir` and `ty` ADTs to implement `PartialEq` and `Eq`.

Fixes https://github.com/rust-lang/project-stable-mir/issues/32

r? `@oli-obk`
2023-10-31 19:03:21 +01:00
Matthias Krüger
83990bad48
Rollup merge of #117388 - oli-obk:dequerification, r=RalfJung
Turn const_caller_location from a query to a hook

blocked on https://github.com/rust-lang/rust/pull/117317

cc `@RalfJung`
2023-10-31 19:03:21 +01:00
Oli Scherer
77174d3f29 Turn const_caller_location from a query to a hook 2023-10-31 16:15:18 +00:00
bors
d7d9f15be2 Auto merge of #117407 - compiler-errors:derive-clone, r=oli-obk
Use derivative for `Clone`/`PartialOrd`/`Ord`/`Hash` in `rustc_type_ir`

This uses `derivative` to derive `Clone`/`PartialOrd`/`Ord`/`Hash` for types in `rustc_type_ir`. This doesn't derive `PartialEq`/`Eq` yet, because I have no idea why those are generating slower implementations from derivative.
2023-10-31 15:08:34 +00:00
Michael Goulet
8b4fa0f8b5 Use derivative for Hash 2023-10-31 13:17:36 +00:00
Michael Goulet
8eb932dcf0 Use derivative for PartialOrd/ord 2023-10-31 13:16:38 +00:00
Michael Goulet
de83057ac4 Use derivative for Clone 2023-10-31 13:16:37 +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
793776f39d
Rollup merge of #117421 - Zalathar:error, r=oli-obk,Swatinem
coverage: Replace impossible `coverage::Error` with assertions

Historically, these errors existed so that the coverage debug code could dump additional information before reporting a compiler bug. That debug code was removed by #115962, so we can now simplify these methods by making them panic immediately when they detect a bug.
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
cb918904fe Only emit != assumptions if the otherwise target is reachable. 2023-10-31 11:44:23 +00:00
Camille GILLOT
096196d5b0 Refactor UninhabitedEnumBranching to mark targets unreachable. 2023-10-31 11:44:23 +00:00
Camille GILLOT
0b13e636f5 Simplify assume of a constant. 2023-10-31 11:44:23 +00:00
Camille GILLOT
c748ac1f11 Replace SwitchInt to unreachable by an assumption. 2023-10-31 11:44:23 +00:00
Camille GILLOT
ed27cb0f49 Reorder passes. 2023-10-31 11:44:23 +00:00
Oli Scherer
f8372df631 Merge simd size and type extraction into checking whether a type is simd, as these always go together. 2023-10-31 11:23:39 +00:00
Oli Scherer
9a49ef38c7 Simplify all require_simd invocations by moving all of the shared invocation arguments into the macro 2023-10-31 11:23:39 +00:00
Oli Scherer
7c673db195 don't use the moral equivalent of assert!(false, "foo") 2023-10-31 11:23:39 +00:00
Zalathar
6d956a228b coverage: Replace impossible coverage::Error with assertions
Historically, these errors existed so that the coverage debug code could dump
additional information before reporting a compiler bug. That debug code was
removed by #115962, so we can now simplify these methods by making them panic
when they detect a bug.
2023-10-31 22:20:30 +11:00
Zalathar
8ef67d0f01 coverage: Promote some debug-only checks to always run
These checks should be cheap, so there's little reason for them to be
debug-only.
2023-10-31 22:19:51 +11:00
lcnr
078144e3e8 prepopulate opaque ty storage before using it :> 2023-10-31 11:50:30 +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
bors
ffb7ed9fa4 Auto merge of #117419 - compiler-errors:gen, r=oli-obk
Some more coroutine renamings

a few places where `gen_` names leaked through but should be coroutine.

r? oli-obk
2023-10-31 06:56:46 +00:00
bors
650991d62c Auto merge of #117363 - saethlin:cross-crate-inline-when-inline, r=tmiasko
Enable cross-crate-inlining when MIR inlining is enabled

This would make https://github.com/rust-lang/rust/issues/117355 generally less obscure, and also seems like a good idea, even if for some reason someone wants MIR opts but no codegen opts.
2023-10-31 00:51:25 +00:00
David Tolnay
8b8906b264
Add method for checking if deprecation is a rustc version 2023-10-30 17:13:38 -07:00
David Tolnay
dccf10e989
Descriptive variant name deprecation versions outside the standard library 2023-10-30 17:13:26 -07:00
Michael Goulet
add09e66f2 Some more coroutine renamings 2023-10-30 23:46:27 +00:00
David Tolnay
e8868af75b
Represent absence of 'since' attribute as a variant of DeprecatedSince 2023-10-30 16:46:02 -07: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
David Tolnay
b106167673
Add a DeprecatedSince::Err variant for versions that fail to parse 2023-10-30 15:41:18 -07:00
Esteban Küber
b8a8ba9c91 Sort errors 2023-10-30 22:19:17 +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
Nicholas Nethercote
499b3098f8 Fix a FIXME, by adding a gate_multi macro.
Note that this adds the `span.allows_unstable` checking that this case
previously lacked.
2023-10-31 08:01:01 +11:00
Nicholas Nethercote
de17ec9dae Rearrange the gate_feature_* macros. 2023-10-31 08:01:01 +11:00
Nicholas Nethercote
c88954e9c1 Use if let to reduce some excessive indentation. 2023-10-31 08:01:01 +11:00
Nicholas Nethercote
dcb72e705f Use a slice pattern to neaten a condition. 2023-10-31 08:01:01 +11:00
Nicholas Nethercote
531b38ac23 Cover two more cases in the gate_doc macro. 2023-10-31 08:01:01 +11:00
Nicholas Nethercote
bb3e09f144 Streamline gate_feature_* macros.
The debug probably isn't useful, and assigning all the `$foo`
metavariables to `foo` variables is verbose and weird. Also, `$x:expr`
usually doesn't have a space after the `:`.
2023-10-31 08:00:53 +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
Celina G. Val
af7472ecbc Add a stable MIR visitor
Add a few utility functions as well and extend most `mir` and `ty`
ADTs to implement `PartialEq` and `Eq`.
2023-10-30 13:11:14 -07: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
d96bdbe218
Rollup merge of #117376 - nnethercote:rustc_interface-more, r=oli-obk
More `rustc_interface` cleanups

In particular, following up #117268 with more improvement to `--cfg`/`--check-cfg` handling.

r? ``@oli-obk``
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
5ac999f133
Rollup merge of #117357 - tmiasko:terminate, r=wesleywiser
Rename a few remaining references to abort terminator

Follow up to e3f2edc75b
2023-10-30 17:33:17 +01:00
Guillaume Gomez
99b032f9ff
Rollup merge of #117356 - he32:netbsd-mipsel, r=oli-obk
Add support for mipsel-unknown-netbsd, 32-bit LE mips.
2023-10-30 17:33:16 +01:00
Guillaume Gomez
73100d8e93
Rollup merge of #117317 - RalfJung:track-caller, r=oli-obk
share some track_caller logic between interpret and codegen

Also move the code that implements the track_caller intrinsics out of the core interpreter engine -- it's just a helper creating a const-allocation, doesn't need to be part of the interpreter core.
2023-10-30 17:33:16 +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
Guillaume Gomez
824e3677c2
Rollup merge of #117068 - nnethercote:clean-up-Cargo-toml, r=wesleywiser
Clean up `compiler/rustc*/Cargo.toml`

Mostly by sorting dependencies, plus some other minor things.

r? ``@wesleywiser``
2023-10-30 17:33:15 +01: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
David Tolnay
1e10fe9eb6
Move deprecation_in_effect to inherent method on Deprecation 2023-10-30 09:02:32 -07:00
yukang
147c4a50e0 Refactor: move suggestion functions from demand to suggestions 2023-10-30 23:33:48 +08: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
Michael Goulet
8076414f89 Don't emit delayed good-path bugs on panic 2023-10-30 10:14:43 -04:00
Oli Scherer
43ff2a7e50 Some manual rustfmt as rustfmt is broken on this file 2023-10-30 13:48:34 +00:00
Oli Scherer
251021c1ab Merge two equal match arms 2023-10-30 13:47:08 +00:00
Oli Scherer
8d03e1394f Don't treat closures/coroutines as part of the public API 2023-10-30 13:46:44 +00:00
yukang
82f34fdd23 Fix #117284, Fix unused variables lint issue for args in macro 2023-10-30 21:35:18 +08:00
Gurinder Singh
a2486dba3b Fix missing leading space in suggestion
For a local pattern with no space between `let` and `(` e.g.:

  let(_a) = 3;

we were previously suggesting this illegal code:

  let_a =3;

After this change the suggestion will instead be:

  let _a =3;

(Note the space after `let`)
2023-10-30 19:04:55 +05:30
Oli Scherer
bc926f7c33 Add a custom panic message for resuming gen blocks after they panicked 2023-10-30 10:23:57 +00:00
Oli Scherer
745c600617 Talk about gen fn in diagnostics about gen fn 2023-10-30 10:13:12 +00:00
León Orell Valerian Liehr
288ab16895
Rollup merge of #117385 - RalfJung:deduce_param_attrs, r=oli-obk
deduce_param_attrs: explain a read-only case

This takes the discussion [here](https://github.com/rust-lang/rust/pull/111517/files#r1243443625) and adds it as comment in the code.

Cc `@lukas-code`
2023-10-30 10:48:21 +01:00
León Orell Valerian Liehr
4f4b38c40f
Rollup merge of #117382 - gurry:114529-ice-const-eval, r=oli-obk
Fail typeck for illegal break-with-value

This is fixes the issue wherein typeck was succeeding for break-with-value exprs at illegal locations such as inside `while`, `while let` and `for` loops which eventually caused an ICE during MIR interpretation for const eval.

Now we fail typeck for such code which prevents faulty MIR from being generated and interpreted, thus fixing the ICE.

Fixes #114529
2023-10-30 10:48:20 +01:00
León Orell Valerian Liehr
12eb539bf2
Rollup merge of #117371 - compiler-errors:unique-params, r=oli-obk
Ignore RPIT duplicated lifetimes in `opaque_types_defined_by`

An RPIT's or TAIT's own generics are kinda useless -- so just ignore them. For TAITs, they will always be empty, and for RPITs, they're always duplicated lifetimes.

Fixes #115013.
2023-10-30 10:48:20 +01:00
León Orell Valerian Liehr
fd5ffab4ab
Rollup merge of #117365 - bjorn3:sync_cg_clif-2023-10-29, r=oli-obk
Stabilize inline asm usage with rustc_codegen_cranelift

Previously using inline asm with the cg_clif version built as part of rustc would return an error that inline asm support is unstable. Recently I implemented everything that remained for full support of inline asm with the exception of sym operands (which remain marked as unstable for cg_clif). As such I think it is time to declare the inline asm support of cg_clif stable.

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2023-10-30 10:48:19 +01:00
León Orell Valerian Liehr
9a8d800180
Rollup merge of #117350 - Zalathar:counters-indent, r=oli-obk
coverage: Replace manual debug indents with nested tracing spans in `counters`

Instead of indenting these debug messages manually, we can get `#[instrument]` to do a better job of it for us, giving us some nice little simplifications.
2023-10-30 10:48:19 +01:00
León Orell Valerian Liehr
5eb76fac7c
Rollup merge of #117205 - weiznich:multiple_notes_for_on_unimplemented, r=compiler-errors
Allows `#[diagnostic::on_unimplemented]` attributes to have multiple

notes

This commit extends the `#[diagnostic::on_unimplemented]` (and `#[rustc_on_unimplemented]`) attributes to allow multiple `note` options. This enables emitting multiple notes for custom error messages. For now I've opted to not change any of the existing usages of `#[rustc_on_unimplemented]` and just updated the relevant compile tests.

r? `@compiler-errors`

I'm happy to adjust any of the existing changed location to emit the old error message if that's desired.
2023-10-30 10:48:18 +01:00
León Orell Valerian Liehr
2915707622
Rollup merge of #117147 - DaniPopes:pphir-fn-variadic, r=compiler-errors
Print variadic argument pattern in HIR pretty printer

Variadic argument name/pattern was ignored during HIR pretty printing.
Could not figure out why it only works on normal functions (`va2`) and not in foreign ones (`va1`).
2023-10-30 10:48:17 +01:00
Nicholas Nethercote
0c381ec05a Streamline some use items. 2023-10-30 20:45:11 +11:00
Nicholas Nethercote
90862f63f9 Remove an unnecessary drop. 2023-10-30 20:45:11 +11:00
Nicholas Nethercote
be8fd8b7d0 Streamline collect_crate_types.
- The early return can be right at the top.
- The control flow is simplified with `if let`.
- The `collect` isn't necessary.
- The "Unconditionally" comment is erroneously duplicated from
  `check_attr_crate_type`, and can be removed.
2023-10-30 20:42:11 +11:00
Ralf Jung
3f7e50696f deduce_param_attrs: explain a read-only case 2023-10-30 10:29:08 +01:00
Gurinder Singh
0c8bdd0bf3 Fail typeck for illegal break-with-value
This is fixes the issue wherein typeck was succeeding for break-with-value
at illegal locations such as inside `while`, `while let` and `for` loops which
eventually caused an ICE during MIR interpetation for const eval.

Now we fail typeck for such code which prevents faulty MIR from being generated
and interpreted, thus fixing the ICE.
2023-10-30 13:03:40 +05:30
David Tolnay
8afb40b3a8
Delete unused InvalidDeprecationVersion diagnostic 2023-10-29 22:50:49 -07:00
David Tolnay
2fe7d17bd9
Store version of deprecated attribute in structured form 2023-10-29 22:42:32 -07:00
Nicholas Nethercote
95b0088e7c Remove check_output.
Using `find` and `any` from `std` makes the code shorter and clearer.
2023-10-30 15:42:03 +11:00
David Tolnay
1e5b2da94b
Rename Since -> StableSince in preparation for a DeprecatedSince 2023-10-29 21:39:57 -07:00
Nicholas Nethercote
a60d6438dc Wrap some overlong comments. 2023-10-30 15:33:05 +11:00
Nicholas Nethercote
85e56e81f8 Remove out-of-date comment.
It was added in 51938c61f6, a commit with
a 7,720 line diff and a one line commit message. Even then the comment
was incorrect; there was a removed a `build_output_filenames` call with
a `&[]` argument in rustdoc, but the commit removed that call. In such a
large commit, it's easy for small errors to occur.
2023-10-30 15:26:47 +11:00
Nicholas Nethercote
371f972571 Improve readability of parse_check_cfg. 2023-10-30 15:06:48 +11:00
bors
91bbdd927a Auto merge of #116485 - coastalwhite:stabilize-riscv-target-features, r=Amanieu
Stabilize Ratified RISC-V Target Features

Stabilization PR for the ratified RISC-V target features. This stabilizes some of the target features tracked by #44839. This is also a part of #114544 and eventually needed for the RISC-V part of rust-lang/rfcs#3268.

There is a similar PR for the the stdarch crate which can be found at rust-lang/stdarch#1476.

This was briefly discussed on Zulip
(https://rust-lang.zulipchat.com/#narrow/stream/250483-t-compiler.2Frisc-v/topic/Stabilization.20of.20RISC-V.20Target.20Features/near/394793704).

Specifically, this PR stabilizes the:
* Atomic Instructions (A) on v2.0
* Compressed Instructions (C) on v2.0
* ~Double-Precision Floating-Point (D) on v2.2~
* ~Embedded Base (E) (Given as `RV32E` / `RV64E`) on v2.0~
* ~Single-Precision Floating-Point (F) on v2.2~
* Integer Multiplication and Division (M) on v2.0
* ~Vector Operations (V) on v1.0~
* Bit Manipulations (B) on v1.0 listed as `zba`, `zbc`, `zbs`
* Scalar Cryptography (Zk) v1.0.1 listed as `zk`, `zkn`, `zknd`, `zkne`, `zknh`, `zkr`, `zks`, `zksed`, `zksh`, `zkt`, `zbkb`, `zbkc` `zkbx`
* ~Double-Precision Floating-Point in Integer Register (Zdinx) on v1.0~
* ~Half-Precision Floating-Point (Zfh) on v1.0~
* ~Minimal Half-Precision Floating-Point (Zfhmin) on v1.0~
* ~Single-Precision Floating-Point in Integer Register (Zfinx) on v1.0~
* ~Half-Precision Floating-Point in Integer Register (Zhinx) on v1.0~
* ~Minimal Half-Precision Floating-Point in Integer Register (Zhinxmin) on v1.0~

r? `@Amanieu`
2023-10-30 03:57:10 +00:00
Nicholas Nethercote
5c6a12c1af Make Cfg and CheckCfg non-generic.
They now only ever contains symbols.
2023-10-30 14:12:53 +11:00
Nicholas Nethercote
8e4ac980fd Change cfg parsers to produce symbols instead of strings. 2023-10-30 14:12:51 +11:00
Nicholas Nethercote
bfcff7933e Reduce exposure of cfg parsers. 2023-10-30 13:52:03 +11:00
Nicholas Nethercote
678e01a3fc Delay parsing of --cfg and --check-cfg options.
By storing the unparsed values in `Config` and then parsing them within
`run_compiler`, the parsing functions can use the main symbol interner,
and not create their own short-lived interners.

This change also eliminates the need for one `EarlyErrorHandler` in
rustdoc, because parsing errors can be reported by another, slightly
later `EarlyErrorHandler`.
2023-10-30 13:46:53 +11:00
Zalathar
10c4734c79 coverage: Use a tracing span to group the parts of a sum-up expression 2023-10-30 12:46:43 +11:00
Zalathar
2f1be08473 coverage: Inline the "recursive" worker methods for assigning counters
Now that we don't manually pass around indent levels, there's no need for these
worker methods to exist separately from their main callers.
2023-10-30 12:46:43 +11:00
Zalathar
6d69eb1f2e coverage: Replace manual debug indents with nested tracing spans 2023-10-30 12:46:43 +11:00
Esteban Küber
50ca5ef07f When encountering unclosed delimiters during parsing, check for diff markers
Fix #116252.
2023-10-30 00:56:46 +00:00
Esteban Küber
b589f47441 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-10-30 00:15:49 +00:00
Esteban Küber
8c04999226 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.

Account for object unsafe `impl Trait on dyn Trait {}`.  Make a
distinction between public and sealed traits.

Fix #80194.
2023-10-29 23:55:46 +00:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Michael Goulet
c5613258bb Ignore RPIT duplicated lifetimes in opaque_types_defined_by 2023-10-29 17:45:05 -04:00
Nicholas Nethercote
28e60de487 Remove memoffset dependency from rustc_query_impl.
The comment explains it's for `unstable_offset_of`, but `offset_of` is
now stable.
2023-10-30 08:25:51 +11:00
bjorn3
a9b21bb727 Merge commit 'dde58803fd6cbb270c7a437f36a8a3a29fbef679' into sync_cg_clif-2023-10-29 2023-10-29 20:30:50 +00:00
bors
ec2b311914 Auto merge of #116733 - compiler-errors:alias-liveness-but-this-time-sound, r=aliemjay
Consider alias bounds when computing liveness in NLL (but this time sound hopefully)

This is a revival of #116040, except removing the changes to opaque lifetime captures check to make sure that we're not triggering any unsoundness due to the lack of general existential regions and the currently-existing `ReErased` hack we use instead.

r? `@aliemjay` -- I appreciate you pointing out the unsoundenss in the previous iteration of this PR, and I'd like to hear that you're happy with this iteration of this PR before this goes back into FCP :>

Fixes #116794 as well

---

(mostly copied from #116040 and reworked slightly)

# Background

Right now, liveness analysis in NLL is a bit simplistic. It simply walks through all of the regions of a type and marks them as being live at points. This is problematic in the case of aliases, since it requires that we mark **all** of the regions in their args[^1] as live, leading to bugs like #42940.

In reality, we may be able to deduce that fewer regions are allowed to be present in the projected type (or "hidden type" for opaques) via item bounds or where clauses, and therefore ideally, we should be able to soundly require fewer regions to be live in the alias.

For example:
```rust
trait Captures<'a> {}
impl<T> Captures<'_> for T {}

fn capture<'o>(_: &'o mut ()) -> impl Sized + Captures<'o> + 'static {}

fn test_two_mut(mut x: ()) {
    let _f1 = capture(&mut x);
    let _f2 = capture(&mut x);
    //~^ ERROR cannot borrow `x` as mutable more than once at a time
}
```

In the example above, we should be able to deduce from the `'static` bound on `capture`'s opaque that even though `'o` is a captured region, it *can never* show up in the opaque's hidden type, and can soundly be ignored for liveness purposes.

# The Fix

We apply a simple version of RFC 1214's `OutlivesProjectionEnv` and `OutlivesProjectionTraitDef` rules to NLL's `make_all_regions_live` computation.

Specifically, when we encounter an alias type, we:
1. Look for a unique outlives bound in the param-env or item bounds for that alias. If there is more than one unique region, bail, unless any of the outlives bound's regions is `'static`, and in that case, prefer `'static`. If we find such a unique region, we can mark that outlives region as live and skip walking through the args of the opaque.
2. Otherwise, walk through the alias's args recursively, as we do today.

## Limitation: Multiple choices

This approach has some limitations. Firstly, since liveness doesn't use the same type-test logic as outlives bounds do, we can't really try several options when we're faced with a choice.

If we encounter two unique outlives regions in the param-env or bounds, we simply fall back to walking the opaque via its args. I expect this to be mostly mitigated by the special treatment of `'static`, and can be fixed in a forwards-compatible by a more sophisticated analysis in the future.

## Limitation: Opaque hidden types

Secondly, we do not employ any of these rules when considering whether the regions captured by a hidden type are valid. That causes this code (cc #42940) to fail:

```rust
trait Captures<'a> {}
impl<T> Captures<'_> for T {}

fn a() -> impl Sized + 'static {
    b(&vec![])
}

fn b<'o>(_: &'o Vec<i32>) -> impl Sized + Captures<'o> + 'static {}
```

We need to have existential regions to avoid [unsoundness](https://github.com/rust-lang/rust/pull/116040#issuecomment-1751628189) when an opaque captures a region which is not represented in its own substs but which outlives a region that does.

## Read more

Context: https://github.com/rust-lang/rust/pull/115822#issuecomment-1731153952 (for the liveness case)
More context: https://github.com/rust-lang/rust/issues/42940#issuecomment-455198309 (for the opaque capture case, which this does not fix)

[^1]: except for bivariant region args in opaques, which will become less relevant when we move onto edition 2024 capture semantics for opaques.
2023-10-29 18:42:02 +00:00
Ben Kimock
e53b18f033 Enable cross-crate-inlining when MIR inlining is enabled 2023-10-29 13:20:51 -04:00
bors
88ae8c9385 Auto merge of #116889 - MU001999:master, r=petrochenkov
Eat close paren if capture_cfg to avoid unbalanced parens

Fixes #116781
2023-10-29 16:46:47 +00:00
bors
83c9732e0c Auto merge of #116270 - cjgillot:gvn-aggregate, r=oli-obk,RalfJung
See through aggregates in GVN

This PR is extracted from https://github.com/rust-lang/rust/pull/111344

The first 2 commit are cleanups to avoid repeated work. I propose to stop removing useless assignments as part of this pass, and let a later `SimplifyLocals` do it. This makes tests easier to read (among others).

The next 3 commits add a constant folding mechanism to the GVN pass, presented in https://github.com/rust-lang/rust/pull/116012. ~This pass is designed to only use global allocations, to avoid any risk of accidental modification of the stored state.~

The following commits implement opportunistic simplifications, in particular:
- projections of aggregates: `MyStruct { x: a }.x` gets replaced by `a`, works with enums too;
- projections of arrays: `[a, b][0]` becomes `a`;
- projections of repeat expressions: `[a; N][x]` becomes `a`;
- transform arrays of equal operands into a repeat rvalue.

Fixes https://github.com/rust-lang/miri/issues/3090

r? `@oli-obk`
2023-10-29 14:50:53 +00:00