Commit Graph

1422 Commits

Author SHA1 Message Date
Matthias Krüger
a1fdea2b78
Rollup merge of #100514 - compiler-errors:issue-100191, r=spastorino
Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls

Fixes #100191

r? ``@spastorino``
2022-08-15 20:11:36 +02:00
Michael Goulet
75dfe55a5d TypeError can be Copy 2022-08-14 19:58:46 +00:00
Dylan DPC
92344e369b
Rollup merge of #99861 - lcnr:orphan-check-cg, r=jackh726
orphan check: rationalize our handling of constants

cc `@rust-lang/types` `@rust-lang/project-const-generics` on whether you agree with this reasoning.

r? types
2022-08-14 17:09:13 +05:30
Michael Goulet
c436930f91 Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls 2022-08-13 22:11:42 +00:00
lcnr
1ec2b9bce8 wf correctly shallow_resolve consts 2022-08-13 21:04:52 +02:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
bors
aeb5067967 Auto merge of #100315 - compiler-errors:norm-ct-in-proj, r=lcnr
Keep going if normalized projection has unevaluated consts in `QueryNormalizer`

#100312 was the wrong approach, I think this is the right one.

When normalizing a type, if we see that it's a projection, we currently defer to `tcx.normalize_projection_ty`, which normalizes the projections away but doesn't touch the unevaluated constants. So now we just continue to fold the type if it has unevaluated constants so we make sure to evaluate those too, if we can.

Fixes #100217
Fixes #83972
Fixes #84669
Fixes #86710
Fixes #82268
Fixes #73298
2022-08-11 10:47:48 +00:00
Michael Goulet
d2667e4b71 Move folding into just projection cases 2022-08-09 18:19:58 +00:00
bors
63e4312e6b Auto merge of #99217 - lcnr:implied-bounds-pre-norm, r=lcnr
consider unnormalized types for implied bounds

extracted, and slightly modified, from #98900

The idea here is that generally, rustc is split into things which can assume its inputs are well formed[^1], and things which have verify that themselves.

