Commit Graph

6028 Commits

Author SHA1 Message Date
bors ae612bedcb Auto merge of #118689 - compiler-errors:const-drop, r=fee1-dead
Fix const drop checking

Fixes confirmation of `~const Destruct` and const drops.

r? fee1-dead
2023-12-08 13:43:12 +00:00
bors 21982a4383 Auto merge of #118725 - lcnr:normalizes-to-projection-split-3, r=BoxyUwU
split `NormalizesTo` out of `Projection` 3

third attempt at #112658. Rebasing #116262 is very annoying, so I am doing it again from scratch. We should now be able to merge it without regressing anything as we handle occurs check failures involving aliases correctly since #117088.

see https://hackmd.io/ktEL8knTSYmtdfrMMnA-Hg

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

r? `@compiler-errors`
2023-12-08 02:28:10 +00:00
lcnr ffb4c08a81 implement and use `NormalizesTo` 2023-12-08 01:31:18 +01:00
bors 503e129328 Auto merge of #118568 - DianQK:no-builtins-symbols, r=pnkfelix
Avoid adding builtin functions to `symbols.o`

We found performance regressions in #113923. The problem seems to be that `--gc-sections` does not remove these symbols. I tested that lld removes these symbols, but ld and gold do not.

I found that `used` adds symbols to `symbols.o` at 3e202ead60/compiler/rustc_codegen_ssa/src/back/linker.rs (L1786-L1791).
The PR removes builtin functions.

Note that under LTO, ld still preserves these symbols. (lld will still remove them.)

The first commit also fixes #118559. But I think the second commit also makes sense.
2023-12-07 20:31:55 +00:00
bors 0e7f91b75e Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlin
compile-time evaluation: detect writes through immutable pointers

This has two motivations:
- it unblocks https://github.com/rust-lang/rust/pull/116745 (and therefore takes a big step towards `const_mut_refs` stabilization), because we can now detect if the memory that we find in `const` can be interned as "immutable"
- it would detect the UB that was uncovered in https://github.com/rust-lang/rust/pull/117905, which was caused by accidental stabilization of `copy` functions in `const` that can only be called with UB

