Commit Graph

3057 Commits

Author SHA1 Message Date
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
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
Michael Howell
62835c9531 diagnostics: avoid wrong unused_parens on x as (T) < y 2023-08-31 20:14:49 -07:00
Gurinder Singh
19574d216a Return ident for ExprField and PatField HIR nodes 2023-09-01 06:36:02 +05:30
bors
2f5df8a94b Auto merge of #115366 - compiler-errors:associated-type-bound-implicit-lifetimes, r=jackh726
Capture lifetimes for associated type bounds destined to be lowered to opaques

Some associated type bounds get lowered to opaques, but they're not represented in the AST as opaques.

That means that we never collect lifetimes for them (`record_lifetime_params_for_impl_trait`) which are used currently for RPITITs, which capture all of their in-scope lifetimes[^1]. This means that the nested RPITITs that arise from some type like `impl Foo<Type: Bar>` (~> `impl Foo<Type = impl Bar>`) don't capture any lifetimes, leading to ICEs.

This PR makes sure we collect the lifetimes for associated type bounds as well, and make sure that they are set up correctly for opaque type lowering later.

Fixes #115360

[^1]: #114489
2023-08-31 21:13:54 +00:00
bors
91942134c6 Auto merge of #115389 - bvanjoi:fix-115380, r=petrochenkov
fix(resolve): update def if binding is warning ambiguity

Fixes #115380
2023-08-31 16:57:11 +00:00
bors
4b71f03039 Auto merge of #115384 - lqd:default-universe-info, r=matthewjasper
Work around ICE in diagnostics for local super-universes missing `UniverseInfo`s

In issue #114907, canonicalization of liveness dropck-outlives results (IIUC) encounters universes absent from the original query.  Some local universes [are created](f3a1bae88c/compiler/rustc_infer/src/infer/canonical/query_response.rs (L417-L425)) for the mapping, but importantly, they won't have associated causes.

These missing `UniverseInfo`s can be [needed](f3a1bae88c/compiler/rustc_borrowck/src/diagnostics/region_errors.rs (L376)) during diagnostics, [causing the `IndexMap: key not found` ICE](d55522aad8/compiler/rustc_borrowck/src/region_infer/mod.rs (L2252)) seen in the issue.

This PR works around this by returning the suboptimal catch-all cause, to avoid the ICE. It does results in suboptimal diagnostics right now, but it's better than an ICE.

r? `@matthewjasper.`

Let me know if there's a good easy-ish way to fix this, but I believe that for some of these erroneous cases and diagnostics, that inference/canonicalization/higher-ranked subtyping/etc may not behave exactly the same with the new trait solver? If that's the case then it'd probably be best to wait a bit more to do the correct fix.

Fixes #114907.

cc `@aliemjay`
2023-08-31 15:13:05 +00:00
bohan
107152141b fix(resolve): update def if binding is warning ambiguity 2023-08-31 20:00:04 +08:00
bors
784916ce24 Auto merge of #115290 - compiler-errors:ctor-unsafe, r=cjgillot
`rustc_layout_scalar_valid_range` makes ctors unsafe

We already validate this when we use the ctor in a call, e.g. `Variant(1)`, but not if we use the ctor as a fn ptr, e.g. `.map(Variant)`. The easiest way to fix the latter is (afaict) is by marking the ctor as unsafe itself.

Fixes #115284
2023-08-31 11:16:37 +00:00
bors
e51c5ea16f Auto merge of #115392 - compiler-errors:coherence-spans, r=aliemjay
Don't record spans for predicates in coherence

