about summary refs log tree commit diff
path: root/tests/ui/impl-trait
AgeCommit message (Collapse)AuthorLines
2024-02-27wf-check RPITslcnr-0/+41
2024-02-26update testslcnr-9/+10
2024-02-24Rollup merge of #121435 - estebank:rpitit-static-119773, r=compiler-errorsMatthias Krüger-2/+28
Account for RPITIT in E0310 explicit lifetime constraint suggestion When given ```rust trait Original { fn f() -> impl Fn(); } trait Erased { fn f(&self) -> Box<dyn Fn()>; } impl<T: Original> Erased for T { fn f(&self) -> Box<dyn Fn()> { Box::new(<T as Original>::f()) } } ``` emit do not emit an invalid suggestion restricting the `Trait::{opaque}` type in a `where` clause: ``` error[E0310]: the associated type `<T as Original>::{opaque#0}` may not live long enough --> $DIR/missing-static-bound-from-impl.rs:11:9 | LL | Box::new(<T as Original>::f()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | the associated type `<T as Original>::{opaque#0}` must be valid for the static lifetime... | ...so that the type `impl Fn()` will meet its required lifetime bounds ``` Partially address #119773. Ideally we'd suggest modifying `Erased::f` instead. r? `@compiler-errors`
2024-02-23Rollup merge of #121480 - nnethercote:fix-more-121208-fallout, r=lcnrMatthias Krüger-0/+48
Fix more #121208 fallout #121208 converted lots of delayed bugs to bugs. Unsurprisingly, there were a few invalid conversion found via fuzzing. r? `@lcnr`
2024-02-23Auto merge of #120730 - estebank:confusable-api, r=oli-obkbors-12/+38
Provide suggestions through `rustc_confusables` annotations Help with common API confusion, like asking for `push` when the data structure really has `append`. ``` error[E0599]: no method named `size` found for struct `Vec<{integer}>` in the current scope --> $DIR/rustc_confusables_std_cases.rs:17:7 | LL | x.size(); | ^^^^ | help: you might have meant to use `len` | LL | x.len(); | ~~~ help: there is a method with a similar name | LL | x.resize(); | ~~~~~~ ``` Fix #59450 (we can open subsequent tickets for specific cases). Fix #108437: ``` error[E0599]: `Option<{integer}>` is not an iterator --> f101.rs:3:9 | 3 | opt.flat_map(|val| Some(val)); | ^^^^^^^^ `Option<{integer}>` is not an iterator | ::: /home/gh-estebank/rust/library/core/src/option.rs:571:1 | 571 | pub enum Option<T> { | ------------------ doesn't satisfy `Option<{integer}>: Iterator` | = note: the following trait bounds were not satisfied: `Option<{integer}>: Iterator` which is required by `&mut Option<{integer}>: Iterator` help: you might have meant to use `and_then` | 3 | opt.and_then(|val| Some(val)); | ~~~~~~~~ ``` On type error of method call arguments, look at confusables for suggestion. Fix #87212: ``` error[E0308]: mismatched types --> f101.rs:8:18 | 8 | stuff.append(Thing); | ------ ^^^^^ expected `&mut Vec<Thing>`, found `Thing` | | | arguments to this method are incorrect | = note: expected mutable reference `&mut Vec<Thing>` found struct `Thing` note: method defined here --> /home/gh-estebank/rust/library/alloc/src/vec/mod.rs:2025:12 | 2025 | pub fn append(&mut self, other: &mut Self) { | ^^^^^^ help: you might have meant to use `push` | 8 | stuff.push(Thing); | ~~~~ ```
2024-02-23Revert some `span_bug`s to `span_delayed_bug`.Nicholas Nethercote-0/+48
Fixes #121445. Fixes #121457.
2024-02-22Account for RPITIT in E0310 explicit lifetime constraint suggestionEsteban Küber-2/+28
When given ```rust trait Original { fn f() -> impl Fn(); } trait Erased { fn f(&self) -> Box<dyn Fn()>; } impl<T: Original> Erased for T { fn f(&self) -> Box<dyn Fn()> { Box::new(<T as Original>::f()) } } ``` avoid suggestion to restrict the `Trait::{opaque}` type in a `where` clause: ``` error[E0310]: the associated type `<T as Original>::{opaque#0}` may not live long enough --> $DIR/missing-static-bound-from-impl.rs:11:9 | LL | Box::new(<T as Original>::f()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | the associated type `<T as Original>::{opaque#0}` must be valid for the static lifetime... | ...so that the type `impl Fn()` will meet its required lifetime bounds ``` CC #119773.
2024-02-22Fix rebaseEsteban Küber-0/+2
2024-02-22Deduplicate some logic and reword outputEsteban Küber-6/+6
2024-02-22Tweak wording of "implemented trait isn't imported" suggestionEsteban Küber-6/+6
2024-02-22Consider methods from traits when suggesting typosEsteban Küber-6/+30
Do not provide a structured suggestion when the arguments don't match. ``` error[E0599]: no method named `test_mut` found for struct `Vec<{integer}>` in the current scope --> $DIR/auto-ref-slice-plus-ref.rs:7:7 | LL | a.test_mut(); | ^^^^^^^^ | = help: items from traits can only be used if the trait is implemented and in scope note: `MyIter` defines an item `test_mut`, perhaps you need to implement it --> $DIR/auto-ref-slice-plus-ref.rs:14:1 | LL | trait MyIter { | ^^^^^^^^^^^^ help: there is a method `get_mut` with a similar name, but with different arguments --> $SRC_DIR/core/src/slice/mod.rs:LL:COL ``` Consider methods beyond inherent ones when suggesting typos. ``` error[E0599]: no method named `owned` found for reference `&dyn Foo` in the current scope --> $DIR/object-pointer-types.rs:11:7 | LL | fn owned(self: Box<Self>); | --------- the method might not be found because of this arbitrary self type ... LL | x.owned(); | ^^^^^ help: there is a method with a similar name: `to_owned` ``` Fix #101013.
2024-02-22change error messages to be incorrect, but more helpfullcnr-2/+2
2024-02-22do not use <: in subtyping overflow msglcnr-2/+2
2024-02-22overflow errors: change source to a concrete enumlcnr-18/+9
2024-02-22freshen: resolve root varslcnr-7/+32
Without doing so we use the same candidate cache entry for `?0: Trait<?1>` and `?0: Trait<?0>`. These goals are different and we must not use the same entry for them.
2024-02-22remove `sub_relations` from infcx, recompute in diagnosticslcnr-10/+5
we don't track them when canonicalizing or when freshening, resulting in instable caching in the old solver, and issues when instantiating query responses in the new one.
2024-02-22Overhaul the handling of errors at the top-level.Nicholas Nethercote-2/+0
Currently `emit_stashed_diagnostic` is called from four(!) different places: `print_error_count`, `DiagCtxtInner::drop`, `abort_if_errors`, and `compile_status`. And `flush_delayed` is called from two different places: `DiagCtxtInner::drop` and `Queries`. This is pretty gross! Each one should really be called from a single place, but there's a bunch of entanglements. This commit cleans up this mess. Specifically, it: - Removes all the existing calls to `emit_stashed_diagnostic`, and adds a single new call in `finish_diagnostics`. - Removes the early `flush_delayed` call in `codegen_and_build_linker`, replacing it with a simple early return if delayed bugs are present. - Changes `DiagCtxtInner::drop` and `DiagCtxtInner::flush_delayed` so they both assert that the stashed diagnostics are empty (i.e. processed beforehand). - Changes `interface::run_compiler` so that any errors emitted during `finish_diagnostics` (i.e. late-emitted stashed diagnostics) are counted and cannot be overlooked. This requires adding `ErrorGuaranteed` return values to several functions. - Removes the `stashed_err_count` call in `analysis`. This is possible now that we don't have to worry about calling `flush_delayed` early from `codegen_and_build_linker` when stashed diagnostics are pending. - Changes the `span_bug` case in `handle_tuple_field_pattern_match` to a `delayed_span_bug`, because it now can be reached due to the removal of the `stashed_err_count` call in `analysis`. - Slightly changes the expected output of three tests. If no errors are emitted but there are delayed bugs, the error count is no longer printed. This is because delayed bugs are now always printed after the error count is printed (or not printed, if the error count is zero). There is a lot going on in this commit. It's hard to break into smaller pieces because the existing code is very tangled. It took me a long time and a lot of effort to understand how the different pieces interact, and I think the new code is a lot simpler and easier to understand.
2024-02-20Rollup merge of #121319 - compiler-errors:err, r=oli-obkNilstrieb-47/+40
return `ty::Error` when equating `ty::Error` This helps iron out a difference in diagnostics between `Sub` and `Equate` relations, which I'm currently trying to unify. r? oli-obk
2024-02-19return ty::Error when equating ty::ErrorMichael Goulet-47/+40
This helps iron out a difference between Sub and Equate
2024-02-19Auto merge of #121211 - lcnr:nll-relate-handle-infer, r=BoxyUwUbors-14/+1
deduplicate infer var instantiation Having 3 separate implementations of one of the most subtle parts of our type system is not a good strategy if we want to maintain a sound type system :sparkles: while working on this I already found some subtle bugs in the existing code, so that's awesome :tada: cc #121159 This was necessary as I am not confident in my nll changes in #119106, so I am first cleaning this up in a separate PR. r? `@BoxyUwU`
2024-02-17use `instantiate_ty_var` in nlllcnr-14/+1
we already use `instantiate_const_var`. This does lose some debugging info for nll because we stop populating the `reg_var_to_origin` table with `RegionCtxt::Existential(None)`, I don't think that matters however. Supporting this adds additional complexity to one of the most involved parts of the type system, so I really don't think it's worth it.
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-264/+264
2024-02-14Continue compilation even if inherent impl checks failOli Scherer-41/+110
2024-02-14Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errorsbors-5/+79
Continue compilation after check_mod_type_wf errors The ICEs fixed here were probably reachable through const eval gymnastics before, but now they are easily reachable without that, too. The new errors are often bugfixes, where useful errors were missing, because they were reported after the early abort. In other cases sometimes they are just duplication of already emitted errors, which won't be user-visible due to deduplication. fixes https://github.com/rust-lang/rust/issues/120860
2024-02-14Continue compilation after check_mod_type_wf errorsOli Scherer-5/+79
2024-02-14Rollup merge of #120530 - trevyn:issue-116434, r=compiler-errorsOli Scherer-1/+1
Be less confident when `dyn` suggestion is not checked for object safety #120275 no longer checks bare traits for object safety when making a `dyn` suggestion on Rust < 2021. In this case, qualify the suggestion with a note that the trait must be object safe, to prevent user confusion as seen in #116434 r? ```@fmease```
2024-02-13Rollup merge of #120549 - lcnr:errs-showcase, r=compiler-errorsMatthias Krüger-4/+29
modify alias-relate to also normalize ambiguous opaques allows a bunch of further cleanups and generally simplifies the type system. To handle https://github.com/rust-lang/trait-system-refactor-initiative/issues/8 we'll have to add a some additional complexity to the `(Alias, Infer)` branches in alias-relate, so removing the opaque type special case here is really valuable. It does worsen `deduce_closure_signature` and friends even more as they now receive an inference variable which is only constrained via an `AliasRelate` goal. These probably have to look into alias relate goals somehow. Leaving that for a future PR as this is something we'll have to tackle regardless. r? `@compiler-errors`
2024-02-13Rollup merge of #120696 - estebank:issue-115405, r=oli-obkMatthias Krüger-0/+2
Properly handle `async` block and `async fn` in `if` exprs without `else` When encountering a tail expression in the then arm of an `if` expression without an `else` arm, account for `async fn` and `async` blocks to suggest `return`ing the value and pointing at the return type of the `async fn`. We now also account for AFIT when looking for the return type to point at. Fix #115405.
2024-02-13use alias-relate to structurally normalize in the solverlcnr-4/+29
2024-02-12Properly handle `async` blocks and `fn`s in `if` exprs without `else`Esteban Küber-0/+2
When encountering a tail expression in the then arm of an `if` expression without an `else` arm, account for `async fn` and `async` blocks to suggest `return`ing the value and pointing at the return type of the `async fn`. We now also account for AFIT when looking for the return type to point at. Fix #115405.
2024-02-10Gracefully handle non-WF alias in assemble_alias_bound_candidates_recurMichael Goulet-0/+36
2024-02-09Be less confident when `dyn` suggestion is not checked for object safetytrevyn-1/+1
2024-02-09Rollup merge of #113671 - oli-obk:normalize_weak_tys, r=petrochenkovMatthias Krüger-33/+1
Make privacy visitor use types more (instead of HIR) r? ``@petrochenkov`` This is a prerequisite to normalizing projections, as otherwise we have too many invalid bound vars (hir_ty_to_ty is creating types that have bound vars, but no binder). The commits are still chaotic, I'm gonna clean them up, but I just wanted to let you know about the general direction and wondering if we could land this before adding normalization, as normalization is where behavioral changes happen, and I'd like to keep that part as minimal as possible. [context can be found on zulip](https://rust-lang.zulipchat.com/#narrow/stream/315482-t-compiler.2Fetc.2Fopaque-types/topic/weak.20type.20aliases.20and.20privacy)
2024-02-08Continue to borrowck even if there were previous errorsOli Scherer-7/+91
2024-02-07Stop using `hir_ty_to_ty` in rustc_privacyOli Scherer-33/+1
2024-02-07Update testsr0cky-3/+25
2024-02-06Rollup merge of #120520 - nnethercote:rename-good-path, r=oli-obkMatthias Krüger-1/+1
Some cleanups around diagnostic levels. Plus some refactoring in and around diagnostic levels and emission. Details in the individual commit logs. r? ````@oli-obk````
2024-02-05Split `Level::DelayedBug` in two.Nicholas Nethercote-1/+1
The two kinds of delayed bug have quite different semantics so a stronger conceptual separation is nice. (`is_error` is a good example, because the two kinds have different behaviour.) The commit also moves the `DelayedBug` variant after `Error` in `Level`, to reflect the fact that it's weaker than `Error` -- it might trigger an error but also might not. (The pre-existing `downgrade_to_delayed_bug` function also reflects the notion that delayed bugs are lower/after normal errors.) Plus it condenses some of the comments on `Level` into a table, for easier reading, and introduces `can_be_top_or_sub` to indicate which levels can be used in top-level diagnostics vs. subdiagnostics. Finally, it renames `DiagCtxtInner::span_delayed_bugs` as `DiagCtxtInner::delayed_bugs`. The `span_` prefix is unnecessary because some delayed bugs don't have a span.
2024-02-01review comment: change wordingEsteban Küber-1/+1
2024-02-01On E0277 be clearer about implicit `Sized` bounds on type params and assoc typesEsteban Küber-4/+4
``` error[E0277]: the size for values of type `[i32]` cannot be known at compilation time --> f100.rs:2:33 | 2 | let _ = std::mem::size_of::<[i32]>(); | ^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[i32]` note: required by an implicit `Sized` bound in `std::mem::size_of` --> /home/gh-estebank/rust/library/core/src/mem/mod.rs:312:22 | 312 | pub const fn size_of<T>() -> usize { | ^ required by the implicit `Sized` requirement on this bound in `size_of` ``` Fix #120178.
2024-01-30Provide more context on derived obligation error primary labelEsteban Küber-10/+10
Expand the primary span of E0277 when the immediate unmet bound is not what the user wrote: ``` error[E0277]: the trait bound `i32: Bar` is not satisfied --> f100.rs:6:6 | 6 | <i32 as Foo>::foo(); | ^^^ the trait `Bar` is not implemented for `i32`, which is required by `i32: Foo` | help: this trait has no implementations, consider adding one --> f100.rs:2:1 | 2 | trait Bar {} | ^^^^^^^^^ note: required for `i32` to implement `Foo` --> f100.rs:3:14 | 3 | impl<T: Bar> Foo for T {} | --- ^^^ ^ | | | unsatisfied trait bound introduced here ``` Fix #40120.
2024-01-30Rollup merge of #120293 - estebank:issue-102629, r=nnethercoteGuillaume Gomez-22/+4
Deduplicate more sized errors on call exprs Change the implicit `Sized` `Obligation` `Span` for call expressions to include the whole expression. This aids the existing deduplication machinery to reduce the number of errors caused by a single unsized expression.
2024-01-24Account for expected `dyn Trait` found `impl Trait`Esteban Küber-0/+61
2024-01-24On E0308 involving `dyn Trait`, mention trait objectsEsteban Küber-0/+2
When encountering a type mismatch error involving `dyn Trait`, mention the existence of boxed trait objects if the other type involved implements `Trait`. Partially addresses #102629.
2024-01-24Deduplicate more sized errors on call exprsEsteban Küber-22/+4
Change the implicit `Sized` `Obligation` `Span` for call expressions to include the whole expression. This aids the existing deduplication machinery to reduce the number of errors caused by a single unsized expression.
2024-01-22Add some testsOli Scherer-0/+39
2024-01-20Auto merge of #119821 - oli-obk:reveal_all_const_evals, r=lcnrbors-0/+172
Always use RevealAll for const eval queries implements what is described in https://github.com/rust-lang/rust/pull/116803#discussion_r1364089471 Using `UserFacing` for const eval does not make sense anymore, unless we significantly change things like avoiding revealing opaque types. New tests are copied from https://github.com/rust-lang/rust/pull/101478
2024-01-19Always use RevealAll for const eval queriesOli Scherer-0/+172
2024-01-18Rollup merge of #119869 - oli-obk:track_errors2, r=matthewjasperMatthias Krüger-2/+26
replace `track_errors` usages with bubbling up `ErrorGuaranteed` more of the same as https://github.com/rust-lang/rust/pull/117449 (removing `track_errors`)
2024-01-17Use FnOnceOutput instead of FnOnce where expectedOli Scherer-0/+99