Commit Graph

157 Commits

Author SHA1 Message Date
Michael Goulet
b7e4433974 Foreign types are trivially drop
- Also rename a trivial_const_drop to match style of other functions in
  the util module.
- Also add a test for `const Drop` that doesn't depend on a `~const`
  bound.
- Also comment a bit why we remove the const bound during dropck impl
  check.
2022-01-19 20:07:04 -08:00
Michael Goulet
8547f5732c never is trivially const-drop, and add test 2022-01-19 12:59:28 -08:00
Michael Goulet
33e5efbd58 adjust tests 2022-01-18 01:46:17 -08:00
Deadbeef
bf5130b502 Add test 2022-01-11 23:52:24 +08:00
Deadbeef
77297e5f1c normalize env constness for nested obligations 2021-12-25 00:33:23 +08:00
fee1-dead
1ea4aa0036 Fixed a small typo in ui test comments 2021-12-22 00:25:50 +08:00
Deadbeef
aaaad5b46b Fix bad caching of ~const Drop bounds 2021-12-21 13:25:43 +08:00
Deadbeef
a1f91aa410 Use a const ParamEnv when in default_method_body_is_const 2021-12-17 20:42:48 +08:00
Deadbeef
4bb65e1c79 Fix default_method_body_is_const when used across crates 2021-12-16 21:38:54 +08:00
Deadbeef
8cd168f6a6 Add trailing newline 2021-12-12 12:34:59 +08:00
Deadbeef
84b1d859c8 Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"
This reverts commit ff2439b7b9, reversing
changes made to 2a9e0831d6.
2021-12-12 12:34:46 +08:00
Deadbeef
5166f68754 Fix #91489 2021-12-12 12:09:27 +08:00
Esteban Kuber
5e1972eba7 Tweak assoc type obligation spans
* Point at RHS of associated type in obligation span
* Point at `impl` assoc type on projection error
* Reduce verbosity of recursive obligations
* Point at source of binding lifetime obligation
* Tweak "required bound" note
* Tweak "expected... found opaque (return) type" labels
* Point at set type in impl assoc type WF errors
2021-12-11 02:32:15 +00:00
Santiago Pastorino
85b723c4e6 Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"
This reverts commit 18bb8c61a9, reversing
changes made to d9baa36190.
2021-12-03 10:11:21 -03:00
Deadbeef
87cd1ce6c1 ParamEnv should be const when ImplItem is within a const impl. 2021-11-29 22:21:38 +08:00
Deadbeef
8710a2e169 Reformat everything 2021-11-29 21:19:51 +08:00
Oli Scherer
40f39e6c6a Fixup 2021-11-29 21:19:48 +08:00
Oli Scherer
d51068ca28 Use the constness from the param env instead of having a separate dimension for it
This breaks a ~const test that will be fixed in a follow up commit of this PR
2021-11-29 21:19:47 +08:00
Deadbeef
b2005117bc Allow features like const_try in d_m_b_i_c 2021-11-24 15:57:44 +08:00
Deadbeef
e0c2ff7ccc Allow more cases to match ~const Drop. 2021-11-24 15:57:40 +08:00
Esteban Kuber
6b9d910639 Point at source of trait bound obligations in more places
Be more thorough in using `ItemObligation` and `BindingObligation` when
evaluating obligations so that we can point at trait bounds that
introduced unfulfilled obligations. We no longer incorrectly point at
unrelated trait bounds (`substs-ppaux.verbose.stderr`).

In particular, we now point at trait bounds on method calls.

We no longer point at "obvious" obligation sources (we no longer have a
note pointing at `Trait` saying "required by a bound in `Trait`", like
in `associated-types-no-suitable-supertrait*`).

Address part of #89418.
2021-11-20 18:54:31 +00:00
lcnr
1296719c06 no overlap errors after failing the orphan check 2021-11-10 15:10:19 +01:00
Michael Howell
8520105464 fix(rustc_typeck): report function argument errors on matching type
Fixes #90101
2021-10-25 12:23:52 -07:00
Yuki Okushi
e2453dc2ff Revert "Rollup merge of #86011 - tlyu:correct-sized-bound-spans, r=estebank"
This reverts commit 36a1076d24, reversing
changes made to e1e9319d93.
2021-10-19 02:33:38 +09:00
Matthias Krüger
36a1076d24 Rollup merge of #86011 - tlyu:correct-sized-bound-spans, r=estebank
move implicit `Sized` predicate to end of list

