summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
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-04add `relaxed_struct_unsize` feature gateBastian Kauschke-15/+44
2021-02-04relax adt unsizing requirementsBastian Kauschke-8/+5
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
2021-01-31Rollup merge of #80404 - JulianKnodt:arr_ref, r=oli-obkJonas Schievink-14/+1
Remove const_in_array_repeat Fixes #80371. Fixes #81315. Fixes #80767. Fixes #75682. I thought there might be some issue with `Repeats(_, 0)`, but if you increase the items in the array it still ICEs. I'm not sure if this is the best fix but it does fix the given issue.
2021-01-31Rollup merge of #80470 - SimonSapin:array-intoiter-type, r=m-ou-seJonas Schievink-1/+0
Stabilize by-value `[T; N]` iterator `core::array::IntoIter` Tracking issue: https://github.com/rust-lang/rust/issues/65798 This is unblocked now that `min_const_generics` has been stabilized in https://github.com/rust-lang/rust/pull/79135. This PR does *not* include the corresponding `IntoIterator` impl, which is https://github.com/rust-lang/rust/pull/65819. Instead, an iterator can be constructed through the `new` method. `new` would become unnecessary when `IntoIterator` is implemented and might be deprecated then, although it will stay stable.
2021-01-30Remove const_in_array_rep_exprkadmin-14/+1
2021-01-28Auto merge of #81055 - matthewjasper:non-fatal-overflow, r=nikomatsakisbors-12/+3
Make hitting the recursion limit in projection non-fatal This change was originally made in #80246 to avoid future (effectively) infinite loop bugs in projections, but wundergraph relies on rustc recovering here. cc #80953 r? `@nikomatsakis`
2021-01-28Rollup merge of #81426 - BoxyUwU:boxychangesv2, r=oli-obkYuki Okushi-4/+22
const_evaluatable: expand abstract consts in try_unify See this [zulip topic](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/combining.20const.20bounds) for more info cc ```@lcnr``` r? ```@oli-obk```
2021-01-27commentsEllen-1/+3
2021-01-27boop, ur abstract consts are now expandedEllen-4/+20
2021-01-27Rollup merge of #81407 - osa1:issue81098, r=estebankYuki Okushi-2/+4
Refine "remove semicolon" suggestion in trait selection Don't suggest it if the last statement doesn't have a semicolon Fixes #81098 See also #54771 for why this suggestion was added
2021-01-26Refine "remove semicolon" suggestion in trait selectionÖmer Sinan Ağacan-2/+4
Don't suggest it if the last statement doesn't have a semicolon Fixes #81098 See also #54771 for why this suggestion was added
2021-01-24Account for generics when suggesting boundEsteban Küber-12/+23
Fix #81175.
2021-01-18Add suggestion for impl_candidates with E0283Daiki Ihara-5/+13
Update compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-01-17Auto merge of #80679 - jackh726:predicate-kind-take2, r=lcnrbors-146/+148
Remove PredicateKind and instead only use Binder<PredicateAtom> Originally brought up in https://github.com/rust-lang/rust/pull/76814#discussion_r546858171 r? `@lcnr`
2021-01-17Rollup merge of #80635 - sexxi-goose:use-place-instead-of-symbol, ↵Mara Bos-4/+4
r=nikomatsakis` Improve diagnostics when closure doesn't meet trait bound Improves the diagnostics when closure doesn't meet trait bound by modifying `TypeckResuts::closure_kind_origins` such that `hir::Place` is used instead of `Symbol`. Using `hir::Place` to describe which capture influenced the decision of selecting a trait a closure satisfies to (Fn/FnMut/FnOnce, Copy) allows us to show precise path in the diagnostics when `capture_disjoint_field` feature is enabled. Closes rust-lang/project-rfc-2229/issues/21 r? ```@nikomatsakis```
2021-01-16Review changesJack Huey-150/+150
2021-01-16CleanupJack Huey-1/+1
2021-01-16Remove PredicateKindJack Huey-1/+1
2021-01-16Intermediate formatting and suchJack Huey-40/+40
2021-01-16Remove PredicateKind::AtomJack Huey-37/+39
2021-01-15Make hitting the recursion limit in projection non-fatalMatthew Jasper-12/+3
This is relied on by wundergraph.
2021-01-15Rollup merge of #80944 - LingMan:map_or, r=nagisaYuki Okushi-1/+1
Use Option::map_or instead of `.map(..).unwrap_or(..)` ``@rustbot`` modify labels +C-cleanup +T-compiler
2021-01-15Rollup merge of #80254 - Aaron1011:rustdoc-auto-param-env, r=estebankYuki Okushi-6/+4
Don't try to add nested predicate to Rustdoc auto-trait `ParamEnv` Fixes #80233 We already have logic in `evaluate_predicates` that tries to add unimplemented predicates to our `ParamEnv`. Trying to add a predicate that already holds can lead to errors later on, since projection will prefer trait candidates from the `ParamEnv` to predicates from an impl.
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-1/+1
2021-01-14Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasperbors-0/+6
Reintroduce hir::ExprKind::If Basically copied and paste #59288/https://github.com/rust-lang/rust-clippy/pull/4080 with some modifications. The vast majority of tests were fixed and now there are only a few remaining. Since I am still unable to figure out the missing pieces, any help with the following list is welcome. - [ ] **Unnecessary `typeck` exception**: [Cheated on this one to make CI green.](https://github.com/rust-lang/rust/pull/79328/files#diff-3faee9ba23fc54a12b7c43364ba81f8c5660045c7e1d7989a02a0cee1c5b2051) - [x] **Incorrect span**: [Span should reference `then` and `else` separately.](https://github.com/rust-lang/rust/pull/79328/files#diff-cf2c46e82222ee4b1037a68fff8a1af3c4f1de7a6b3fd798aacbf3c0475abe3d) - [x] **New note regarding `assert!`**: [Modified but not "wrong". Maybe can be a good thing?](https://github.com/rust-lang/rust/pull/79328/files#diff-9e0d7c89ed0224e2b62060c957177c27db43c30dfe3c2974cb6b5091cda9cfb5) - [x] **Inverted report location**: [Modified but not "wrong". Locations were inverted.](https://github.com/rust-lang/rust/pull/79328/files#diff-f637ce7c1f68d523a165aa9651765df05e36c4d7d279194b1a6b28b48a323691) - [x] **`src/test/ui/point-to-type-err-cause-on-impl-trait-return.rs` has weird errors**: [Not sure why this is happening.](https://github.com/rust-lang/rust/pull/79328/files#diff-c823c09660f5b112f95e97e8ff71f1797b6c7f37dbb3d16f8e98bbaea8072e95) - [x] **Missing diagnostic**: [???](https://github.com/rust-lang/rust/pull/79328/files#diff-6b8ab09360d725ba4513933827f9796b42ff9522b0690f80b76de067143af2fc)
2021-01-13Auto merge of #79322 - jyn514:refactor-impl, r=estebankbors-4/+6
Separate out a `hir::Impl` struct This makes it possible to pass the `Impl` directly to functions, instead of having to pass each of the many fields one at a time. It also simplifies matches in many cases. See `rustc_save_analysis::dump_visitor::process_impl` or `rustdoc::clean::clean_impl` for a good example of how this makes `impl`s easier to work with. r? `@petrochenkov` maybe?
2021-01-12Separate out a `hir::Impl` structJoshua Nelson-4/+6
This makes it possible to pass the `Impl` directly to functions, instead of having to pass each of the many fields one at a time. It also simplifies matches in many cases.
2021-01-12Auto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelixbors-1/+1
Make CTFE able to check for UB... ... by not doing any optimizations on the `const fn` MIR used in CTFE. This means we duplicate all `const fn`'s MIR now, once for CTFE, once for runtime. This PR is for checking the perf effect, so we have some data when talking about https://github.com/rust-lang/const-eval/blob/master/rfcs/0000-const-ub.md To do this, we now have two queries for obtaining mir: `optimized_mir` and `mir_for_ctfe`. It is now illegal to invoke `optimized_mir` to obtain the MIR of a const/static item's initializer, an array length, an inline const expression or an enum discriminant initializer. For `const fn`, both `optimized_mir` and `mir_for_ctfe` work, the former returning the MIR that LLVM should use if the function is called at runtime. Similarly it is illegal to invoke `mir_for_ctfe` on regular functions. This is all checked via appropriate assertions and I don't think it is easy to get wrong, as there should be no `mir_for_ctfe` calls outside the const evaluator or metadata encoding. Almost all rustc devs should keep using `optimized_mir` (or `instance_mir` for that matter).
2021-01-10Note inference failures using `?` conversionWilliam Bain-11/+3
2021-01-07Reintroduce hir::ExprKind::IfCaio-0/+6
2021-01-04Keep an unoptimized duplicate of `const fn` aroundoli-1/+1
This allows CTFE to reliably detect UB, as otherwise optimizations may hide UB.
2021-01-02use hir::Place instead of Symbol in closure_kind_originRoxane-4/+4
2021-01-02reduce borrowing and (de)referencing around match patterns ↵Matthias Krüger-11/+11
(clippy::match_ref_pats)
2020-12-30remove unused return types such as empty Results or Options that would ↵Matthias Krüger-35/+21
always be Some(..) remove unused return type of dropck::check_drop_obligations() don't wrap return type in Option in get_macro_by_def_id() since we would always return Some(..) remove redundant return type of back::write::optimize() don't Option-wrap return type of compute_type_parameters() since we always return Some(..) don't return empty Result in assemble_generator_candidates() don't return empty Result in assemble_closure_candidates() don't return empty result in assemble_fn_pointer_candidates() don't return empty result in assemble_candidates_from_impls() don't return empty result in assemble_candidates_from_auto_impls() don't return emtpy result in assemble_candidates_for_trait_alias() don't return empty result in assemble_builtin_bound_candidates() don't return empty results in assemble_extension_candidates_for_traits_in_scope() and assemble_extension_candidates_for_trait() remove redundant wrapping of return type of StripItem::strip() since it always returns Some(..) remove unused return type of assemble_extension_candidates_for_all_traits()
2020-12-29Remove `compile-fail` test suiteVadim Petrochenkov-2/+2
2020-12-29Stabilize by-value `[T; N]` iterator `core::array::IntoIter`Simon Sapin-1/+0
Tracking issue: https://github.com/rust-lang/rust/issues/65798 This is unblocked now that `min_const_generics` has been stabilized in https://github.com/rust-lang/rust/pull/79135. This PR does *not* include the corresponding `IntoIterator` impl, which is https://github.com/rust-lang/rust/pull/65819. Instead, an iterator can be constructed through the `new` method. `new` would become unnecessary when `IntoIterator` is implemented and might be deprecated then, although it will stay stable.
2020-12-28Rollup merge of #80344 - matthiaskrgr:matches, r=Dylan-DPCDylan DPC-24/+9
use matches!() macro in more places
2020-12-26Auto merge of #80246 - matthewjasper:projection-cycle-caching, r=Mark-Simulacrumbors-7/+20
Prevent caching normalization results with a cycle When normalizing a projection which results in a cycle, we would cache the result of `project_type` without the nested obligations (because they're not needed for inference). This would result in the nested obligations only being handled once in fulfill, which would avoid the cycle error. `get_paranoid_cache_value_obligation` used to add an obligation that resulted in a cycle in this case previously, but was removed by #73905. This PR makes the projection cache not cache the value of a projection if it was ever normalized in a cycle (except in a snapshot that's rolled back). Fixes #79714. r? `@nikomatsakis`
2020-12-24use matches!() macro in more placesMatthias Krüger-24/+9
2020-12-20Don't try to add nested predicate to Rustdoc auto-trait `ParamEnv`Aaron Hill-6/+4
Fixes #80233 We already have logic in `evaluate_predicates` that tries to add unimplemented predicates to our `ParamEnv`. Trying to add a predicate that already holds can lead to errors later on, since projection will prefer trait candidates from the `ParamEnv` to predicates from an impl.
2020-12-20Prevent caching projections in the case of cyclesMatthew Jasper-6/+12
When normalizing a projection which results in a cycle, we would cache the result of `project_type` without the nested obligations (because they're not needed for inference). This would result in the nested obligations only being handled once in fulfill, which would avoid the cycle error. Fixes #79714, a regresion from #79305 caused by the removal of `get_paranoid_cache_value_obligation`.