about summary refs log tree commit diff
path: root/tests/ui/impl-trait
AgeCommit message (Collapse)AuthorLines
2025-01-27Remove all dead files inside tests/ui/León Orell Valerian Liehr-52/+0
2025-01-25Auto merge of #133154 - estebank:issue-133137, r=wesleywiserbors-7/+13
Reword resolve errors caused by likely missing crate in dep tree Reword label and add `help`: ``` error[E0432]: unresolved import `some_novel_crate` --> f704.rs:1:5 | 1 | use some_novel_crate::Type; | ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate` | = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml` ``` Fix #133137.
2025-01-24Reword "crate not found" resolve messageEsteban Küber-7/+13
``` error[E0432]: unresolved import `some_novel_crate` --> file.rs:1:5 | 1 | use some_novel_crate::Type; | ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate` ``` On resolve errors where there might be a missing crate, mention `cargo add foo`: ``` error[E0433]: failed to resolve: use of unresolved module or unlinked crate `nope` --> $DIR/conflicting-impl-with-err.rs:4:11 | LL | impl From<nope::Thing> for Error { | ^^^^ use of unresolved module or unlinked crate `nope` | = help: if you wanted to use a crate named `nope`, use `cargo add nope` to add it to your `Cargo.toml` ```
2025-01-23Rollup merge of #135492 - metamuffin:bug-invalid-await-suggest, ↵Matthias Krüger-9/+0
r=compiler-errors Add missing check for async body when suggesting await on futures. Currently the compiler suggests adding `.await` to resolve some type conflicts without checking if the conflict happens in an async context. This can lead to the compiler suggesting `.await` in function signatures where it is invalid. Example: ```rs trait A { fn a() -> impl Future<Output = ()>; } struct B; impl A for B { fn a() -> impl Future<Output = impl Future<Output = ()>> { async { async { () } } } } ``` ``` error[E0271]: expected `impl Future<Output = impl Future<Output = ()>>` to be a future that resolves to `()`, but it resolves to `impl Future<Output = ()>` --> bug.rs:6:15 | 6 | fn a() -> impl Future<Output = impl Future<Output = ()>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found future | note: calling an async function returns a future --> bug.rs:6:15 | 6 | fn a() -> impl Future<Output = impl Future<Output = ()>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `A::{synthetic#0}` --> bug.rs:2:27 | 2 | fn a() -> impl Future<Output = ()>; | ^^^^^^^^^^^ required by this bound in `A::{synthetic#0}` help: consider `await`ing on the `Future` | 6 | fn a() -> impl Future<Output = impl Future<Output = ()>>.await { | ++++++ ``` The documentation of suggest_await_on_expect_found (`compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs:156`) even mentions such a check but does not actually implement it. This PR adds that check to ensure `.await` is only suggested within async blocks. There were 3 unit tests whose expected output needed to be changed because they had the suggestion outside of async. One of them (`tests/ui/async-await/dont-suggest-missing-await.rs`) actually tests that exact problem but expects it to be present. Thanks to `@llenck` for initially noticing the bug and helping with fixing it
2025-01-22Rollup merge of #135816 - BoxyUwU:root_normalizes_to_goal_ice, r=lcnrMatthias Krüger-5/+38
Use `structurally_normalize` instead of manual `normalizes-to` goals in alias relate errors r? `@lcnr` I added `structurally_normalize_term` so that code that is generic over ty or const can use the structurally normalize helpers. See `tests/ui/traits/next-solver/diagnostics/alias_relate_error_uses_structurally_normalize.rs` for a description of the reason for the (now fixed) ICEs
2025-01-22Refactor dyn-compatibility error and suggestionsTaylor Cramer-72/+92
This CL makes a number of small changes to dyn compatibility errors: - "object safety" has been renamed to "dyn-compatibility" throughout - "Convert to enum" suggestions are no longer generated when there exists a type-generic impl of the trait or an impl for `dyn OtherTrait` - Several error messages are reorganized for user readability Additionally, the dyn compatibility error creation code has been split out into functions. cc #132713 cc #133267
2025-01-22Use `structurally_normalize` instead of manual `normalizes-to` goalsBoxy-5/+38
2025-01-16Add missing check for async body when suggesting await on futures.metamuffin-9/+0
2025-01-15fix known-bug link in normalize-tait-in-constRalf Jung-4/+5
2025-01-13Rollup merge of #135441 - compiler-errors:redundant-captures-lint, r=lqdJacob Pratt-11/+15
Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024 I never got sign-off on #127672 for this lint being warn by default in edition 2024, so let's turn downgrade this lint to allow for now. Should be backported so it ships with the edition. ```@rustbot``` label: +beta-nominated
2025-01-13Make sure to mark IMPL_TRAIT_REDUNDANT_CAPTURES as Allow in edition 2024Michael Goulet-11/+15
2025-01-11Remove a bunch of diagnostic stashing that doesn't do anythingMichael Goulet-47/+60
2025-01-08Implement const Destruct in old solverMichael Goulet-17/+2
2025-01-06point out unblamed constraints from `Copy`/`Sized` bounds in region errorsdianne-0/+3
2025-01-06`best_blame_constraint`: don't filter constraints by sup SCCdianne-10/+10
The SCCs of the region graph are not a reliable heuristic to use for blaming an interesting constraint for diagnostics. For region errors, if the outlived region is `'static`, or the involved types are invariant in their lifetiems, there will be cycles in the constraint graph containing both the target region and the most interesting constraints to blame. To get better diagnostics in these cases, this commit removes that heuristic.
2025-01-04Rollup merge of #135055 - compiler-errors:rpitit-infer-in-stricter-impl, ↵Matthias Krüger-38/+61
r=estebank Report impl method has stricter requirements even when RPITIT inference gets in the way See the comment I added in the code. Fixes #122506.
2025-01-03Do not project when there are unconstrained impl paramsMichael Goulet-27/+4
2025-01-03Report impl has stricter requirements even when RPITIT inference gets in the wayMichael Goulet-38/+61
2025-01-01Fix ICE when opaque captures a duplicated/invalid lifetimeMichael Goulet-0/+30
2024-12-27Rollup merge of #134798 - compiler-errors:err-auto, r=jackh726Matthias Krüger-0/+36
Make `ty::Error` implement all auto traits I have no idea what's up with the crashes test I fixed--I really don't want to look into it since it has to do something with borrowck and multiple layers of opaques. I think the underlying idea of allowing error types to implement all auto traits is justified though. Fixes #134796 Fixes #131050 r? lcnr
2024-12-27Remove the `-test` suffix from normalize directivesZalathar-1/+1
2024-12-26Make ty::Error implement auto traitsMichael Goulet-0/+36
2024-12-16Regression test for RPIT inheriting lifetimeRyan Mehri-0/+24
2024-12-14Don't make a def id for impl_trait_in_bindingsMichael Goulet-0/+10
2024-12-14Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obkbors-0/+179
(Re-)Implement `impl_trait_in_bindings` This reimplements the `impl_trait_in_bindings` feature for local bindings. "`impl Trait` in bindings" serve as a form of *trait* ascription, where the type basically functions as an infer var but additionally registering the `impl Trait`'s trait bounds for the infer type. These trait bounds can be used to enforce that predicates hold, and can guide inference (e.g. for closure signature inference): ```rust let _: impl Fn(&u8) -> &u8 = |x| x; ``` They are implemented as an additional set of bounds that are registered when the type is lowered during typeck, and then these bounds are tied to a given `CanonicalUserTypeAscription` for borrowck. We enforce these `CanonicalUserTypeAscription` bounds during borrowck to make sure that the `impl Trait` types are sensitive to lifetimes: ```rust trait Static: 'static {} impl<T> Static for T where T: 'static {} let local = 1; let x: impl Static = &local; //~^ ERROR `local` does not live long enough ``` r? oli-obk cc #63065 --- Why can't we just use TAIT inference or something? Well, TAITs in bodies have the problem that they cannot reference lifetimes local to a body. For example: ```rust type TAIT = impl Display; let local = 0; let x: TAIT = &local; //~^ ERROR `local` does not live long enough ``` That's because TAITs requires us to do *opaque type inference* which is pretty strict, since we need to remap all of the lifetimes of the hidden type to universal regions. This is simply not possible here. --- I consider this part of the "impl trait everywhere" experiment. I'm not certain if this needs yet another lang team experiment.
2024-12-14(Re-)Implement impl_trait_in_bindingsMichael Goulet-0/+179
2024-12-14Rollup merge of #134181 - estebank:trim-render, r=oli-obkMatthias Krüger-9/+0
Tweak multispan rendering to reduce output length Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments. We do that check not only on the first 4 lines of the multispan, but now also on the previous to last line as well.
2024-12-12Tweak multispan renderingEsteban Küber-9/+0
Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments.
2024-12-12Rollup merge of #133122 - compiler-errors:afidt, r=oli-obkMatthias Krüger-0/+13
Add unpolished, experimental support for AFIDT (async fn in dyn trait) This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`. To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`. This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error). [^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do. This could also be generalized: * To work on functions that are `-> impl Future` (soon). * To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon). Tracking: * https://github.com/rust-lang/rust/issues/133119
2024-12-11Rollup merge of #134142 - compiler-errors:paren-sug, r=jieyouxuJacob Pratt-1/+28
Rudimentary heuristic to insert parentheses when needed for RPIT overcaptures lint We don't have basically any preexisting machinery to detect when parentheses are needed for *types*. AFAICT, all of the diagnostics we have for opaques just... fail when they suggest `+ 'a` when that's ambiguous. Fixes #132853
2024-12-10Rudimentary heuristic to insert parentheses when needed for RPIT ↵Michael Goulet-1/+28
overcaptures lint
2024-12-10Don't check RPITITs that are Self:Sized for PointerLikeMichael Goulet-0/+13
2024-12-10Tweak wording of non-const traits used as const boundsEsteban Küber-2/+7
Use verbose suggestions and add additional labels/notes. Add more test cases for stable/nightly and feature enabled/disabled.
2024-12-07Mention type parameter in more cases and don't suggest ~const bound already ↵Esteban Küber-11/+7
there
2024-12-07Use trait name instead of full constraint in suggestion messageEsteban Küber-7/+7
``` help: consider restricting type parameter `T` with traits `Copy` and `Trait` | LL | fn duplicate_custom<T: Copy + Trait>(t: S<T>) -> (S<T>, S<T>) { | ++++++++++++++ ``` ``` help: consider restricting type parameter `V` with trait `Copy` | LL | fn index<'a, K, V: std::marker::Copy>(map: &'a HashMap<K, V>, k: K) -> &'a V { | +++++++++++++++++++ ```
2024-12-07reword trait bound suggestion message to include the boundsEsteban Küber-8/+8
2024-12-06Auto merge of #133559 - ↵bors-34/+8
compiler-errors:structurally-resolve-adjust-for-branch, r=lcnr Structurally resolve in `adjust_for_branches` r? lcnr
2024-12-05Resolve moreMichael Goulet-34/+8
2024-12-04Avoid `opaque type not constrained` errors in the presence of other errorsOli Scherer-40/+14
2024-12-03Rollup merge of #132612 - compiler-errors:async-trait-bounds, r=lcnrMatthias Krüger-4/+4
Gate async fn trait bound modifier on `async_trait_bounds` This PR moves `async Fn()` trait bounds into a new feature gate: `feature(async_trait_bounds)`. The general vibe is that we will most likely stabilize the `feature(async_closure)` *without* the `async Fn()` trait bound modifier, so we need to gate that separately. We're trying to work on the general vision of `async` trait bound modifier general in: https://github.com/rust-lang/rfcs/pull/3710, however that RFC still needs more time for consensus to converge, and we've decided that the value that users get from calling the bound `async Fn()` is *not really* worth blocking landing async closures in general.
2024-12-02Assert that obligations are empty before deeply normalizingMichael Goulet-2/+2
2024-12-02Gate async fn trait bound modifier on async_trait_boundsMichael Goulet-4/+4
2024-12-01Adjust HostEffect error spans correctly to point at argsMichael Goulet-2/+10
2024-11-30Move refinement check out of compare_impl_itemMichael Goulet-0/+26
2024-11-29Rollup merge of #133584 - ehuss:more-2024-unstable-options, r=compiler-errorsMatthias Krüger-13/+12
Update more 2024 tests to remove -Zunstable-options This removes `-Zunsable-options` from more tests that I missed in https://github.com/rust-lang/rust/pull/133349.
2024-11-29Rollup merge of #133590 - nnethercote:rename-parse-only, r=estebankMatthias Krüger-1/+1
Rename `-Zparse-only` It's a misleading name. r? ````@estebank````
2024-11-28Update more 2024 tests to remove -Zunstable-optionsEric Huss-13/+12
2024-11-29Rename `-Zparse-only`.Nicholas Nethercote-1/+1
I was surprised to find that running with `-Zparse-only` only parses the crate root file. Other files aren't parsed because that happens later during expansion. This commit renames the option and updates the help message to make this clearer.
2024-11-28Auto merge of #133540 - ehuss:compiletest-proc-macro, r=jieyouxubors-6/+1
Compiletest: add proc-macro header This adds a `proc-macro` header to simplify using proc-macros, and to reduce boilerplate. This header works similar to the `aux-build` header where you pass a path for a proc-macro to be built. This allows the `force-host`, `no-prefer-dynamic` headers, and `crate_type` attribute to be removed. Additionally it uses `--extern` like `aux_crate` (allows implicit `extern crate` in 2018) and `--extern proc_macro` (to place in the prelude in 2018). ~~This also includes a secondary change which defaults the edition of proc-macros to 2024. This further reduces boilerplate (removing `extern crate proc_macro;`), and allows using modern Rust syntax. I was a little on the fence including this. I personally prefer it, but I can imagine it might be confusing to others.~~ EDIT: Removed Some tests were changed so that when there is a chain of dependencies A→B→C, that the `@ proc-macro` is placed in `B` instead of `A` so that the `--extern` flag works correctly (previously it depended on `-L` to find `C`). I think this is better to make the dependencies more explicit. None of these tests looked like the were actually testing this behavior. There is one test that had an unexplained output change: `tests/ui/macros/same-sequence-span.rs`. I do not know why it changed, but it didn't look like it was particularly important. Perhaps there was a normalization issue? This is currently not compatible with the rustdoc `build-aux-docs` header. It can probably be fixed, I'm just not feeling motivated to do that right now. ### Implementation steps - [x] Document this new behavior in rustc-dev-guide once we figure out the specifics. https://github.com/rust-lang/rustc-dev-guide/pull/2149
2024-11-28Auto merge of #133561 - GuillaumeGomez:rollup-g4upmv4, r=GuillaumeGomezbors-17/+71
Rollup of 12 pull requests Successful merges: - #129409 (Expand std::os::unix::fs::chown() doc with a warning) - #133320 (Add release notes for Rust 1.83.0) - #133368 (Delay a bug when encountering an impl with unconstrained generics in `codegen_select`) - #133428 (Actually use placeholder regions for trait method late bound regions in `collect_return_position_impl_trait_in_trait_tys`) - #133512 (Add `as_array` and `as_mut_array` conversion methods to slices.) - #133519 (Check `xform_ret_ty` for WF in the new solver to improve method winnowing) - #133520 (Structurally resolve before applying projection in borrowck) - #133534 (extend group-forbid-always-trumps-cli test) - #133537 ([rustdoc] Fix new clippy lints) - #133543 ([AIX] create shim for lgammaf_r) - #133547 (rustc_span: Replace a `HashMap<_, ()>` with `HashSet`) - #133550 (print generated doc paths) r? `@ghost` `@rustbot` modify labels: rollup