Commit Graph

3316 Commits

Author SHA1 Message Date
Ralf Jung
89ac57db4d move required_consts check to general post-mono-check function 2023-09-14 22:30:42 +02:00
bors
dac91a82e1 Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber
Improve invalid let expression handling

- Move all of the checks for valid let expression positions to parsing.
- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location.
- Suppress some later errors and MIR construction for invalid let expressions.
- Fix a (drop) scope issue that was also responsible for #104172.

Fixes #104172
Fixes #104868
2023-09-14 19:56:55 +00:00
Matthias Krüger
9362604518
Rollup merge of #115844 - oli-obk:opaque_lifetime_ambiguity, r=jackh726
Paper over an accidental regression

r? types

cc https://github.com/rust-lang/rust/issues/115781 (do not close issue until beta backport has been performed)

The PR reasons are explained with comments in the source.

In order to keep the diff simple, this PR effectively reverts https://github.com/rust-lang/rust/pull/113661, but only for RPITs. I will submit a follow up PR that fixes this correctly instead of just disabling the newly added check for RPITs. This PR should be significantly easier to review for beta backport
2023-09-14 19:12:33 +02:00
Matthias Krüger
57370828b9
Rollup merge of #115834 - compiler-errors:binder-vars, r=jackh726
Properly consider binder vars in `HasTypeFlagsVisitor`

Given a PolyTraitRef like `for<'a> Ty: Trait` (where neither `Ty` nor `Trait` mention `'a`), we do *not* return true for `.has_type_flags(TypeFlags::HAS_LATE_BOUND)`, even though binders are supposed to act as if they have late-bound vars even if they don't mention them in their bound value: 31ae3b2bdb. This is because we use `HasTypeFlagsVisitor`, which only computes the type flags for `Ty`, `Const` and `Region` and `Predicates`, and we consequently skip any binders (and setting flags for their vars) that are not contained in one of these types.

This ends up causing a problem, because when we call `TyCtxt::erase_regions` (which both erases regions *and* anonymizes bound vars), we will skip such a PolyTraitRef, not anonymizing it, and therefore not making it structurally equal to other binders. This breaks vtable computations.

This PR computes the flags for all binders we enter in `HasTypeFlagsVisitor` if we're looking for `TypeFlags::HAS_LATE_BOUND` (or `TypeFlags::HAS_{RE,TY,CT}_LATE_BOUND`).

Fixes #115807
2023-09-14 19:12:32 +02:00
Matthias Krüger
3dbcc28884
Rollup merge of #115832 - Zalathar:fix-no-coverage, r=oli-obk
Fix the error message for `#![feature(no_coverage)]`

When #114656 was written, the feature flag to replace `no_coverage` was originally spelled `coverage`, but it was eventually changed to `coverage_attribute` instead.

That update happened to miss this error message in `removed.rs`, and unfortunately I only noticed just *after* the original PR was approved and merged.

cc ``@bossmc`` (original author) ``@oli-obk`` (original reviewer)
``@rustbot`` label +A-code-coverage
2023-09-14 19:12:32 +02:00
Oli Scherer
0277184977 Paper over an accidental regression 2023-09-14 15:16:48 +00:00
bors
df63c5f140 Auto merge of #112038 - Nemo157:edition-2024-unsafe_op_in_unsafe_fn, r=RalfJung
Change `unsafe_op_in_unsafe_fn` to be `warn`-by-default from edition 2024

This was previously FCPed: https://github.com/rust-lang/rust/issues/71668#issuecomment-1189396886

There were two blocking requirements:
* Fix the `unused_unsafe` lint, done in https://github.com/rust-lang/rust/pull/100081
* Have `cargo fix` able to fix the lint, done in https://github.com/rust-lang/rust/pull/112017
2023-09-14 11:52:08 +00:00
bors
d97e04fbfc Auto merge of #115764 - RalfJung:const-by-ref-alloc-id, r=oli-obk
some ConstValue refactoring

In particular, use AllocId instead of Allocation in ConstValue::ByRef. This helps avoid redundant AllocIds when a  `ByRef` constant gets put back into the interpreter.

r? `@oli-obk`

Fixes https://github.com/rust-lang/rust/issues/105536
2023-09-14 10:04:45 +00:00
Ralf Jung
04a4df5f16 add regression test for something we fixed 2023-09-14 11:56:55 +02:00
bors
e17235105c Auto merge of #115825 - cjgillot:expr-field-lint, r=compiler-errors
Visit ExprField for lint levels.

Fixes https://github.com/rust-lang/rust/issues/115823
2023-09-14 06:29:23 +00:00
Michael Goulet
7ae301ec47 Properly consider binder vars in HasTypeFlagsVisitor 2023-09-14 03:49:59 +00:00
Zalathar
c397ca0677 Fix the error message for #![feature(no_coverage)] 2023-09-14 13:01:54 +10:00
bors
c728bf3963 Auto merge of #114656 - bossmc:rework-no-coverage-attr, r=oli-obk
Rework `no_coverage` to `coverage(off)`

As discussed at the tail of https://github.com/rust-lang/rust/issues/84605 this replaces the `no_coverage` attribute with a `coverage` attribute that takes sub-parameters (currently `off` and `on`) to control the coverage instrumentation.

Allows future-proofing for things like `coverage(off, reason="Tested live", issue="#12345")` or similar.
2023-09-14 01:05:18 +00:00
Camille GILLOT
01d7bf09f3 Visit ExprField for lint levels. 2023-09-13 19:47:20 +00:00
Michael Goulet
8fbd78ccea Detect cycle errors hidden by opaques during monomorphization 2023-09-13 17:35:44 +00:00
Matthias Krüger
48d89a8759
Rollup merge of #115815 - bvanjoi:fix-115809, r=oli-obk
fix: return early when has tainted in mir pass

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

