Commit graph

764 commits

Author SHA1 Message Date
Matthias Krüger
7ab385e2e1
Rollup merge of #139854 - fmease:modern-diag-for-lt-in-ty, r=davidtwco
Improve parse errors for stray lifetimes in type position

While technically & syntactically speaking lifetimes do begin[^1] types in type contexts (this essentially excludes generic argument lists) and require a following `+` to form a complete type (`'a +` denotes a bare trait object type), the likelihood that a user meant to write a lifetime-prefixed bare trait object type in *modern* editions (Rust ≥2021) when placing a lifetime into a type context is incredibly low (they would need to add at least three tokens to turn it into a *semantically* well-formed TOT: `'a` → `dyn 'a + Trait`).

Therefore let's *lie* in modern editions (just like in PR https://github.com/rust-lang/rust/pull/131239, a precedent if you will) by stating "*expected type, found lifetime*" in such cases which is a lot more a approachable, digestible and friendly compared to "*lifetime in trait object type must be followed by `+`*" (as added in PR https://github.com/rust-lang/rust/pull/69760).

I've also added recovery for "ampersand-less" reference types (e.g., `'a ()`, `'a mut Ty`) in modern editions because it was trivial to do and I think it's not unlikely to occur in practice.

Fixes #133413.

[^1]: For example, in the context of decl macros, this implies that a lone `'a` always matches syntax fragment `ty` ("even if" there's a later macro matcher expecting syntax fragment `lifetime`). Rephrased, lifetimes (in type contexts) *commit* to the type parser.
2025-04-17 00:16:22 +02:00
Michael Goulet
11e5987d01 Don't compute name of associated item if it's an RPITIT 2025-04-15 18:46:26 +00:00
León Orell Valerian Liehr
6242335fdb
Improve diagnostic for E0178 (bad + in type)
Namely, use a more sensical primary span.
Don't pretty-print AST nodes for the diagnostic message. Why:
* It's lossy (e.g., it doesn't replicate trailing `+`s in trait objects.
* It's prone to leak error nodes (printed as `(/*ERROR*/)`) since
  the LHS can easily represent recovered code (e.g., `fn(i32?) + T`).
2025-04-15 10:08:49 +02:00
lcnr
836ea25b4d add RPITIT tests: method compat auto trait leakage 2025-04-14 13:26:13 +02:00
lcnr
2e79f7cd61 move tests 2025-04-14 13:26:13 +02:00
lcnr
ce9d8678ca do not leak auto traits in item bounds 2025-04-14 13:26:13 +02:00
Jacob Pratt
2b54f9bfb1
Rollup merge of #139662 - nnethercote:tweak-DefPathData, r=compiler-errors
Tweak `DefPathData`

Some improvements in and around `DefPathData`, following on from #137977.

r? `@spastorino`
2025-04-11 21:21:01 +02:00
bors
71b68da1bd Auto merge of #139578 - ferrocene:pa-compiletest-edition, r=jieyouxu
Fix breakage when running compiletest with `--test-args=--edition=2015`

Compiletest has an `--edition` flag to change the default edition tests are run with. Unfortunately no test suite successfully executes when that flag is passed. If the edition is set to something greater than 2015 the breakage is expected, since the test suite currently supports only edition 2015 (Ferrous Systems will open an MCP about fixing that soonish). Surprisingly, the test suite is also broken if `--edition=2015` is passed to compiletest. This PR focuses on fixing the latter.

This PR fixes the two categories of failures happening when `--edition=2015` is passed:

* Some edition-specific tests set their edition through `//@ compile-flags` instead of `//@ edition`. Compiletest doesn't parse the compile flags, so it would see no `//@ edition` and add another `--edition` flag, leading to a rustc error.
* Compiletest would add the edition after `//@ compile-flags`, while some tests depend on flags passed to `//@ compile-flags` being the last flags in the rustc invocation.

Note that for the first category, I opted to manually go and replace all `//@ compile-flags` setting an edition with an explicit `//@ edition`. We could've changed compiletest to instead check whether an edition was set in `//@ compile-flags`, but I thought it was better to enforce a consistent way to set the edition in tests.

I also added the edition to the stamp, so that changing `--edition` results in tests being re-executed.

r? `@jieyouxu`
2025-04-11 10:53:45 +00:00
Nicholas Nethercote
cdf5b8d4e7 Change how anonymous associated types are printed.
Give them their own symbol `anon_assoc`, as is done for all the other
anonymous `DefPathData` variants.
2025-04-11 20:13:16 +10:00
Nicholas Nethercote
7e8184fa2a Improve AssocItem::descr.
The commit adds "associated" to the description of associated types and
associated consts, to match the description of associated functions.
This increases error message precision and consistency with
`AssocKind::fmt`.

The commit also notes an imperfection in `AssocKind::fmt`; fixing this
imperfection is possible but beyond the scope of this PR.
2025-04-11 11:03:08 +10:00
Pietro Albini
cd371b90e2
replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
bors
c1b8b7e86f Auto merge of #139555 - petrochenkov:errkind-ann, r=jieyouxu
UI tests: add missing diagnostic kinds where possible

The subset of https://github.com/rust-lang/rust/pull/139427 that only adds diagnostic kinds to line annotations, without changing any other things in annotations or compiletest.
After this only non-viral `NOTE`s and `HELP`s should be missing.

r? `@jieyouxu`
2025-04-09 02:19:37 +00:00
Vadim Petrochenkov
b3f75353a2 UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
Matthias Krüger
9ea9339435
Rollup merge of #139501 - compiler-errors:suppress-stack-overflow, r=lcnr
Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types

This fixes several spicy non-trivial recursive opaque definitions inferred from HIR typeck, ensuring that they don't cause stack overflows in exhaustiveness code, which currently reveals opaques manually in a way that is not overflow aware (as opposed to something like the normalizer folders).

These should eventually be outright rejected, but today (some) non-trivial recursive opaque definitions are accepted, and changing that requires an FCP, so for now just make sure we don't stack overflow :^)

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

r? lcnr
2025-04-08 18:05:31 +02:00
Michael Goulet
b08e9c2a60 Fix stack overflow in exhaustiveness due to recursive HIR opaque type values 2025-04-07 22:41:48 +00:00
Vadim Petrochenkov
5c160f511e compiletest: Stricter parsing for diagnostic kinds 2025-04-07 19:13:31 +03:00
lcnr
509a144eed add TypingMode::Borrowck 2025-04-03 11:13:10 +02:00
Matthias Krüger
52aed95060
Rollup merge of #139063 - fmease:fix-tait-atpit-gating, r=oli-obk
Fix TAIT & ATPIT feature gating in the presence of anon consts

Fixes #139055 (https://github.com/rust-lang/rust/issues/119924#issuecomment-1928659690).

r? oli-obk or anybody else
2025-03-28 21:18:30 +01:00
León Orell Valerian Liehr
7a295d1be0
Fix TAIT & ATPIT feature gating in the presence of anon consts 2025-03-28 18:15:23 +01:00
Jacob Pratt
5bd69d940e
Rollup merge of #138911 - compiler-errors:define-opaque, r=oli-obk
Allow defining opaques in statics and consts

r? oli-obk

Fixes https://github.com/rust-lang/rust/issues/138902
2025-03-25 20:34:49 -04:00
Michael Goulet
0827f76586 Test define opaques in extern items 2025-03-25 16:44:59 +00:00
Michael Goulet
f8df298d74 Allow defining opaques in statics and consts 2025-03-25 16:44:59 +00:00
Michael Goulet
eb3707e4b4 Stabilize precise_capturing_in_traits 2025-03-23 14:11:04 +00:00
lcnr
cfc78cec79 merge opaque types of nested bodies 2025-03-19 17:52:53 +01:00
Oli Scherer
cb4751d4b8 Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
许杰友 Jieyou Xu (Joe)
257b4947ed
Rollup merge of #137728 - Darksonn:no-tuple-unsize, r=oli-obk
Remove unsizing coercions for tuples

See https://github.com/rust-lang/rust/issues/42877#issuecomment-2686010847 and below comments for justification.

Tracking issue: #42877
Fixes: #135217
2025-03-05 21:46:44 +08:00
Michael Goulet
0ad48b47e6 Do not recover missing lifetime with random in-scope lifetime 2025-03-03 05:57:55 +00:00
Alice Ryhl
44cccae02a Delete tuple unsizing 2025-02-27 10:26:33 +00:00
Matthias Krüger
3499846073
Rollup merge of #137304 - pitaj:rangebounds-is_empty-intersect, r=ibraheemdev
add `IntoBounds::intersect` and `RangeBounds::is_empty`

- ACP: https://github.com/rust-lang/libs-team/issues/539
- Tracking issue for `is_empty`: #137300
- Tracking issue for `IntoBounds`: #136903
2025-02-27 08:56:38 +01:00
bors
b87eda7fdf Auto merge of #137406 - matthiaskrgr:rollup-9nknrsb, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #136458 (Do not deduplicate list of associated types provided by dyn principal)
 - #136474 ([`compiletest`-related cleanups 3/7] Make the distinction between sources root vs test suite sources root in compiletest less confusing)
 - #136592 (Make sure we don't overrun the stack in canonicalizer)
 - #136787 (Remove `lifetime_capture_rules_2024` feature)
 - #137207 (Add #[track_caller] to Duration Div impl)
 - #137245 (Tweak E0277 when predicate comes indirectly from ?)
 - #137257 (Ignore fake borrows for packed field check)
 - #137399 (fix ICE in layout computation with unnormalizable const)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-22 03:05:26 +00:00
Matthias Krüger
085adfda3c
Rollup merge of #136787 - compiler-errors:lt2024feat, r=oli-obk
Remove `lifetime_capture_rules_2024` feature

Just use edition 2024 instead
2025-02-22 01:01:40 +01:00
Michael Goulet
0a7ab1d6df More sophisticated span trimming 2025-02-21 00:41:17 +00:00
Peter Jaszkowiak
c293af9b57 add IntoBounds::intersect and RangeBounds::is_empty 2025-02-19 23:04:10 -07:00
Michael Goulet
b002b5cc82 Deeply normalize associated type bounds before proving them 2025-02-17 17:21:24 +00:00
Jubilee
2ec48fb687
Rollup merge of #136971 - HypheX:patch1, r=WaffleLapkin
Add a new check-pass UI test for returning `impl Fn(T) -> impl Trait`

This PR closes #107883 by adding a ui test.
2025-02-14 14:05:23 -08:00
Xelph
7d1262adf2 Add new ui test for returning an Fn trait that returns impl Trait
Change description from compiletest to regression test

Co-authored-by: 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>

Improve test name, location, and description

Update tests/ui/impl-trait/impl-fn-rpit-opaque-107883.rs

Co-authored-by: waffle <waffle.lapkin@gmail.com>
2025-02-14 05:55:30 -07:00
Michael Goulet
6d71251cf9 Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
Michael Goulet
b480a9214a Use underline suggestions for purely 'additive' replacements 2025-02-14 00:27:13 -08:00
Jubilee
1b603f959b
Rollup merge of #136928 - lcnr:method-lookup-check-wf, r=compiler-errors
eagerly prove WF when resolving fully qualified paths

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

This hopefully shouldn't impact perf. I do think we need to deal with at least part of the fallout here, opening for vibes.

r? ``@compiler-errors``
2025-02-13 17:46:09 -08:00
lcnr
83a02619d5 fallout :skull_emoji: 2025-02-14 00:37:23 +01:00
lcnr
059288ed44 adjust derive_error 2025-02-13 23:49:09 +01:00
Oli Scherer
c294da3310 Reject impl Trait bounds in various places where we unconditionally warned since 1.0 2025-02-11 09:19:37 +00:00
Esteban Küber
f0845adb0c Show diff suggestion format on verbose replacement
```
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
  --> $DIR/attempted-access-non-fatal.rs:7:15
   |
LL |     let _ = 2.l;
   |               ^
   |
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
   |
LL -     let _ = 2.l;
LL +     let _ = 2.0f64;
   |
```
2025-02-10 20:21:39 +00:00
Michael Goulet
6fe8b8d4a0 Remove lifetime_capture_rules_2024 feature 2025-02-09 19:09:45 +00:00
bors
0148a2be13 Auto merge of #136713 - matthiaskrgr:rollup-sy6py39, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #135179 (Make sure to use `Receiver` trait when extracting object method candidate)
 - #136554 (Add `opt_alias_variances` and use it in outlives code)
 - #136556 ([AIX] Update tests/ui/wait-forked-but-failed-child.rs to accomodate exiting and idle processes.)
 - #136589 (Enable "jump to def" feature on rustc docs)
 - #136615 (sys: net: Add UEFI stubs)
 - #136635 (Remove outdated `base_port` calculation in std net test)
 - #136682 (Move two windows process tests to tests/ui)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-08 02:57:14 +00:00
Matthias Krüger
7ca0fd18f6
Rollup merge of #136554 - compiler-errors:opt-alias-variances, r=lcnr
Add `opt_alias_variances` and use it in outlives code

...so to fix some subtle outlives bugs with precise capturing in traits, and eventually make it easier to compute variances for "forced unconstrained" trait lifetimes.

r? lcnr
2025-02-07 21:31:00 +01:00
Waffle Lapkin
e9d5d1113f
remove feature(trait_upcasting) from tests and bless them 2025-02-06 23:44:23 +01:00
Michael Goulet
d17a4a7f9a Add opt_alias_variances and use it in outlives code 2025-02-06 15:16:27 +00:00
Matthias Krüger
7ca29360a7
Rollup merge of #136073 - compiler-errors:recursive-coro-always, r=oli-obk
Always compute coroutine layout for eagerly emitting recursive layout errors

Detect recursive coroutine layouts even if we don't detect opaque type recursion in the new solver. This is for two reasons:
1. It helps us detect (bad) recursive async function calls in the new solver, which due to its approach to normalization causes us to not detect this via a recursive RPIT (since the opaques are more eagerly revealed in the opaque body).
    * Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/137.
2. It helps us detect (bad) recursive async functions behind AFITs. See the AFIT test that changed for the old solver too.
3. It also greatly simplifies the recursive impl trait check, since I can remove some jankness around how it handles coroutines.
2025-02-06 13:09:57 +01:00
Jubilee
1361ef37ff
Rollup merge of #136550 - compiler-errors:rpitit-empty-body, r=oli-obk
Fix `rustc_hidden_type_of_opaques` for RPITITs with no default body

Needed this when debugging something
2025-02-05 19:53:47 -08:00