Commit graph

7586 commits

Author SHA1 Message Date
Esteban Küber a2298a6f19 Do not ICE when suggesting dereferencing closure arg
Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid.

Fix #125634, fix #124563.
2024-06-24 03:39:54 +00:00
carbotaniuman a23917cfd0 Add hard error and migration lint for unsafe attrs 2024-06-23 19:02:14 -05:00
Esteban Küber 284437d434 Special case when a code line only has multiline span starts
```
3 |       X0 Y0 Z0
  |  _____^  -  -
  | | _______|  |
  | || _________|
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
```
2024-06-23 22:00:52 +00:00
Matthias Krüger 2c0311dbbe
Rollup merge of #126837 - petrochenkov:delegfix, r=compiler-errors
delegation: Do not crash on qpaths without a trait

Fixes https://github.com/rust-lang/rust/issues/126742
2024-06-23 22:39:01 +02:00
Matthias Krüger a9959bd1ab
Rollup merge of #126833 - RalfJung:extern-type-field-ice, r=compiler-errors
don't ICE when encountering an extern type field during validation

"extern type" is a pain that keeps on giving...

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

r? ```@oli-obk```
2024-06-23 22:39:00 +02:00
Xiangfei Ding f1be59fa72
SmartPointer derive-macro
Co-authored-by: Wedson Almeida Filho <walmeida@microsoft.com>
2024-06-24 03:03:34 +08:00
bohan 594fa01aba not use offset when there is not ends with brace 2024-06-23 23:44:22 +08:00
bors aabbf84b45 Auto merge of #123088 - tgross35:f16-f128-pattern-analysis, r=Nadrieril
Replace `f16` and `f128` pattern matching stubs with real implementations

This section of code depends on `rustc_apfloat` rather than our internal types, so this is one potential ICE that we should be able to melt now.

r? `@Nadrieril`
2024-06-23 14:14:48 +00:00
Trevor Gross 28ce7cd03e Change a fixed crash test to a standard test
Fixes <https://github.com/rust-lang/rust/issues/122587>
2024-06-23 04:28:42 -05:00
Trevor Gross 6fb6c19c96 Replace f16 and f128 pattern matching stubs with real implementations
This section of code depends on `rustc_apfloat` rather than our internal
types, so this is one potential ICE that we should be able to melt now.

This also fixes some missing range and match handling in `rustc_middle`.
2024-06-23 04:28:42 -05:00
Jubilee Young 43a6b018a2 compiler: Mention C-unwind in C-variadic error 2024-06-22 23:30:31 -07:00
Jubilee Young 0d8f734172 compiler: Fix arm32 asm issues by hierarchically sorting reg classes 2024-06-22 21:39:58 -07:00
surechen e8b5ba1111 For [E0308]: mismatched types, when expr is in an arm's body, not add semicolon ';' at the end of it.
fixes #126222
2024-06-23 10:19:02 +08:00
Jubilee Young 26dccadb47 Allow "C-unwind" fn to have C variadics 2024-06-22 15:14:14 -07:00
Matthias Krüger dc9a08f535
Rollup merge of #126552 - fee1-dead-contrib:rmfx, r=compiler-errors
Remove use of const traits (and `feature(effects)`) from stdlib

The current uses are already unsound because they are using non-const impls in const contexts. We can reintroduce them by reverting the commit in this PR, after #120639 lands.

Also, make `effects` an incomplete feature.

cc `@rust-lang/project-const-traits`
r? `@compiler-errors`
2024-06-22 19:33:56 +02:00
bjorn3 8d1f5b30ef Avoid a couple of unnecessary EarlyDiagCtxt uses 2024-06-22 17:06:47 +00:00
Vadim Petrochenkov 0a265957dd delegation: Do not crash on qpaths without a trait 2024-06-22 19:57:19 +03:00
Ralf Jung 763e3131cc don't ICE when encountering an extern type field during validation 2024-06-22 17:39:01 +02:00
Deadbeef 81da6a6d40 Make effects an incomplete feature 2024-06-22 14:11:11 +00:00
Guillaume Gomez 399c5cabdd
Rollup merge of #126723 - estebank:dot-dot-dot, r=Nadrieril
Fix `...` in multline code-skips in suggestions