As in #115643, `run_pass` is skipped if the body has tainted errors.

r? `@oli-obk`
2023-09-13 18:37:43 +02:00
Matthias Krüger
1ec29fb24f
Rollup merge of #115771 - RalfJung:no-more-const-err-lint, r=oli-obk
cleanup leftovers of const_err lint

Some code / comments seem to not have been updated when const_err was turned into a hard error, so we can do a bit of cleanup here.

r? `@oli-obk`
2023-09-13 18:37:42 +02:00
bohan
7c53e87d55 fix: skip opt if body has tainted error 2023-09-13 23:07:39 +08:00
Matthew Jasper
e324a59eb6 Address review comments
- Add doc comment to new type
- Restore "only supported directly in conditions of `if` and `while` expressions" note
- Rename variant with clearer name
2023-09-13 15:00:31 +00:00
bohan
f1536507e1 resolve: determined binding after parent module macro expand 2023-09-13 16:38:05 +08:00
bors
367db835dc Auto merge of #115785 - fmease:fix-pat-regression, r=wesleywiser
Only suggest turbofish in patterns if we may recover

Fixes [after backport] #115780.

CC #103534.
2023-09-13 00:05:33 +00:00
Georg Semmler
5b8a7a0917
#[diagnostic::on_unimplemented] without filters
This commit adds support for a `#[diagnostic::on_unimplemented]`
attribute with the following options:

* `message` to customize the primary error message
* `note` to add a customized note message to an error message
* `label` to customize the label part of the error message

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
Co-authored-by: Michael Goulet <michael@errs.io>
2023-09-12 20:03:18 +02:00
León Orell Valerian Liehr
3ed77e98fa
Only suggest turbofish in patterns if we may recover 2023-09-12 16:38:59 +02:00
bors
e5fedceabf Auto merge of #115215 - ouz-a:mir_issue, r=lcnr
Remove assert that checks type equality

https://github.com/rust-lang/rust/pull/112307 although this prevented `unsound` issues it also seems to introduce regressions https://github.com/rust-lang/rust/issues/114858 is example of this regression. I locally tested this https://github.com/rust-lang/rust/issues/114858#issuecomment-1686502262 issue and failing assert is [this](https://www.diffchecker.com/cjb7jSQm/).

This is also related to https://github.com/rust-lang/rust/pull/115025
2023-09-12 13:27:29 +00:00
Ralf Jung
fd91dfb494 cleanup leftovers of const_err lint 2023-09-12 13:41:42 +02:00
bors
deb708af12 Auto merge of #115678 - RalfJung:abi-compat-test, r=petrochenkov
test ABI compatibility for some unsized types as well

and test for what `DispatchFromDyn` needs.

Also I ran this on a whole bunch of targets via Miri and added enough `cfg` to make it all work, as documentation for what does and doesn't currently work. (Most of those targets do not have their tests run on CI anyway.)

Here's the shell rune I used for that:
```
for TARGET in x86_64-unknown-linux-gnu x86_64-pc-windows-gnu aarch64-unknown-linux-gnu s390x-unknown-linux-gnu mips64-unknown-linux-gnuabi64 sparc64-unknown-linux-gnu  powerpc64-unknown-linux-gnu powerpc64le-unknown-linux-gnu riscv64gc-unknown-linux-gnu loongarch64-unknown-linux-gnu wasm32-unknown-unknown; do
   BOOTSTRAP_SKIP_TARGET_SANITY=1 ./x.py run miri --stage 0 --args tests/ui/abi/compatibility.rs --target $TARGET;
done
```
2023-09-12 07:11:48 +00:00
Ralf Jung
6f2c051aba add some DispatchFromDyn ABI compatibility tests 2023-09-12 07:27:17 +02:00
Ralf Jung
4f606eb423 add enough cfg to make the test pass on problematic targets 2023-09-12 07:27:15 +02:00
Ralf Jung
721dfc5994 also test ABI-compatibility for some unsized types 2023-09-12 07:23:53 +02:00
Ralf Jung
10951f3500 make sure the types in the ABI compat test actually type-check 2023-09-12 07:23:52 +02:00
Matthias Krüger
32cf2c4b68
Rollup merge of #115765 - asquared31415:cast_diag, r=WaffleLapkin
Add source type for invalid bool casts

Also adds tests for casting various types to `bool` that were otherwise untested.

r? `@WaffleLapkin`
2023-09-12 06:34:46 +02:00
bors
b4e54c6e39 Auto merge of #115767 - matthiaskrgr:rollup-byf3lvq, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #115548 (Extract parallel operations in `rustc_data_structures::sync` into a new `parallel` submodule)
 - #115591 (Add regression test for LLVM 17-rc3 miscompile)
 - #115631 (Don't ICE when computing ctype's `repr_nullable_ptr` for possibly-unsized ty)
 - #115708 (fix homogeneous_aggregate not ignoring some ZST)
 - #115730 (Some more small driver refactors)
 - #115749 (Allow loading the SMIR for constants and statics)
 - #115757 (Add a test for #108030)
 - #115761 (Update books)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-11 20:53:42 +00:00
ouz-a
3ec0165f5f Remove assert that checks type equality 2023-09-11 23:08:40 +03:00
Matthias Krüger
279e2576a0
Rollup merge of #115708 - RalfJung:homogeneous, r=davidtwco
fix homogeneous_aggregate not ignoring some ZST

This is an ABI-breaking change, because it fixes bugs in our ABI code. I'm not sure what that means for this PR, we don't really have a process for such changes, do we? I can only hope nobody relied on the old buggy behavior.

