summary refs log tree commit diff
path: root/src/test/ui/traits
AgeCommit message (Collapse)AuthorLines
2022-06-07Remove arg_matrix.rs, bless testsMichael Goulet-24/+3
2022-05-13Rollup merge of #96989 - cjgillot:defpath-use, r=davidtwcoMatthias Krüger-2/+2
Be more precise than DefPathData::Misc. This variant was used for two unrelated things. Let's make this cleaner.
2022-05-12Bless tests.Camille GILLOT-2/+2
2022-05-12Auto merge of #96940 - TaKO8Ki:stop-suggesting-wrong-fully-qualified-path, ↵bors-0/+59
r=estebank Stop suggesting non-existing fully qualified paths This patch fixes a part of #96295. r? `@estebank`
2022-05-11stop suggesting non-existing fully qualified pathsTakayuki Maeda-0/+59
2022-05-10Auto merge of #96715 - cjgillot:trait-alias-loop, r=compiler-errorsbors-11/+45
Fortify handing of where bounds on trait & trait alias definitions Closes https://github.com/rust-lang/rust/issues/96664 Closes https://github.com/rust-lang/rust/issues/96665 Since https://github.com/rust-lang/rust/pull/93803, when listing all bounds and predicates we now need to account for the possible presence of predicates on any of the generic parameters. Both bugs were hidden by the special handling of bounds at the generic parameter declaration position. Trait alias expansion used to confuse predicates on `Self` and where predicates. Exiting too late when listing all the bounds caused a cycle error.
2022-05-09Point to the empty trait alias.Camille GILLOT-0/+9
2022-05-08Auto merge of #96155 - jackh726:param-heuristics-followup, r=estebankbors-2/+2
Followups for method call error change Each commit is self-contained. Fixes most of the followup reviews from that PR. r? `@estebank`
2022-05-06Resolve vars in note_type_errJack Huey-2/+2
2022-05-06suggest fully qualified path with appropriate paramsTakayuki Maeda-0/+85
2022-05-04Exit before fetching bounds on associated items.Camille GILLOT-0/+16
2022-05-04Only keep predicates on `Self` when checking `dyn TraitAlias`.Camille GILLOT-11/+20
2022-05-01Move some tests to more reasonable placesCaio-0/+76
2022-04-30Auto merge of #96347 - estebank:issue-96292, r=compiler-errorsbors-4/+61
Erase type params when suggesting fully qualified path When suggesting the use of a fully qualified path for a method call that is ambiguous because it has multiple candidates, erase type params in the resulting code, as they would result in an error when applied. We replace them with `_` in the output to rely on inference. There might be cases where this still produces slighlty incomplete suggestions, but it otherwise produces many more errors in relatively common cases. Fix #96292
2022-04-30Save colon span to suggest bounds.Camille GILLOT-2/+2
2022-04-30Bless tests.Camille GILLOT-4/+4
2022-04-25Replace suggest_constraining_param with suggest_restricting_param_boundWill Crichton-3/+3
to fix incorrect suggestion for trait bounds involving binary operators. Fixes #93927, #92347, #93744.
2022-04-23Provide consistent output order for suggestionsEsteban Küber-8/+8
2022-04-23Use more targetted suggestion span for fully qualified pathEsteban Küber-20/+20
2022-04-23Erase type params when suggesting fully qualified pathEsteban Küber-0/+57
When suggesting the use of a fully qualified path for a method call that is ambiguous because it has multiple candidates, erase type params in the resulting code, as they would result in an error when applied. We replace them with `_` in the output to rely on inference. There might be cases where this still produces slighlty incomplete suggestions, but it otherwise produces many more errors in relatively common cases. Fix #96292
2022-04-21Move some tests to more reasonable directoriesCaio-0/+94
2022-04-17Auto merge of #96010 - eduardosm:Unique-on-top-of-NonNull, r=m-ou-se,tmiaskobors-1/+1
Implement `core::ptr::Unique` on top of `NonNull` Removes the use `rustc_layout_scalar_valid_range_start` and some `unsafe` blocks.
2022-04-16Implementation for 65853Jack Huey-5/+26
This attempts to bring better error messages to invalid method calls, by applying some heuristics to identify common mistakes. The algorithm is inspired by Levenshtein distance and longest common sub-sequence. In essence, we treat the types of the function, and the types of the arguments you provided as two "words" and compute the edits to get from one to the other. We then modify that algorithm to detect 4 cases: - A function input is missing - An extra argument was provided - The type of an argument is straight up invalid - Two arguments have been swapped - A subset of the arguments have been shuffled (We detect the last two as separate cases so that we can detect two swaps, instead of 4 parameters permuted.) It helps to understand this argument by paying special attention to terminology: "inputs" refers to the inputs being *expected* by the function, and "arguments" refers to what has been provided at the call site. The basic sketch of the algorithm is as follows: - Construct a boolean grid, with a row for each argument, and a column for each input. The cell [i, j] is true if the i'th argument could satisfy the j'th input. - If we find an argument that could satisfy no inputs, provided for an input that can't be satisfied by any other argument, we consider this an "invalid type". - Extra arguments are those that can't satisfy any input, provided for an input that *could* be satisfied by another argument. - Missing inputs are inputs that can't be satisfied by any argument, where the provided argument could satisfy another input - Swapped / Permuted arguments are identified with a cycle detection algorithm. As each issue is found, we remove the relevant inputs / arguments and check for more issues. If we find no issues, we match up any "valid" arguments, and start again. Note that there's a lot of extra complexity: - We try to stay efficient on the happy path, only computing the diagonal until we find a problem, and then filling in the rest of the matrix. - Closure arguments are wrapped in a tuple and need to be unwrapped - We need to resolve closure types after the rest, to allow the most specific type constraints - We need to handle imported C functions that might be variadic in their inputs. I tried to document a lot of this in comments in the code and keep the naming clear.
2022-04-14Update output of cycle-cache-err-60010 testEduardo Sánchez Muñoz-1/+1
2022-04-14Auto merge of #95315 - compiler-errors:pointee-fix, r=pnkfelixbors-0/+19
when checking pointee metadata, canonicalize the `Sized` check Use `infcx.predicate_must_hold_modulo_regions` with a `Sized` obligation instead of just calling `ty.is_sized`, because the latter does not canonicalize region and type vars (and in the test case I added in this PR, there's a region var in the `ParamEnv`). Fixes #95311
2022-04-13fix: wrong trait import suggestion for T:Bruno Felipe Francisco-0/+24
2022-04-12Compute a more precise span for opaque type implsOli Scherer-2/+2
2022-04-06don't report int/float ambiguity when we have previous errorsMichael Goulet-32/+29
2022-04-05Rollup merge of #95525 - ohno418:suggest-derivable-trait-E0277, ↵Dylan DPC-0/+8
r=compiler-errors Suggest derivable trait on E0277 error Closes https://github.com/rust-lang/rust/issues/95099 .
2022-04-05Suggest derivable trait on E0277ohno418-0/+8
2022-04-04Remove hack, fix fmt and testsEsteban Kuber-2/+0
2022-04-04Refer to the TraitRef::identity in the message to be clearerEsteban Kuber-3/+3
2022-04-04Dedup logic and improve output for other types that impl traitEsteban Kuber-10/+14
2022-04-04Suggest dereferncing when possible in E0277, fix #87437Esteban Kuber-3/+55
2022-04-04Fix #90970, doesn't address #87437Esteban Kuber-0/+35
2022-04-04Mention implementers of unsatisfied traitEsteban Kuber-15/+16
When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the following other types implement trait `Foo`: Option<T> i32 str note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` Mention implementers of traits in `ImplObligation`s. Do not mention other `impl`s for closures, ranges and `?`.
2022-03-30Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakisbors-7/+7
Lazy type-alias-impl-trait take two ### user visible change 1: RPIT inference from recursive call sites Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned. ```rust fn bar(b: bool) -> impl std::fmt::Debug { if b { return 42 } let x: u32 = bar(false); // this errors on stable 99 } ``` The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type. ### user visible change 2: divergence between RPIT and TAIT in return statements Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So ```rust #![feature(type_alias_impl_trait)] type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![42]; } std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![42] } std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended) } ``` But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same: ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![]; } let mut x = foo(false); x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator vec![] } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![]; } let mut x = bar(false); x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator vec![] } ``` ### user visible change 3: TAIT does not merge types across branches In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile. ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { vec![42_i32] } else { std::iter::empty().collect() //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_` } } ``` It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this). ### PR formalities previous attempt: #92007 This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893 fixes #93411 fixes #88236 fixes #89312 fixes #87340 fixes #86800 fixes #86719 fixes #84073 fixes #83919 fixes #82139 fixes #77987 fixes #74282 fixes #67830 fixes #62742 fixes #54895
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-7/+7
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.
2022-03-27resolve: Simplify some diagnostic code to avoid an ICEVadim Petrochenkov-2/+24
2022-03-25when checking pointee metadata, canonicalize the Sized queryMichael Goulet-0/+19
2022-03-24Properly track `ImplObligation`sEsteban Kuber-1/+7
Instead of probing for all possible impls that could have caused an `ImplObligation`, keep track of its `DefId` and obligation spans for accurate error reporting. Follow up to #89580. Addresses #89418. Remove some unnecessary clones. Tweak output for auto trait impl obligations.
2022-03-15Auto merge of #92285 - compiler-errors:dyn-proj-bounds, r=nikomatsakisbors-11/+85
check ~Projection~ all supertrait bounds when confirming dyn candidate I'm pretty sure Projection is the only other PredicateKind that we care about enforcing here. Fixes #80800
2022-03-14check all dyn obligations, actuallyMichael Goulet-11/+35
2022-03-14check Projection supertrait bounds when confirming dyn candidateMichael Goulet-0/+50
2022-03-03add tests for metadata for unsized generics and opaquesMichael Goulet-0/+62
2022-03-03opaque types may also be sizedMichael Goulet-3/+20
2022-03-03type parameters have unit metadata if they are sizedMichael Goulet-0/+12
2022-02-24better ObligationCause for normalization errors in can_type_implement_copyMichael Goulet-0/+39
2022-02-14Auto merge of #93652 - spastorino:fix-negative-overlap-check-regions, ↵bors-4/+6
r=nikomatsakis Fix negative overlap check regions r? `@nikomatsakis`
2022-02-14Properly check regions on negative overlap checkSantiago Pastorino-4/+6