about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
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-14update messageHenry Boisdequin-5/+5
2021-02-13Remove unnecessary function parameters project.rsMatthew Jasper-21/+9
2021-02-13Make ProjectionTy::trait_ref truncate substs againMatthew Jasper-2/+1
Also make sure that type arguments of associated types are printed in some error messages.
2021-02-13Remove some unnecessary `trait_ref` callsMatthew Jasper-15/+11
2021-02-13Don't go through TraitRef to relate projectionsMatthew Jasper-17/+18
2021-02-13Remove ProjectionTy::from_ref_and_nameMatthew Jasper-6/+4
2021-02-13Use debug log level for developer oriented logsTomasz Miąsko-2/+2
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.
2021-02-12Auto merge of #81744 - rylev:overlapping-early-exit2, r=lcnrbors-1/+29
Try fast_reject::simplify_type in coherence before doing full check This is a reattempt at landing #69010 (by `@jonas-schievink).` The change adds a fast path for coherence checking to see if there's no way for types to unify since full coherence checking can be somewhat expensive. This has big effects on code generated by the [`windows`](https://github.com/microsoft/windows-rs) which in some cases spends as much as 20% of compilation time in the `specialization_graph_of` query. In local benchmarks this took a compilation that previously took ~500 seconds down to ~380 seconds. This is surely not going to make a difference on much smaller crates, so the question is whether it will have a negative impact. #69010 was closed because some of the perf suite crates did show small regressions. Additional discussion of this issue is happening [here](https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/windows-rs.20perf).
2021-02-12Don't check self type twiceRyan Levick-4/+1
2021-02-12Switch boolean checksRyan Levick-1/+1
2021-02-12Short circuit full corherence check when dealing with types with different ↵Ryan Levick-5/+6
reference mutability
2021-02-12Rollup merge of #81990 - matsujika:suggest-mut-reference, r=estebankYuki Okushi-16/+15
Make suggestion of changing mutability of arguments broader Fix #81421 Previously rustc tries to emit the suggestion of changing mutablity unless `!trait_ref.has_infer_types_or_consts() && self.predicate_can_apply(obligation.param_env, trait_ref)` and this led to some false negatives to occur.
2021-02-11Auto merge of #81350 - tmiasko:instrument-debug, r=lcnrbors-1/+1
Reduce log level used by tracing instrumentation from info to debug Restore log level to debug to avoid make info log level overly verbose (the uses of instrument attribute modified there, were for the most part a replacement for `debug!`; one use was novel).
2021-02-11Make suggestion of changing mutability of arguments broaderHirochika Matsumoto-16/+15
2021-02-09Rollup merge of #80732 - spastorino:trait-inheritance-self2, r=nikomatsakisDylan DPC-1/+2
Allow Trait inheritance with cycles on associated types take 2 This reverts the revert of #79209 and fixes the ICEs that's occasioned by that PR exposing some problems that are addressed in #80648 and #79811. For easier review I'd say, check only the last commit, the first one is just a revert of the revert of #79209 which was already approved. This also could be considered part or the actual fix of #79560 but I guess for that to be closed and fixed completely we would need to land #80648 and #79811 too. r? `@nikomatsakis` cc `@Aaron1011`
2021-02-06Rollup merge of #81738 - camelid:misc-small-diag-cleanup, r=lcnrJonas Schievink-3/+3
Miscellaneous small diagnostics cleanup
2021-02-05Revert "Auto merge of #79637 - spastorino:revert-trait-inheritance-self, ↵Santiago Pastorino-1/+2
r=Mark-Simulacrum" This reverts commit b4def89d76896eec73b4af33642ba7e5eb53c567, reversing changes made to 7dc1e852d43cb8c9e77dc1e53014f0eb85d2ebfb.
2021-02-05Rollup merge of #80726 - lcnr:unsize-query, r=oli-obkMara Bos-18/+44
relax adt unsizing requirements Changes unsizing of structs in case the last struct field shares generic params with other adt fields which do not change. This change is currently insta stable and changes the language, so it at least requires a lang fcp. I feel like the current state is fairly unintuitive. An example for what's now allowed would be https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6dd331d23f5c9ffc8c978175aae2e967 ```rust struct A<T, U: ?Sized>(T, B<T, U>); // previously ERR // struct A<T, U: ?Sized>(T, B<[u32; 1], U>); // ok struct B<T, U: ?Sized>(T, U); fn main() { let x = A([0; 1], B([0; 1], [0; 1])); let y: &A<[u32; 1], [u32]> = &x; assert_eq!(y.1.1.len(), 1); } ```
2021-02-04remove subst_supertrait callb-naber-3/+1
2021-02-04Try fast_reject::simplify_type in coherence before doing full checkRyan Levick-1/+31
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com> Co-authored-by: Ryan Levick <me@ryanlevick.com>
2021-02-03Miscellaneous small diagnostics cleanupCamelid-3/+3
2021-02-04add `relaxed_struct_unsize` feature gateBastian Kauschke-15/+44
2021-02-04relax adt unsizing requirementsBastian Kauschke-8/+5
2021-02-03added a suggestion to create a `const` item if the `fn` in the array repeat ↵Henry Boisdequin-1/+17
expression is a `const fn`
2021-02-02Rollup merge of #81544 - JulianKnodt:sat_where, r=lcnrJack Huey-13/+17
Add better diagnostic for unbounded Abst. Const ~~In the case where a generic abst. const requires a trivial where bound: `where TypeWithConst<const_fn(N)>: ,`, instead of requiring a where bound, just check that only consts are being substituted in to skip over where check.~~ ~~This is pretty sketchy, but I think it works. Presumably, if there is checking for type bounds added later, it can first check nested requirements, and see if they're satisfied by the current `ParamEnv`.~~ Changed the diagnostic to add a better example, which is more practical than what was previously proposed. r? ```@lcnr```
2021-02-02Add better diagnostic for missing where clausekadmin-13/+17
Previously, it's not clear what exactly should be added in the suggested where clause, so this adds an example to demonstrate.
2021-02-02Auto merge of #80843 - Mark-Simulacrum:fmt-bump, r=petrochenkovbors-6/+9
Bump rustfmt version
2021-02-02Bump rustfmt versionMark Rousskov-6/+9
Also switches on formatting of the mir build module
2021-02-01more things are const evaluatable *sparkles*Ellen-11/+24
2021-02-01Rollup merge of #79291 - JulianKnodt:ce_priv, r=petrochenkovJonas Schievink-1/+1
Add error message for private fn Attempts to add a more detailed error when a `const_evaluatable` fn from another scope is used inside of a scope which cannot access it. r? ````@lcnr````
2021-01-31Add error message for private fnkadmin-1/+1
Bless tests Update with changes from comments