Fixes https://github.com/rust-lang/rust/issues/115664
2023-09-11 21:16:22 +02:00
Matthias Krüger
5a2b589ac7
Rollup merge of #115631 - compiler-errors:ctypes-unsized, r=davidtwco
Don't ICE when computing ctype's `repr_nullable_ptr` for possibly-unsized ty

We may not always be able to compute the layout of a type like `&T` when `T: ?Sized`, even if we're able to estimate its size skeleton.

r? davidtwco

Fixes #115628
2023-09-11 21:16:21 +02:00
bors
e2b3676733 Auto merge of #114586 - oli-obk:patch_tait_rpit_order_check, r=lcnr,compiler-errors
Bubble up opaque <eq> opaque operations instead of picking an order

In case we are in `Bubble` mode (meaning every opaque type that is defined in the current crate is treated as if it were in its defining scope), we don't try to register an opaque type as the hidden type of another opaque type, but instead bubble up an obligation to equate them at the query caller site. Usually that means we have a `DefiningAnchor::Bind` and thus can reliably figure out whether an opaque type is in its defining scope. Where we can't, we'll error out, so the default is sound.

With this change we start using `AliasTyEq` predicates in the old solver, too.

fixes https://github.com/rust-lang/rust/issues/108498

But also regresses `tests/ui/impl-trait/anon_scope_creep.rs`. Our use of `Bubble` for `check_opaque_type_well_formed` is going to keep biting us.

r? `@lcnr` `@compiler-errors`
2023-09-11 19:01:38 +00:00
Tomasz Miąsko
ce19bc3964 Use no_core for KCFI tests to exercise them in CI 2023-09-11 20:54:52 +02:00
asquared31415
e36adff4c2 add source type for invalid bool casts 2023-09-11 18:10:07 +00:00
Oli Scherer
930affa39d Bubble up opaque <eq> opaque operations instead of picking an order 2023-09-11 16:53:39 +00:00
bors
0a199e4e93 Auto merge of #115758 - matthiaskrgr:rollup-khwbjj7, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #115335 (fix overflow in array length computation)
 - #115440 (bootstrap/format: remove unnecessary paths.push)
 - #115702 (Update mailmap)
 - #115727 (Implement fallback for effect param)
 - #115739 (Call `LateLintPass::check_attribute` from `with_lint_attrs`)
 - #115743 (Point out if a local trait has no implementations)
 - #115744 (Improve diagnostic for generic params from outer items (E0401))
 - #115752 (rustdoc: Add missing "Aliased type" title in the sidebar)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-11 16:50:22 +00:00
Matthew Jasper
b011a0a13b Reduce double errors for invalid let expressions
Previously some invalid let expressions would result in both a feature
error and a parsing error. Avoid this and ensure that we only emit the
parsing error when this happens.
2023-09-11 16:17:06 +00:00
Matthew Jasper
333388fd3c Move let expression checking to parsing
There was an incomplete version of the check in parsing and a second
version in AST validation. This meant that some, but not all, invalid
uses were allowed inside macros/disabled cfgs. It also means that later
passes have a hard time knowing when the let expression is in a valid
location, sometimes causing ICEs.

- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a
  valid location.
- Suppress later errors and MIR construction for invalid let
  expressions.
2023-09-11 15:51:18 +00:00
Matthew Jasper
7b61f7f002 Don't create drop scopes after item statements
These scopes would not exist in MIR and can cause ICEs with invalid uses
of let expressions.
2023-09-11 15:51:18 +00:00
Matthias Krüger
8b49731211
Rollup merge of #115744 - fmease:fix-e0401, r=compiler-errors
Improve diagnostic for generic params from outer items (E0401)

Generalize the wording of E0401 to talk about *outer items* instead of *outer functions* since the current phrasing is outdated. The outer item can be a function, constant, trait, ADT or impl block (see the new UI test for the more exotic examples).

Further, don't suggest introducing generic parameters to constant items unless the feature `generic_const_items` is enabled.

Lastly, make E0401 translatable while we're at it.

Fixes #115720.
2023-09-11 17:03:32 +02:00
Matthias Krüger
f279afb455
Rollup merge of #115743 - compiler-errors:no-impls, r=davidtwco
Point out if a local trait has no implementations

Slightly helps with #115741
2023-09-11 17:03:32 +02:00
Matthias Krüger
e7a347baf8
Rollup merge of #115727 - fee1-dead-contrib:effect-fallback, r=oli-obk
Implement fallback for effect param

r? `@oli-obk` or `@lcnr`

tracking issue for this ongoing work: https://github.com/rust-lang/rust/issues/110395
2023-09-11 17:03:31 +02:00
bors
3ebb5629d1 Auto merge of #115595 - surechen:114896, r=davidtwco
Fix incorrect mutable suggestion information for binding in ref pattern like:  `let &b = a;`

fixes #114896

