about summary refs log tree commit diff
path: root/src/librustc/traits
AgeCommit message (Collapse)AuthorLines
2020-02-09Rollup merge of #68857 - Marwes:allocations, r=matthewjasperDylan DPC-61/+100
perf: Reduce Vec allocations in normalization by passing &mut Vec Complicates the code a bit but allocation/freeing were a few percent of the overall runtime in trait heavy code.
2020-02-08Reduce Vec allocations in normalization by passing &mut VecMarkus Westerlind-61/+100
2020-02-08Make `associated_items` query return a sliceJonas Schievink-8/+17
2020-02-07Auto merge of #65232 - nikomatsakis:lazy-norm-anon-const-push-2, r=matthewjasperbors-8/+59
replace the leak check with universes, take 2 This PR is an attempt to revive the "universe-based region check", which is an important step towards lazy normalization. Unlike before, we also modify the definition of `'empty` so that it is indexed by a universe. This sidesteps some of the surprising effects we saw before -- at the core, we no longer think that `exists<'a> { forall<'b> { 'b: 'a } }` is solveable. The new region lattice looks like this: ``` static ----------+-----...------+ (greatest) | | | early-bound and | | free regions | | | | | scope regions | | | | | empty(root) placeholder(U1) | | / | | / placeholder(Un) empty(U1) -- / | / ... / | / empty(Un) -------- (smallest) ``` This PR has three effects: * It changes a fair number of error messages, I think for the better. * It fixes a number of bugs. The old algorithm was too conservative and caused us to reject legal subtypings. * It also causes two regressions (things that used to compile, but now do not). * `coherence-subtyping.rs` gets an additional error. This is expected. * `issue-57639.rs` regresses as before, for the reasons covered in #57639. Both of the regressions stem from the same underlying property: without the leak check, the instantaneous "subtype" check is not able to tell whether higher-ranked subtyping will succeed or not. In both cases, we might be able to fix the problem by doing a 'leak-check like change' at some later point (e.g., as part of coherence). This is a draft PR because: * I didn't finish ripping out the leak-check completely. * We might want to consider a crater run before landing this. * We might want some kind of design meeting to cover the overall strategy. * I just remembered I never finished 100% integrating this into the canonicalization code. * I should also review what happens in NLL region checking -- it probably still has a notion of bottom (empty set). r? @matthewjasper
2020-02-06Rollup merge of #68524 - jonas-schievink:generator-resume-arguments, r=ZoxcDylan DPC-2/+4
Generator Resume Arguments cc https://github.com/rust-lang/rust/issues/43122 and https://github.com/rust-lang/rust/issues/56974 Blockers: * [x] Fix miscompilation when resume argument is live across a yield point (https://github.com/rust-lang/rust/pull/68524#issuecomment-578459069) * [x] Fix 10% compile time regression in `await-call-tree` benchmarks (https://github.com/rust-lang/rust/pull/68524#issuecomment-578487162) * [x] Fix remaining 1-3% regression (https://github.com/rust-lang/rust/pull/68524#issuecomment-579566255) - resolved (https://github.com/rust-lang/rust/pull/68524#issuecomment-581144901) * [x] Make dropck rules account for resume arguments (https://github.com/rust-lang/rust/pull/68524#issuecomment-578541137) Follow-up work: * Change async/await desugaring to make use of this feature * Rewrite [`box_region.rs`](https://github.com/rust-lang/rust/blob/3d8778d767f0dde6fe2bc9459f21ead8e124d8cb/src/librustc_data_structures/box_region.rs) to use resume arguments (this shows up in profiles too)
2020-02-06lint impls that will become incoherent when leak-check is removedNiko Matsakis-8/+59
2020-02-06Auto merge of #68861 - Dylan-DPC:rollup-0m09hsg, r=Dylan-DPCbors-2/+2
Rollup of 8 pull requests Successful merges: - #68762 (Strip unnecessary subexpression) - #68790 (Improve `merge_from_succ`) - #68809 (Make more arithmetic functions unstably const) - #68832 (Clean up E0264, E0267 and E0268 explanations) - #68840 (On suggesting `#![recursion_limit = "X"]`, note current crate name) - #68846 (doc fix on doc attribute) - #68851 (Fix issue number of `capacity` method) - #68858 (Merge item id stable hashing functions) Failed merges: r? @ghost
2020-02-05Rollup merge of #68840 - Centril:rec-lim-curr-crate, r=estebankDylan DPC-2/+2
On suggesting `#![recursion_limit = "X"]`, note current crate name This would have saved me much confusion e.g. when reading the log output in https://github.com/rust-lang/rust/pull/68788#issuecomment-581852191. r? @estebank
2020-02-05Move EvaluationCache::clear.Camille GILLOT-7/+7
2020-02-05Move specialization_graph definition in traits::types.Camille GILLOT-196/+204
2020-02-05Split traits::structural_impls in two.Camille GILLOT-703/+714
2020-02-05Move traits::query datatypes to traits::types.Camille GILLOT-249/+353
2020-02-05Move traits::select datatypes to traits::types.Camille GILLOT-295/+290
2020-02-05Move traits::Reveal to traits::types.Camille GILLOT-43/+45
2020-02-05Move rustc::traits datatypes to module traits::types.Camille GILLOT-681/+691
2020-02-05`#![recursion_limit = "X"]`: note current crate name.Mazdak Farrokhzad-2/+2
2020-02-04Rollup merge of #68815 - matthiaskrgr:redundant_imports, r=alexcrichtonDylan DPC-2/+0
remove redundant imports (clippy::single_component_path_imports)
2020-02-04remove redundant imports (clippy::single_component_path_imports)Matthias Krüger-2/+0
2020-02-03Change wording for object unsafe because of assoc constEsteban Küber-5/+3
2020-02-02Improve needs_drop queryMatthew Jasper-133/+0
* Handle cycles in `needs_drop` correctly * Normalize types when computing `needs_drop` * Move queries from rustc to rustc_ty
2020-02-02Point at reason in object unsafe trait with `Self` in supertraits or ↵Esteban Küber-16/+38
`where`-clause
2020-02-02Account for `?Sized` type parameter boundsEsteban Küber-1/+11
2020-02-02Remove duplicated codeEsteban Küber-72/+0
2020-02-02Suggest `?Sized` on type parametersEsteban Küber-0/+38
2020-02-02Use more appropriate spans on object unsafe traits and provide structured ↵Esteban Küber-28/+85
suggestions when possible
2020-02-02Wording changes to object unsafe trait errorsEsteban Küber-10/+65
Stemming from the thread at https://twitter.com/indygreg/status/1223279056398929920
2020-02-02review commentsEsteban Küber-3/+3
2020-02-02Remove duplicated codeEsteban Küber-8/+1
2020-02-02Slight rewording of diagnostic messageEsteban Küber-1/+1
2020-02-02Point at the `Sized` obligation in `where` clausesEsteban Küber-4/+35
2020-02-02Tweak `Self: Sized` restriction diagnostic outputEsteban Küber-32/+50
2020-02-02Point at `Sized` boundEsteban Küber-7/+33
2020-02-02Add a resume type param to the generator substsJonas Schievink-1/+1
...and unify it with `()` for now
2020-02-02Add a resume type parameter to `Generator`Jonas Schievink-2/+4
2020-02-01Move builtin attribute logic to new rustc_attr crate.Mazdak Farrokhzad-1/+1
For now, this is all the crate contains, but more attribute logic & types will be moved there over time.
2020-01-28Add an early-exit to `QueryNormalizer::fold_ty`Jonas Schievink-0/+4
2020-01-27don't clone types that are copy, round two.Matthias Krüger-20/+13
2020-01-26Auto merge of #68522 - estebank:impl-trait-sugg-2, r=oli-obkbors-17/+52
Further improve `impl Trait`/`dyn Trait` suggestions After reading [_Returning Trait Objects_ by Bryce Fisher-Fleig](https://bryce.fisher-fleig.org/blog/returning-trait-objects/), [I noticed that](https://www.reddit.com/r/rust/comments/esueur/returning_trait_objects/ffczl4k/) #68195 had a few bugs due to not ignoring `ty::Error`. - Account for `ty::Error`. - Account for `if`/`else` and `match` blocks when pointing at return types and referencing their types. - Increase the multiline suggestion output from 6 lines to 20.
2020-01-25Auto merge of #68269 - csmoe:temp, r=estebankbors-5/+32
Suggest to shorten temporary borrow from raw pointer Closes https://github.com/rust-lang/rust/issues/65436 r? @estebank cc @tmandry
2020-01-24review commentsEsteban Küber-10/+8
2020-01-24Apply `resolve_vars_if_possible` to returned types for more accurate suggestionsEsteban Küber-2/+6
2020-01-24Use more accurate return path spansEsteban Küber-11/+42
No longer suggest `Box::new(if foo { Type1 } else { Type2 })`, instead suggesting `if foo { Box::new(Type1) } else { Box::new(Type2) }`.
2020-01-23Account for `ty::Error` when suggesting `impl Trait` or `Box<dyn Trait>`Esteban Küber-6/+8
2020-01-22Use a `ParamEnvAnd<Predicate>` for caching in `ObligationForest`Aaron Hill-3/+6
Previously, we used a plain `Predicate` to cache results (e.g. successes and failures) in ObligationForest. However, fulfillment depends on the precise `ParamEnv` used, so this is unsound in general. This commit changes the impl of `ForestObligation` for `PendingPredicateObligation` to use `ParamEnvAnd<Predicate>` instead of `Predicate` for the associated type. The associated type and method are renamed from 'predicate' to 'cache_key' to reflect the fact that type is no longer just a predicate.
2020-01-22Rollup merge of #68425 - phi-gamma:try-method, r=varkorTyler Mandry-20/+34
Fix try-op diagnostic in E0277 for methods For methods the try-op diagnostic displays the empty string where it has more descriptive strings like “a function” otherwise: error[E0277]: the `?` operator can only be used in that returns `Result` or `Option` (or another type that implements `std::ops::Try`) ^^ | | ^^ cannot use the `?` operator in that returns `()` ^^ I’m seeing this on nightly (rustc 1.42.0-nightly (b5a3341f1 2020-01-20)) and [on the playpen](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=0e7ce7792c2aceb8056941710d539124). The changeset add strings for impl methods and trait provided methods and test cases for the option type.
2020-01-22Rollup merge of #68388 - varkor:toogeneric-wf, r=eddybTyler Mandry-11/+23
Make `TooGeneric` error in WF checking a proper error `TooGeneric` is encountered during WF checking when we cannot determine that a constant involving a generic parameter will always be evaluated successfully (rather than resulting in an error). In these cases, the burden of proof should be with the caller, so that we can avoid post-monomorphisation tim errors (which was the previous previous behaviour). This commit ensures that this situation produces a proper compiler error, rather than silently ignoring it or ICEing. Fixes https://github.com/rust-lang/rust/issues/66962. r? @eddyb
2020-01-21Cleanup: rewrite conditional as matchPhilipp Gesang-35/+31
As suggested by @Centril. Signed-off-by: Philipp Gesang <phg@phi-gamma.net>
2020-01-21Rollup merge of #68140 - ecstatic-morse:const-trait-bound-opt-out, r=oli-obkMazdak Farrokhzad-60/+88
Implement `?const` opt-out for trait bounds For now, such bounds are treated exactly the same as unprefixed ones in all contexts. [RFC 2632](https://github.com/rust-lang/rfcs/pull/2632) does not specify whether such bounds are forbidden outside of `const` contexts, so they are allowed at the moment. Prior to this PR, the constness of a trait bound/impl was stored in `TraitRef`. Now, the constness of an `impl` is stored in `ast::ItemKind::Impl` and the constness of a bound in `ast::TraitBoundModifer`. Additionally, constness of trait bounds is now stored in an additional field of `ty::Predicate::Trait`, and the combination of the constness of the item along with any `TraitBoundModifier` determines the constness of the bound in accordance with the RFC. Encoding the constness of impls at the `ty` level is left for a later PR. After a discussion in \#wg-grammar on Discord, it was decided that the grammar should not encode the mutual exclusivity of trait bound modifiers. The grammar for trait bound modifiers remains `[?const] [?]`. To encode this, I add a dummy variant to `ast::TraitBoundModifier` that is used when the syntax `?const ?` appears. This variant causes an error in AST validation and disappears during HIR lowering. cc #67794 r? @oli-obk
2020-01-21Handle methods in try diagnosticPhilipp Gesang-0/+18
The diagnostic for diagnostic for methods and trait provided methods would only show the empty string: error[E0277]: the `?` operator can only be used in that returns `Result` or `Option` (or another type that implements `std::ops::Try`) Handle the missing cases so it reads ``a method'' / ``an async method'' / ``a trait method'' respectively. Signed-off-by: Philipp Gesang <phg@phi-gamma.net>
2020-01-21Make `TooGeneric` error in WF checking a proper errorvarkor-11/+23
`TooGeneric` is encountered during WF checking when we cannot determine that a constant involving a generic parameter will always be evaluated successfully (rather than resulting in an error). In these cases, the burden of proof should be with the caller, so that we can avoid post-monomorphisation tim errors (which was the previous previous behaviour). This commit ensures that this situation produces a proper compiler error, rather than silently ignoring it or ICEing.