about summary refs log tree commit diff
path: root/src/librustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2020-03-30Use if let instead of match when only matching a single variant ↵Matthias Krüger-94/+83
(clippy::single_match) Makes code more compact and reduces nestig.
2020-03-30rustc -> rustc_middle part 3 (rustfmt)Mazdak Farrokhzad-43/+49
2020-03-30rustc -> rustc_middle part 2Mazdak Farrokhzad-93/+93
2020-03-30rustc -> rustc_middle part 1Mazdak Farrokhzad-1/+1
2020-03-29Tweak `suggest_constraining_type_param`Esteban Küber-146/+62
Some of the bound restriction structured suggestions were incorrect while others had subpar output.
2020-03-29Auto merge of #70370 - petrochenkov:nosmatch, r=Centrilbors-5/+5
Remove attribute `#[structural_match]` and any references to it A small remaining part of https://github.com/rust-lang/rust/issues/63438.
2020-03-27Rollup merge of #70344 - Centril:hir-pretty, r=eddybDylan DPC-24/+24
Decouple `rustc_hir::print` into `rustc_hir_pretty` High level summary: - The HIR pretty printer, `rustc_hir::print` is moved into a new crate `rustc_hir_pretty`. - `rustc_ast_pretty` and `rustc_errors` are dropped as `rustc_hir` dependencies. - The dependence on HIR pretty is generally reduced, leaving `rustc_save_analysis`, `rustdoc`, `rustc_metadata`, and `rustc_driver` as the remaining clients. The main goal here is to reduce `rustc_hir`'s dependencies and its size such that it can start and finish earlier, thereby working towards https://github.com/rust-lang/rust/issues/65031. r? @Zoxc
2020-03-26make a custom error for overlap with negative implsNiko Matsakis-80/+165
2020-03-26trait_bound_spans -> sized_trait_bound_spansMazdak Farrokhzad-3/+3
2020-03-26Rollup merge of #69866 - estebank:guess_head_span, r=eddybMazdak Farrokhzad-14/+13
Rename `def_span` to `guess_head_span` r? @eddyb
2020-03-25Rename `def_span` to `guess_head_span`Esteban Küber-14/+13
2020-03-25Rollup merge of #70319 - lcnr:issue63695, r=eddybDylan DPC-0/+2
correctly normalize constants closes #70317 implements https://github.com/rust-lang/rust/issues/70125#issuecomment-602133708 r? eddyb cc @varkor
2020-03-24Remove attribute `#[structural_match]` and any references to itVadim Petrochenkov-5/+5
2020-03-24Rollup merge of #70213 - eddyb:stalled-on-ty-or-const, r=nikomatsakisMazdak Farrokhzad-27/+27
traits/fulfill: allow `stalled_on` to track `ty::Const::Infer(_)` (unused yet). This PR addresses the representation side of #70180, but only *actually collects* `ty::Infer`s via `Ty::walk` into `stalled_on` (collecting `ty::ConstKind::Infer`s requires #70164). However, it should be enough to handle #70107's needs (WF obligations are stalled only on the outermost type/const being an inference variable, no `walk`-ing is involved). This is my second attempt, see #70181 for the previous one, which unacceptably regressed perf. r? @nikomatsakis cc @nnethercote
2020-03-24rustc_hir: nix rustc_errors depMazdak Farrokhzad-24/+24
2020-03-24Rollup merge of #70277 - matthewjasper:remove-closurebound, r=nikomatsakisMazdak Farrokhzad-5/+1
Remove `ReClosureBound` We now substitute external names for regions in the query response. r? @nikomatsakis
2020-03-23add missing const super foldsBastian Kauschke-0/+2
2020-03-23Remove `ReClosureBound`Matthew Jasper-5/+1
2020-03-23Rollup merge of #69968 - eddyb:tupled-closure-captures, r=nikomatsakisMazdak Farrokhzad-56/+35
rustc: keep upvars tupled in {Closure,Generator}Substs. Previously, each closure/generator capture's (aka "upvar") type was tracked as one "synthetic" type parameter in the closure/generator substs, and figuring out where the parent `fn`'s generics end and the synthetics start involved slicing at `tcx.generics_of(def_id).parent_count`. Needing to query `generics_of` limited @davidtwco (who wants to compute some `TypeFlags` differently for parent generics vs upvars, and `TyCtxt` is not available there), which is how I got started on this, but it's also possible that the `generics_of` queries are slowing down `{Closure,Generator}Substs` methods. To give an example, for a `foo::<T, U>::{closure#0}` with captures `x: X` and `y: Y`, substs are: * before this PR: `[T, U, /*kind*/, /*signature*/, X, Y]` * after this PR: `[T, U, /*kind*/, /*signature*/, (X, Y)]` You can see that, with this PR, no matter how many captures, the last 3 entries in the substs (or 5 for a generator) are always the "synthetic" ones, with the last one being the tuple of capture types. r? @nikomatsakis cc @Zoxc
2020-03-23Rollup merge of #69942 - estebank:sized-verbose-sugg, r=matthewjasperMazdak Farrokhzad-17/+18
Increase verbosity when suggesting subtle code changes Do not suggest changes that are actually quite small inline, to minimize the likelihood of confusion. Fix #69243.
2020-03-23Rollup merge of #70269 - matthiaskrgr:clippy_closures, r=Dylan-DPCMazdak Farrokhzad-9/+5
remove redundant closures (clippy::redundant_closure)
2020-03-22Increase verbosity when suggesting subtle code changesEsteban Küber-17/+18
2020-03-22Rollup merge of #70229 - matthiaskrgr:cl3ppy, r=Mark-SimulacrumDylan DPC-1/+1
more clippy fixes * remove unused unit values (clippy::unused_unit) * make some let-if-bindings more idiomatic (clippy::useless_let_if_seq) * clarify when we pass () to functions (clippy::unit_arg) * don't redundantly repeat field names (clippy::redundant_field_names) * remove redundant returns (clippy::needless_return) * use let instead of match for matches with single bindings (clippy::match_single_binding) * don't convert results to options just for matching (clippy::if_let_some_result)
2020-03-22remove redundant closures (clippy::redundant_closure)Matthias Krüger-9/+5
2020-03-21don't redundantly repeat field names (clippy::redundant_field_names)Matthias Krüger-1/+1
2020-03-21rustc: keep upvars tupled in {Closure,Generator}Substs.Eduard-Mihai Burtescu-56/+35
2020-03-21Rollup merge of #70119 - eddyb:typeck-tables-local-def-id, r=petrochenkovDylan DPC-3/+3
rustc: use LocalDefId instead of DefId in TypeckTables. The logic in `TypeckTables`' implementation of `HashStable`, which created `DefId`s by combining a `CrateNum` from a `DefId` and a `DefIndex` from a `LocalDefId`, bothered me a bit. I don't know how much this matters, but it works so might as well submit it.
2020-03-21traits/fulfill: add a couple FIXME comments about potential optimizations.Eduard-Mihai Burtescu-0/+5
2020-03-21traits/fulfill: allow `stalled_on` to track `ty::Const::Infer(_)` (unused yet).Eduard-Mihai Burtescu-27/+22
2020-03-21infer: export methods on `InferCtxt` instead of `ShallowResolver`.Eduard-Mihai Burtescu-3/+3
2020-03-21Rollup merge of #70089 - eddyb:closure-sig-infer, r=nikomatsakisMazdak Farrokhzad-8/+6
rustc_infer: remove InferCtxt::closure_sig as the FnSig is always shallowly known. That is, `ClosureSubsts` is always created (in `rustc_typeck::check::closure`) with a `FnSig`, as the number of inputs is known, even if they might all have inference types. The only useful thing `InferCtxt::closure_sig` was doing is resolving an inference variable used just to get the `ty::FnPtr` containing that `FnSig` into `ClosureSubsts`. The ideal way to solve this would be to add a constructor for `ClosureSubsts`, that combines the parent `Substs`, the closure kind, the signature, and capture types together, but for now I've went with resolving the inference types just after unifying them with the real types. r? @nikomatsakis
2020-03-20remove redundant returns (clippy::needless_return)Matthias Krüger-20/+16
2020-03-19rustc: use LocalDefId instead of DefId in TypeckTables.Eduard-Mihai Burtescu-3/+3
2020-03-19rustc: use LocalDefId instead of DefIndex in HirId.Eduard-Mihai Burtescu-2/+2
2020-03-18Rollup merge of #69920 - Centril:hir-cleanup, r=ZoxcMazdak Farrokhzad-3/+3
Remove some imports to the rustc crate - When we have `NestedVisitorMap::None`, we use `type Map = dyn intravisit::Map<'v>;` instead of the actual map. This doesn't actually result in dynamic dispatch (in the future we may want to use an associated type default to simplify the code). - Use `rustc_session::` imports instead of `rustc::{session, lint}`. r? @Zoxc
2020-03-18rustc_infer: remove InferCtxt::closure_sig as the FnSig is always shallowly ↵Eduard-Mihai Burtescu-8/+6
known.
2020-03-17Erase regions in writebackMatthew Jasper-2/+2
Also skip duplicated region solving entirely with `-Zborrowck=mir`.
2020-03-16Auto merge of #68970 - matthewjasper:min-spec, r=nikomatsakisbors-28/+38
Implement a feature for a sound specialization subset This implements a new feature (`min_specialization`) that restricts specialization to a subset that is reasonable for the standard library to use. The plan is to then: * Update `libcore` and `liballoc` to compile with `min_specialization`. * Add a lint to forbid use of `feature(specialization)` (and other unsound, type system extending features) in the standard library. * Fix the soundness issues around `specialization`. * Remove `min_specialization` The rest of this is an overview from a comment in this PR ## Basic approach To enforce this requirement on specializations we take the following approach: 1. Match up the substs for `impl2` so that the implemented trait and self-type match those for `impl1`. 2. Check for any direct use of `'static` in the substs of `impl2`. 3. Check that all of the generic parameters of `impl1` occur at most once in the *unconstrained* substs for `impl2`. A parameter is constrained if its value is completely determined by an associated type projection predicate. 4. Check that all predicates on `impl1` also exist on `impl2` (after matching substs). ## Example Suppose we have the following always applicable impl: ```rust impl<T> SpecExtend<T> for std::vec::IntoIter<T> { /* specialized impl */ } impl<T, I: Iterator<Item=T>> SpecExtend<T> for I { /* default impl */ } ``` We get that the subst for `impl2` are `[T, std::vec::IntoIter<T>]`. `T` is constrained to be `<I as Iterator>::Item`, so we check only `std::vec::IntoIter<T>` for repeated parameters, which it doesn't have. The predicates of `impl1` are only `T: Sized`, which is also a predicate of impl2`. So this specialization is sound. ## Extensions Unfortunately not all specializations in the standard library are allowed by this. So there are two extensions to these rules that allow specializing on some traits. ### rustc_specialization_trait If a trait is always applicable, then it's sound to specialize on it. We check trait is always applicable in the same way as impls, except that step 4 is now "all predicates on `impl1` are always applicable". We require that `specialization` or `min_specialization` is enabled to implement these traits. ### rustc_specialization_marker There are also some specialization on traits with no methods, including the `FusedIterator` trait which is advertised as allowing optimizations. We allow marking marker traits with an unstable attribute that means we ignore them in point 3 of the checks above. This is unsound but we allow it in the short term because it can't cause use after frees with purely safe code in the same way as specializing on traits methods can. r? @nikomatsakis cc #31844 #67194
2020-03-16use direct imports for `rustc::{lint, session}`.Mazdak Farrokhzad-2/+2
2020-03-16remove unnecessary hir::map importsMazdak Farrokhzad-1/+1
2020-03-15More Method->Fn renamingMark Mansi-4/+4
2020-03-15Avoid ICEs when we emit errors constructing the specialization graphMatthew Jasper-27/+35
2020-03-15Add `min_specialization` featureMatthew Jasper-1/+3
Currently the only difference between it and `specialization` is that it only allows specializing functions.
2020-03-14Index HIR after creating TyCtxtJohn Kåre Alsaker-1/+1
2020-03-14Update `krate_attrs` and `get_module`John Kåre Alsaker-1/+1
2020-03-14Trim dependencies and features.Camille GILLOT-11/+2
2020-03-14Split librustc_infer.Camille GILLOT-1187/+1280
2020-03-14Move rustc_infer::traits to new crate rustc_trait_selection.Camille GILLOT-0/+17893