about summary refs log tree commit diff
path: root/src/test/ui/impl-trait
AgeCommit message (Collapse)AuthorLines
2022-09-12A SubstitutionPart is not a deletion if it replaces nothing with nothingMichael Goulet-3/+2
2022-09-12Rollup merge of #101681 - compiler-errors:rpitit-obj-safety, r=lcnrDylan DPC-0/+72
Deny return-position `impl Trait` in traits for object safety Fixes #101667
2022-09-12Rollup merge of #101676 - compiler-errors:rpitit-wf, r=lcnrDylan DPC-0/+49
Check that the types in return position `impl Trait` in traits are well-formed This effectively duplicates `check_associated_type_bounds`, but that shouldn't be for long, since we're going to remove it once we refactor RPITITs into regular associated items. Fixes #101663 --- We don't check ```rust trait Foo { fn bar() -> impl ?Sized; } ``` currently, but that's for a different reason, which is that we don't currently check that a trait function's return type is sized (i.e. `fn bar() -> [u8]` also works in a trait).
2022-09-11Only encode RPITIT when trait method has default bodyMichael Goulet-0/+9
2022-09-11Deny RPITIT for object safetyMichael Goulet-0/+72
2022-09-11Check that the types in RPITITs are WFMichael Goulet-0/+49
2022-09-10split compare_predicate_entailment and collect_trait_impl_trait_tys outMichael Goulet-10/+5
2022-09-09Tweak feature error, add testMichael Goulet-0/+24
2022-09-09Handle generic parameters.Camille GILLOT-4/+32
2022-09-09Deeply check that method signatures match, and allow for nested RPITITsMichael Goulet-0/+83
2022-09-09Add testsMichael Goulet-0/+126
2022-09-06fix RPIT ICE for implicit HRTB when missing dynSantiago Pastorino-0/+43
2022-08-31Rollup merge of #101185 - compiler-errors:tweak-wf-locs, r=davidtwcoMatthias Krüger-2/+2
Tweak `WellFormedLoc`s a bit Gives a bit tighter spans in returns and generic ty defaults
2022-08-31Rollup merge of #101100 - compiler-errors:generalize-call-suggestions, ↵Matthias Krüger-1/+1
r=petrochenkov Make call suggestions more general and more accurate Cleans up some suggestions that have to do with adding `()` to make typeck happy. 1. Drive-by rename of `expr_t` to `base_ty` since it's the type of the `base_expr` 1. Autoderef until we get to a callable type in `suggest_fn_call`. 1. Don't erroneously suggest calling constructor when a method/field does not exist on it. 1. Suggest calling a method receiver if its function output has a method (e.g. `fn.method()` => `fn().method()`) 1. Extend call suggestions to type parameters, fn pointers, trait objects where possible 1. Suggest calling in operators too (fixes #101054) 1. Use `/* {ty} */` as argument placeholder instead of just `_`, which is confusing and makes suggestions look less like `if let` syntax.
2022-08-30Rollup merge of #99928 - compiler-errors:issue-99914, r=oli-obkDylan DPC-0/+34
Do not leak type variables from opaque type relation The "root cause" is that we call `InferCtxt::resolve_vars_if_possible` (3d9dd681f520d1d59f38aed0056cf9474894cc74) on the types we get back in `TypeError::Sorts` since I added a call to it in `InferCtxt::same_type_modulo_infer`. However if this `TypeError` comes from a `InferCtxt::commit_if_ok`, then it may reference type variables that do not exist anymore, which is problematic. We avoid this by substituting the `TypeError` with the types we had before being generalized while handling opaques. This is kinda gross, and I feel like we can get the same issue from other places where we generalize type/const inference variables. Maybe not? I don't know. Fixes #99914 Fixes #99970 Fixes #100463
2022-08-30Tweak WellFormedLocs a bitMichael Goulet-2/+2
2022-08-30Rollup merge of #100092 - compiler-errors:issue-100075, r=oli-obkDylan DPC-0/+65
Fall back when relating two opaques by substs in MIR typeck This is certainly _one_ way to fix #100075. Not really confident it's the _best_ way to do it, though. The root cause of this issue is that during MIR type-check, we end up trying to equate an opaque against the same opaque def-id but with different substs. Because of the way that we replace RPITs during (HIR) typeck with an inference variable, we don't end up emitting a type-checking error, so the delayed MIR bug causes an ICE. See the `src/test/ui/impl-trait/issue-100075-2.rs` test below to make that clear -- in that example, we try to equate `{impl Sized} substs=[T]` and `{impl Sized} substs=[Option<T>]`, which causes an ICE. This new logic will instead cause us to infer `{impl Sized} substs=[Option<T>]` as the hidden type for `{impl Sized} substs=[T]`, which causes a proper error to be emitted later on when we check that an opaque isn't recursive. I'm open to closing this in favor of something else. Ideally we'd fix this in typeck, but the thing we do to ensure backwards compatibility with weird RPIT cases makes that difficult. Also open to discussing this further.
2022-08-27Suggest calling trait objects and parameters too, when possibleMichael Goulet-1/+1
2022-08-24add a missing test case for impl generic mismatchTakayuki Maeda-2/+25
2022-08-18Reword "Required because of the requirements on the impl of ..."Andy Wang-5/+5
2022-08-18Auto merge of #99860 - oli-obk:revert_97346, r=pnkfelixbors-57/+47
Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, … …r=oli-obk" This reverts commit c703d11dccb4a895c7aead3b2fcd8cea8c483184, reversing changes made to 64eb9ab869bc3f9ef3645302fbf22e706eea16cf. it didn't apply cleanly, so now it works the same for RPIT and for TAIT instead of just working for RPIT, but we should keep those in sync anyway. It also exposed a TAIT bug (see the feature gated test that now ICEs). r? `@pnkfelix` fixes #99536
2022-08-10Fall back when relating two opaques by substs in MIR typeckMichael Goulet-0/+65
2022-08-09Add regression test for issue 100187Santiago Pastorino-0/+12
2022-08-08Auto merge of #98863 - compiler-errors:projection-msg, r=estebankbors-2/+2
Implement special-cased projection error message for some common traits Not sure what the best phrasing is, but I feel like these are more clear than the plain `<Type as Iterator>::Output == Type` messages. If this is actually a good idea, are there any other traits this could benefit?
2022-08-08Adjust wordingMichael Goulet-2/+2
2022-08-07Implement special-cased projection error message for some common traitsMichael Goulet-2/+2
2022-08-07revive suggestions for boxed trait objects instead of impl TraitTakayuki Maeda-0/+29
2022-08-07Rollup merge of #100130 - compiler-errors:erroneous-return-span, r=lcnrMatthias Krüger-9/+69
Avoid pointing out `return` span if it has nothing to do with type error This code: ```rust fn f(_: String) {} fn main() { let x = || { if true { return (); } f(""); }; } ``` Emits this: ``` Compiling playground v0.0.1 (/playground) error[E0308]: mismatched types --> src/main.rs:8:11 | 8 | f(""); | ^^- help: try using a conversion method: `.to_string()` | | | expected struct `String`, found `&str` | note: return type inferred to be `String` here --> src/main.rs:6:20 | 6 | return (); | ^^ ``` Specifically, that note has nothing to do with the type error in question. This is because the change implemented in #84244 tries to point out the `return` span on _any_ type coercion error within a closure that happens after a `return` statement, regardless of if the error has anything to do with it. This is really easy to trigger -- just needs a closure (or an `async`) and an early return (or any other form, e.g. `?` operator suffices) -- and super distracting in production codebases. I'm letting #84128 regress because that issue is much harder to fix correctly, and I can re-open that issue after this lands. As a drive-by, I added a `resolve_vars_if_possible` to the coercion error logic, which leads to some error improvements. Unrelated to the issue above, though.
2022-08-05Auto merge of #95977 - FabianWolff:issue-92790-dead-tuple, r=estebankbors-1/+1
Warn about dead tuple struct fields Continuation of #92972. Fixes #92790. The language team has already commented on this in https://github.com/rust-lang/rust/pull/92972#issuecomment-1021511970; I have incorporated their requests here. Specifically, there is now a new allow-by-default `unused_tuple_struct_fields` lint (name bikesheddable), and fields of unit type are ignored (https://github.com/rust-lang/rust/pull/92972#issuecomment-1021815408), so error messages look like this: ``` error: field is never read: `1` --> $DIR/tuple-struct-field.rs:6:21 | LL | struct Wrapper(i32, [u8; LEN], String); | ^^^^^^^^^ | help: change the field to unit type to suppress this warning while preserving the field numbering | LL | struct Wrapper(i32, (), String); | ~~ ``` r? `@joshtriplett`
2022-08-04Completely remove captures flagSantiago Pastorino-0/+7
2022-08-04Resolve vars before emitting coerce errorMichael Goulet-9/+69
2022-08-03Warn about dead tuple struct fieldsFabian Wolff-1/+1
2022-07-30Do not leak type variables from opaque type relationMichael Goulet-0/+34
2022-07-28Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, r=oli-obk"Oli Scherer-57/+47
This reverts commit c703d11dccb4a895c7aead3b2fcd8cea8c483184, reversing changes made to 64eb9ab869bc3f9ef3645302fbf22e706eea16cf.
2022-07-28Rollup merge of #99714 - ouz-a:issue_57961, r=oli-obkDylan DPC-0/+15
Fix regression introduced with #99383 Fixes #99642
2022-07-27add tests and commentouz-a-0/+15
2022-07-27Rollup merge of #99079 - compiler-errors:issue-99073, r=oli-obkYuki Okushi-21/+20
Check that RPITs constrained by a recursive call in a closure are compatible Fixes #99073 Adapts a similar visitor pattern to `find_opaque_ty_constraints` (that we use to check TAITs), but with some changes: 0. Only walk the "OnlyBody" children, instead of all items in the RPIT's defining scope 1. Only walk through the body's children if we found a constraining usage 2. Don't actually do any inference, just do a comparison and error if they're mismatched ---- r? `@oli-obk` -- you know all this impl-trait stuff best... is this the right approach? I can explain the underlying issue better if you'd like, in case that might reveal a better solution. Not sure if it's possible to gather up the closure's defining usages of the RPIT while borrowck'ing the outer function, that might be a better place to put this check...
2022-07-26Rollup merge of #99748 - compiler-errors:better-impl-trait-printing, r=fee1-deadDylan DPC-17/+17
Use full type name instead of just saying `impl Trait` in "captures lifetime" error I think this is very useful, especially when there's >1 `impl Trait`, and it just means passing around a bit more info that we already have access to.
2022-07-26Check that RPITs constrained by a recursive call in a closure are compatibleMichael Goulet-21/+20
2022-07-26Use real opaque type instead of just saying impl TraitMichael Goulet-17/+17
2022-07-25Restore Opaque behavior to coherence checkMichael Goulet-1/+1
2022-07-21orphan check: opaque types are an errorlcnr-1/+1
2022-07-20Rollup merge of #99383 - ouz-a:issue_57961, r=oli-obkDylan DPC-7/+17
Formalize defining_use_anchor This tackles issue #57961 Introduces new enum called `DefiningAnchor` that replaces `Option<LocalDefId>` of `defining_use_anchor`. Now every use of it is explicit and exhaustively matched, catching errors like one in the linked issue. This is not a perfect fix but it's a step in the right direction. r? `@oli-obk`
2022-07-20take opaq typesouz-a-7/+17
2022-07-19Do not allow typeck children items to constrain outer RPITsMichael Goulet-0/+54
2022-07-16Do not constraint TAITs when checking impl/trait item compatibilityMichael Goulet-0/+41
2022-07-08Auto merge of #98816 - estebank:implicit-sized, r=oli-obkbors-6/+6
Track implicit `Sized` obligations in type params When we evaluate `ty::GenericPredicates` we introduce the implicit `Sized` predicate of type params, but we do so with only the `Predicate` its `Span` as context, we don't have an `Obligation` or `ObligationCauseCode` we could influence. To try and carry this information through, we add a new field to `ty::GenericPredicates` that tracks both which predicates come from a type param and whether that param has any bounds already (to use in suggestions). We also suggest adding a `?Sized` bound if appropriate on E0599. Address part of #98539.
2022-07-08Auto merge of #98614 - oli-obk:take_unsound_opaque_types, r=wesleywiserbors-98/+15
don't succeed `evaluate_obligation` query if new opaque types were registered fixes #98608 fixes #98604 The root cause of all this is that in type flag computation we entirely ignore nongeneric things like struct fields and the signature of function items. So if a flag had to be set for a struct if it is set for a field, that will only happen if the field is generic, as only the generic parameters are checked. I now believe we cannot use type flags to handle opaque types. They seem like the wrong tool for this. Instead, this PR replaces the previous logic by adding a new variant of `EvaluatedToOk`: `EvaluatedToOkModuloOpaqueTypes`, which says that there were some opaque types that got hidden types bound, but that binding may not have been legal (because we don't know if the opaque type was in its defining scope or not).
2022-07-07Track implicit `Sized` obligations in type paramsEsteban Küber-6/+6
Suggest adding a `?Sized` bound if appropriate on E0599 by inspecting the HIR Generics. (Fix #98539)
2022-07-07Shorten span for closures.Camille GILLOT-18/+18