When UB is detected, we emit a future-compat warn-by-default lint. This is not a breaking change, so completely in line with [the const-UB RFC](https://rust-lang.github.io/rfcs/3016-const-ub.html), meaning we don't need t-lang FCP here. I made the lint immediately show up for dependencies since it is nearly impossible to even trigger this lint without `const_mut_refs` -- the accidentally stabilized `copy` functions are the only way this can happen, so the crates that popped up in #117905 are the only causes of such UB (in the code that crater covers), and the three cases of UB that we know about have all been fixed in their respective crates already.

The way this is implemented is by making use of the fact that our interpreter is already generic over the notion of provenance. For CTFE we now use the new `CtfeProvenance` type which is conceptually an `AllocId` plus a boolean `immutable` flag (but packed for a more efficient representation). This means we can mark a pointer as immutable when it is created as a shared reference. The flag will be propagated to all pointers derived from this one. We can then check the immutable flag on each write to reject writes through immutable pointers.

I just hope perf works out.
2023-12-07 18:11:01 +00:00
lcnr 3978f545ba add unused `NormalizesTo` predicate 2023-12-07 17:52:51 +01:00
Ralf Jung 29c95e98e3 also print 'immutable' flag 2023-12-07 17:46:36 +01:00
Ralf Jung cb86303342 ctfe interpreter: extend provenance so that it can track whether a pointer is immutable 2023-12-07 17:46:36 +01:00
Michael Goulet efe8ae730f Fix const drop checking 2023-12-07 16:28:33 +00:00
bors f90f898fa5 Auto merge of #118685 - compiler-errors:stack-dependent, r=lcnr
`EvaluatedToUnknown` -> `EvaluatedToAmbigStackDependent`, `EvaluatedToRecur` -> `EvaluatedToErrStackDependent`

Less confusing names, since the only difference between them and their parallel `EvalutedTo..` is that they are stack dependent.

r? lcnr
2023-12-07 08:00:12 +00:00
bors 670188cec9 Auto merge of #118684 - compiler-errors:yeet-poly-gen-sig, r=spastorino
Remove `PolyGenSig` since it's always a dummy binder

Coroutines are never polymorphic in their signature. This cleans up a FIXME in the code:

```
    /// Returns the "coroutine signature", which consists of its yield
    /// and return types.
    ///
    /// N.B., some bits of the code prefers to see this wrapped in a
    /// binder, but it never contains bound regions. Probably this
    /// function should be removed.
```
2023-12-07 00:30:07 +00:00
Matthias Krüger cf78a79020
Rollup merge of #118660 - cuviper:alloc_str, r=petrochenkov
rustc_arena: add `alloc_str`

Two places called `from_utf8_unchecked` for strings from `alloc_slice`,
and one's SAFETY comment said this was for lack of `alloc_str` -- so
let's just add that instead!
2023-12-06 21:52:32 +01:00
Michael Goulet d732c3b756 EvaluatedToUnknown -> EvaluatedToAmbigStackDependent, EvaluatedToRecur -> EvaluatedToErrStackDependent 2023-12-06 19:59:47 +00:00
Michael Goulet 1ec3ef7d81 Yeet PolyGenSig 2023-12-06 19:50:35 +00:00
bors f32d29837d Auto merge of #118605 - fee1-dead-contrib:rm-rustc_host, r=compiler-errors
Remove `#[rustc_host]`, use internal desugaring

Also removed a way for users to explicitly specify the host param since that isn't particularly useful. This should eliminate any pain with encoding attributes across crates and etc.

r? `@compiler-errors`
2023-12-06 16:00:24 +00:00
Josh Stone 92bf40ffe3 rustc_arena: add `alloc_str`
Two places called `from_utf8_unchecked` for strings from `alloc_slice`,
and one's SAFETY comment said this was for lack of `alloc_str` -- so
let's just add that instead!
2023-12-05 17:52:51 -08:00
Michael Goulet b97ff8eb16 Add print_trait_sugared 2023-12-05 17:15:46 +00:00
Deadbeef 65212a07e7 Remove `#[rustc_host]`, use internal desugaring 2023-12-05 01:15:21 +00:00
DianQK 9ed0d11efb
Avoid adding compiler-used functions to `symbols.o` 2023-12-04 22:28:00 +08:00
Vadim Petrochenkov 17e799c270 rustc: Harmonize `DefKind` and `DefPathData`
`DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`.

`DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`.
It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` could be a better solution, but that would be a much more invasive change.

Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values.

`DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-12-03 16:24:56 +03:00
Ralf Jung 1d120e6169 fix an ICE when a valtree failed to evaluate 2023-12-02 10:38:42 +01:00
bors 2da59b8676 Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errors
Cleanup error handlers

Mostly by making function naming more consistent. More to do after this, but this is enough for one PR.

r? compiler-errors
2023-12-02 02:48:34 +00:00
Nicholas Nethercote cb91235131 Rename `LayoutCalculator::delay_bug` as `LayoutCalculator::delayed_bug`.
To match with the previous commits.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote c9008c6c8b Rename `Handler::delay_good_path_bug` as `Handler::good_path_delayed_bug`.
In line with the previous commits.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote 5d1d384443 Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug`
follows the pattern used everywhere else: `span_err`, `span_warning`,
etc.
2023-12-02 09:01:19 +11:00
bohan d0941f92d7 vis note for no pub reexports glob import 2023-12-01 12:10:07 +08:00
bors e55544c804 Auto merge of #118379 - compiler-errors:const-params-for-partialeq, r=fee1-dead
Fix `PartialEq` args when `#[const_trait]` is enabled

This is based off of your PR that enforces effects on all methods, so just see the last commits.

r? fee1-dead
2023-11-30 05:24:53 +00:00
Matthias Krüger 911a5ee7ff
Rollup merge of #118333 - eduardosm:print-missing-target-features, r=est31
Print list of missing target features when calling a function with target features outside an unsafe block

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

Supersedes https://github.com/rust-lang/rust/pull/109710. I used the same wording for the messages, but the implementation is different.

r? `@est31`
2023-11-29 12:34:50 +01:00
Matthias Krüger c03f8917ee
Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors
Add `never_patterns` feature gate

This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (https://github.com/rust-lang/rust/issues/118155) for details on the experiment.

`@scottmcm` has agreed to be my lang-team liaison for this experiment.
2023-11-29 12:34:47 +01:00
Nadrieril a3838c8550 Add `never_patterns` feature gate 2023-11-29 03:58:29 +01:00
Michael Goulet d3404d2b98 Add with_opt_const_effect_param helper, simplify 2023-11-28 21:17:55 +00:00
Michael Goulet 82a9e872d8 Fix PartialEq args when #[const_trait] is enabled 2023-11-28 21:17:19 +00:00
Vadim Petrochenkov f0dc906319 resolve: Feed the `def_kind` query immediately on `DefId` creation 2023-11-28 15:39:31 +03:00
bors 6eb9524047 Auto merge of #117200 - rmehri01:repeated_help, r=WaffleLapkin
Don't add redundant help for object safety violations

Fixes #117186

r? WaffleLapkin
2023-11-27 19:37:35 +00:00
Eduardo Sánchez Muñoz 51ba662d23 Print list of missing target features when calling a function with target features outside an unsafe block 2023-11-27 19:13:11 +01:00
Takayuki Maeda 3dc807ca07
Rollup merge of #118340 - compiler-errors:tweaks, r=lqd
Use helper functions in `pretty.rs` instead of accessing the `Cell`s manually

Pulled this out of another PR that I never landed.
2023-11-27 22:38:24 +09:00
Michael Goulet 0eb85ff03f Use helpers 2023-11-26 23:24:53 +00:00
bors 6cf088810f Auto merge of #118316 - Mark-Simulacrum:delete-copy-to-upvars, r=cjgillot
Remove borrowck Upvar duplication

This cuts out an extra allocation and copying over from the already cached closure capture information.
2023-11-26 21:47:19 +00:00
Mark Rousskov d920dd8d38 Remove Upvar duplication
This cuts out an extra allocation and copying over from the already
cached closure capture information.
2023-11-26 13:19:10 -05:00
Ryan Mehri af6b84aaab
don't add redundant help for object safety violations 2023-11-26 09:53:58 -08:00
bors 3bb0171999 Auto merge of #118319 - GuillaumeGomez:rollup-vte50yq, r=GuillaumeGomez
Rollup of 4 pull requests

Successful merges:

 - #118296 (rustdoc: replace `elemIsInParent` with `Node.contains`)
 - #118302 (Clean dead codes)
 - #118311 (merge `DefKind::Coroutine` into `Defkind::Closure`)
 - #118318 (Remove myself from users on vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-26 16:42:32 +00:00
Guillaume Gomez c6d20d70b4
Rollup merge of #118311 - bvanjoi:merge_coroutinue_into_closure, r=petrochenkov
merge `DefKind::Coroutine` into `Defkind::Closure`

Related to #118188

We no longer need to be concerned about the precise type whether it's `DefKind::Closure` or `DefKind::Coroutine`.

Furthermore, thanks for the great work done by `@petrochenkov` on investigating https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Why.20does.20it.20hang.20when.20querying.20.EF.BB.BF.60opt_def_kind.60.3F

r? `@petrochenkov`
2023-11-26 15:44:54 +01:00
bors 3dbb4da042 Auto merge of #117301 - saethlin:finish-rmeta-encoding, r=WaffleLapkin
Call FileEncoder::finish in rmeta encoding

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

The bug here was that rmeta encoding never called FileEncoder::finish. Now it does. Most of the changes here are needed to support that, since rmeta encoding wants to finish _then_ access the File in the encoder, so finish can't move out.

I tried adding a `cfg(debug_assertions)` exploding Drop impl to FileEncoder that checked for finish being called before dropping, but fatal errors cause unwinding so this isn't really possible. If we encounter a fatal error with a dirty FileEncoder, the Drop impl ICEs even though the implementation is correct. If we try to paper over that by wrapping FileEncoder in ManuallyDrop then that just erases the fact that Drop automatically checks that we call finish on all paths.

I also changed the name of DepGraph::encode to DepGraph::finish_encoding, because that's what it does and it makes the fact that it is the path to FileEncoder::finish less confusing.

r? `@WaffleLapkin`
2023-11-26 14:43:02 +00:00
bohan f23befe6c1 merge `DefKind::Coroutine` into `DefKind::Closure` 2023-11-26 21:05:08 +08:00
Vadim Petrochenkov c697927f44 rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` cleanup 2023-11-26 12:41:21 +03:00
bors 5c97719393 Auto merge of #118250 - petrochenkov:optdefkind, r=compiler-errors
rustc: Make `def_kind` mandatory for all `DefId`s

Prerequisite for https://github.com/rust-lang/rust/pull/118188.
2023-11-26 04:44:20 +00:00
Michael Goulet 8dd8db5073
Rollup merge of #118288 - compiler-errors:is_some_and, r=lqd,dtolnay
Use `is_{some,ok}_and` more in the compiler

slightly more fluent-reading code
2023-11-25 17:23:34 -05:00
Michael Goulet f4b7f35c4d
Rollup merge of #118201 - compiler-errors:obligation-causes, r=cjgillot
Miscellaneous `ObligationCauseCode` cleanups

Remove some dead code/unused `ObligationCauseCode`s.
2023-11-25 17:23:34 -05:00
Michael Goulet 3b2f33ee28
Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, r=compiler-errors
Reduce fluent boilerplate

Best reviewed one commit at a time.

r? `@davidtwco`
2023-11-25 17:23:33 -05:00
Michael Goulet ca56739366 Remove 3 more unused ObligationCauseCodes 2023-11-25 22:10:52 +00:00