about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2021-03-27Remove (lots of) dead codeJoshua Nelson-6/+0
Found with https://github.com/est31/warnalyzer. Dubious changes: - Is anyone else using rustc_apfloat? I feel weird completely deleting x87 support. - Maybe some of the dead code in rustc_data_structures, in case someone wants to use it in the future? - Don't change rustc_serialize I plan to scrap most of the json module in the near future (see https://github.com/rust-lang/compiler-team/issues/418) and fixing the tests needed more work than I expected. TODO: check if any of the comments on the deleted code should be kept.
2021-03-27Rollup merge of #82917 - cuviper:iter-zip, r=m-ou-seDylan DPC-34/+33
Add function core::iter::zip This makes it a little easier to `zip` iterators: ```rust for (x, y) in zip(xs, ys) {} // vs. for (x, y) in xs.into_iter().zip(ys) {} ``` You can `zip(&mut xs, &ys)` for the conventional `iter_mut()` and `iter()`, respectively. This can also support arbitrary nesting, where it's easier to see the item layout than with arbitrary `zip` chains: ```rust for ((x, y), z) in zip(zip(xs, ys), zs) {} for (x, (y, z)) in zip(xs, zip(ys, zs)) {} // vs. for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {} for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {} ``` It may also format more nicely, especially when the first iterator is a longer chain of methods -- for example: ```rust iter::zip( trait_ref.substs.types().skip(1), impl_trait_ref.substs.types().skip(1), ) // vs. trait_ref .substs .types() .skip(1) .zip(impl_trait_ref.substs.types().skip(1)) ``` This replaces the tuple-pair `IntoIterator` in #78204. There is prior art for the utility of this in [`itertools::zip`]. [`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
2021-03-26fix rustc_on_implemented `_Self` pathslcnr-47/+51
2021-03-26Use iter::zip in compiler/Josh Stone-34/+33
2021-03-24Use `EvaluatedToOkModuloRegions` whenever we erase regionsAaron Hill-1/+14
Fixes #80691 When we evaluate a trait predicate, we convert an `EvaluatedToOk` result to `EvaluatedToOkModuloRegions` if we erased any regions. We cache the result under a region-erased 'freshened' predicate, so `EvaluatedToOk` may not be correct for other predicates that have the same cache key.
2021-03-23Add has_default to GenericParamDefKind::Constkadmin-3/+3
This currently creates a field which is always false on GenericParamDefKind for future use when consts are permitted to have defaults Update const_generics:default locations Previously just ignored them, now actually do something about them. Fix using type check instead of value Add parsing This adds all the necessary changes to lower const-generics defaults from parsing. Change P<Expr> to AnonConst This matches the arguments passed to instantiations of const generics, and makes it specific to just anonymous constants. Attempt to fix lowering bugs
2021-03-22Auto merge of #79278 - mark-i-m:stabilize-or-pattern, r=nikomatsakisbors-1/+1
Stabilize or_patterns (RFC 2535, 2530, 2175) closes #54883 This PR stabilizes the or_patterns feature in Rust 1.53. This is blocked on the following (in order): - [x] The crater run in https://github.com/rust-lang/rust/pull/78935#issuecomment-731564021 - [x] The resolution of the unresolved questions and a second crater run (https://github.com/rust-lang/rust/pull/78935#issuecomment-735412705) - It looks like we will need to pursue some sort of edition-based transition for `:pat`. - [x] Nomination and discussion by T-lang - [x] Implement new behavior for `:pat` based on consensus (https://github.com/rust-lang/rust/pull/80100). - [ ] An FCP on stabilization EDIT: Stabilization report is in https://github.com/rust-lang/rust/pull/79278#issuecomment-772815177
2021-03-21Rollup merge of #83040 - lcnr:unused-ct-substs, r=oli-obkDylan DPC-37/+45
extract `ConstKind::Unevaluated` into a struct r? `@oli-obk`
2021-03-21Rollup merge of #82707 - BoxyUwU:errooaaar, r=oli-obkDylan DPC-76/+82
const_evaluatable_checked: Stop eagerly erroring in `is_const_evaluatable` Fixes #82279 We don't want to be emitting errors inside of is_const_evaluatable because we may call this during selection where it should be able to fail silently There were two errors being emitted in `is_const_evaluatable`. The one causing the compile error in #82279 was inside the match arm for `FailureKind::MentionsParam` but I moved the other error being emitted too since it made things cleaner imo The `NotConstEvaluatable` enum \*should\* have a fourth variant for when we fail to evaluate a concrete const, e.g. `0 - 1` but that cant happen until #81339 cc `@oli-obk` `@lcnr` r? `@nikomatsakis`
2021-03-20update `const_eval_resolve`lcnr-29/+13
2021-03-20extract `ConstKind::Unevaluated` into a structlcnr-26/+50
2021-03-19stabilize or_patternsmark-1/+1
2021-03-18Fix use of bare trait objects everywhereVadim Petrochenkov-2/+2
2021-03-16Auto merge of #82936 - oli-obk:valtree, r=RalfJung,lcnr,matthewjasperbors-1/+4
Implement (but don't use) valtree and refactor in preparation of use This PR does not cause any functional change. It refactors various things that are needed to make valtrees possible. This refactoring got big enough that I decided I'd want it reviewed as a PR instead of trying to make one huge PR with all the changes. cc `@rust-lang/wg-const-eval` on the following commits: * 2027184 implement valtree * eeecea9 fallible Scalar -> ScalarInt * 042f663 ScalarInt convenience methods cc `@eddyb` on ef04a6d cc `@rust-lang/wg-mir-opt` for cf1700c (`mir::Constant` can now represent either a `ConstValue` or a `ty::Const`, and it is totally possible to have two different representations for the same value)
2021-03-15Special case type aliases from impl trait in const/static typesOli Scherer-1/+4
2021-03-15s/ConstantSource/ConstantKind/Oli Scherer-2/+2
2021-03-12Prepare mir::Constant for ty::Const only supporting valtreesOli Scherer-1/+4
2021-03-12Auto merge of #82935 - henryboisdequin:diagnostic-cleanups, r=estebankbors-2/+2
Diagnostic cleanups Follow up to #81503 Helps with #82916 (don't show note if `span` is `DUMMY_SP`)
2021-03-09Rollup merge of #82841 - hvdijk:x32, r=joshtriplettMara Bos-2/+2
Change x64 size checks to not apply to x32. Rust contains various size checks conditional on target_arch = "x86_64", but these checks were never intended to apply to x86_64-unknown-linux-gnux32. Add target_pointer_width = "64" to the conditions.
2021-03-09improve `const fn` `RepeatVec` diagnosticsHenry Boisdequin-2/+2
2021-03-08Auto merge of #82727 - oli-obk:shrinkmem, r=pnkfelixbors-2/+4
Test the effect of shrinking the size of Rvalue by 16 bytes r? `@ghost`
2021-03-06Change x64 size checks to not apply to x32.Harald van Dijk-2/+2
Rust contains various size checks conditional on target_arch = "x86_64", but these checks were never intended to apply to x86_64-unknown-linux-gnux32. Add target_pointer_width = "64" to the conditions.
2021-03-05Shrink the size of Rvalue by 16 bytesOli Scherer-2/+4
2021-03-03Fix tidy err and reviewEllen-16/+10
2021-03-03Fix testsRyan Levick-1/+1
2021-03-03Remove extraneous return statementEllen-2/+2
2021-03-02nitsEllen-4/+9
2021-03-02errooaaar~Ellen-79/+86
2021-03-02Auto merge of #82698 - JohnTitor:rollup-htd533c, r=JohnTitorbors-2/+2
Rollup of 10 pull requests Successful merges: - #80189 (Convert primitives in the standard library to intra-doc links) - #80874 (Update intra-doc link documentation to match the implementation) - #82376 (Add option to enable MIR inlining independently of mir-opt-level) - #82516 (Add incomplete feature gate for inherent associate types.) - #82579 (Fix turbofish recovery with multiple generic args) - #82593 (Teach rustdoc how to display WASI.) - #82597 (Get TyCtxt from self instead of passing as argument in AutoTraitFinder) - #82627 (Erase late bound regions to avoid ICE) - #82661 (:arrow_up: rust-analyzer) - #82691 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-03-01Get TyCtxt from self instead of passing as argument in AutoTraitFinderNoam Koren-2/+2
methods
2021-02-28Remove an old FIXME comment and inline attributeÖmer Sinan Ağacan-1/+0
Apparently #35870 caused a problem in this code (which originally returned an impl trait) and `#[inline]` was added as a workaround, in ade79d76090. The issue is now fixed and the comment and `#[inline]` can now be removed.
2021-02-27Auto merge of #80454 - JulianKnodt:ob_forest_op, r=matthewjasperbors-19/+24
Skip Ty w/o infer ty/const in trait select Remove some allocations & also add `skip_current_subtree` to skip subtrees with no inferred items. r? `@eddyb` since marked in the FIXME
2021-02-25fix reviewklensy-5/+3
2021-02-24replaced some map_or with map_or_elseklensy-3/+8
2021-02-23Small optimizations to obligation forestkadmin-19/+24
2021-02-19Auto merge of #82020 - jyn514:mut-passes, r=camelid,GuillaumeGomezbors-1/+1
Make `Clean` take &mut DocContext - Take `FnMut` in `rustc_trait_selection::find_auto_trait_generics` - Take `&mut DocContext` in most of `clean` - Collect the iterator in auto_trait_impls instead of iterating lazily; the lifetimes were really bad. This combined with https://github.com/rust-lang/rust/pull/82018 should hopefully help with https://github.com/rust-lang/rust/pull/82014 by allowing `cx.cache.exported_traits` to be modified in `register_res`. Previously it had to use interior mutability, which required either adding a RefCell to `cache.exported_traits` on *top* of the existing `RefCell<Cache>` or mixing reads and writes between `cx.exported_traits` and `cx.cache.exported_traits`. I don't currently have that working but I expect it to be reasonably easy to add after this.
2021-02-19Rollup merge of #81496 - guswynn:expected_async_block, r=oli-obkDylan DPC-2/+2
name async generators something more human friendly in type error diagnostic fixes #81457 Some details: 1. I opted to load the generator kind from the hir in TyCategory. I also use 1 impl in the hir for the descr 2. I named both the source of the future, in addition to the general type (`future`), not sure what is preferred 3. I am not sure what is required to make sure "generator" is not referred to anywhere. A brief `rg "\"generator\"" showed me that most diagnostics correctly distinguish from generators and async generator, but the `descr` of `DefKind` is pretty general (not sure how thats used) 4. should the descr impl of AsyncGeneratorKind use its display impl instead of copying the string?
2021-02-18Rollup merge of #82194 - estebank:arbitrary-bounds-suggestion, r=petrochenkovDylan DPC-3/+23
In some limited cases, suggest `where` bounds for non-type params Partially address #81971.
2021-02-18Rollup merge of #82112 - BoxyUwU:tumbleweed, r=varkorDylan DPC-23/+15
const_generics: Dont evaluate array length const when handling yet another error Same ICE as #82009 except triggered by a different error. cc ``@lcnr`` r? ``@varkor``
2021-02-18Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726Dylan DPC-61/+43
Ensure valid TraitRefs are created for GATs This fixes `ProjectionTy::trait_ref` to use the correct substs. Places that need all of the substs have been updated to not use `trait_ref`. r? ````@jackh726````
2021-02-18Auto merge of #82249 - JohnTitor:rollup-3jbqija, r=JohnTitorbors-1/+1
Rollup of 8 pull requests Successful merges: - #82055 (Add diagnostics for specific cases for const/type mismatch err) - #82155 (Use !Sync std::lazy::OnceCell in usefulness checking) - #82202 (add specs for riscv32/riscv64 musl targets) - #82203 (Move some tests to more reasonable directories - 4) - #82211 (make `suggest_setup` help messages better) - #82212 (Remove redundant rustc_data_structures path component) - #82240 (remove useless ?s (clippy::needless_question_marks)) - #82243 (Add more intra-doc links to std::io) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-02-18Auto merge of #81172 - SimonSapin:ptr-metadata, r=oli-obkbors-6/+88
Implement RFC 2580: Pointer metadata & VTable RFC: https://github.com/rust-lang/rfcs/pull/2580 ~~Before merging this PR:~~ * [x] Wait for the end of the RFC’s [FCP to merge](https://github.com/rust-lang/rfcs/pull/2580#issuecomment-759145278). * [x] Open a tracking issue: https://github.com/rust-lang/rust/issues/81513 * [x] Update `#[unstable]` attributes in the PR with the tracking issue number ---- This PR extends the language with a new lang item for the `Pointee` trait which is special-cased in trait resolution to implement it for all types. Even in generic contexts, parameters can be assumed to implement it without a corresponding bound. For this I mostly imitated what the compiler was already doing for the `DiscriminantKind` trait. I’m very unfamiliar with compiler internals, so careful review is appreciated. This PR also extends the standard library with new unstable APIs in `core::ptr` and `std::ptr`: ```rust pub trait Pointee { /// One of `()`, `usize`, or `DynMetadata<dyn SomeTrait>` type Metadata: Copy + Send + Sync + Ord + Hash + Unpin; } pub trait Thin = Pointee<Metadata = ()>; pub const fn metadata<T: ?Sized>(ptr: *const T) -> <T as Pointee>::Metadata {} pub const fn from_raw_parts<T: ?Sized>(*const (), <T as Pointee>::Metadata) -> *const T {} pub const fn from_raw_parts_mut<T: ?Sized>(*mut (),<T as Pointee>::Metadata) -> *mut T {} impl<T: ?Sized> NonNull<T> { pub const fn from_raw_parts(NonNull<()>, <T as Pointee>::Metadata) -> NonNull<T> {} /// Convenience for `(ptr.cast(), metadata(ptr))` pub const fn to_raw_parts(self) -> (NonNull<()>, <T as Pointee>::Metadata) {} } impl<T: ?Sized> *const T { pub const fn to_raw_parts(self) -> (*const (), <T as Pointee>::Metadata) {} } impl<T: ?Sized> *mut T { pub const fn to_raw_parts(self) -> (*mut (), <T as Pointee>::Metadata) {} } /// `<dyn SomeTrait as Pointee>::Metadata == DynMetadata<dyn SomeTrait>` pub struct DynMetadata<Dyn: ?Sized> { // Private pointer to vtable } impl<Dyn: ?Sized> DynMetadata<Dyn> { pub fn size_of(self) -> usize {} pub fn align_of(self) -> usize {} pub fn layout(self) -> crate::alloc::Layout {} } unsafe impl<Dyn: ?Sized> Send for DynMetadata<Dyn> {} unsafe impl<Dyn: ?Sized> Sync for DynMetadata<Dyn> {} impl<Dyn: ?Sized> Debug for DynMetadata<Dyn> {} impl<Dyn: ?Sized> Unpin for DynMetadata<Dyn> {} impl<Dyn: ?Sized> Copy for DynMetadata<Dyn> {} impl<Dyn: ?Sized> Clone for DynMetadata<Dyn> {} impl<Dyn: ?Sized> Eq for DynMetadata<Dyn> {} impl<Dyn: ?Sized> PartialEq for DynMetadata<Dyn> {} impl<Dyn: ?Sized> Ord for DynMetadata<Dyn> {} impl<Dyn: ?Sized> PartialOrd for DynMetadata<Dyn> {} impl<Dyn: ?Sized> Hash for DynMetadata<Dyn> {} ``` API differences from the RFC, in areas noted as unresolved questions in the RFC: * Module-level functions instead of associated `from_raw_parts` functions on `*const T` and `*mut T`, following the precedent of `null`, `slice_from_raw_parts`, etc. * Added `to_raw_parts`
2021-02-17remove useless ?s (clippy::needless_question_marks)Matthias Krüger-1/+1
Example code: ``` fn opts() -> Option<String> { let s: Option<String> = Some(String::new()); Some(s?) // this can just be "s" } ```
2021-02-17In some limited cases, suggest `where` bounds for non-type paramsEsteban Küber-3/+23
Partially address #81971.
2021-02-16Make `Clean` take &mut DocContextJoshua Nelson-1/+1
- Take `FnMut` in `rustc_trait_selection::find_auto_trait_generics` - Take `&mut DocContext` in most of `clean` - Collect the iterator in auto_trait_impls instead of iterating lazily; the lifetimes were really bad. - Changes `fn sess` to properly return a borrow with the lifetime of `'tcx`, not the mutable borrow.
2021-02-15name async generators something more human friendly in type error diagnosticsGus Wynn-2/+2
2021-02-15Rollup merge of #81503 - henryboisdequin:fix-const-fn-arr-err-msg, r=estebankJonas Schievink-1/+17
Suggest to create a new `const` item if the `fn` in the array is a `const fn` Fixes #73734. If the `fn` in the array repeat expression is a `const fn`, suggest creating a new `const` item. On nightly, suggest creating an inline `const` block. This PR also removes the `suggest_const_in_array_repeat_expressions` as it is no longer necessary. Example: ```rust fn main() { // Should not compile but hint to create a new const item (stable) or an inline const block (nightly) let strings: [String; 5] = [String::new(); 5]; println!("{:?}", strings); } ``` Gives this error: ``` error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied --> $DIR/const-fn-in-vec.rs:3:32 | 2 | let strings: [String; 5] = [String::new(); 5]; | ^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `String` | = note: the `Copy` trait is required because the repeated element will be copied ``` With this change, this is the error message: ``` error[E0277]: the trait bound `String: Copy` is not satisfied --> $DIR/const-fn-in-vec.rs:3:32 | LL | let strings: [String; 5] = [String::new(); 5]; | ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | = help: moving the function call to a new `const` item will resolve the error ```
2021-02-15Add `ptr::Pointee` trait (for all types) and `ptr::metadata` functionSimon Sapin-6/+88
RFC: https://github.com/rust-lang/rfcs/pull/2580
2021-02-15the environment round here is awfully emptyEllen-23/+15
capitalism
2021-02-14Rollup merge of #82029 - tmiasko:debug, r=matthewjasperDylan DPC-2/+2
Use debug log level for developer oriented logs The information logged here is of limited general interest, while at the same times makes it impractical to simply enable logging and share the resulting logs due to the amount of the output produced. Reduce log level from info to debug for developer oriented information. For example, when building cargo, this reduces the amount of logs generated by `RUSTC_LOG=info cargo build` from 265 MB to 79 MB. Continuation of changes from 81350.