In `Bounds::predicates()`, move the implicit `Sized` predicate to the
end of the generated list. This means that if there is an explicit
`Sized` bound, it will be checked first, and any resulting
diagnostics will have a more useful span.

Fixes #85998, at least partially. ~~Based on #85979, but only the last 2 commits are new for this pull request.~~ (edit: rebased) A full fix would need to deal with where-clauses, and that seems difficult. Basically, predicates are being collected in multiple stages, and there are two places where implicit `Sized` predicates can be inserted: once for generic parameters, and once for where-clauses. I think this insertion is happening too early, and we should actually do it only at points where we collect all of the relevant trait bounds for a type parameter.

I could use some help interpreting the changes to the stderr output. It looks like reordering the predicates changed some diagnostics that don't obviously have anything to do with `Sized` bounds. Possibly some error reporting code is making assumptions about ordering of predicates? The diagnostics for src/test/ui/derives/derives-span-Hash-*.rs seem to have improved, no longer pointing at the type parameter identifier, but src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs became less verbose for some reason.

I also ran into an instance of #84970 while working on this, but I kind of expected that could happen, because I'm reordering predicates. I can open a separate issue on that if it would be helpful.

``@estebank`` this seems likely to conflict (slightly?) with your work on #85947; how would you like to resolve that?
2021-10-15 07:44:44 +02:00
Gary Guo
0a03f8c78b Split impl-with-default-fn test into a pass test and a fail test 2021-10-11 18:20:20 +01:00
Taylor Yu
c07f5c43fc update ui test expectations 2021-10-08 18:15:53 -05:00
Manish Goregaokar
04314a6061 Rollup merge of #89482 - hkmatsumoto:patch-diagnostics, r=joshtriplett
Follow the diagnostic output style guide

Detected by #89455.
2021-10-04 23:56:23 -07:00
Jacob Pratt
bce8621983 Stabilize const_panic 2021-10-04 02:33:33 -04:00
Hirochika Matsumoto
fb0b1a5466 Follow the diagnostic output style guide 2021-10-03 14:28:39 +09:00
Manish Goregaokar
743e842afb Rollup merge of #88963 - fee1-dead:const-iterator, r=oli-obk
Coerce const FnDefs to implement const Fn traits

You can now pass a FnDef to a function expecting `F` where `F: ~const FnTrait`.

r? ``@oli-obk``

``@rustbot`` label T-compiler F-const_trait_impl
2021-10-01 14:46:48 -07:00
Esteban Kuber
0a4540b08f fix rebase 2021-09-16 14:01:37 +00:00
Esteban Kuber
569a842730 Point at call span that introduced obligation for the arg 2021-09-16 12:12:27 +00:00
Deadbeef
f8aa73d3dd Coerce const FnDefs to implement const Fn traits 2021-09-15 11:48:27 +00:00
bors
cdeba02ff7 Auto merge of #88558 - fee1-dead:const-drop, r=oli-obk
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-15 03:51:03 +00:00
Deadbeef
a0b83f542f Fix duplicate bounds for const_trait_impl 2021-09-11 09:40:19 +00:00
Deadbeef
f749e05f6b Allow ~const bounds on inherent impls 2021-09-09 05:21:33 +00:00
Deadbeef
146abdd119 Add another test case + fmt 2021-09-09 05:21:33 +00:00
Deadbeef
49ac725d51 fix precise live drops 2021-09-09 05:21:33 +00:00
Deadbeef
1ca83c6451 Use trait select logic instead of query 2021-09-09 05:21:32 +00:00
Deadbeef
f0a52128ee fmt 2021-09-09 05:21:31 +00:00
Deadbeef
4eab5c1f7b Failing test 2021-09-09 05:21:31 +00:00
Deadbeef
a13b13ff46 Const drop selection candidates 2021-09-09 05:21:31 +00:00
Deadbeef
894ce921a0 better test 2021-09-09 05:21:30 +00:00
Deadbeef
f6f5180d5f Add a simple test case 2021-09-09 05:21:29 +00:00
Deadbeef
ee02c8e20a Add test cases 2021-08-28 15:53:26 +00:00
Deadbeef
523490e94a Allow ~const bounds on trait assoc functions 2021-08-28 08:03:16 +00:00
Deadbeef
0a3a6087fb Revive tests 2021-08-27 10:33:15 +00:00
Deadbeef
580ca930ac Fix UI test 2021-08-27 07:12:40 +00:00
Deadbeef
c75aeaac0b Fix #88155 2021-08-27 05:07:38 +00:00