Generally most predicates should only deal with well formed inputs, e.g. a `&'a &'b (): Trait` predicate should be able to assume that `'b: 'a` holds. Normalization can loosen wf requirements (see #91068) and must therefore not be used in places which still have to check well formedness. The only such place should hopefully be `WellFormed` predicates

fixes #87748 and #98543

r? `@jackh726` cc `@rust-lang/types`

[^1]: These places may still encounter non-wf inputs and have to deal with them without causing an ICE as we may check for well formedness out of order.
2022-08-09 16:39:43 +00:00
Dylan DPC
d910e5376b
Rollup merge of #100221 - compiler-errors:impossible-trait-items, r=lcnr,notriddle,camelid
Don't document impossible to call default trait items on impls

Closes #100176

This only skips documenting _default_ trait items on impls, not ones that are written inside the impl block. This is a conservative approach, since I think we should document all items written in an impl block (I guess unless hidden or whatever), but the existence of this new query I added makes this easy to extend to other rustdoc cases.
2022-08-09 17:34:54 +05:30
lcnr
f25cb83296 don't normalize wf predicates
this allows us to soundly use unnormalized projections for wf
2022-08-09 12:54:32 +02:00
Michael Goulet
ca7e3c4a83 Keep going if normalized projection has unevaluated consts in QueryNormalizer 2022-08-09 09:41:28 +00:00
Michael Goulet
3fdf3cb80c Adjust wording 2022-08-08 00:13:41 +00:00
Michael Goulet
750f04d309 Implement special-cased projection error message for some common traits 2022-08-07 23:57:53 +00:00
Michael Goulet
b3b23aada9 Don't document impossible to call default trait items on impls 2022-08-07 23:44:05 +00:00
bors
bd04658eb6 Auto merge of #99743 - compiler-errors:fulfillment-context-cleanups, r=jackh726
Some `FulfillmentContext`-related cleanups

Use `ObligationCtxt` in some places, remove some `FulfillmentContext`s in others...

r? types
2022-08-06 06:48:15 +00:00
Matthias Krüger
01ccde5ec8
Rollup merge of #100095 - jackh726:early-binder, r=lcnr
More EarlyBinder cleanups

Each commit is independent

r? types
2022-08-04 22:25:04 +02:00
Michael Goulet
f5af266b6d Address nits 2022-08-04 13:59:25 +00:00
Michael Goulet
fe894756f8 Add traits::fully_solve_obligation that acts like traits::fully_normalize
It spawns up a trait engine, registers the single obligation, then fully
solves it
2022-08-04 13:50:56 +00:00
Michael Goulet
3e48434cc7 Use ObligationCtxt in impossible_predicates 2022-08-04 13:42:13 +00:00
Michael Goulet
61d9b1656d Remove unnecessary FulfillmentContext from need_migrate_deref_output_trait_object 2022-08-04 13:42:13 +00:00
Michael Goulet
37d412cff7 Remove FulfillmentContext param from fully_normalize 2022-08-04 13:42:13 +00:00
Matthias Krüger
02fcec2ac8
Rollup merge of #99795 - compiler-errors:delay-specialization-normalize-error, r=spastorino
Delay a bug when failed to normalize trait ref during specialization

The error messages still kinda suck here but they don't ICE anymore...

Fixes #45814
Fixes #43037

r? types
2022-08-03 22:29:30 +02:00
Matthias Krüger
0de7f756f0
Rollup merge of #99746 - compiler-errors:more-trait-engine, r=jackh726
Use `TraitEngine` in more places that don't specifically need `FulfillmentContext::new_in_snapshot`

Not sure if this change is worthwhile, but couldn't hurt re: chalkification

r? types
2022-08-03 22:29:27 +02:00
Jack Huey
955fcad758 Add bound_impl_subject and bound_return_ty 2022-08-03 01:02:46 -04:00
Jack Huey
96a69dce2c Change sized_constraints to return EarlyBinder 2022-08-03 00:14:24 -04:00
Jack Huey
e21624dc80 Add bound_predicates_of and bound_explicit_predicates_of 2022-08-02 22:44:08 -04:00
bors
b759b2efad Auto merge of #99509 - lcnr:commit_unconditionally, r=jackh726
remove `commit_unconditionally`

`commit_unconditionally` is a noop unless we somehow inspect the current state of our snapshot. The only thing which does that is the leak check which was only used in one place where `commit_if_ok` is probably at least as, or even more, correct.

r? rust-lang/types
2022-08-03 01:55:20 +00:00
Michael Goulet
16a3601f62 Delay a bug when failed to normalize trait ref during specialization 2022-08-03 01:37:02 +00:00
bors
e4417cf020 Auto merge of #92268 - jswrenn:transmute, r=oli-obk
Initial implementation of transmutability trait.

*T'was the night before Christmas and all through the codebase, not a miri was stirring — no hint of `unsafe`!*

This PR provides an initial, **incomplete** implementation of *[MCP 411: Lang Item for Transmutability](https://github.com/rust-lang/compiler-team/issues/411)*. The `core::mem::BikeshedIntrinsicFrom` trait provided by this PR is implemented on-the-fly by the compiler for types `Src` and `Dst` when the bits of all possible values of type `Src` are safely reinterpretable as a value of type `Dst`.

What this PR provides is:
- [x] [support for transmutations involving primitives](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/primitives)
- [x] [support for transmutations involving arrays](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/arrays)
- [x] [support for transmutations involving structs](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/structs)
- [x] [support for transmutations involving enums](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/enums)
- [x] [support for transmutations involving unions](https://github.com/jswrenn/rust/tree/transmute/src/test/ui/transmutability/unions)
- [x] [support for weaker validity checks](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/unions/should_permit_intersecting_if_validity_is_assumed.rs) (i.e., `Assume::VALIDITY`)
- [x] visibility checking

What isn't yet implemented:
- [ ] transmutability options passed using the `Assume` struct
- [ ] [support for references](https://github.com/jswrenn/rust/blob/transmute/src/test/ui/transmutability/references.rs)
- [ ] smarter error messages

These features will be implemented in future PRs.
2022-08-02 21:17:31 +00:00
bors
4493a0f472 Auto merge of #100063 - matthiaskrgr:rollup-lznouys, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #99987 (Always include a position span in `rustc_parse_format::Argument`)
 - #100005 (Remove Clean trait for ast::Attribute and improve Attributes::from_ast)
 - #100025 (Remove redundant `TransferWrapper` struct)
 - #100045 (Properly reject the `may_unwind` option in `global_asm!`)
 - #100052 (RISC-V ASM test: relax label name constraint.)
 - #100053 (move [`assertions_on_result_states`] to restriction)
 - #100057 (Remove more Clean trait implementations)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-02 17:18:58 +00:00
Matthias Krüger
a0991b8ba8
Rollup merge of #99987 - Alexendoo:parse-format-position-span, r=fee1-dead
Always include a position span in `rustc_parse_format::Argument`

Moves the spans from the `Position` enum to always be included in the `Argument` struct. Doesn't make any changes to use it in rustc, but it will be useful for some upcoming Clippy lints
2022-08-02 17:17:30 +02:00
bors
06f4950cbd Auto merge of #100032 - BoxyUwU:no_ty_in_placeholder_const, r=compiler-errors
make `PlaceholderConst` not store the type of the const

Currently the `Placeholder` variant on `ConstKind` is 28 bytes when with this PR its 8 bytes, i am not sure this is really useful at all rn since `Unevaluated` and `Value` variants are huge still but eventually it should be possible to get both down to 16 bytes 🤔. Mostly opening this to see if this change has any perf impact when done before it can make `ConstKind`/`ConstS` smaller
2022-08-02 13:10:49 +00:00
Matthias Krüger
0629445300
Rollup merge of #99156 - lcnr:omoe-wa, r=wesleywiser
`codegen_fulfill_obligation` expect erased regions

it's a query, so by erasing regions before calling it, we get better caching.
This doesn't actually change anything as its already the status quo.
2022-08-02 07:30:39 +02:00
Camille GILLOT
957548183d Remove trait_of_item query. 2022-08-01 21:39:26 +02:00
Camille GILLOT
d7ea161b7e Remove DefId from AssocItemContainer. 2022-08-01 21:38:45 +02:00
Camille GILLOT
110f0656cb Store associated item defaultness in impl_defaultness. 2022-08-01 21:38:16 +02:00
Ellen
49d001c5f3 fmt... 2022-08-01 20:15:58 +01:00
Matthias Krüger
4606830f83
Rollup merge of #100012 - TaKO8Ki:avoid-ty-to-string-conversions, r=fee1-dead
Avoid `Ty` to `String` conversions

follow-up to #98668
2022-08-01 16:49:34 +02:00
Matthias Krüger
8db3d7cfb6
Rollup merge of #99911 - cjgillot:no-guess, r=davidtwco
Remove some uses of `guess_head_span`

That function cuts a span at the first occurrence of `{`.  Using `def_span` is almost always more precise.
2022-08-01 16:49:31 +02:00
Ellen
825a7cc65c make PlaceholderConst not store the type of the const 2022-08-01 15:42:38 +01:00
Takayuki Maeda
92b31ccb73 avoid Ty to String conversions 2022-08-01 12:52:30 +09:00
Alex Macleod
2a0b51d852 Always include a position span in rustc_parse_format::Argument 2022-07-31 15:11:33 +00:00
Dylan DPC
eb378d2015
Rollup merge of #99862 - WaffleLapkin:type_mismatch_fix, r=compiler-errors
Improve type mismatch w/ function signatures

This PR makes use of `note: expected/found` (instead of labeling types in labels) in type mismatch with function signatures. Pros: it's easier to compare the signatures, cons: the error is a little more verbose now.

This is especially nice when
- The signatures differ in a small subset of parameters (same parameters are elided)
- The difference is in details, for example `isize` vs `usize` (there is a better chance that the types align)

Also this PR fixes the inconsistency in variable names in the edited code (`expected` and `found`).

A zulip thread from which this pr started: [[link]](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Type.20error.20regression.3F.2E.2E.2E/near/289756602).

An example diagnostic:

<table>
<tr>
<th>this pr</th>
<th>nightly</th>
</tr>
<tr>
<td>

```text
error[E0631]: type mismatch in function arguments
  --> ./t.rs:4:12
   |
4  |     expect(&f);
   |     ------ ^^ expected due to this
   |     |
   |     required by a bound introduced by this call
...
10 | fn f(_: isize, _: u8, _: Vec<u32>) {}
   | ---------------------------------- found signature defined here
   |
   = note: expected function signature `fn(usize, _, Vec<u64>) -> _`
              found function signature `fn(isize, _, Vec<u32>) -> _`
note: required because of the requirements on the impl of `Trait` for `fn(isize, u8, Vec<u32>) {f}`
  --> ./t.rs:8:9
   |
8  | impl<F> Trait for F where F: Fn(usize, u8, Vec<u64>) -> u8 {}
   |         ^^^^^     ^
   = note: required for the cast from `fn(isize, u8, Vec<u32>) {f}` to the object type `dyn Trait`
```

</td>
<td>

```text
error[E0631]: type mismatch in function arguments
  --> ./t.rs:4:12
   |
4  |     expect(&f);
   |     ------ ^^ expected signature of `fn(usize, u8, Vec<u64>) -> _`
   |     |
   |     required by a bound introduced by this call
...
10 | fn f(_: isize, _: u8, _: Vec<u32>) {}
   | ---------------------------------- found signature of `fn(isize, u8, Vec<u32>) -> _`
   |
note: required because of the requirements on the impl of `Trait` for `fn(isize, u8, Vec<u32>) {f}`
  --> ./t.rs:8:9
   |
8  | impl<F> Trait for F where F: Fn(usize, u8, Vec<u64>) -> u8 {}
   |         ^^^^^     ^
   = note: required for the cast to the object type `dyn Trait`
```

</td>
</tr>
</table>

<details><summary>code</summary>
<p>

```rust
fn main() {
    fn expect(_: &dyn Trait) {}

    expect(&f);
}

trait Trait {}
impl<F> Trait for F where F: Fn(usize, u8, Vec<u64>) -> u8 {}

fn f(_: isize, _: u8, _: Vec<u32>) {}
```

</p>
</details>

r? `@compiler-errors`
2022-07-30 20:39:47 +05:30
Dylan DPC
c668820365
Rollup merge of #99311 - kckeiks:clean-up-body-owner-methods, r=cjgillot
change maybe_body_owned_by to take local def id

Issue https://github.com/rust-lang/rust/issues/96341
r? `@cjgillot`
2022-07-30 20:39:46 +05:30
bors
110777b60c Auto merge of #99796 - compiler-errors:issue-53475, r=oli-obk
use `check_region_obligations_and_report_errors` to avoid ICEs

If we don't call `process_registered_region_obligations` before `resolve_regions_and_report_errors` then we'll ICE if we have any region obligations, and `check_region_obligations_and_report_errors` just does both of these for us in a nice convenient function.

Fixes #53475

r? types
2022-07-30 09:35:22 +00:00
Yuki Okushi
4a44efae14
Rollup merge of #99671 - TaKO8Ki:suggest-dereferencing-index, r=compiler-errors
Suggest dereferencing index when trying to use a reference of usize as index

fixes #96678
2022-07-30 07:39:50 +09:00
Miguel Guarniz
16513d689e Rename local_did to def_id
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:26:10 -04:00
Miguel Guarniz
25bdc8965e Change maybe_body_owned_by to take local def id
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-29 18:25:58 -04:00
lcnr
2634309eb3 update comment 2022-07-29 09:44:20 +02:00