Commit Graph

152 Commits

Author SHA1 Message Date
bors
4b91288484 Auto merge of #115486 - compiler-errors:dont-capture-late-pls, r=cjgillot
Correctly deny late-bound lifetimes from parent in anon consts and TAITs

Reuse the `AnonConstBoundary` scope (introduced in #108553, renamed in this PR to `LateBoundary`) to deny late-bound vars of *all* kinds (ty/const/lifetime) in anon consts and TAITs.

Side-note, but I would like to consolidate this with the error reporting for RPITs (E0657):
c4f25777a0/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs (L733-L754) but the semantics about what we're allowed to capture there are slightly different, so I'm leaving that untouched.

Fixes #115474
2023-09-20 03:34:51 +00:00
Ralf Jung
9ac8b363e3 don't point at const usage site for resolution-time errors
also share the code that emits the actual error
2023-09-14 22:34:05 +02:00
Ralf Jung
89ac57db4d move required_consts check to general post-mono-check function 2023-09-14 22:30:42 +02:00
Ralf Jung
04a4df5f16 add regression test for something we fixed 2023-09-14 11:56:55 +02:00
bors
1e746d7741 Auto merge of #115527 - oli-obk:drop_maybe_uninit_in_const, r=lcnr
Don't require `Drop` for `[PhantomData<T>; N]` where `N` and `T` are generic, if `T` requires `Drop`

fixes https://github.com/rust-lang/rust/issues/115403
fixes https://github.com/rust-lang/rust/issues/115410

This was accidentally regressed in https://github.com/rust-lang/rust/pull/114134, because it was accidentally stabilized in #102204 (cc `@rust-lang/lang,` seems like an innocent stabilization, considering this PR is more of a bugfix than a feature).

While we have a whole month to beta backport this change before the regression hits stable, I'd still prefer not to go through an FCP on this PR (which fixes a regression), if T-lang wants an FCP, I can can open an issue about the change itself.
2023-09-07 19:10:07 +00:00
Oli Scherer
320bb8116f Don't require Drop for [PhantomData<T>; N] where N and T are generic, if T requires Drop 2023-09-07 18:31:17 +00:00
Michael Goulet
52aff53812 Correctly deny late-bound lifetimes from parent in anon consts and TAITs 2023-09-05 20:20:55 +00:00
bors
626a6ab93f Auto merge of #115531 - RalfJung:read_via_copy, r=scottmcm
read_via_copy: don't prematurely optimize away the read

Always do the read to ensure consistent UB error messages in const-eval/Miri.

r? `@scottmcm`
2023-09-05 03:45:17 +00:00
Ralf Jung
7093903ba7 read_via_copy: don't prematurely optimize away the read 2023-09-04 18:27:34 +02:00
bors
bf1e3f31f9 Auto merge of #115513 - Urgau:normalize-msg-after-translate, r=petrochenkov
Don't forget to normalize the translated message

This PR adds a missing call to `normalize_whitespace` after translating an label.

Fixes https://github.com/rust-lang/rust/issues/115498
2023-09-04 10:02:57 +00:00
Urgau
ec0975dd6b Don't forget to normalize the translated message 2023-09-03 17:10:42 +02:00
Michael Goulet
13e8b13e15 Handle Self in paths too 2023-08-25 19:05:38 +00:00
Matthias Krüger
d4b6cff42f
Rollup merge of #115169 - RalfJung:do-not-ignore-debug, r=cjgillot
remove some unnecessary ignore-debug clauses

ignore-debug is only needed when the debug assertions *in the standard library* somehow affect the test. This can happen with inlining but otherwise should be rare. ignore-debug is problematic since PR CI is only run with debug assertions.

r? `@cjgillot` since it looks like you added most of these
2023-08-25 09:00:14 +02:00
Ralf Jung
e4c4f9b9d9 remove some unnecessary ignore-debug clauses 2023-08-24 14:10:18 +02:00
Ulrich Weigand
2063067a81 Fix ub-int-array test for big-endian platforms
As of commit 7767cbb3b0,
the tests/ui/consts/const-eval/ub-int-array.rs test is
failing on big-endian platforms (in particular s390x),
as the stderr output contains a hex dump that depends
on endianness.

Since this point intentionally verifies the hex dump to
check the uninitialized byte markers, I think we should
not simply standardize away the hex dump as is done with
some of the other tests in this directory.

However, most of the test is already endian-independent.
The only exception is one line of hex dump, which can
also be made endian-independent by choosing appropriate
constants in the source code.

Since the 32bit and 64bit stderr outputs were already
(and remain) identical, I've merged them and removed
the stderr-per-bitwidth marker.

Fixes (again) https://github.com/rust-lang/rust/issues/105383.
2023-08-24 12:49:53 +02: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
Ralf Jung
ac3bca24b7 interpret: have assert_* intrinsics call the panic machinery instead of a direct abort 2023-08-20 15:52:40 +02:00
Michael Goulet
fad7d220fd Warn on elided lifetimes in associated constants 2023-08-20 00:21:47 +00:00
bors
f88a8b71ce Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obk
correctly lower `impl const` to bind to host effect param

r? `@oli-obk`
2023-08-08 19:23:41 +00:00
Deadbeef
057be381c6 Fix ICE 2023-08-07 17:16:10 +00:00
Scott McMurray
502af03445 Add a new compare_bytes intrinsic instead of calling memcmp directly 2023-08-06 15:47:40 -07:00
Deadbeef
6c1e3bb6e9 bless tests 2023-08-06 13:34:53 +00:00
Matthias Krüger
99e4127d85
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.

r? compiler-errors
2023-08-04 21:31:57 +02:00
Nilstrieb
5706be1854 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
Matthias Krüger
00dcc7b97c
Rollup merge of #114372 - RalfJung:const-pointer-as-int, r=oli-obk
const validation: point at where we found a pointer but expected an integer

Instead of validation just printing "unable to turn pointer into bytes", make this a regular validation error that says where in the value the bad pointer was found. Also distinguish "expected integer, got pointer" from "expected pointer, got partial pointer or mix of pointers".

To avoid duplicating things too much I refactored the diagnostics for validity a bit, so that "got uninit, expected X" and "got pointer, expected X" can share the "X" part. Also all the errors emitted for validation are now grouped under `const_eval_validation` so that they are in a single group in the ftl file.

r? `@oli-obk`
2023-08-03 17:29:08 +02:00
Matthias Krüger
7518ae566e
Rollup merge of #113657 - Urgau:expand-incorrect_fn_null_check-lint, r=cjgillot
Expand, rename and improve `incorrect_fn_null_checks` lint

This PR,

 - firstly, expand the lint by now linting on references
 - secondly, it renames the lint `incorrect_fn_null_checks` -> `useless_ptr_null_checks`
 - and thirdly it improves the lint by catching `ptr::from_mut`, `ptr::from_ref`, as well as `<*mut _>::cast` and `<*const _>::cast_mut`

Fixes https://github.com/rust-lang/rust/issues/113601
cc ```@est31```
2023-08-03 17:29:06 +02:00
Urgau
4b3dadbe5a Also lint on cast/cast_mut and ptr::from_mut/ptr::from_ref 2023-08-03 10:52:15 +02:00
Ralf Jung
7767cbb3b0 const validation: point at where we found a pointer but expected an integer 2023-08-02 18:51:50 +02:00
Deadbeef
4fec845c3f Remove constness from TraitPredicate 2023-08-02 15:38:00 +00:00
Nilstrieb
60399a888d
Rollup merge of #114335 - RalfJung:ptr_comparisons, r=oli-obk
fix and extend ptr_comparison test

r? ```@oli-obk```
2023-08-02 13:46:55 +02:00
bors
64ad036307 Auto merge of #114333 - RalfJung:dangling-ptr-offset, r=oli-obk
Miri: fix error on dangling pointer inbounds offset

We used to claim that the pointer was "dereferenced", but that is just not true.

Can be reviewed commit-by-commit. The first commit is an unrelated rename that didn't seem worth splitting into its own PR.

r? `@oli-obk`
2023-08-02 09:12:32 +00:00
Ralf Jung
69b02ef4be fix and extend ptr_comparison test 2023-08-01 18:23:37 +02:00
Ralf Jung
8496292dda properly track why we checked whether a pointer is in-bounds
also simplify the in-bounds checking in Miri's borrow trackers
2023-08-01 17:57:13 +02:00
bors
828bdc2c26 Auto merge of #112849 - m-ou-se:panic-message-format, r=thomcc
Change default panic handler message format.

This changes the default panic hook's message format from:

```
thread '{thread}' panicked at '{message}', {location}
```

to

```
thread '{thread}' panicked at {location}:
{message}
```

This puts the message on its own line without surrounding quotes, making it easiser to read. For example:

Before:
```
thread 'main' panicked at 'env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`', src/main.rs:4:6
```
After:
```
thread 'main' panicked at src/main.rs:4:6:
env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`
```

---

See this PR by `@nyurik,` which does that for only multi-line messages (specifically because of `assert_eq`): https://github.com/rust-lang/rust/pull/111071

This is the change that does that for *all* panic messages.
2023-08-01 14:15:09 +00:00
bors
d4145eeef4 Auto merge of #112843 - chenyukang:yukang-more-on-backtrace, r=workingjubilee
Print omitted frames count for short backtrace mode

Fixes #111730
2023-07-30 22:31:52 +00:00
Matthias Krüger
e3ca397593
Rollup merge of #102198 - lukas-code:nonnull_as_ref, r=Amanieu
`const`-stablilize `NonNull::as_ref`

A bunch of pointer to reference methods have been made unstably const some time ago in #91823 under the feature gate `const_ptr_as_ref`.
Out of these, `NonNull::as_ref` can be implemented as a `const fn` in stable rust today, so i hereby propose to const stabilize this function only.

Tracking issue: #91822

``@rustbot`` label +T-libs-api -T-libs
2023-07-30 20:36:34 +02:00
yukang
90db98d074 print omitted frames count for short backtrace mode 2023-07-29 20:36:05 +08:00
Mara Bos
4017c5c945 Fix tests. 2023-07-29 11:47:26 +02:00
Mara Bos
0e729404da Change default panic handler message format. 2023-07-29 11:42:50 +02:00
Deadbeef
2d59451274 update tests, adding known-bug 2023-07-27 15:51:02 +00:00
Ralf Jung
4ea2bd1c8f bless more 2023-07-25 14:30:58 +02:00
Ralf Jung
a2bcafa500 interpret: refactor projection code to work on a common trait, and use that for visitors 2023-07-25 14:30:58 +02:00
Ralf Jung
a593de4fab interpret: support projecting into Place::Local without force_allocation 2023-07-24 15:35:47 +02:00
David Tolnay
5bbf0a8306
Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"
This reverts commit 557359f925, reversing
changes made to 1e6c09a803.
2023-07-21 22:35:57 -07:00
Moulins
cb8b1d1bc9 add naive_layout_of query 2023-07-21 03:31:45 +02:00
nxya
a54a66830d moved note as unspanned note, moved note to the bottom of the msg 2023-07-18 21:53:34 -04:00
nxya
e6e8892051 added links as a note 2023-07-18 09:27:35 -04:00
nxya
f92a9f6808 add links to query documentation for E0391 2023-07-18 09:27:26 -04:00
nxya
bef91ee687 added links as a note 2023-07-18 09:20:25 -04:00
nxya
c429a72db9 add links to query documentation for E0391 2023-07-18 09:20:25 -04:00