about summary refs log tree commit diff
path: root/src/librustc_trait_selection/traits
AgeCommit message (Collapse)AuthorLines
2020-05-04Suggest restricting type param when it doesn't satisfy projectionEsteban Küber-184/+6
When encountering a projection that isn't satisfied by a type parameter, suggest constraining the type parameter.
2020-05-04Rollup merge of #71038 - lcnr:dyn_trait_structural_match, r=pnkfelixDylan DPC-0/+5
forbid `dyn Trait` in patterns Do not allow `&dyn Trait` as a generic const parameters. This also changes dyn trait in pattern from ICE to error. closes #63322 closes #70972 r? @eddyb
2020-05-04Auto merge of #71108 - estebank:suggest-proj-type-mismatch-constraint, r=oli-obkbors-0/+7
On type mismatch involving associated type, suggest constraint When an associated type is found when a specific type was expected, if possible provide a structured suggestion constraining the associated type in a bound. ``` error[E0271]: type mismatch resolving `<T as Foo>::Y == i32` --> $DIR/associated-types-multiple-types-one-trait.rs:13:5 | LL | want_y(t); | ^^^^^^ expected `i32`, found associated type ... LL | fn want_y<T:Foo<Y=i32>>(t: &T) { } | ----- required by this bound in `want_y` | = note: expected type `i32` found associated type `<T as Foo>::Y` help: consider constraining the associated type `<T as Foo>::Y` to `i32` | LL | fn have_x_want_y<T:Foo<X=u32, Y = i32>>(t: &T) | ^^^^^^^^^ ``` ``` error[E0308]: mismatched types --> $DIR/trait-with-missing-associated-type-restriction.rs:12:9 | LL | qux(x.func()) | ^^^^^^^^ expected `usize`, found associated type | = note: expected type `usize` found associated type `<impl Trait as Trait>::A` help: consider constraining the associated type `<impl Trait as Trait>::A` to `usize` | LL | fn foo(x: impl Trait<A = usize>) { | ^^^^^^^^^^ ``` Fix #71035. Related to #70908.
2020-05-03Fix tidy checksKevin Per-22/+19
2020-05-03Adding if to prevent borrowing suggestion in structs #71136Kevin Per-6/+46
2020-05-03Rollup merge of #71314 - mibac138:cfg-version, r=petrochenkovDylan DPC-6/+11
Implement RFC 2523, `#[cfg(version(..))]` Hi! This is my first contribution to rust, I hope I didn't miss anything. I tried to implement this feature so that `#[cfg(version(1.44.0))]` works but the parser was printing an error that I wasn't sure how to fix so I just opted for implementing `#[cfg(version("1.44.0"))]` (note the quotes). Tracking issue: #64796
2020-05-02Point at associated types when they have a default typeEsteban Küber-0/+7
Associated types with a default type in a trait can't be relied upon to remain of that default type when in use, so literals of that type can't be used in the trait's items. Point at the associated type and state that information. Reduce verbosity for associated consts of the wrong type.
2020-05-03Implement RFC 2523, `#[cfg(version(..))]`mibac138-6/+11
2020-05-02Rollup merge of #71787 - tshepang:rustdoc-warnings, r=varkorDylan DPC-2/+2
fix rustdoc warnings
2020-05-02Move ensure_sufficient_stack to data_structuresSimonas Kazlauskas-3/+3
We anticipate this to have uses in all sorts of crates and keeping it in `rustc_data_structures` enables access to it from more locations without necessarily pulling in the large `librustc` crate.
2020-05-02Prevent stack overflow for deeply recursive codeOliver Scherer-88/+108
2020-05-02Auto merge of #71795 - RalfJung:rollup-yqxfi5a, r=RalfJungbors-1/+0
Rollup of 6 pull requests Successful merges: - #71712 (Miri: port error backtraces to std::backtrace) - #71736 (bootstrap: also apply unused-attributes hack without deny_warnings) - #71738 (remove AllocId generalization of Pointer) - #71739 (remove obsolete comment) - #71781 (Uncomment test code for failure to use `Box::pin`) - #71782 (Use a non-existent test path instead of clobbering /dev/null) Failed merges: r? @ghost
2020-05-02fix rustdoc warningsTshepang Lekhonkhobe-2/+2
2020-05-02Auto merge of #70170 - eddyb:wf-early-exit, r=nikomatsakisbors-43/+45
wf: handle "livelock" checking before reaching `WfPredicates::compute`. For `wf::obligations`'s "livelock" handling, this PR shouldn't cause any behavioral changes, as the check moved to it should be equivalent to the old one in `WfPredicates::compute`. However, it fixes #70168 by making *other* users of `WfPredicates::compute` (that is, `wf::predicate_obligations` and `compute`'s own upvar handling) correct for `ty::Infer`, in that they now get a `WellFormed(ty::Infer(_))` obligation instead of silently ignoring the type. r? @nikomatsakis
2020-05-01remove obsolete commentTshepang Lekhonkhobe-1/+0
Referenced was removed in 9f492fefef8d9a75f6dc27c834561fe977ca70c5
2020-04-30wf: {Int,Float}Var can only infer to always-WF ints/floats.Eduard-Mihai Burtescu-2/+8
2020-04-30wf: handle "livelock" checking before reaching `WfPredicates::compute`.Eduard-Mihai Burtescu-42/+38
2020-04-29forbid `dyn Trait` in const genericsBastian Kauschke-0/+5
2020-04-28Use the query system to allocate.Camille GILLOT-2/+2
2020-04-27Use `LocalDefId` in `typeck_tables_of` and `used_trait_imports` queriesmarmeladema-1/+1
2020-04-27Auto merge of #71268 - estebank:devectorize, r=eddybbors-107/+85
Remove some `Vec` allocations to improve performance This claws back most of the performance lost in https://github.com/rust-lang/rust/pull/69745. r? @eddyb
2020-04-27Rollup merge of #71409 - estebank:point-at-ret-question-mark-op, r=petrochenkovDylan DPC-14/+37
Point at the return type on `.into()` failure caused by `?` Fix #35946.
2020-04-26Point at the return type on `.into()` failure caused by `?`Esteban Küber-14/+37
Fix #35946.
2020-04-24Remove `Option` from the return type of `def_kind`.Eduard-Mihai Burtescu-1/+1
2020-04-24Auto merge of #71215 - ↵bors-19/+24
marmeladema:issue70853/librustc_middle-local-def-id-2, r=eddyb Simplify `local_def_id` and `as_local_hir_id` See #70853
2020-04-24Rollup merge of #71426 - contrun:fix-e0751-explanation, r=estebankDylan DPC-1/+1
fix error code in E0751.md reference: https://github.com/rust-lang/rust/issues/71304
2020-04-23Modify `as_local_hir_id` to return a bare `HirId`marmeladema-6/+5
2020-04-23Modify `as_local_hir_id` to accept a `LocalDefId` instead of a `DefId`marmeladema-17/+23
2020-04-23fix error code for E0751YI-1/+1
2020-04-22Rollup merge of #71203 - csmoe:issue-71137, r=csmoeDylan DPC-6/+18
Correct await span for async-await error reporting Closes #71137 r? @tmandry
2020-04-22Rollup merge of #70970 - eddyb:trait-vs-impl-mismatch, r=oli-obkDylan DPC-3/+4
Detect mistyped associated consts in `Instance::resolve`. *Based on #71049 to prevent redundant/misleading downstream errors.* Fixes #70942 by refusing to resolve an associated `const` if it doesn't have the same type in the `impl` that it does in the `trait` (which we assume had errored, and `delay_span_bug` guards against bugs).
2020-04-22add test for correct await spancsmoe-9/+15
2020-04-22Rollup merge of #70998 - estebank:suggest-impl-trait-empty-fn, r=varkorYuki Okushi-32/+92
Suggest `-> impl Trait` and `-> Box<dyn Trait>` on fn that doesn't return During development, a function could have a return type set that is a bare trait object by accident. We already suggest using either a boxed trait object or `impl Trait` if the return paths will allow it. We now do so too when there are *no* return paths or they all resolve to `!`. We still don't handle cases where the trait object is *not* the entirety of the return type gracefully. Closes #38376.
2020-04-21Rollup merge of #71174 - Nokel81:fix-async-main-error, r=petrochenkovDylan DPC-12/+7
Check that main/start is not async * Add new error code E0752 * Add span to hir::IsAsync::Yes * Emit an error if main or the start function is marked as async * Add two regression tests This PR fixes #68523.
2020-04-20Ensure tail expression will have a `Ty` for E0746Esteban Küber-48/+73
When the return type is `!Sized` we look for all the returned expressions in the body to fetch their types and provide a reasonable suggestion. The tail expression of the body is normally evaluated after checking whether the return type is `Sized`. Changing the order of the evaluation produces undesirable knock down effects, so we detect the specific case that newcomers are likely to encounter ,returning a single bare trait object, and only in that case we evaluate the tail expression's type so that the suggestion will be accurate.
2020-04-20Remove some allocations in predicate evaluationEsteban Küber-5/+7
2020-04-20Use more `Iterator`s instead of `Vec`sEsteban Küber-51/+35
2020-04-20Remove unnecessary allocationEsteban Küber-26/+25
2020-04-20Remove some `Vec` allocations in an effort to improve perfEsteban Küber-26/+19
2020-04-20Suggest `-> impl Trait` and `-> Box<dyn Trait>` on fn that doesn't returnEsteban Küber-25/+60
During development, a function could have a return type set that is a bare trait object by accident. We already suggest using either a boxed trait object or `impl Trait` if the return paths will allow it. We now do so too when there are *no* return paths or they all resolve to `!`. We still don't handle cases where the trait object is *not* the entirety of the return type gracefully.
2020-04-20Check that main/start is not asyncSebastian Malton-12/+7
* Add new error code E0752 * Add span to hir::IsAsync::Yes * Emit an error if main or the start function is marked as async * Add two regression tests Fix formatting errors and bless test outputs * move tests to ui/async-await fix test error text remove span from IsAsync
2020-04-19Dogfood more or_patterns in the compilerJosh Stone-35/+30
2020-04-19Auto merge of #69793 - estebank:predicate-obligations-4, r=nikomatsakisbors-183/+67
Maintain chain of derived obligations 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. Continuation (and built on) #69745, subset of #69709. r? @eddyb
2020-04-18Add label to item source of bound obligationEsteban Küber-2/+2
2020-04-18Do not emit note for projected derived obligationsEsteban Küber-3/+15
2020-04-18Remove `AssocTypeBound` and propagate bound `Span`sEsteban Küber-188/+50
2020-04-18Maintain chain of derived obligationsEsteban Küber-0/+10
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-18remove build warningsTshepang Lekhonkhobe-2/+2
Code blocks that are not annotated are assumed to be Rust
2020-04-18Detect mistyped associated consts in `Instance::resolve`.Eduard-Mihai Burtescu-3/+4
2020-04-17Auto merge of #71049 - eddyb:const-err, r=oli-obkbors-3/+12
Add `ConstKind::Error` and convert `ErrorHandled::Reported` to it. By replicating the `ty::Error` approach to encoding "an error has occurred", all of the mechanisms that skip redundant/downstream errors are engaged and help out (see the reduction in test output). This PR also adds `ErrorHandled::Linted` for the lint case because using `ErrorHandled::Reported` *without* having emitted an error that is *guaranteed* to stop compilation, is incorrect now. r? @oli-obk cc @rust-lang/wg-const-eval @varkor @yodaldevoid