I find we have to get pat_span but not local_decl.source_info.span for suggestion. In `let &b = a;`  pat_span is &b. I think check `let &b = a` in hir to make sure it is hir::Node::Local(hir::Local {pat: hir::Pat{kind: hir::PatKind::Ref(.......   can distinguish it from other situation, but I'm not sure.

If my processing method is not accurate, please guide me to modify it, thank you.

r? `@davidtwco`
2023-09-11 15:02:59 +00:00
bors
68c2f5ba0f Auto merge of #115308 - chenyukang:yukang-fix-62387-iter-mut, r=davidtwco
suggest iter_mut() where trying to modify elements from .iter()

Fixes https://github.com/rust-lang/rust/issues/115259
Fixes https://github.com/rust-lang/rust/issues/62387
2023-09-11 12:41:30 +00:00
bors
5d62ab8981 Auto merge of #115387 - weihanglo:merge-check-and-lint, r=oli-obk
Make unknown/renamed/removed lints passed via command line respect lint levels
2023-09-11 08:56:29 +00:00
Nicholas Nethercote
64ea8eb1a9 Disentangle Debug and Display for Ty.
The `Debug` impl for `Ty` just calls the `Display` impl for `Ty`. This
is surprising and annoying. In particular, it means `Debug` doesn't show
as much information as `Debug` for `TyKind` does. And `Debug` is used in
some user-facing error messages, which seems bad.

This commit changes the `Debug` impl for `Ty` to call the `Debug` impl
for `TyKind`. It also does a number of follow-up changes to preserve
existing output, many of which involve inserting
`with_no_trimmed_paths!` calls. It also adds `Display` impls for
`UserType` and `Canonical`.

Some tests have changes to expected output:
- Those that use the `rustc_abi(debug)` attribute.
- Those that use the `EMIT_MIR` annotation.

In each case the output is slightly uglier than before. This isn't
ideal, but it's pretty weird (particularly for the attribute) that the
output is using `Debug` in the first place. They're fairly obscure
attributes (I hadn't heard of them) so I'm not worried by this.

For `async-is-unwindsafe.stderr`, there is one line that now lacks a
full path. This is a consistency improvement, because all the other
mentions of `Context` in this test lack a path.
2023-09-11 12:51:07 +10:00
Michael Goulet
30e6cea0ae Point out if a local trait has no implementations 2023-09-10 21:20:36 +00:00
León Orell Valerian Liehr
daf3c45531
Do not suggest generic const items unless enabled 2023-09-10 23:07:48 +02:00
León Orell Valerian Liehr
b00e408e61
Generalize E0401 2023-09-10 23:06:14 +02:00
Deadbeef
84a490712a Implement fallback for effect param 2023-09-10 07:48:47 +00:00
Ralf Jung
254e13d9f9 fix homogeneous_aggregate not ignoring some 1-ZST 2023-09-10 07:38:03 +02:00
bors
0d0ad42e27 Auto merge of #115712 - RalfJung:wf, r=compiler-errors
rustc_layout, rustc_abi: make sure the types are well-formed

Fixes https://github.com/rust-lang/rust/issues/115676
2023-09-10 01:36:15 +00:00
Ralf Jung
3bd8bcb8bb better spans for WF errors 2023-09-09 18:00:13 +02:00
Ralf Jung
c2a7e684cd use hir_crate_items(()).definitions() instead of hir().items() 2023-09-09 17:39:53 +02:00
Ralf Jung
a5b0311367 rustc_layout, rustc_abi: make sure the types are well-formed 2023-09-09 17:32:12 +02:00
Gurinder Singh
e7c51320db Fix ICE in improper_ctypes_definitions lint
The lint panicked for an input like 'extern "C" fn(Option<&<T as FooTrait>::FooType>)' because the type T therein cannot be normalized. The normalization failure caused SizeSkeleton::compute() to return an error and trigger a panic in the unwrap().
2023-09-09 12:30:25 +05:30
Matthias Krüger
2ae5dc9b65
Rollup merge of #115673 - tmiasko:sanitizer-cfg, r=compiler-errors
Fix sanitize/cfg.rs test

* Move needs-sanitizer conditions to specific revisions that require them (otherwise the conditions are mutually exclusive with needs-sanitizer-kcfi and test is always ignored).
* Add missing revisions
2023-09-09 00:28:21 +02:00
Matthias Krüger
69044a1693
Rollup merge of #115662 - ShE3py:E0220-note, r=compiler-errors
Improve "associated type not found" diagnostics

```rs
use core::ops::Deref;

fn foo<T>() where T: Deref<Output = u32> {}
```

Before:
```
error[E0220]: associated type `Output` not found for `Deref`
 --> E0220.rs:5:28
  |
5 | fn foo<T>() where T: Deref<Output = u32> {}
  |                            ^^^^^^ associated type `Output` not found
```

After:
```
error[E0220]: associated type `Output` not found for `Deref`
 --> E0220.rs:5:28
  |
5 | fn foo<T>() where T: Deref<Output = u32> {}
  |                            ^^^^^^ help: `Deref` has the following associated type: `Target`
```

---

`@rustbot` label +A-diagnostics +D-papercut
2023-09-09 00:28:20 +02:00
Matthias Krüger
b33ac52106
Rollup merge of #115630 - compiler-errors:dont-suggest-use-btw-use-and-attr, r=wesleywiser
Dont suggest use between `use` and cfg attr

Fixes #115618
2023-09-09 00:28:20 +02:00
Matthias Krüger
6b65d377c5
Rollup merge of #113807 - mojingran:master, r=WaffleLapkin
Tests crash from inappropriate use of common linkage

Follows up my proposal under the [tracking issue for the linkage feature](https://github.com/rust-lang/rust/issues/29603#issuecomment-1597662999). Adds test for [issue 109681](https://github.com/rust-lang/rust/issues/109681).
2023-09-09 00:28:19 +02:00
bors
309af3442a Auto merge of #115672 - GuillaumeGomez:rollup-mjiy56f, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #104299 (Clarify stability guarantee for lifetimes in enum discriminants)
 - #115088 (Fix Step Skipping Caused by Using the `--exclude` Option)
 - #115201 (rustdoc: list matching impls on type aliases)
 - #115633 (Lint node for `PRIVATE_BOUNDS`/`PRIVATE_INTERFACES` is the item which names the private type)
 - #115638 (`-Cllvm-args` usability improvement)
 - #115643 (fix: return early when has tainted in mir-lint)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-08 13:43:08 +00:00
Tomasz Miąsko
7f45d16cb2 Fix sanitize/cfg.rs test
* Move needs-sanitizer conditions to specific revisions that
  require them (otherwise the conditions are mutually exclusive
  with needs-sanitizer-kcfi and test is always ignored).
* Add missing revisions
2023-09-08 15:12:17 +02:00
Guillaume Gomez
60327bb8b0
Rollup merge of #115643 - bvanjoi:fix-115203, r=RalfJung,oli-obk
fix: return early when has tainted in mir-lint

Fixes #115203

`a[..]` is of indeterminate size, it had been reported error during borrow check, therefore we skip the mir lint process.
2023-09-08 14:10:52 +02:00
Guillaume Gomez
e3b6122530
Rollup merge of #115633 - compiler-errors:PRIVATE_BOUNDS-lint-node, r=petrochenkov
Lint node for `PRIVATE_BOUNDS`/`PRIVATE_INTERFACES` is the item which names the private type

The HIR that the `PRIVATE_BOUNDS` lint should be attached to is the item that has the *bounds*, not the private type. This PR also aligns this behavior with the `EXPORTED_PRIVATE_DEPENDENCIES` lint, which also requires putting the `allow` on the item that names the private type.

Fixes #115475

r? petrochenkov
2023-09-08 14:10:51 +02:00
bors
cd71a37f32 Auto merge of #115372 - RalfJung:abi-assert-eq, r=davidtwco
add rustc_abi(assert_eq) to test some guaranteed or at least highly expected ABI compatibility guarantees

This new repr(transparent) test is super useful, it would have found https://github.com/rust-lang/rust/issues/115336 and found https://github.com/rust-lang/rust/issues/115404, https://github.com/rust-lang/rust/issues/115481, https://github.com/rust-lang/rust/issues/115509.
2023-09-08 11:56:08 +00:00
Andy Caldwell
679267f2ac
Rename the feature, but not the attribute, to coverage_attribute 2023-09-08 12:46:09 +01:00
Andy Caldwell
de1600d110
Add no_coverage to the 'removed features' list 2023-09-08 12:46:08 +01:00
Andy Caldwell
8e03371fc3
Rework no_coverage to coverage(off) 2023-09-08 12:46:06 +01:00
Ralf Jung
e726be21ab need to disable part of this test on arm 2023-09-08 13:25:51 +02:00
Ralf Jung
243ef313a5 add a testcase for another MIPS64 bug 2023-09-08 08:59:55 +02:00
Ralf Jung
a53c6ee0ba also ensure that size and alignment are the same 2023-09-08 08:59:55 +02:00
Ralf Jung
f6ef555823 merge transparent-abi test into general abi compatibility test, and test repr(transparent) unions 2023-09-08 08:59:55 +02:00
Ralf Jung
02217d1a16 add tests for RFC 3391 2023-09-08 08:59:55 +02:00
Ralf Jung
c3e14edd8b accept some differences for rustc_abi(assert_eq), so that we can test more things to be compatible 2023-09-08 08:59:55 +02:00
Lieselotte
a0e0a3261e
E0220: only suggests associated types if there's only one candidate 2023-09-08 08:44:23 +02:00
Matthias Krüger
7ec813643a
Rollup merge of #115649 - notriddle:notriddle/82038, r=compiler-errors
diagnostics: add test case for trait bounds diagnostic

Closes #82038

It was fixed by https://github.com/rust-lang/rust/pull/89580, a wide-reaching obligation tracking improvement. This commit adds a test case.
2023-09-08 08:23:04 +02:00
Matthias Krüger
38adedc598
Rollup merge of #115629 - compiler-errors:sugg-deref-unsize, r=oli-obk
Don't suggest dereferencing to unsized type

Rudimentary check that the self type is Sized. I don't really like any of this diagnostics code -- it's really messy and also really prone to false positives and negatives, but oh well.

Fixes #115569
2023-09-08 08:23:03 +02:00
Matthias Krüger
bef5187e8b
Rollup merge of #115624 - compiler-errors:rtn-path, r=WaffleLapkin
Print the path of a return-position impl trait in trait when `return_type_notation` is enabled

When we're printing a return-position impl trait in trait, we usually just print it like an opaque. This is *usually* fine, but can be confusing when using `return_type_notation`. Print the path of the method from where the RPITIT originates when this feature gate is enabled.
2023-09-08 08:23:03 +02:00
Lieselotte
96c96645c7
Improve "associated type not found" diagnostics 2023-09-08 06:52:17 +02:00
bohan
967410c640 fix: return ealry when has tainted in mir-lint 2023-09-08 09:30:23 +08: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
Michael Howell
31e5dd3a79 diagnostics: add test case for trait bounds diagnostic
Closes #82038

It was fixed by b8e5ab20ed, a wide-reaching
obligation tracking improvement. This commit adds a test case.
2023-09-07 11:36:23 -07: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
bors
f06b7c59a3 Auto merge of #114183 - Urgau:stabilize-print-with-path, r=oli-obk
Stabilize `PATH` option for `--print KIND=PATH`

This PR propose stabilizing the `PATH` option for `--print KIND=PATH`. This option was previously added in https://github.com/rust-lang/rust/pull/113780 (as insta-stable before being un-stablized in https://github.com/rust-lang/rust/pull/114139).

Description of the `PATH` option:
> A filepath may optionally be specified for each requested information kind, in the format `--print KIND=PATH`, just like for `--emit`. When a path is specified, information will be written there instead of to stdout.

------

Description of the original PR [\[link\]](https://github.com/rust-lang/rust/pull/113780#issue-1807080607):
> **Support --print KIND=PATH command line syntax**
>
> As is already done for `--emit KIND=PATH` and `-L KIND=PATH`.
>
> In the discussion of https://github.com/rust-lang/rust/pull/110785, it was pointed out that `--print KIND=PATH` is nicer than trying to apply the single global `-o path` to `--print`'s output, because in general there can be multiple print requests within a single rustc invocation, and anyway `-o` would already be used for a different meaning in the case of `link-args` and `native-static-libs`.
>
> I am interested in using `--print cfg=PATH` in Buck2. Currently Buck2 works around the lack of support for `--print KIND=PATH` by [indirecting through a Python wrapper script](d43cf3a51a/prelude/rust/tools/get_rustc_cfg.py) to redirect rustc's stdout into the location dictated by the build system.
>
> From skimming Cargo's usages of `--print`, it definitely seems like it would benefit from `--print KIND=PATH` too. Currently it is working around the lack of this by inserting `--crate-name=___ --print=crate-name` so that it can look for a line containing `___` as a delimiter between the 2 other `--print` informations it actually cares about. This is commented as a "HACK" and "abuse". 31eda6f7c3/src/cargo/core/compiler/build_context/target_info.rs (L242)

-----

cc `@dtolnay`
r? `@jackh726`
2023-09-07 14:24:46 +00:00
Urgau
caf6ce5ea2 Stabilize PATH option for --print KIND=PATH
Description of the `PATH` option:
> A filepath may optionally be specified for each requested information
> kind, in the format `--print KIND=PATH`, just like for `--emit`. When
> a path is specified, information will be written there instead of to
> stdout.
2023-09-07 15:07:30 +02:00
bors
7f0fa485a6 Auto merge of #115582 - compiler-errors:refine-yeet, r=oli-obk
Implement refinement lint for RPITIT

Implements a lint that warns against accidentally refining an RPITIT in an implementation. This is not a hard error, and can be suppressed with `#[allow(refining_impl_trait)]`, since this behavior may be desirable -- the lint just serves as an acknowledgement from the impl author that they understand that the types they write in the implementation are an API guarantee.

This compares bounds syntactically, not semantically -- semantic implication is more difficult and essentially relies on adding the ability to keep the RPITIT hidden in the trait system so that things can be proven about the type that shows up in the impl without its own bounds leaking through, either via a new reveal mode or something else. This was experimentally implemented in #111931.

Somewhat opinionated choices:
1. Putting the lint behind `refining_impl_trait` rather than a blanket `refine` lint. This could be changed, but I like keeping the lint specialized to RPITITs so the explanation can be tailored to it.
2. This PR does not include the `#[refine]` attribute or the feature gate, since it's kind of orthogonal and can be added in a separate PR.

r? `@oli-obk`
2023-09-07 07:26:26 +00:00
Ralf Jung
8922c0c541 add support for rustc_abi(assert_eq) and use it to test some repr(transparent) cases 2023-09-07 09:14:29 +02:00
Michael Goulet
3bf3dadbc0 Ensure that dyn trait bounds stay sorted 2023-09-07 06:57:08 +00:00
Michael Goulet
14e59bb317 Lint node for PRIVATE_BOUNDS is the item which has the bounds 2023-09-07 06:48:24 +00:00
Michael Goulet
086cf34634 Don't ICE when computing ctype's repr_nullable_ptr for possibly-unsized ty 2023-09-07 06:04:37 +00:00
Michael Goulet
03bee1f53d Find lowest span out of use + attrs 2023-09-07 05:19:43 +00:00
Michael Goulet
4da6eb2ec6 Test showing it doesnt work 2023-09-07 05:18:54 +00:00
Michael Goulet
67e7d85ad2 Rename folder typo 2023-09-07 04:52:26 +00:00
Michael Goulet
ee9727e263 Don't suggest dereferencing to unsized type 2023-09-07 04:52:00 +00:00
surechen
a8f3c7684d fixes #114896 2023-09-07 11:07:33 +08:00
Michael Goulet
748476d94d Print the path of an RPITIT in RTN 2023-09-07 02:08:51 +00:00
Michael Goulet
7714db873e Add note 2023-09-07 01:31:33 +00:00
Michael Goulet
4d05da46e7 Don't emit refining_impl_trait for private items 2023-09-07 01:31:32 +00:00
Michael Goulet
4745d34bc3 Use self instead of the actual self ty 2023-09-07 00:49:09 +00:00
Michael Goulet
e10262ca0a Implement refinement lint for RPITIT 2023-09-07 00:49:09 +00:00
bors
4e5b31c2b0 Auto merge of #115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, r=est31
Lint on invalid usage of `UnsafeCell::raw_get` in reference casting

This PR proposes to take into account `UnsafeCell::raw_get` method call for non-Freeze types for the `invalid_reference_casting` lint.

The goal of this is to catch those kind of invalid reference casting:
```rust
fn as_mut<T>(x: &T) -> &mut T {
    unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
    //~^ ERROR casting `&T` to `&mut T` is undefined behavior
}
```

r? `@est31`
2023-09-07 00:24:45 +00:00
Matthias Krüger
3e42a12a54
Rollup merge of #115587 - mojave2:issue-115348, r=oli-obk
fix #115348

fix #115348
It looks that:

- In `rustc_mir_build::build`, the body of function will not be built, when the `tcx.check_match(def)` fails due to `non-exhaustive patterns`
- In `rustc_mir_transform::check_unsafety`, the `UnsafetyChecker` collects all `used_unsafe_blocks` in the MIR of a function, and the `UnusedUnsafeVisitor` will visit all `UnsafeBlock`s in the HIR and collect `unused_unsafes`, which are not contained in `used_unsafe_blocks`, and report `unnecessary_unsafe`s
- So the unsafe block in the issue example code will be reported as `unnecessary_unsafe`.
2023-09-06 19:31:50 +02:00
Matthias Krüger
93543bc8bc
Rollup merge of #115578 - ouz-a:rustc_clarify, r=oli-obk
Clarify cryptic comments

Clarifies some unclear comments that lurked in the compiler.

r? ``@oli-obk``
2023-09-06 19:31:49 +02:00
Matthias Krüger
4a31cc859b
Rollup merge of #115473 - gurry:113110-expected-item, r=compiler-errors
Add explanatory note to 'expected item' error

Fixes #113110

It changes the diagnostic from this:

```
error: expected item, found `5`
 --> ../test.rs:1:1
  |
1 | 5
  | ^ expected item
 ```
to this:
```
error: expected item, found `5`
 --> ../test.rs:1:1
  |
1 | 5
  | ^ expected item
  |
  = note: items are things that can appear at the root of a module
  = note: for a full list see https://doc.rust-lang.org/reference/items.html
```
2023-09-06 19:31:48 +02:00
Matthias Krüger
b046541b62
Rollup merge of #114511 - chenyukang:yukang-fix-114374-fmt-args, r=b-naber
Remove the unhelpful let binding diag comes from FormatArguments

Fixes #114374
2023-09-06 19:31:48 +02:00
Lukas Markeffsky
d990eee0c8 add diagnostic for raw identifiers in format string 2023-09-06 18:55:45 +02:00
yukang
3988ff25bc suggest iter_mut() where trying to modify elements from .iter() 2023-09-07 00:20:38 +08:00
mojave2
cfa2119563
add a regression test 2023-09-06 17:46:46 +08:00
Ralf Jung
e66913f8fe rustc_layout/abi: error when attribute is applied to the wrong thing 2023-09-06 11:11:06 +02:00
Ralf Jung
9570cac019 rustc_abi: also support debugging function pointers 2023-09-06 11:11:06 +02:00
ouz-a
7928c5f830 make comments less cryptic 2023-09-06 12:09:29 +03:00
Wim Looman
119e0fff8a
Change unsafe_op_in_unsafe_fn to be warn-by-default from edition 2024 2023-09-06 09:30:04 +02:00
Gurinder Singh
6a286e775c Add explanatory note to 'expected item' error 2023-09-06 09:05:07 +05:30
bors
aeddd2ddfd Auto merge of #115529 - chenyukang:yukang-fix-115402-overflowsize, r=compiler-errors
Fix error report for size overflow from transmute

Fixes #115402

The span in the error reporting always points to the `dst`, this is an old issue, I may open another PR to fix it.
2023-09-06 02:37:41 +00:00
bors
25283f4e13 Auto merge of #115371 - matthewjasper:if-let-guard-parsing, r=cjgillot
Make if let guard parsing consistent with normal guards

- Add tests that struct expressions are not allowed in `if let` and `while let` (no change, consistent with `if` and `while`)
- Allow struct expressions in `if let` guards (consistent with `if` guards).

r? `@cjgillot`

Closes #93817
cc #51114
2023-09-06 00:46:21 +00:00
yukang
00010eda8b Fix error report for size overflow from transmute 2023-09-06 06:48:34 +08:00
Michael Goulet
f479a7aa8d Restore some removed tests 2023-09-05 20:20:55 +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
lcnr
98fa0c93ee unconstrained region vars: do not ICE ICE baby 2023-09-05 11:15:05 +02:00
bors
8cfaf70c32 Auto merge of #115553 - matthiaskrgr:rollup-c0045hz, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #115353 (Emit error instead of ICE when optimized MIR is missing)
 - #115488 (Take `&mut Results` in `ResultsVisitor`)
 - #115492 (Allow `large_assignments` for Box/Arc/Rc initialization)
 - #115519 (Don't ICE on associated type projection without feature gate in new solver)
 - #115534 (Expose more information with DefId in smir)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-09-05 05:34:18 +00:00
Matthias Krüger
f5e6aa3c4a
Rollup merge of #115519 - compiler-errors:next-solver-assoc-ice, r=lcnr
Don't ICE on associated type projection without feature gate in new solver

Self-explanatory, we should avoid ICEs when the feature gate is not enabled. Continue to ICE when the feature gate *is* enabled, though.

Fixes #115500
2023-09-05 07:15:16 +02:00
Matthias Krüger
6f180ea954
Rollup merge of #115492 - Enselic:large-box-move, r=oli-obk
Allow `large_assignments` for Box/Arc/Rc initialization

Does the `stop linting in box/arc initialization` task of #83518.

r? `@oli-obk` who is E-mentor.
2023-09-05 07:15:16 +02:00
Matthias Krüger
a73c663ec4
Rollup merge of #115353 - Enselic:no-optimized-mir, r=oli-obk
Emit error instead of ICE when optimized MIR is missing

Closes #51388
2023-09-05 07:15:15 +02: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
bors
9c609ae158 Auto merge of #115467 - compiler-errors:assoc-ty-object-safety, r=oli-obk
Do not require associated types with Self: Sized to uphold bounds when confirming object candidate

RPITITs and associated types that have `Self: Sized` bounds are opted out of the `dyn Trait` well-formedness check that happens during confirmation. This ensures that we can actually *use* `dyn Trait`s that have associated types that, e.g., have GATs and RPITITs and other naughty things as long as those are opted-out of object safety via a `Self: Sized` bound.

Fixes #115464

This seems like a natural part of https://github.com/rust-lang/rust/pull/112319#issuecomment-1592574451, and I don't think needs re-litigation.

r? `@oli-obk`
2023-09-05 01:09:48 +00:00
Ralf Jung
7093903ba7 read_via_copy: don't prematurely optimize away the read 2023-09-04 18:27:34 +02:00
Urgau
efbe445ba7 Add help to allow lint for the implied by suggestion 2023-09-04 14:21:38 +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
Michael Goulet
8c667febbd Don't ICE on associated type projection without feature gate 2023-09-03 19:43:58 +00:00
bors
21305f4d5f Auto merge of #115270 - sebastiantoh:issue-105479, r=Nadrieril
Add note on non-exhaustiveness when matching on str and nested non-exhaustive enums

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

r? `@Nadrieril`
2023-09-03 19:31:47 +00:00
Urgau
ec0975dd6b Don't forget to normalize the translated message 2023-09-03 17:10:42 +02:00
Guillaume Gomez
3db7fc1481
Rollup merge of #115478 - gurry:115462-exprfield-no-warn, r=compiler-errors
Emit unused doc comment warnings for pat and expr fields

Fixes #115462
2023-09-03 15:42:11 +02:00
Sebastian Toh
d87b87d10e Improve clarity of diagnostic message on non-exhaustive matches 2023-09-03 19:55:11 +08:00
Martin Nordholts
789451b43a Allow large_assignments for Box/Arc/Rc initialization
Does the `stop linting in box/arc initialization` task of 83518.
2023-09-03 08:15:25 +02:00
Gurinder Singh
10f4917568 Emit unused doc comment warnings for pat and expr fields 2023-09-03 08:21:18 +05:30
bors
9229b1eab4 Auto merge of #115429 - compiler-errors:assoc-ct-lt-fallthrough, r=cjgillot
Fall through when resolving elided assoc const lifetimes

`@QuineDot` makes a good point in https://github.com/rust-lang/rust/issues/115010#issuecomment-1702127634 that we probably should not accept *more* code due to #115011 even though that code will eventually become a forbid-warning in a few versions (https://github.com/rust-lang/rust/issues/115010#issuecomment-1701598067).

Fall through when walking thru the `AnonymousWarnToStatic` (renamed to `AnonymousWarn`) rib so that we can resolve as a fresh lifetime like we did before.
2023-09-02 10:55:49 +00:00
Michael Goulet
07fc644132 Do not require associated types with Self: Sized to uphold bounds when confirming object candidate 2023-09-02 05:08:38 +00:00
Michael Goulet
7a6b52bf0d RPITITs are considered object-safe, they're always on Self:Sized methods 2023-09-02 04:58:23 +00:00
bors
f9ba43ce14 Auto merge of #113295 - clarfonthey:ascii-step, r=cuviper
Implement Step for ascii::Char

This allows iterating over ranges of `ascii::Char`, similarly to ranges of `char`.

Note that `ascii::Char` is still unstable, tracked in #110998.
2023-09-02 00:02:50 +00:00
David Mo
4160337c85 Tests crash from inappropriate use of common linkage
Normally, variables with common linkage must be zero-initialized. In Rust,
common linkage variables that are not zero-initialized causes a crash in the
compiler backend.

This commit adds a test case to confirm this behavior, which will inform us if
it changes in the future.
2023-09-01 14:08:31 -07:00
Matthias Krüger
888dc2e3b0
Rollup merge of #115424 - notriddle:notriddle/issue-106413, r=oli-obk
diagnostics: avoid wrong `unused_parens` on `x as (T) < y`

Fixes #106413
Fixes #80636
2023-09-01 21:41:39 +02:00
bors
1accf068d8 Auto merge of #113126 - Bryanskiy:delete_old, r=petrochenkov
Replace old private-in-public diagnostic with type privacy lints

Next part of RFC https://github.com/rust-lang/rust/issues/48054.

r? `@petrochenkov`
2023-09-01 12:40:01 +00:00
bors
f4555ef5e1 Auto merge of #111752 - dingxiangfei2009:lower-or-pattern, r=cjgillot
Lower `Or` pattern without allocating place

cc `@azizghuloum` `@cjgillot`

Related to #111583 and #111644

While reviewing #111644, it occurs to me that while we directly lower conjunctive predicates, which are connected with `&&`, into the desirable control flow, today we don't directly lower the disjunctive predicates, which are connected with `||`, in the similar fashion. Instead, we allocate a place for the boolean temporary to hold the result of evaluating the `||` expression.

Usually I would expect optimization at later stages to "inline" the evaluation of boolean predicates into simple CFG, but #111583 is an example where `&&` is failing to be optimized away and the assembly shows that both the expensive operands are evaluated. Therefore, I would like to make a small change to make the CFG a bit more straight-forward without invoking the `as_temp` machinery, and plus avoid allocating the place to hold the boolean result as well.
2023-09-01 10:54:56 +00:00
Michael Goulet
b62eeb2aac Fall through when resolving elided assoc const lifetimes 2023-09-01 07:23:39 +00:00
bors
96f62fce00 Auto merge of #113201 - oli-obk:recursive_type_alias, r=estebank,compiler-errors
Permit recursive weak type aliases

I saw #63097 and thought "we can do ~~better~~ funnier". So here it is. It's not useful, but it's certainly something. This may actually become feasible with lazy norm (so in 5 years (constant, not reducing over time)).

r? `@estebank`

cc `@GuillaumeGomez`
2023-09-01 07:10:21 +00:00
bors
88d9b37a15 Auto merge of #115400 - gurry:issue-115264-ice, r=compiler-errors
Return ident for ExprField and PatField HIR nodes

Fixes #115264
2023-09-01 03:36:48 +00:00