Should improve perf (https://github.com/rust-lang/rust/pull/115107#issuecomment-1695090589) for https://github.com/rust-lang/rust/pull/114023#issuecomment-1688514709

r? aliemjay
2023-08-31 00:34:04 +00:00
bors
b1b244da65 Auto merge of #115194 - tmiasko:inline-always-encode-mir, r=compiler-errors
Fix inlining with -Zalways-encode-mir

Only inline functions that are considered eligible for inlining
by the reachability pass.

This constraint was previously indirectly enforced by only exporting MIR
of eligible functions, but that approach doesn't work with
-Zalways-encode-mir enabled.
2023-08-30 22:51:12 +00:00
Michael Goulet
bf66723c0e Test and note unsafe ctor to fn ptr coercion
Also remove a note that I don't consider to be very useful in context.
2023-08-30 15:09:40 -07:00
Michael Goulet
0100a94231 rustc_layout_scalar_valid_range makes ctors unsafe 2023-08-30 15:01:58 -07:00
bors
59a8294849 Auto merge of #115144 - Zoxc:parallel-guard, r=compiler-errors
Add `ParallelGuard` type to handle unwinding in parallel sections

This adds a `ParallelGuard` type to handle unwinding in parallel sections instead of manually dealing with panics in each parallel operation. This also adds proper panic handling to the `join` operation.

cc `@SparrowLii`
2023-08-30 19:33:13 +00:00
Michael Goulet
4647aea7aa Don't record spans for predicates in coherence 2023-08-30 18:24:18 +00:00
John Kåre Alsaker
242805442b Update failure status 2023-08-30 18:13:09 +02:00
Rémy Rakic
f3a1bae88c add test for issue 114907 2023-08-30 14:10:52 +00:00
Oli Scherer
5d850e0f50 Permit recursive weak type aliases 2023-08-30 11:55:03 +00:00
Oli Scherer
e82ccd52db Test variances of TAITs 2023-08-30 11:23:42 +00:00
Oli Scherer
e0a60f0740 Revert "Auto merge of #102417 - oli-obk:opaque_lifetimes2, r=jackh726"
This reverts commit cb9467515b, reversing
changes made to 57781b24c5.
2023-08-30 11:06:46 +00:00
Ding Xiang Fei
d9ed11872f
lower bare boolean expression with if-construct 2023-08-30 17:24:11 +08:00
Ding Xiang Fei
e5453b4806
lower ExprKind::Use, LogicalOp::Or and UnOp::Not
Co-authored-by: Abdulaziz Ghuloum <aghuloum@gmail.com>
2023-08-30 17:24:10 +08:00
Matthias Krüger
ea2347843c
Rollup merge of #115363 - kpreid:suggest-private, r=compiler-errors
Don't suggest adding parentheses to call an inaccessible method.

Previously, code of this form would emit E0615 (attempt to use a method as a field), thus emphasizing the existence of private methods that the programmer probably does not care about. Now it ignores their existence instead, producing error E0609 (no field). The motivating example is:

```rust
let x = std::rc::Rc::new(());
x.inner;
```

which would previously mention the private method `Rc::inner()`, even though `Rc<T>` intentionally has no public methods so that it can be a transparent smart pointer for any `T`.

```rust
error[E0615]: attempted to take value of method `inner` on type `Rc<()>`
 --> src/main.rs:3:3
  |
3 | x.inner;
  |   ^^^^^ method, not a field
  |
help: use parentheses to call the method
  |
3 | x.inner();
  |        ++
  ```

  With this change, it emits E0609 and no suggestion.
2023-08-30 07:18:13 +02:00
Matthias Krüger
36182f1f13
Rollup merge of #115355 - lqd:issue-115351, r=compiler-errors
new solver: handle edge case of a recursion limit of 0

Apparently a recursion limit of 0 is possible/valid/useful/used/cute, the more you know 🌟 .

(It's somewhat interesting to me that the old solver seemingly handles this, and that the new solver currently requires a recursion limit of 2 here)

r? `@compiler-errors.`

Fixes #115351.
2023-08-30 07:18:13 +02:00
Matthias Krüger
58c690729c
Rollup merge of #115347 - y21:generic-bound-impl-trait-ty, r=compiler-errors
suggest removing `impl` in generic trait bound position

rustc already does this recovery in type param position (`<T: impl Trait>` -> `<T: Trait>`).
This PR also adds that suggestion in trait bound position (e.g. `where T: impl Trait` or `trait Trait { type Assoc: impl Trait; }`)
2023-08-30 07:18:12 +02:00
Matthias Krüger
2128efd87f
Rollup merge of #115313 - gurry:issue-114918-cycle-detected, r=compiler-errors
Make `get_return_block()` return `Some` only for HIR nodes in body

Fixes #114918

The issue occurred while compiling the following input:

```rust
fn uwu() -> [(); { () }] {
    loop {}
}
```

It was caused by the code below trying to suggest a missing return type which resulted in a const eval cycle: 1bd043098e/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs (L68-L75)

The root cause was `get_return_block()` returning an `Fn` node for a node in the return type (i.e. the second `()` in the return type `[(); { () }]` of the input) although it is supposed to do so only for nodes that lie in the body of the function and return `None` otherwise (at least as per my understanding).

The PR fixes the issue by fixing this behaviour of `get_return_block()`.
2023-08-30 07:18:11 +02:00
Matthias Krüger
639116505a
Rollup merge of #114704 - bvanjoi:fix-114636, r=compiler-errors
parser: not insert dummy field in struct

Fixes #114636

This PR eliminates the dummy field, initially introduced in #113999, thereby enabling unrestricted use of `ident.unwrap()`. A side effect of this action is that we can only report the error of the first macro invocation field within the struct node.

An alternative solution might be giving a virtual name to the macro, but it appears more complex.(https://github.com/rust-lang/rust/issues/114636#issuecomment-1670228715). Furthermore, if you think https://github.com/rust-lang/rust/issues/114636#issuecomment-1670228715 is a better solution, feel free to close this PR.
2023-08-30 07:18:10 +02:00
Gurinder Singh
136f0579d8 Make get_return_block() return Some only for HIR nodes in body
Fixes # 114918
2023-08-30 07:40:08 +05:30
Michael Goulet
f1679f7dd6 Capture lifetimes for associated type bounds destined to be lowered to opaques 2023-08-30 00:31:00 +00:00
Kevin Reid
7b837e075a Don't suggest adding parentheses to call an inaccessible method.
Previously, the test code would emit E0615, thus revealing the existence
of private methods that the programmer probably does not care about.
Now it ignores their existence instead, producing error E0609 (no field).

The motivating example is:

```rust
let x = std::rc::Rc::new(());
x.inner;
```

which would previously mention the private method `Rc::inner()`, even
though `Rc<T>` intentionally has no public methods so that it can be a
transparent smart pointer for any `T`.
2023-08-29 14:47:28 -07:00
Rémy Rakic
325b585259 add non-regression test for issue 115351 2023-08-29 19:03:08 +00:00
Matthias Krüger
56d7d93a4b
Rollup merge of #111580 - atsuzaki:layout-ice, r=oli-obk
Don't ICE on layout computation failure

Fixes #111176 regression.

r? `@oli-obk`
2023-08-29 20:49:02 +02:00
y21
507f10baee suggest removing impl in generic trait bound position 2023-08-29 20:27:38 +02:00
bors
bb90f81070 Auto merge of #112775 - c410-f3r:t3st3ss, r=petrochenkov
Move tests

r? `@petrochenkov`
2023-08-29 13:53:34 +00:00
Ralf Jung
bf91321e0f there seems to be no reason to treat ZST specially in these cases 2023-08-29 08:58:58 +02:00
Ralf Jung
0da9409e08 rustc_abi: audit uses of is_zst; fix a case of giving an enum insufficient alignment 2023-08-29 08:58:58 +02:00
Caio
5a69151d7d Move tests 2023-08-28 17:47:37 -03:00
bors
4e78abb437 Auto merge of #115326 - matthiaskrgr:rollup-qsoa8ar, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #115164 (MIR validation: reject in-place argument/return for packed fields)
 - #115240 (codegen_llvm/llvm_type: avoid matching on the Rust type)
 - #115294 (More precisely detect cycle errors from type_of on opaque)
 - #115310 (Document panic behavior across editions, and improve xrefs)
 - #115311 (Revert "Suggest using `Arc` on `!Send`/`!Sync` types")
 - #115317 (Devacationize oli-obk)
 - #115319 (don't use SnapshotVec in Graph implementation, as it looks unused; use Vec instead)
 - #115322 (Tweak output of `to_pretty_impl_header` involving only anon lifetimes)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-28 19:57:32 +00:00
Katherine Philip
56b767322b Don't ICE on layout computation failure 2023-08-28 12:40:39 -07:00
bors
93dd620241 Auto merge of #114489 - compiler-errors:rpitit-capture-all, r=oli-obk
Make RPITITs capture all in-scope lifetimes

Much like #114616, this implements the lang team decision from this T-lang meeting on [opaque captures strategy moving forward](https://hackmd.io/sFaSIMJOQcuwCdnUvCxtuQ?view). This will be RFC'd soon, but given that RPITITs are a nightly feature, this shouldn't necessarily be blocked on that.

We unconditionally capture all lifetimes in RPITITs -- impl is not as simple as #114616, since we still need to duplicate RPIT lifetimes to make sure we reify any late-bound lifetimes in scope.

Closes #112194
2023-08-28 18:05:16 +00:00
Matthias Krüger
07a32e2dbd
Rollup merge of #115322 - estebank:list-tweak, r=compiler-errors
Tweak output of `to_pretty_impl_header` involving only anon lifetimes

Do not print `impl<> Foo for &Bar`.
2023-08-28 19:53:59 +02:00
Matthias Krüger
9b0abe3537
Rollup merge of #115311 - dtolnay:usearcself, r=compiler-errors
Revert "Suggest using `Arc` on `!Send`/`!Sync` types"

Closes https://github.com/rust-lang/rust/issues/114687. This is a clean revert of https://github.com/rust-lang/rust/pull/88936 + https://github.com/rust-lang/rust/pull/115210. The suggestion to Arc\<{Self}\> when Self does not implement Send is *always* wrong.

https://github.com/rust-lang/rust/pull/114842 is considering a way to make a more refined suggestion.
2023-08-28 19:53:57 +02:00
Matthias Krüger
b4c63f06e8
Rollup merge of #115294 - compiler-errors:cycle-err, r=oli-obk
More precisely detect cycle errors from type_of on opaque

Not sure if this still needs work. Just putting it up for initial impressions, since it seems that a few people are frustrated with the increased error verbosity due to #113320.

Essentially we introduce a new sub-query for `type_of` specifically for opaques which returns a value that is able to distinguish "has errors" from "due to cycle recovery".

Fixes #115188

r? `@oli-obk`
2023-08-28 19:53:56 +02:00
Esteban Küber
ecf2f68e45 Tweak output of to_pretty_impl_header involving only anon lifetimes
Do not print `impl<> Foo for &Bar`.
2023-08-28 17:17:11 +00:00
bors
c587fd4185 Auto merge of #114774 - Enselic:less-move-size-noise, r=oli-obk
Avoid duplicate `large_assignments` lints

By checking for overlapping spans.

This PR does the "reduce noisiness" task in #83518.

r? `@oli-obk` who added E-mentor and E-help-wanted and wrote the initial code.

(The fix itself is in dc82736677. The two commits before that are just small refactorings.)
2023-08-28 13:36:19 +00:00
David Tolnay
823bacb6e3
Revert "Suggest using Arc on !Send/!Sync types"
This reverts commit 9de1a472b6.
2023-08-28 03:16:48 -07:00
Matthias Krüger
32053f7602
Rollup merge of #115280 - RalfJung:panic-cleanup-triple-backtrace, r=Amanieu
avoid triple-backtrace due to panic-during-cleanup

Supersedes https://github.com/rust-lang/rust/pull/115020
Cc https://github.com/rust-lang/rust/issues/114954
r? ``@Amanieu``
2023-08-28 08:13:59 +02:00