about summary refs log tree commit diff
path: root/src/test/ui/traits
AgeCommit message (Collapse)AuthorLines
2021-03-20Move some tests to more reasonable directories - 5Caio-0/+76
2021-03-18Fix use of bare trait objects everywhereVadim Petrochenkov-20/+20
2021-03-15More precise spans for HIR pathsVadim Petrochenkov-1/+1
2021-03-13Avoid sorting predicates by `DefId`Aaron Hill-1/+1
Fixes issue #82920 Even if an item does not change between compilation sessions, it may end up with a different `DefId`, since inserting/deleting an item affects the `DefId`s of all subsequent items. Therefore, we use a `DefPathHash` in the incremental compilation system, which is stable in the face of changes to unrelated items. In particular, the query system will consider the inputs to a query to be unchanged if any `DefId`s in the inputs have their `DefPathHash`es unchanged. Queries are pure functions, so the query result should be unchanged if the query inputs are unchanged. Unfortunately, it's possible to inadvertantly make a query result incorrectly change across compilations, by relying on the specific value of a `DefId`. Specifically, if the query result is a slice that gets sorted by `DefId`, the precise order will depend on how the `DefId`s got assigned in a particular compilation session. If some definitions end up with different `DefId`s (but the same `DefPathHash`es) in a subsequent compilation session, we will end up re-computing a *different* value for the query, even though the query system expects the result to unchanged due to the unchanged inputs. It turns out that we have been sorting the predicates computed during `astconv` by their `DefId`. These predicates make their way into the `super_predicates_that_define_assoc_type`, which ends up getting used to compute the vtables of trait objects. This, re-ordering these predicates between compilation sessions can lead to undefined behavior at runtime - the query system will re-use code built with a *differently ordered* vtable, resulting in the wrong method being invoked at runtime. This PR avoids sorting by `DefId` in `astconv`, fixing the miscompilation. However, it's possible that other instances of this issue exist - they could also be easily introduced in the future. To fully fix this issue, we should 1. Turn on `-Z incremental-verify-ich` by default. This will cause the compiler to ICE whenver an 'unchanged' query result changes between compilation sessions, instead of causing a miscompilation. 2. Remove the `Ord` impls for `CrateNum` and `DefId`. This will make it difficult to introduce ICEs in the first place.
2021-03-06Move some tests to more suitable subdirsYuki Okushi-0/+285
2021-02-17In some limited cases, suggest `where` bounds for non-type paramsEsteban Küber-0/+8
Partially address #81971.
2021-02-09Organize trait test filesBram van den Heuvel-285/+285
2021-02-06path trimming: ignore type aliasesDan Aloni-4/+4
2021-01-31Move some tests to more reasonable directoriesCaio-0/+244
2021-01-21Rollup merge of #80429 - JulianKnodt:ob_forest, r=Mark-SimulacrumYuki Okushi-0/+31
Add regression test for mutual recursion in obligation forest Add regression test for #75860 with a slightly smaller example. I was looking at what caused the issue and was surprised when it errors out on nightly, so I just added a regression test which should effectively close the issue, altho it would be nice to find the fix for reference. Also I found that 80066 is not fixed by whatever fixed 75860.
2021-01-16Move some tests to more reasonable directories - 2Caio-0/+134
Address comments Update limits
2021-01-10Rework diagnostics for wrong number of generic argsPatryk Wychowaniec-17/+53
2020-12-29Remove `compile-fail` test suiteVadim Petrochenkov-1/+1
2020-12-29Add regr. test for mutual recursionkadmin-0/+31
2020-12-17Revert change to evaluation orderMatthew Jasper-0/+39
This change breaks some code and doesn't appear to enable any new code.
2020-12-16Take into account negative impls in "trait item not found" suggestionsLeSeulArtichaut-0/+113
2020-12-01Add regression test for #79458ThePuzzlemaker-0/+25
2020-11-24Use the name "auto traits" everywhere in the compilerCamelid-4/+4
Goodbye, OIBIT!
2020-11-23Rename `optin_builtin_traits` to `auto_traits`Camelid-1/+1
They were originally called "opt-in, built-in traits" (OIBITs), but people realized that the name was too confusing and a mouthful, and so they were renamed to just "auto traits". The feature flag's name wasn't updated, though, so that's what this PR does. There are some other spots in the compiler that still refer to OIBITs, but I don't think changing those now is worth it since they are internal and not particularly relevant to this PR. Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-16improve error message for const ty param mismatchBastian Kauschke-2/+0
2020-10-27Add unsized_fn_params featureSantiago Pastorino-3/+3
2020-10-22Normalize when finding trait object candidatesMatthew Jasper-0/+37
2020-10-21Rollup merge of #78063 - camelid:improve-cannot-multiply-error, r=estebankYuki Okushi-2/+2
Improve wording of "cannot multiply" type error For example, if you had this code: fn foo(x: i32, y: f32) -> f32 { x * y } You would get this error: error[E0277]: cannot multiply `f32` to `i32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32` However, that's not usually how people describe multiplication. People usually describe multiplication like how the division error words it: error[E0277]: cannot divide `i32` by `f32` --> src/lib.rs:2:7 | 2 | x / y | ^ no implementation for `i32 / f32` | = help: the trait `Div<f32>` is not implemented for `i32` So that's what this change does. It changes this: error[E0277]: cannot multiply `f32` to `i32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32` To this: error[E0277]: cannot multiply `i32` by `f32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32`
2020-10-20review commentsEsteban Küber-9/+9
2020-10-20Tweak "object unsafe" errorsEsteban Küber-39/+66
Fix #77598.
2020-10-19don't assume trait ambiguity happens in `Self`SNCPlay42-0/+84
2020-10-17Improve wording of "cannot multiply" type errorCamelid-2/+2
For example, if you had this code: fn foo(x: i32, y: f32) -> f32 { x * y } You would get this error: error[E0277]: cannot multiply `f32` to `i32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32` However, that's not usually how people describe multiplication. People usually describe multiplication like how the division error words it: error[E0277]: cannot divide `i32` by `f32` --> src/lib.rs:2:7 | 2 | x / y | ^ no implementation for `i32 / f32` | = help: the trait `Div<f32>` is not implemented for `i32` So that's what this change does. It changes this: error[E0277]: cannot multiply `f32` to `i32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32` To this: error[E0277]: cannot multiply `i32` by `f32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32`
2020-10-18Add test for issue-75983Yuki Okushi-0/+17
2020-10-18Add test for issue-70944Yuki Okushi-0/+23
2020-10-17Suggest minimal subset features in `incomplete_features` lintYuki Okushi-0/+5
2020-10-09address review commentsEsteban Küber-1/+71
2020-10-09Given `<T as Trait>::A: Ty` suggest `T: Trait<A = Ty>`Esteban Küber-0/+32
Fix #75829
2020-10-09Suggest removing bounds even when potential typoEsteban Küber-1/+17
2020-10-09Tweak output and add test casesEsteban Küber-11/+171
2020-10-09Point out why a trait is expected on `Struct + 'lt`Esteban Küber-0/+6
2020-10-06Fix tests from rebaseMatthew Jasper-31/+15
2020-10-06Don't require lifetime super-bounds on traits apply to trait objects of that ↵Matthew Jasper-0/+16
trait
2020-10-06Avoid cycle with projections from object typesMatthew Jasper-6/+15
Normalizing `<dyn Iterator<Item = ()> as Iterator>::Item` no longer requires selecting `dyn Iterator<Item = ()>: Iterator`. This was previously worked around by using a special type-folder to normalize things.
2020-10-06Avoid cycle in nested obligations for object candidateMatthew Jasper-0/+206
Bounds of the form `type Future: Future<Result=Self::Result>` exist in some ecosystem crates. To validate these bounds for trait objects we need to normalize `Self::Result` in a way that doesn't cause a cycle.
2020-10-06Fix tests and bootstrapMatthew Jasper-9/+11
2020-10-06Ensure that associated types for trait objects satisfy their boundsMatthew Jasper-0/+103
2020-10-06Separate bounds and predicates for associated/opaque typesMatthew Jasper-4/+22
2020-10-05Rollup merge of #75928 - JulianKnodt:non_utf8, r=estebankDylan DPC-0/+15
Remove trait_selection error message in specific case In the case that a trait is not implemented for an ADT with type errors, cancel the error. Fixes #75627
2020-09-03specialization_graph: avoid trimmed paths for OverlapErrorDan Aloni-5/+5
2020-09-02pretty: trim paths of unique symbolsDan Aloni-111/+111
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. This adds a new '-Z trim-diagnostic-paths=false' option to control this feature. On the good path, with no diagnosis printed, we should try to avoid issuing this query, so we need to prevent trimmed_def_paths query on several cases. This change also relies on a previous commit that differentiates between `Debug` and `Display` on various rustc types, where the latter is trimmed and presented to the user and the former is not.
2020-08-30Remove error message in specific casekadmin-0/+15
In the case that a trait is not implemented for an ADT with type errors, cancel the error.
2020-08-22Use smaller def span for functionsAaron Hill-2/+2
Currently, the def span of a funtion encompasses the entire function signature and body. However, this is usually unnecessarily verbose - when we are pointing at an entire function in a diagnostic, we almost always want to point at the signature. The actual contents of the body tends to be irrelevant to the diagnostic we are emitting, and just takes up additional screen space. This commit changes the `def_span` of all function items (freestanding functions, `impl`-block methods, and `trait`-block methods) to be the span of the signature. For example, the function ```rust pub fn foo<T>(val: T) -> T { val } ``` now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T` (everything before the opening curly brace). Trait methods without a body have a `def_span` which includes the trailing semicolon. For example: ```rust trait Foo { fn bar(); }``` the function definition `Foo::bar` has a `def_span` of `fn bar();` This makes our diagnostic output much shorter, and emphasizes information that is relevant to whatever diagnostic we are reporting. We continue to use the full span (including the body) in a few of places: * MIR building uses the full span when building source scopes. * 'Outlives suggestions' use the full span to sort the diagnostics being emitted. * The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]` attribute points the entire scope body. * The 'unconditional recursion' lint uses the full span to show additional context for the recursive call. All of these cases work only with local items, so we don't need to add anything extra to crate metadata.
2020-08-14Tweak output of E0225Esteban Küber-75/+210
When encountering multiple non-auto trait bounds suggest creating a new trait and explain what auto-traits are.
2020-07-27mv std libs to library/mark-6/+6
2020-07-18Fix debug assertion in typeckYuki Okushi-0/+36