When we have long code skips, we write `...` in the line number gutter.

For suggestions, we were "centering" the `...` with the line, but that was inconsistent with what we do in every other case *and* off-center.
2024-06-22 12:57:19 +02:00
Guillaume Gomez 3ed2cd74b5
Rollup merge of #126686 - fmease:dump-preds-n-item-bounds, r=compiler-errors
Add `#[rustc_dump_{predicates,item_bounds}]`

Conflicts with #126668.

As discussed
r? compiler-errors CC ``@fee1-dead``
2024-06-22 12:57:19 +02:00
León Orell Valerian Liehr 38bd7a0fcb
Add #[rustc_dump_{predicates,item_bounds}] 2024-06-22 06:34:09 +02:00
Jubilee 1916b3d57f
Rollup merge of #126811 - compiler-errors:tidy-ftl, r=estebank
Add a tidy rule to check that fluent messages and attrs don't end in `.`

This adds a new dependency on `fluent-parse` to `tidy` -- we already rely on it in rustc so I feel like it's not that big of a deal.

This PR also adjusts many error messages that currently end in `.`; not all of them since I added an `ALLOWLIST`, excluded `rustc_codegen_*` ftl files, and `.teach_note` attributes.

r? ``@estebank`` ``@oli-obk``
2024-06-21 21:02:29 -07:00
Jubilee 539090e5cd
Rollup merge of #126809 - estebank:wording-tweak, r=oli-obk
Remove stray `.` from error message
2024-06-21 21:02:28 -07:00
Michael Goulet ffd72b1700 Fix remaining cases 2024-06-21 19:00:18 -04:00
Esteban Küber 5d5892e966 Remove stray . from error message 2024-06-21 21:13:10 +00:00
Santiago Pastorino 22831ed117
Do not allow safe usafe on static and fn items 2024-06-21 09:12:13 -03:00
Deadbeef a6a83d3d4e bless tests 2024-06-21 11:57:24 +00:00
Matthias Krüger d86736c9be
Rollup merge of #126774 - nnethercote:fix-126751, r=oli-obk
Fix another assertion failure for some Expect diagnostics.

Very similar to #126719. So much so that I added a new case to the test from that PR rather than creating a new one.

r? `@oli-obk`
2024-06-21 09:12:38 +02:00
Matthias Krüger 3bd84f18bc
Rollup merge of #126700 - compiler-errors:fragment, r=fmease
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does

Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`.

Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it).

This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated?

r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo```
cc #123865

Tracking:

- https://github.com/rust-lang/rust/issues/123742
2024-06-21 09:12:36 +02:00
Matthias Krüger 2b7f6e274e
Rollup merge of #126617 - sayantn:veorq, r=workingjubilee
Expand `avx512_target_feature` to include VEX variants

Added 5 new target features for x86:

 - `AVX-IFMA`
 - `AVX-NE-CONVERT`
 - `AVX-VNNI`
 - `AVX-VNNI_INT8`
 - `AVX-VNNI_INT16`

Both LLVM and GCC already have support for these.

