summary refs log tree commit diff
path: root/src/test/ui/traits
AgeCommit message (Collapse)AuthorLines
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-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.
2020-06-16warn against 'specialization' featureRalf Jung-9/+57
2020-06-15Only display other method receiver candidates if they actually applyAaron Hill-7/+0
Previously, we would suggest `Box<Self>` as a valid receiver, even if method resolution only succeeded due to an autoderef (e.g. to `&self`)
2020-06-15Rollup merge of #72556 - matthew-mcallister:trait-alias-inherent-impl, ↵Ralf Jung-0/+33
r=estebank Fix trait alias inherent impl resolution Fixes #60021 and fixes #72415. Obviously, the fix was very easy, but getting started with the testing and debugging rust compiler was an interesting experience. Now I can cross it off my bucket list!
2020-05-28Account for `Self` as a type paramEsteban Küber-0/+72
2020-05-27review comments: change wording and visual outputEsteban Küber-8/+6
2020-05-27Modify wordingEsteban Küber-3/+6
2020-05-27review commentsEsteban Küber-2/+2
2020-05-27Tweak output for mismatched impl itemEsteban Küber-1/+39
Detect type parameter that might require lifetime constraint. Do not name `ReVar`s in expected/found output. Reword text suggesting to check the lifetimes.
2020-05-27Name `RegionKind::ReVar` lifetimes in diagnosticsEsteban Küber-1/+1
2020-05-27Fix spacing of expected/found notes without a labelEsteban Küber-2/+2
2020-05-24Fix trait alias inherent impl resolutionMatthew McAllister-0/+33
Fixes #60021 and #72415.
2020-05-22Rollup merge of #71829 - kper:issue71136, r=matthewjasperRalf Jung-0/+21
Fix suggestion to borrow in struct The corresponding issue is #71136. The compiler suggests that borrowing `the_foos` might solve the problem. This is obviously incorrect. ``` struct Foo(u8); #[derive(Clone)] struct FooHolster { the_foos: Vec<Foo>, } ``` I propose as fix to check if there is any colon in the span. However, there might a case where `my_method(B { a: 1, b : foo })` would be appropriate to show a suggestion for `&B ...`. To fix that too, we can simply check if there is a bracket in the span. This is only possible because both spans are different. Issue's span: `the_foos: Vec<Foo>` other's span: `B { a : 1, b : foo }`
2020-05-03Adding new test #71136Kevin Per-0/+21
2020-04-26Use Cell::take in a couple placesThinkChaos-2/+2
2020-04-24Rollup merge of #71235 - estebank:lt-sugg-2, r=ecstatic-morseDylan DPC-1/+1
Tweak `'static` suggestion code Fix #71196.
2020-04-23fix error code for E0751YI-15/+15
2020-04-22Sort `MultiSpan`s on creationEsteban Küber-1/+1
2020-04-18Add label to item source of bound obligationEsteban Küber-1/+1
2020-04-18Do not emit note for projected derived obligationsEsteban Küber-1/+0
2020-04-18Remove `AssocTypeBound` and propagate bound `Span`sEsteban Küber-15/+11
2020-04-18Maintain chain of derived obligationsEsteban Küber-0/+5
When evaluating the derived obligations from super traits, maintain a reference to the original obligation in order to give more actionable context in the output.
2020-04-14Rename AssocKind::Method to AssocKind::FnRustin-Liu-2/+2
Rename fn_has_self_argument to fn_has_self_parameter Rename AssocItemKind::Method to AssocItemKind::Fn Refine has_no_input_arg Refine has_no_input_arg Revert has_no_input_arg Refine suggestion_descr Move as_def_kind into AssocKind Signed-off-by: Rustin-Liu <rustin.liu@gmail.com> Fix tidy check issue Signed-off-by: Rustin-Liu <rustin.liu@gmail.com>
2020-04-11rustc: Add a warning count upon completionRoccoDev-1/+1
2020-04-08Small tweaks to required bound spanEsteban Küber-25/+25
2020-04-08Use `PredicateObligation`s instead of `Predicate`sEsteban Küber-17/+26
Keep more information about trait binding failures.
2020-04-05"cannot resolve" → "cannot satisfy"Esteban Küber-1/+1
2020-04-03Rollup merge of #70741 - DutchGhost:test-59023, r=CentrilMazdak Farrokhzad-0/+17
Add test for #59023 Adds a test for https://github.com/rust-lang/rust/issues/59023 Closes https://github.com/rust-lang/rust/issues/59023
2020-04-03Add test for #59023DutchGhost-0/+17
2020-04-02tests: remove ignore directives from tests that mention core/alloc/std spans.Eduard-Mihai Burtescu-18/+9
2020-03-29Tweak `suggest_constraining_type_param`Esteban Küber-24/+18
Some of the bound restriction structured suggestions were incorrect while others had subpar output.