summary refs log tree commit diff
path: root/src/test/ui/traits
AgeCommit message (Collapse)AuthorLines
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
2020-07-14Remove redundant explanatory `note` for type parametersEsteban Küber-3/+0
2020-07-14Suggest borrowing in more unsized fn param casesEsteban Küber-1/+4
2020-07-14Remove `Sized` `on_unimplemented` noteEsteban Küber-5/+0
2020-07-14Suggest boxing or borrowing unsized fieldsEsteban Küber-6/+6
2020-07-14Point at type on E0275 instead of whole fieldEsteban Küber-2/+2
2020-06-25Rollup merge of #73674 - estebank:op-trait-bound-suggestion, r=davidtwcoManish Goregaokar-0/+5
Tweak binop errors * Suggest potentially missing binop trait bound (fix #73416) * Use structured suggestion for dereference in binop
2020-06-24Suggest type param trait bound for binop only when appropriateEsteban Küber-1/+0
Verify that the binop trait *is* implemented for the types *if* all the involved type parameters are replaced with fresh inferred types. When this is the case, it means that the type parameter was indeed missing a trait bound. If this is not the case, provide a generic `note` refering to the type that doesn't implement the expected trait.
2020-06-23Tweak binop errorsEsteban Küber-0/+6
* Suggest potentially missing binop trait bound (fix #73416) * Use structured suggestion for dereference in binop
2020-06-20Rollup merge of #72456 - ldm0:dereftrait, r=estebankManish Goregaokar-0/+253
Try to suggest dereferences on trait selection failed Fixes #39029 Fixes #62530 This PR consists of two parts: 1. Decouple `Autoderef` with `FnCtxt` and move `Autoderef` to `librustc_trait_selection`. 2. Try to suggest dereferences when trait selection failed. The first is needed because: 1. For suggesting dereferences, the struct `Autoderef` should be used. But before this PR, it is placed in `librustc_typeck`, which depends on `librustc_trait_selection`. But trait selection error emitting happens in `librustc_trait_selection`, if we want to use `Autoderef` in it, dependency loop is inevitable. So I moved the `Autoderef` to `librustc_trait_selection`. 2. Before this PR, `FnCtxt` is coupled to `Autoderef`, and `FnCtxt` only exists in `librustc_typeck`. So decoupling is needed. After this PR, we can get suggestion like this: ``` error[E0277]: the trait bound `&Baz: Happy` is not satisfied --> $DIR/trait-suggest-deferences-multiple.rs:34:9 | LL | fn foo<T>(_: T) where T: Happy {} | ----- required by this bound in `foo` ... LL | foo(&baz); | ^^^^ | | | the trait `Happy` is not implemented for `&Baz` | help: consider adding dereference here: `&***baz` error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. ``` r? @estebank
2020-06-20Prevent incorrect help message for dereference suggestionDonough Liu-1/+67
2020-06-20Try to suggest dereferences when trait selection failed.Donough Liu-0/+187
2020-06-19Rollup merge of #73452 - matthewjasper:auto-rec, r=nikomatsakisManish Goregaokar-32/+44
Unify region variables when projecting associated types This is required to avoid cycles when evaluating auto trait predicates. Notably, this is required to be able add Chalk types to `CtxtInterners` for `cfg(parallel_compiler)`. r? @nikomatsakis
2020-06-19Rollup merge of #71420 - RalfJung:specialization-incomplete, r=matthewjasperManish Goregaokar-9/+57
Specialization is unsound As discussed in https://github.com/rust-lang/rust/issues/31844#issuecomment-617013949, it might be a good idea to warn users of specialization that the feature they are using is unsound. I also expanded the "incomplete feature" warning to link the user to the tracking issue.
2020-06-17Unify region variables when projecting associated typesmatthewjasper-32/+44
This is required to avoid cycles when evaluating auto trait predicates.