See also the [stdarch PR](https://github.com/rust-lang/stdarch/pull/1586)
2024-06-21 09:12:35 +02:00
Matthias Krüger 73cc4eca56
Rollup merge of #126125 - dev-ardi:conflict-markers, r=estebank
Improve conflict marker recovery

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
closes #113826
r? ```@estebank``` since you reviewed #115413
cc: ```@rben01``` since you opened up the issue in the first place
2024-06-21 09:12:34 +02:00
Nicholas Nethercote d6efcbb760 Fix another assertion failure for some Expect diagnostics.
Very similar to #126719. So much so that I added a new case to the test
from that PR rather than creating a new one.
2024-06-21 14:29:25 +10:00
bors 4e6de37349 Auto merge of #126757 - compiler-errors:safe, r=spastorino
Properly gate `safe` keyword in pre-expansion

This PR gates `safe` keyword in pre-expansion contexts. Should mitigate the fallout of https://github.com/rust-lang/rust/issues/126755, which is that `safe` is now usable on beta lol.

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

cc #124482 tracking #123743
2024-06-21 04:22:02 +00:00
Michael Goulet 108b3f214a Properly gate safe keyword in pre-expansion 2024-06-20 14:14:49 -04:00
Matthias Krüger 7b5ed5a66c
Rollup merge of #126740 - ferrocene:ja-ui-test-needs-unwind, r=lcnr
add `needs-unwind` to UI test

the `tail-expr-lock-poisoning` UI test uses the `panic::catch_unwind` API so it relies on unwinding being implemented. this test ought not to run on targets that do not support unwinding. add the `needs-unwind` attribute to signal this
2024-06-20 18:20:14 +02:00
Matthias Krüger 2fa148e11a
Rollup merge of #126735 - bvanjoi:fix-126647, r=petrochenkov
collect attrs in const block expr

Fixes #126516
Fixes #126647

It was forgotten to collect these attributes in the const block expression.

r? `@petrochenkov`
2024-06-20 18:20:12 +02:00
Michael Goulet dd557d8c37 Add a test demonstrating that RPITITs cant use precise capturing 2024-06-20 12:04:59 -04:00
Jorge Aparicio f42fa4f6e0 add needs-unwind to UI test
the `tail-expr-lock-poisoning` UI test uses the `panic::catch_unwind`
API so it relies on unwinding being implemented. this test ought not to
run on targets that do not support unwinding. add the `needs-unwind`
attribute to signal this
2024-06-20 17:42:40 +02:00
bors 1ca578e68e Auto merge of #126736 - matthiaskrgr:rollup-rb20oe3, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #126380 (Add std Xtensa targets support)
 - #126636 (Resolve Clippy `f16` and `f128` `unimplemented!`/`FIXME`s )
 - #126659 (More status-quo tests for the `#[coverage(..)]` attribute)
 - #126711 (Make Option::as_[mut_]slice const)
 - #126717 (Clean up some comments near `use` declarations)
 - #126719 (Fix assertion failure for some `Expect` diagnostics.)
 - #126730 (Add opaque type corner case test)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-20 13:36:42 +00:00
Matthias Krüger b099c05b3a
Rollup merge of #126730 - oli-obk:opaque_type_diff_next_solver, r=lcnr
Add opaque type corner case test

r? ``@lcnr``

I can't make sense of the new solver tracing logs yet, so I just added the test without explanation.

The old solver does not yet figure out that `Foo == ()` from the where bounds. Unfortunately, even if we make it understand that, it will later try to prove `<X as Trait<'static>>::Out<Foo>: Sized` via the `is_sized_raw` query, which does not take a list of defineable opaque types, causing that check to fail with an ICE.

Thus I'm submitting this test case on its own just to ensure we handle it correctly in the future with any new solver or old solver changes.
2024-06-20 14:07:05 +02:00
Matthias Krüger f511f2b18d
Rollup merge of #126719 - nnethercote:fix-126521, r=oli-obk
Fix assertion failure for some `Expect` diagnostics.

In #120699 I moved some code dealing with `has_future_breakage` earlier in `emit_diagnostic`. Issue #126521 identified a case where that reordering was invalid (leading to an assertion failure) for some `Expect` diagnostics.

This commit partially undoes the change, by moving the handling of unstable `Expect` diagnostics earlier again. This makes `emit_diagnostic` a bit uglier, but is necessary to fix the problem.

Fixes #126521.

r? ``@oli-obk``
2024-06-20 14:07:04 +02:00
Matthias Krüger 9cbfbda165
Rollup merge of #126659 - Zalathar:test-coverage-attr, r=cjgillot
More status-quo tests for the `#[coverage(..)]` attribute

Follow-up to #126621, after I found even more weird corner-cases in the handling of the coverage attribute.

These tests reveal some inconsistencies that are tracked by #126658.
2024-06-20 14:07:02 +02:00
bohan 1e42bb606d collect attrs in const block expr 2024-06-20 19:59:27 +08:00
bors 1aaab8b9f8 Auto merge of #116088 - nbdd0121:unwind, r=Amanieu,RalfJung
Stabilise `c_unwind`

Fix #74990
Fix #115285 (that's also where FCP is happening)

Marking as draft PR for now due to `compiler_builtins` issues

r? `@Amanieu`
2024-06-20 11:22:59 +00:00
Oli Scherer 53f10b936b Add opaque type test 2024-06-20 09:20:45 +00:00
Zalathar ebb3aa0d46 Also test that yes/no must be bare words 2024-06-20 17:11:53 +10:00
Zalathar 388aea471f More status-quo tests for the #[coverage(..)] attribute
These tests reveal some inconsistencies that are tracked by
<https://github.com/rust-lang/rust/issues/126658>.
2024-06-20 17:11:53 +10:00
Matthias Krüger 03d558f5b6
Rollup merge of #126652 - Manishearth:anon-const-scope, r=bjorn3,Urgau
Clarify that anonymous consts still do introduce a new scope

See https://github.com/rust-lang/rust/issues/120363#issuecomment-2177064702

This error message is misleading: it's trying to say that `const _ : () = ...` is a workaround for the lint, but by saying that anonymous constants are treated as being in the parent scope, it makes them appear useless for scope-hiding.

They *are* useful for scope-hiding, they are simply treated as part of the parent scope when it comes to this lint.
2024-06-20 07:52:44 +02:00
Matthias Krüger e7be3562b7
Rollup merge of #126620 - oli-obk:taint_errors, r=fee1-dead
Actually taint InferCtxt when a fulfillment error is emitted

And avoid checking the global error counter

fixes #122044
fixes #123255
fixes #123276
fixes #125799
2024-06-20 07:52:43 +02:00
Esteban Küber 9fd7784b97 Fix ... in multline code-skips in suggestions
When we have long code skips, we write `...` in the line number gutter.

For suggestions, we were "centering" the `...` with the line, but that was consistent with what we do in every other case.
2024-06-20 04:25:17 +00:00
Manish Goregaokar e8a9af9ad9 Clarify that anonymous consts still do introduce a new scope 2024-06-19 18:34:15 -07:00
Nicholas Nethercote 19b7192c72 Fix assertion failure for some Expect diagnostics.
In #120699 I moved some code dealing with `has_future_breakage` earlier
in `emit_diagnostic`. Issue #126521 identified a case where that
reordering was invalid (leading to an assertion failure) for some `Expect`
diagnostics.

This commit partially undoes the change, by moving the handling of
unstable `Expect` diagnostics earlier again. This makes
`emit_diagnostic` a bit uglier, but is necessary to fix the problem.

Fixes #126521.
2024-06-20 10:17:40 +10:00
Michael Goulet 3e8898a4e1 Allow naming expr_2021 in all editions 2024-06-19 12:37:49 -04:00
Michael Goulet 50d1efa3e2 Add a test demonstrating the problem 2024-06-19 12:37:32 -04:00
Oli Scherer e4c9a8cf9b Const generic parameters aren't bounds, even if we end up erroring because of the bound that binds the parameter's type 2024-06-19 14:58:29 +00:00
bors 894f7a4ba6 Auto merge of #126678 - nnethercote:fix-duplicated-attrs-on-nt-expr, r=petrochenkov
Fix duplicated attributes on nonterminal expressions

This PR fixes a long-standing bug (#86055) whereby expression attributes can be duplicated when expanded through declarative macros.

First, consider how items are parsed in declarative macros:
```
Items:
- parse_nonterminal
  - parse_item(ForceCollect::Yes)
    - parse_item_
      - attrs = parse_outer_attributes
      - parse_item_common(attrs)
        - maybe_whole!
        - collect_tokens_trailing_token
```
The important thing is that the parsing of outer attributes is outside token collection, so the item's tokens don't include the attributes. This is how it's supposed to be.

Now consider how expression are parsed in declarative macros:
```
Exprs:
- parse_nonterminal
  - parse_expr_force_collect
    - collect_tokens_no_attrs
      - collect_tokens_trailing_token
        - parse_expr
          - parse_expr_res(None)
            - parse_expr_assoc_with
              - parse_expr_prefix
                - parse_or_use_outer_attributes
                - parse_expr_dot_or_call
```
The important thing is that the parsing of outer attributes is inside token collection, so the the expr's tokens do include the attributes, i.e. in `AttributesData::tokens`.

This PR fixes the bug by rearranging expression parsing to that outer attribute parsing happens outside of token collection. This requires a number of small refactorings because expression parsing is somewhat complicated. While doing so the PR makes the code a bit cleaner and simpler, by eliminating `parse_or_use_outer_attributes` and `Option<AttrWrapper>` arguments (in favour of the simpler `parse_outer_attributes` and `AttrWrapper` arguments), and simplifying `LhsExpr`.

r? `@petrochenkov`
2024-06-19 13:58:21 +00:00
Gary Guo 9d2b932d71 Fix broken aarch64 unwind test 2024-06-19 13:54:55 +01:00
Gary Guo 5812b1fd12 Remove c_unwind from tests and fix tests 2024-06-19 13:54:55 +01:00
bors 3186d17d56 Auto merge of #126679 - fmease:rollup-njrv2py, r=fmease
Rollup of 6 pull requests

Successful merges:

 - #125447 (Allow constraining opaque types during subtyping in the trait system)
 - #125766 (MCDC Coverage: instrument last boolean RHS operands from condition coverage)
 - #125880 (Remove `src/tools/rust-demangler`)
 - #126154 (StorageLive: refresh storage (instead of UB) when local is already live)
 - #126572 (override user defined channel when using precompiled rustc)
 - #126662 (Unconditionally warn on usage of `wasm32-wasi`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-19 11:09:31 +00:00
León Orell Valerian Liehr 25d47fe388
Rollup merge of #125447 - oli-obk:eq_opaque_pred, r=compiler-errors
Allow constraining opaque types during subtyping in the trait system

Previous attempt: https://github.com/rust-lang/rust/pull/123979

Sometimes we don't immediately perform subtyping, but instead register a subtyping obligation and solve that obligation when its inference variables become resolved. Unlike immediate subtyping, we currently do not allow registering hidden types for opaque types. This PR also allows that.
2024-06-19 13:04:56 +02:00
Nicholas Nethercote 64c2e9ed3b Change how parse_expr_force_collect works.
It now parses outer attributes before collecting tokens. This avoids the
problem where the outer attribute tokens were being stored twice -- for
the attribute tokesn, and also for the expression tokens.

Fixes #86055.
2024-06-19 19:15:06 +10:00
Nicholas Nethercote aaa220e875 Move parse_or_use_outer_attributes out of parse_expr_prefix_range.
This eliminates another `Option<AttrWrapper>` argument and changes one
obscure error message.
2024-06-19 19:12:00 +10:00
bors 5978f35330 Auto merge of #126671 - fmease:rollup-dmet4fi, r=fmease
Rollup of 7 pull requests

Successful merges:

 - #123782 (Test that opaque types can't have themselves as a hidden type with incompatible lifetimes)
 - #124580 (Suggest removing unused tuple fields if they are the last fields)
 - #125787 (Migrate `bin-emit-no-symbols` `run-make` test to `rmake`)
 - #126553 (match lowering: expand or-candidates mixed with candidates above)
 - #126594 (Make async drop code more consistent with regular drop code)
 - #126654 (Make pretty printing for `f16` and `f128` consistent)
 - #126656 (rustc_type_ir: Omit some struct fields from Debug output)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-19 08:56:43 +00:00
Oli Scherer 45da03541c More tests 2024-06-19 08:40:29 +00:00
Oli Scherer ba4510ece8 Allow constraining opaque types during subtyping in the trait system 2024-06-19 08:29:17 +00:00
Oli Scherer f5f298dad4 Add more tests 2024-06-19 08:28:31 +00:00
Oli Scherer 4a86ef6f4c Allow constraining opaque types during auto trait casting 2024-06-19 08:28:31 +00:00
Oli Scherer cbadf786bc Add tests 2024-06-19 08:28:31 +00:00
Oli Scherer 4dcb70b8cf Allow constraining opaque types during unsizing 2024-06-19 08:28:31 +00:00
León Orell Valerian Liehr b980f6d7b1
Rollup merge of #126656 - fmease:skip-debug-for-_, r=compiler-errors
rustc_type_ir: Omit some struct fields from Debug output

r? compiler-errors or compiler
2024-06-19 09:52:02 +02:00
León Orell Valerian Liehr e111e99253
Rollup merge of #126553 - Nadrieril:expand-or-pat-into-above, r=matthewjasper
match lowering: expand or-candidates mixed with candidates above

This PR tweaks match lowering of or-patterns. Consider this:
```rust
match (x, y) {
    (1, true) => 1,
    (2, false) => 2,
    (1 | 2, true | false) => 3,
    (3 | 4, true | false) => 4,
    _ => 5,
}
```
One might hope that this can be compiled to a single `SwitchInt` on `x` followed by some boolean checks. Before this PR, we compile this to 3 `SwitchInt`s on `x`, because an arm that contains more than one or-pattern was compiled on its own. This PR groups branch `3` with the two branches above, getting us down to 2 `SwitchInt`s on `x`.

We can't in general expand or-patterns freely, because this interacts poorly with another optimization we do: or-pattern simplification. When an or-pattern doesn't involve bindings, we branch the success paths of all its alternatives to the same block. The drawback is that in a case like:
```rust
match (1, true) {
    (1 | 2, false) => unreachable!(),
    (2, _) => unreachable!(),
    _ => {}
}
```
if we used a single `SwitchInt`, by the time we test `false` we don't know whether we came from the `1` case or the `2` case, so we don't know where to go if `false` doesn't match.

Hence the limitation: we can process or-pattern alternatives alongside candidates that precede it, but not candidates that follow it. (Unless the or-pattern is the only remaining match pair of its candidate, in which case we can process it alongside whatever).

This PR allows the processing of or-pattern alternatives alongside candidates that precede it. One benefit is that we now process or-patterns in a single place in `mod.rs`.

r? ``@matthewjasper``
2024-06-19 09:52:00 +02:00
León Orell Valerian Liehr 96144c94af
Rollup merge of #124580 - gurry:124556-suggest-remove-tuple-field, r=jackh726
Suggest removing unused tuple fields if they are the last fields

Fixes #124556

We now check if dead/unused fields are the last fields of the tuple and suggest their removal instead of suggesting them to be changed to `()`.
2024-06-19 09:51:59 +02:00
León Orell Valerian Liehr f03bd96d66
Rollup merge of #123782 - oli-obk:equal_tait_args, r=compiler-errors
Test that opaque types can't have themselves as a hidden type with incompatible lifetimes

fixes #122876

This PR used to add extra logic to prevent those cases, but after https://github.com/rust-lang/rust/pull/113169 this is implicitly rejected, because such usages are not defining.
2024-06-19 09:51:59 +02:00
bors 3c0f019b3c Auto merge of #125852 - bvanjoi:improve-tip-for-invisible-trait, r=compiler-errors
improve tip for inaccessible traits

Improve the tips when the candidate method is from an inaccessible trait.

For example:

```rs
mod m {
  trait Trait {
    fn f() {}
  }
  impl<T> Trait for T {}
}

fn main() {
  struct S;
  S::f();
}
```

The difference between before and now is:

```diff
error[E0599]: no function or associated item named `f` found for struct `S` in the current scope
  --> ./src/main.rs:88:6
   |
LL |   struct S;
   |   -------- function or associated item `f` not found for this struct
LL |   S::f();
   |      ^ function or associated item not found in `S`
   |
   = help: items from traits can only be used if the trait is implemented and in scope
- help: trait `Trait` which provides `f` is implemented but not in scope; perhaps you want to import it
+ help: trait `crate:Ⓜ️:Trait` which provides `f` is implemented but not reachable
   |
- LL + use crate:Ⓜ️:Trait;
   |
```
2024-06-19 06:19:22 +00:00
sayantn 1e1b3fcada Fix stderr cases 2024-06-19 11:19:25 +05:30
Oli Scherer 3594a19f2a Taint infcx when reporting errors 2024-06-19 04:41:56 +00:00
León Orell Valerian Liehr 2126c1d446
rustc_type_ir: Omit some struct fields from Debug output 2024-06-19 03:08:34 +02:00
许杰友 Jieyou Xu (Joe) bf841c4773
Rollup merge of #126558 - jieyouxu:caller-chooses-ty, r=fmease
hir_typeck: be more conservative in making "note caller chooses ty param" note

In https://github.com/rust-lang/rust/pull/122195 I added a "caller chooses ty for type param" note for when the return expression type a.k.a. found type does not match the expected return type.

#126547 found that this note was confusing when the found return type *contains* the expected type, e.g.

```rs
fn f<T>(t: &T) -> T {
    t
}
```

because the found return type `&T` will *always* be different from the expected return type `T`, so the note was needlessly redundant and confusing.

This PR addresses that by not making the note if the found return type contains the expected return type.

r? ``@fmease`` (since you reviewed the original PR)

Fixes https://github.com/rust-lang/rust/issues/126547
2024-06-19 01:51:41 +01:00
许杰友 Jieyou Xu (Joe) 0e46111660
Rollup merge of #126493 - jswrenn:fix-126460, r=compiler-errors
safe transmute: support non-ZST, variantful, uninhabited enums

Previously, `Tree::from_enum`'s implementation branched into three disjoint cases:

 1. enums that uninhabited
 2. enums for which all but one variant is uninhabited
 3. enums with multiple variants

This branching (incorrectly) did not differentiate between variantful and variantless uninhabited enums. In both cases, we assumed (and asserted) that uninhabited enums are zero-sized types. This assumption is false for enums like:

    enum Uninhabited { A(!, u128) }

...which, currently, has the same size as `u128`. This faulty assumption manifested as the ICE reported in #126460.

In this PR, we revise the first case of `Tree::from_enum` to consider only the narrow category of "enums that are uninhabited ZSTs". These enums, whose layouts are described with `Variants::Single { index }`, are special in their layouts otherwise resemble the `!` type and cannot be descended into like typical enums. This first case captures uninhabited enums like:

    enum Uninhabited { A(!, !), B(!) }

The second case is revised to consider the broader category of "enums that defer their layout to one of their variants"; i.e., enums whose layouts are described with `Variants::Single { index }` and that do have a variant at `index`. This second case captures uninhabited enums that are not ZSTs, like:

    enum Uninhabited { A(!, u128) }

...which represent their variants with `Variants::Single`.

Finally, the third case is revised to cover the broader category of "enums with multiple variants", which captures uninhabited enums like:

    enum Uninhabited { A(u8, !), B(!, u32) }

...which represent their variants with `Variants::Multiple`.

This PR also adds a comment requested by ````@RalfJung```` in his review of #126358 to `compiler/rustc_const_eval/src/interpret/discriminant.rs`.

Fixes #126460

r? ````@compiler-errors````
2024-06-19 01:51:39 +01:00
许杰友 Jieyou Xu (Joe) 8eb2e5f4c8
Rollup merge of #125293 - dingxiangfei2009:tail-expr-temp-lifetime, r=estebank,davidtwco
Place tail expression behind terminating scope

This PR implements #123739 so that we can do further experiments in nightly.

A little rewrite has been applied to `for await` lowering. It was previously `unsafe { Pin::unchecked_new(into_async_iter(..)) }`. Under the edition 2024 rule, however, `into_async_iter` gets dropped at the end of the `unsafe` block. This presumably the first Edition 2024 migration rule goes by hoisting `into_async_iter(..)` into `match` one level above, so it now looks like the following.
```rust
match into_async_iter($iter_expr) {
  ref mut iter => match unsafe { Pin::unchecked_new(iter) } {
    ...
  }
}
```
2024-06-19 01:51:38 +01:00
许杰友 Jieyou Xu (Joe) c9a9d5cee7
Rollup merge of #125078 - linyihai:issue-124496, r=compiler-errors
fix: break inside async closure has incorrect span for enclosing closure

Fixes #124496
2024-06-19 01:51:38 +01:00
许杰友 Jieyou Xu (Joe) f8ce1cfbf5
Rollup merge of #124135 - petrochenkov:deleglob, r=fmease
delegation: Implement glob delegation

Support delegating to all trait methods in one go.
Overriding globs with explicit definitions is also supported.

The implementation is generally based on the design from https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2020869823, but unlike with list delegation in https://github.com/rust-lang/rust/pull/123413 we cannot expand glob delegation eagerly.
We have to enqueue it into the queue of unexpanded macros (most other macros are processed this way too), and then a glob delegation waits in that queue until its trait path is resolved, and enough code expands to generate the identifier list produced from the glob.

Glob delegation is only allowed in impls, and can only point to traits.
Supporting it in other places gives very little practical benefit, but significantly raises the implementation complexity.

Part of https://github.com/rust-lang/rust/issues/118212.
2024-06-19 01:51:36 +01:00
ardi d51b4462ec Improve conflict marker recovery 2024-06-19 00:27:41 +02:00
许杰友 Jieyou Xu (Joe) 939026c8fb tests: update tests for more conservative return ty mismatch note 2024-06-18 21:06:53 +00:00
Oli Scherer a183989e88 Only check locally for reported errors 2024-06-18 15:43:27 +00:00
Oli Scherer de473a5a2b Test that opaque types can't have themselves as a hidden type with incompatible lifetimes 2024-06-18 15:41:27 +00:00
Guillaume Gomez 9f455d3246
Rollup merge of #126621 - Zalathar:test-coverage-attr, r=petrochenkov
More thorough status-quo tests for `#[coverage(..)]`

In light of the stabilization push at https://github.com/rust-lang/rust/issues/84605#issuecomment-2166514660, I have written some tests to more thoroughly capture the current behaviour of the `#[coverage(..)]` attribute.

These tests aim to capture the *current* behaviour, which is not necessarily the desired behaviour. For example, some of the error message are not great, some things that perhaps ought to cause an error do not, and recursive coverage attributes have not been implemented yet.

`@rustbot` label +A-code-coverage
2024-06-18 15:30:47 +02:00
Guillaume Gomez bbec736f2d
Rollup merge of #126587 - Zalathar:no-mir-spans, r=oli-obk
coverage: Add debugging flag `-Zcoverage-options=no-mir-spans`

When set, this flag skips the code that normally extracts coverage spans from MIR statements and terminators. That sometimes makes it easier to debug branch coverage and MC/DC coverage instrumentation, because the coverage output is less noisy.

For internal debugging only. If future code changes would make it hard to keep supporting this flag, it should be removed at that time.

`@rustbot` label +A-code-coverage
2024-06-18 15:30:46 +02:00
Zalathar 9a084e6310 Add a more thorough test of incorrect/unusal #[coverage(..)] syntax
This test reflects the current implementation behaviour, which is not
necessarily the desired behaviour.
2024-06-18 21:07:37 +10:00
Zalathar 605b61534a Create tests/ui/coverage-attr/ 2024-06-18 20:30:25 +10:00
mu001999 a264bff9d5 Mark assoc tys live only if the trait is live 2024-06-18 16:00:57 +08:00
Michael Goulet 227374714f Delay a bug and mark precise_capturing as not incomplete 2024-06-17 22:35:25 -04:00
Michael Goulet 2e03130e11 Detect duplicates 2024-06-17 22:35:25 -04:00
Michael Goulet f66558d2bf Add tests for illegal use bound syntax 2024-06-17 22:35:25 -04:00
Michael Goulet b1efe1ab5d Rework precise capturing syntax 2024-06-17 22:35:25 -04:00
Michael Goulet 68bd001c00 Make parse_seq_to_before_tokens take expected/nonexpected tokens, use in parse_precise_capturing_syntax 2024-06-17 22:35:25 -04:00
Ding Xiang Fei 0f8c3f7882
tail expression behind terminating scope 2024-06-18 04:14:43 +08:00
bors 11380368dc Auto merge of #126593 - matthiaskrgr:rollup-a5jfg7w, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #126568 (mark undetermined if target binding in current ns is not got)
 - #126577 (const_refs_to_static test and cleanup)
 - #126584 (Do not ICE in privacy when type inference fails.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-17 14:22:10 +00:00
Matthias Krüger 592f9aa544
Rollup merge of #126584 - cjgillot:issue-122736, r=michaelwoerister
Do not ICE in privacy when type inference fails.

Fixes https://github.com/rust-lang/rust/issues/122736
2024-06-17 15:43:33 +02:00