about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2021-09-27better suggestionsTakayuki Maeda-5/+5
2021-09-26suggest both immutable and mutable trait implementationsTakayuki Maeda-32/+34
2021-09-24Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakisJubilee-36/+46
Be explicit about using Binder::dummy This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders. Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet. r? ``@nikomatsakis``
2021-09-23Auto merge of #88804 - Mark-Simulacrum:never-algo-v2, r=nikomatsakis,jackh726bors-2/+96
Revise never type fallback algorithm This is a rebase of https://github.com/rust-lang/rust/pull/84573, but dropping the stabilization of never type (and the accompanying large test diff). Each commit builds & has tests updated alongside it, and could be reviewed in a more or less standalone fashion. But it may make more sense to review the PR as a whole, I'm not sure. It should be noted that tests being updated isn't really a good indicator of final behavior -- never_type_fallback is not enabled by default in this PR, so we can't really see the full effects of the commits here. This combines the work by Niko, which is [documented in this gist](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660), with some additional rules largely derived to target specific known patterns that regress with the algorithm solely derived by Niko. We build these from an intuition that: * In general, fallback to `()` is *sound* in all cases * But, in general, we *prefer* fallback to `!` as it accepts more code, particularly that written to intentionally use `!` (e.g., Result's with a Infallible/! variant). When evaluating Niko's proposed algorithm, we find that there are certain cases where fallback to `!` leads to compilation failures in real-world code, and fallback to `()` fixes those errors. In order to allow for stabilization, we need to fix a good portion of these patterns. The final rule set this PR proposes is that, by default, we fallback from `?T` to `!`, with the following exceptions: 1. `?T: Foo` and `Bar::Baz = ?T` and `(): Foo`, then fallback to `()` 2. Per [Niko's algorithm](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660#proposal-fallback-chooses-between--and--based-on-the-coercion-graph), the "live" `?T` also fallback to `()`. The first rule is necessary to address a fairly common pattern which boils down to something like the snippet below. Without rule 1, we do not see the closure's return type as needing a () fallback, which leads to compilation failure. ```rust #![feature(never_type_fallback)] trait Bar { } impl Bar for () { } impl Bar for u32 { } fn foo<R: Bar>(_: impl Fn() -> R) {} fn main() { foo(|| panic!()); } ``` r? `@jackh726`
2021-09-23Auto merge of #89024 - ↵bors-5/+1
oli-obk:lazy_tait_is_not_limited_to_being_used_in_return_position, r=nikomatsakis Lazy TAIT preparation cleanups Check that TAIT generics are fully generic in mir typeck instead of wf-check, as wf-check can by definition only check TAIT in return position and not account for TAITs defined in the body of the function r? `@spastorino` `@nikomatsakis`
2021-09-23Auto merge of #89016 - lcnr:non_blanket_impls, r=nikomatsakis,michaelwoeristerbors-4/+4
fix non_blanket_impls iteration order We sometimes iterate over all `non_blanket_impls`, not sure if this is observable outside of error messages (i.e. as incremental bugs). This should fix the underlying issue of #86986. second attempt of #88718 r? `@nikomatsakis`
2021-09-23Check that TAIT generics are fully generic in mir typeck instead of ↵Oli Scherer-5/+1
wf-check, as wf-check can by definition only check TAIT in return position and not account for TAITs defined in the body of the function
2021-09-21Auto merge of #89103 - Mark-Simulacrum:migrate-2021, r=estebankbors-13/+15
Migrate in-tree crates to 2021 This replaces #89075 (cherry picking some of the commits from there), and closes #88637 and fixes #89074. It excludes a migration of the library crates for now (see tidy diff) because we have some pending bugs around macro spans to fix there. I instrumented bootstrap during the migration to make sure all crates moved from 2018 to 2021 had the compatibility warnings applied first. Originally, the intent was to support cargo fix --edition within bootstrap, but this proved fairly difficult to pull off. We'd need to architect the check functionality to support running cargo check and cargo fix within the same x.py invocation, and only resetting sysroots on check. Further, it was found that cargo fix doesn't behave too well with "not quite workspaces", such as Clippy which has several crates. Bootstrap runs with --manifest-path ... for all the tools, and this makes cargo fix only attempt migration for that crate. We can't use e.g. --workspace due to needing to maintain sysroots for different phases of compilation appropriately. It is recommended to skip the mass migration of Cargo.toml's to 2021 for review purposes; you can also use `git diff d6cd2c6c877110748296760aefddc21a0ea1d316 -I'^edition = .20...$'` to ignore the edition = 2018/21 lines in the diff.
2021-09-21Auto merge of #89125 - Aaron1011:remove-intercrate-cache, r=jackh726bors-6/+42
Don't use projection cache or candidate cache in intercrate mode Fixes #88969 It appears that *just* disabling the evaluation cache (in #88994) leads to other issues involving intercrate mode caching. I suspect that since we now always end up performing the full evaluation in intercrate mode, we end up 'polluting' the candidate and projection caches with results that depend on being in intercrate mode in some way. Previously, we might have hit a cached evaluation (stored during non-intercrate mode), and skipped doing this extra work in intercrate mode. The whole situation with intercrate mode caching is turning into a mess. Ideally, we would remove intercrate mode entirely - however, this might require waiting on Chalk.
2021-09-21Auto merge of #89045 - oli-obk:lazy_normalization_in_opaque_types, ↵bors-51/+32
r=nikomatsakis Register normalization obligations instead of immediately normalizing in opaque type instantiation For lazy TAIT we will need to instantiate opaque types from within `rustc_infer`, which cannot invoke normalization methods (they are in `rustc_trait_resolution`). So before we move the logic over to `rustc_infer`, we need make sure no normalization happens anymore. This PR resolves that by just registering normalization obligations and continuing. This PR is best reviewed commit by commit I also included f7ad36e which is just an independent cleanup that touches the same code and reduces diagnostics noise a bit r? `@nikomatsakis` cc `@spastorino`
2021-09-21use indexmap instead of hashmaplcnr-1/+1
2021-09-21renamelcnr-4/+4
2021-09-20Remove Drop-caused migration-added capturesMark Rousskov-6/+1
All of these were added due to insignificant Drop types being present.
2021-09-20Don't use projection cache or candidate cache in intercrate modeAaron Hill-6/+42
Fixes #88969 It appears that *just* disabling the evaluation cache (in #88994) leads to other issues involving intercrate mode caching. I suspect that since we now always end up performing the full evaluation in intercrate mode, we end up 'polluting' the candidate and projection caches with results that depend on being in intercrate mode in some way. Previously, we might have hit a cached evaluation (stored during non-intercrate mode), and skipped doing this extra work in intercrate mode. The whole situation with intercrate mode caching is turning into a mess. Ideally, we would remove intercrate mode entirely - however, this might require waiting on Chalk.
2021-09-20Use `ty::Error` for opaque types with errors in its bounds.Oli Scherer-1/+1
This reduces unhelpful diagnostics down the road.
2021-09-20Generate inference vars and obligations for projections in opaque types ↵Oli Scherer-19/+24
instead of trying to normalize them.
2021-09-20Inline a function that is only called onceOli Scherer-10/+4
2021-09-20Use tracing debugging in `fold_opaque_ty`Oli Scherer-14/+6
2021-09-20Add helper function to `InferCtxt` that generates inference vars for ↵Oli Scherer-11/+1
unresolved associated types
2021-09-20Enable 2021 compatibility lints for all in-tree codeMark Rousskov-14/+21
This just applies the suggested fixes from the compatibility warnings, leaving any that are in practice spurious in. This is primarily intended to provide a starting point to identify possible fixes to the migrations (e.g., by avoiding spurious warnings). A secondary commit cleans these up where they are false positives (as is true in many of the cases).
2021-09-20Do not store visibility in *ItemRef.Camille GILLOT-1/+1
2021-09-18Auto merge of #89000 - Mark-Simulacrum:no-new-lrc, r=petrochenkovbors-1/+1
Reuse existing shared Lrc for MatchImpl parent This is a small performance win for the hot path, which helps to address this regression: https://github.com/rust-lang/rust/pull/87244#issuecomment-883635813.
2021-09-18Auto merge of #88994 - Aaron1011:intercrate-caching, r=jackh726bors-0/+16
Disable the evaluation cache when in intercrate mode It's possible to use the same `InferCtxt` with both an intercrate and non-intercrate `SelectionContext`. However, the local (inferctxt) evaluation cache is not aware of this distinction, so this kind of `InferCtxt` re-use will pollute the cache wth bad results. This commit avoids the issue by disabling the evaluation cache entirely during intercrate mode.
2021-09-18Auto merge of #88980 - tmiasko:instrument-debug, r=oli-obkbors-2/+2
Use explicit log level in tracing instrument macro Specify a log level in tracing instrument macro explicitly. Additionally reduce the used log level from a default info level to a debug level (all of those appear to be developer oriented logs, so there should be no need to include them in release builds).
2021-09-17Auto merge of #88962 - fee1-dead:const-drop, r=oli-obkbors-0/+1
inline(always) on check_recursion_limit r? `@oli-obk` #88558 caused a regression, this PR adds `#[inline(always)]` to `check_recursion_limit`, a possible suspect of that regression.
2021-09-17Add another case of fallback to () avoid breakageMark Rousskov-2/+96
This adds src/test/ui/never_type/fallback-closure-ret.rs as a test case which showcases the failure mode fixed by this commit.
2021-09-17Auto merge of #88945 - Aaron1011:no-projection-completion, ↵bors-10/+2
r=wesleywiser,jackh726 Remove concept of 'completion' from the projection cache Fixes #88910 When we initially store a `NormalizedTy` in the projection cache, we discard all obligations that we can (while ensuring that we don't cause any issues with incremental compilation). Marking a projection cache entry as 'completed' discards all obligations associated with it. This can only cause problems, since any obligations stored in the cache are there for a reason (e.g. they evaluate to `EvaluatedToOkModuloRegions`). This commit removes `complete` and `complete_normalized` entirely.
2021-09-17Rollup merge of #88911 - FabianWolff:issue-88653, r=petrochenkovYuki Okushi-14/+24
Improve error message for type mismatch in generator arguments Fixes #88653. The code example given there is invalid because the `Generator` trait (unlike the `Fn` traits) does not take the generator arguments in tupled-up form (because there can only be one argument, from my understanding). Hence, the type error in the example in #88653 is correct, because the given generator takes a `bool` argument, whereas the function's return type talks about a generator with a `(bool,)` argument. The error message is both confusing and wrong, though: It is wrong because it displays the wrong "expected signature", and it is confusing because both the "expected" and "found" notes point at the same span. With my changes, I get the following, more helpful output: ``` error[E0631]: type mismatch in generator arguments --> test.rs:5:22 | 5 | fn foo(bar: bool) -> impl Generator<(bool,)> { | ^^^^^^^^^^^^^^^^^^^^^^^ expected signature of `fn((bool,)) -> _` 6 | |bar| { | ----- found signature of `fn(bool) -> _` ```
2021-09-16Auto merge of #88719 - estebank:point-at-arg-for-obligation, r=nagisabors-37/+81
Point at argument instead of call for their obligations When an obligation is introduced by a specific `fn` argument, point at the argument instead of the `fn` call if the obligation fails to be fulfilled. Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`. When giving an error about an obligation introduced by a function call that an argument doesn't fulfill, and that argument is a block, add a span_label pointing at the innermost tail expression. Current output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:31 | 2 | let p = Some(45).and_then({ | ______________________--------_^ | | | | | required by a bound introduced by this call 3 | | |x| println!("doubling {}", x); 4 | | Some(x * 2) | | ----------- 5 | | }); | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Previous output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:22 | 2 | let p = Some(45).and_then({ | ^^^^^^^^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Partially address #27300. Will require rebasing on top of #88546.
2021-09-16Rollup merge of #88875 - notriddle:notriddle/cleanup-unused-trait-selection, ↵Manish Goregaokar-3/+0
r=Mark-Simulacrum cleanup(rustc_trait_selection): remove vestigial code from rustc_on_unimplemented This isn't allowed by the validator, and seems to be unused. When it was added in ed10a3faae1fd1176b2edf4a61438e0542c103b9, it was used on `Sized`, and that usage is gone.
2021-09-16Fix rebaseEsteban Kuber-12/+12
2021-09-16Remove unnecessary labelEsteban Kuber-9/+14
2021-09-16fix `clone` callEsteban Kuber-2/+2
2021-09-16Account for blocks in argumentsEsteban Kuber-2/+22
When giving an error about an obligation introduced by a function call that an argument doesn't fulfill, and that argument is a block, add a span_label pointing at the innermost tail expression.
2021-09-16Point at call span that introduced obligation for the argEsteban Kuber-1/+11
2021-09-16Refactor `FulfillmentError` to track less dataEsteban Kuber-34/+43
Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`.
2021-09-15Reuse existing shared Lrc for MatchImpl parentMark Rousskov-1/+1
This is hopefully a small performance win for the hot path.
2021-09-15Remove ToPolyTraitRef impl for TraitRefjackh726-11/+11
2021-09-15Remove ToPredicate impls that use Binder::dummyjackh726-25/+35
2021-09-15Disable the evaluation cache when in intercrate modeAaron Hill-0/+16
It's possible to use the same `InferCtxt` with both an intercrate and non-intercrate `SelectionContext`. However, the local (inferctxt) evaluation cache is not aware of this distinction, so this kind of `InferCtxt` re-use will pollute the cache wth bad results. This commit avoids the issue by disabling the evaluation cache entirely during intercrate mode.
2021-09-15Use explicit log level in tracing instrument macroTomasz Miąsko-2/+2
Specify a log level in tracing instrument macro explicitly. Additionally reduce the used log level from a default info level to a debug level (all of those appear to be developer oriented logs, so there should be no need to include them in release builds).
2021-09-15Coerce const FnDefs to implement const Fn traitsDeadbeef-9/+16
2021-09-15inline(always) on check_recursion_limitDeadbeef-0/+1
2021-09-15Auto merge of #88558 - fee1-dead:const-drop, r=oli-obkbors-37/+170
Const drop The changes are pretty primitive at this point. But at least it works. ^-^ Problems with the current change that I can think of now: - [x] `~const Drop` shouldn't change anything in the non-const world. - [x] types that do not have drop glues shouldn't fail to satisfy `~const Drop` in const contexts. `struct S { a: u8, b: u16 }` This might not fail for `needs_non_const_drop`, but it will fail in `rustc_trait_selection`. - [x] The current change accepts types that have `const Drop` impls but have non-const `Drop` glue. Fixes #88424. Significant Changes: - `~const Drop` is no longer treated as a normal trait bound. In non-const contexts, this bound has no effect, but in const contexts, this restricts the input type and all of its transitive fields to either a) have a `const Drop` impl or b) can be trivially dropped (i.e. no drop glue) - `T: ~const Drop` will not be linted like `T: Drop`. - Instead of recursing and iterating through the type in `rustc_mir::transform::check_consts`, we use the trait system to special case `~const Drop`. See [`rustc_trait_selection::...::candidate_assembly#assemble_const_drop_candidates`](https://github.com/fee1-dead/rust/blob/const-drop/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs#L817) and others. Changes not related to `const Drop`ping and/or changes that are insignificant: - `Node.constness_for_typeck` no longer returns `hir::Constness::Const` for type aliases in traits. This was previously used to hack how we determine default bound constness for items. But because we now use an explicit opt-in, it is no longer needed. - Removed `is_const_impl_raw` query. We have `impl_constness`, and the only existing use of that query uses `HirId`, which means we can just operate it with hir. - `ty::Destructor` now has a field `constness`, which represents the constness of the destructor. r? `@oli-obk`
2021-09-14Remove concept of 'completion' from the projection cacheAaron Hill-10/+2
Fixes #88910 When we initially store a `NormalizedTy` in the projection cache, we discard all obligations that we can (while ensuring that we don't cause any issues with incremental compilation). Marking a projection cache entry as 'completed' discards all obligations associated with it. This can only cause problems, since any obligations stored in the cache are there for a reason (e.g. they evaluate to `EvaluatedToOkModuloRegions`). This commit removes `complete` and `complete_normalized` entirely.
2021-09-13Rollup merge of #88851 - fee1-dead:dup-bound, r=oli-obkGuillaume Gomez-2/+3
Fix duplicate bounds for const_trait_impl Fixes #88383. Compare the constness of the candidates before winnowing and removing a `~const` `BoundCandidate`.
2021-09-13Improve error message for type mismatch in generator argumentsFabian Wolff-14/+24
2021-09-12Auto merge of #88881 - Manishearth:rollup-alohfwx, r=Manishearthbors-267/+176
Rollup of 7 pull requests Successful merges: - #88336 ( Detect stricter constraints on gats where clauses in impls vs trait) - #88677 (rustc: Remove local variable IDs from `Export`s) - #88699 (Remove extra unshallow from cherry-pick checker) - #88709 (generic_const_exprs: use thir for abstract consts instead of mir) - #88711 (Rework DepthFirstSearch API) - #88810 (rustdoc: Cleanup `clean` part 1) - #88813 (explicitly link to external `ena` docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-09-12Rollup merge of #88709 - BoxyUwU:thir-abstract-const, r=lcnrManish Goregaokar-267/+176
generic_const_exprs: use thir for abstract consts instead of mir Changes `AbstractConst` building to use `thir` instead of `mir` so that there's less chance of consts unifying when they shouldn't because lowering to mir dropped information (see `abstract-consts-as-cast-5.rs` test) r? `@lcnr`
2021-09-12Auto merge of #88771 - jackh726:wf_tys_set, r=nikomatsakisbors-3/+4
Use FxHashSet instead of Vec for well formed tys Trying to recover perf from #88312 r? `@ghost`