about summary refs log tree commit diff
path: root/src/librustc/ty/trait_def.rs
AgeCommit message (Collapse)AuthorLines
2020-03-30rustc -> rustc_middle part 1Mazdak Farrokhzad-233/+0
2020-03-24normalize some imports, prefer direct ones.Mazdak Farrokhzad-1/+1
2020-03-16Auto merge of #68970 - matthewjasper:min-spec, r=nikomatsakisbors-2/+34
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-15Avoid ICEs when we emit errors constructing the specialization graphMatthew Jasper-1/+2
2020-03-15Add attributes to allow specializing on traitsMatthew Jasper-1/+32
2020-03-14Update `trait_impls`John Kåre Alsaker-1/+11
2020-01-05Remove rustc_hir reexports in rustc::hir.Mazdak Farrokhzad-2/+2
2019-12-22Format the worldMark Rousskov-38/+25
2019-09-28Switch over all StableHash impls to new formatMark Rousskov-5/+2
2019-07-04rename hir::map::local_def_id_from_hir_id to local_def_idljedrz-1/+1
2019-06-21Remove needless lifetimesJeremy Stucki-3/+3
2019-06-14Unify all uses of 'gcx and 'tcx.Eduard-Mihai Burtescu-5/+5
2019-06-12Run `rustfmt --file-lines ...` for changes from previous commits.Eduard-Mihai Burtescu-6/+9
2019-06-12rustc: replace `TyCtxt<'tcx, 'gcx, 'tcx>` with `TyCtxt<'gcx, 'tcx>`.Eduard-Mihai Burtescu-3/+3
2019-06-12Fix fallout from `deny(unused_lifetimes)`.Eduard-Mihai Burtescu-3/+3
2019-06-12rustc: replace `TyCtxt<'a, 'gcx, 'tcx>` with `TyCtxt<'tcx, 'gcx, 'tcx>`.Eduard-Mihai Burtescu-3/+3
2019-04-25Update trait_impls_ofJohn Kåre Alsaker-3/+2
2019-04-05Introduce an arena type which may be used to allocate a list of types with ↵John Kåre Alsaker-1/+1
destructors
2019-03-23Auto merge of #59068 - ljedrz:kill_off_NodeId_stragglers, r=Zoxcbors-2/+2
HirIdification: kill off NodeId stragglers The final stages of HirIdification (#57578). This PR, along with https://github.com/rust-lang/rust/pull/59042, should finalize the HirIdification process (at least the more straightforward bits). - replace `NodeId` with `HirId` in `trait_impls` - remove all `NodeId`s from `borrowck` - remove all `NodeId`s from `typeck` - remove all `NodeId`s from `mir` - remove `trait_auto_impl` (unused) I would be cool to also remove `NodeId` from `hir::def::Def`, `middle::privacy::AccessLevel` and `hir::ItemId`, but I don't know if this is feasible. I'll be happy to do more if I've missed anything.
2019-03-13Use derive macro for HashStableJohn Kåre Alsaker-0/+4
2019-03-10hir: replace NodeId with HirId in trait_implsljedrz-2/+2
2019-02-10rustc: doc commentsAlexander Regueiro-3/+3
2019-02-05move librustc to 2018Mark Mansi-8/+8
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-06Use a function to access the Hir map to be able to turn it into a query laterJohn Kåre Alsaker-2/+2
2018-10-03rustc/ty: simplify some patternsljedrz-4/+2
2018-10-03rustc/ty: whitespace fixesljedrz-3/+3
2018-09-25Auto merge of #53693 - scottmcm:marker-trait-attribute, r=nikomatsakisbors-1/+8
Support an explicit annotation for marker traits From the tracking issue for rust-lang/rfcs#1268: > It seems obvious that we should make a `#[marker]` annotation. ~ https://github.com/rust-lang/rust/issues/29864#issuecomment-368959441 This PR allows you to put `#[marker]` on a trait, at which point: - [x] The trait must not have any items ~~All of the trait's items must have defaults~~ - [x] Any impl of the trait must be empty (not override any items) - [x] But impls of the trait are allowed to overlap r? @nikomatsakis
2018-09-19Add an is_marker flag to TraitDefScott McMurray-1/+8
2018-09-18A few cleanups and minor improvements to rustc/traitsljedrz-0/+9
2018-08-18Use the new Entry::or_default method where possible.Eduard-Mihai Burtescu-34/+31
2018-03-08Add InterpretInterner to StableHashingContext for AllocId serializationOliver Schneider-2/+2
2018-03-02Replace Rc with Lrc for shared dataJohn Kåre Alsaker-3/+3
2017-11-03[Syntax Breaking] Rename DefaultImpl to AutoImplleonardo.yvens-3/+3
DefaultImpl is a highly confusing name for what we now call auto impls, as in `impl Send for ..`. The name auto impl is not formally decided but for sanity anything is better than `DefaultImpl` which refers neither to `default impl` nor to `impl Default`.
2017-09-18incr.comp.: Remove tcx from StableHashingContext.Michael Woerister-2/+2
2017-09-18incr.comp.: Compute hashes of all query results.Michael Woerister-1/+16
2017-09-07rustc: Remove `CrateStore::crates` as a methodAlex Crichton-1/+1
This commit moves the `crates` method to a query and then migrates all callers to use a query instead of the now-renamed `crates_untracked` method where possible. Closes #41417
2017-09-05rustc: Move implementations_of_trait to a queryAlex Crichton-7/+10
While we're at it, make it two separate queries so one's for rustdoc and one's for the compiler, hopefully being a bit more targeted.
2017-08-08make `for_all_relevant_impls` O(1) againAriel Ben-Yehuda-104/+64
A change in #41911 had made `for_all_relevant_impls` do a linear scan over all impls, instead of using an HashMap. Use an HashMap again to avoid quadratic blowup when there is a large number of structs with impls. I think this fixes #43141 completely, but I want better measurements in order to be sure. As a perf patch, please don't roll this up.
2017-05-31Make a newtype for DefPathHash so they are not confused with content hashesMichael Woerister-3/+3
2017-05-18Use 128 instead of 64 bits for DefPath hashesMichael Woerister-2/+3
2017-05-16Use tcx.type_of(impl) instead of TraitRef::self_ty() for getting Self in ↵Michael Woerister-5/+5
relevant_impls_for().
2017-05-15Share lists of blanket impls in results of relevant_impls_for() query.Michael Woerister-24/+93
2017-05-15Remove interior mutability from TraitDef by turning fields into queries.Michael Woerister-258/+78
2017-02-25rustc_typeck: rework coherence to be almost completely on-demand.Eduard-Mihai Burtescu-3/+72
2017-01-22better comment wordingking6cong-1/+1
2016-11-29rustc: remove type information from TraitDef.Eduard-Mihai Burtescu-26/+13
2016-11-10rustc: clean up lookup_item_type and remove TypeScheme.Eduard Burtescu-1/+1
2016-11-08Replace FnvHasher use with FxHasher.Nicholas Nethercote-3/+3
This speeds up compilation by 3--6% across most of rustc-benchmarks.
2016-09-20rustc: remove ImplOrTraitItemId and TraitDef's associated_type_names.Eduard Burtescu-7/+0