Commit Graph

222 Commits

Author SHA1 Message Date
Camille GILLOT
5fc261e9a0 Inherit generics for impl-trait. 2022-11-12 09:59:36 +00:00
Camille GILLOT
b95650930b Compute variance for opaques too. 2022-11-12 09:56:23 +00:00
bors
825f8edc2f Auto merge of #103530 - cjgillot:hir-lifetimes-direct, r=estebank
Resolve lifetimes independently for each item-like.

Now that the heavy-lifting is done on the AST and during lowering, we do not need to perform HIR lifetime resolution on a full item at once.  Instead, we can treat each item-like independently, and look at `generics_of` the parent exceptionally for associated items.
2022-11-12 05:22:17 +00:00
Camille GILLOT
6c95805a34 Clean-up formatting. 2022-11-11 10:32:49 +00:00
Camille GILLOT
60892e8b1d Visit opaque types during type collection too. 2022-11-11 10:29:27 +00:00
Camille GILLOT
3075f03513 Resolve lifetimes using the regular logic for RPIT. 2022-11-11 10:12:28 +00:00
Camille GILLOT
44c10e4cb0 Resolve lifetimes independently for each item-like. 2022-11-11 10:11:50 +00:00
Camille GILLOT
0ff1d1e122 Tweak signatures in rustc_middle::hir::map. 2022-11-11 10:10:16 +00:00
Ben Reeves
fe53cacff9 Apply PR feedback. 2022-11-10 12:56:33 -06:00
Ben Reeves
c0ae62ee95 Require ~const qualifier on trait bounds in specializing impls if present in base impl. 2022-11-10 12:37:07 -06:00
Ben Reeves
ce03d259da Disallow specializing on const impls with non-const impls. 2022-11-10 12:37:06 -06:00
Ben Reeves
5c25d30f6f Allow specialized const trait impls.
Fixes #95186.
Fixes #95187.
2022-11-10 12:37:06 -06:00
Manish Goregaokar
a709cc1f32
Rollup merge of #104156 - oli-obk:autoderef, r=estebank
Cleanups in autoderef impl

Just something I noticed. Turns out the `overloaded_span` is not actually used separately from the main span, so I merged them.
2022-11-09 15:39:06 -05:00
bors
cc9b259b5e Auto merge of #103723 - CastilloDel:master, r=jackh726
Remove allow(rustc::potential_query_instability) in rustc_trait_selection

Related to https://github.com/rust-lang/rust/issues/84447

This PR needs to be benchmarked to check for regressions.
2022-11-09 13:45:27 +00:00
bors
91385d5776 Auto merge of #104179 - Manishearth:rollup-yvsx5hh, r=Manishearth
Rollup of 7 pull requests

Successful merges:

 - #100508 (avoid making substs of type aliases late bound when used as fn args)
 - #101381 (Test that target feature mix up with homogeneous floats is sound)
 - #103353 (Fix Access Violation when using lld & ThinLTO on windows-msvc)
 - #103521 (Avoid possible infinite  loop when next_point reaching the end of file)
 - #103559 (first move on a nested span_label)
 - #103778 (Update several crates for improved support of the new targets)
 - #103827 (Properly remap and check for substs compatibility in `confirm_impl_trait_in_trait_candidate`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-11-09 04:43:43 +00:00
Manish Goregaokar
f162e3a1b1
Rollup merge of #100508 - BoxyUwU:make_less_things_late_bound, r=nikomatsakis
avoid making substs of type aliases late bound when used as fn args

fixes #47511
fixes #85533
(although I did not know theses issues existed when i was working on this 🙃)

currently `Alias<...>` is treated the same as `Struct<...>` when deciding if generics should be late bound or early bound but this is not correct as `Alias` might normalize to a projection which does not constrain the generics.

I think this needs more tests before merging
more explanation of PR [here](https://hackmd.io/v44a-QVjTIqqhK9uretyQg?view)

Hackmd inline for future readers:
---

This assumes reader is familiar with the concept of early/late bound lifetimes. There's a section on rustc-dev-guide if not (although i think some details are a bit out of date)

## problem & background

Not all lifetimes on a fn can be late bound:
```rust
fn foo<'a>() -> &'a ();
impl<'a> Fn<()> for FooFnDef {
    type Output = &'a (); // uh oh unconstrained lifetime
}
```
so we make make them early bound
```rust
fn foo<'a>() -> &'a ();
impl<'a> Fn<()> for FooFnDef<'a> {// wow look at all that lifetimey
     type Output = &'a ();
}
```
(Closures have the same constraint however it is not enforced leading to soundness bugs, [#84385](https://github.com/rust-lang/rust/pull/84385) implements this "downgrading late bound to early bound" for closures)

lifetimes on fn items are only late bound when they are "constrained" by the fn args:
```rust
fn foo<'a>(_: &'a ()) -> &'a ();
//               late bound, not present on `FooFnItem`
//               vv
impl<'a> Trait<(&'a (),)> for FooFnItem {
    type Output = &'a ();
}

// projections do not constrain inputs
fn bar<'a, T: Trait>(_: <T as Trait<'a>>::Assoc) -> &'a (); //  early bound
                                                            //  vv
impl<'a, T: Trait> Fn<(<T as Trait<'a>>::Assoc,)> for BarFnItem<'a, T> {
    type Output = &'a ();
}
```

current logic for determining if inputs "constrain" a lifetime works off of HIR so does not normalize aliases. It also assumes that any path with no self type constrains all its substs (i.e. `Foo<'a, u32>` has no self type but `T::Assoc` does). This falls apart for top level type aliases (see linked issues):

```rust
type Alias<'a, T> = <T as Trait<'a>>::Assoc;
//                      wow look its a path with no self type uwu
//                      i bet that constrains `'a` so it should be latebound
//                      vvvvvvvvvvv
fn foo<'a, T: Trait>(_: Alias<'a, T>) -> &'a ();
//                     `Alias` normalized to make things clearer
//                     vvvvvvvvvvvvvvvvvvvvvvv
impl<'a, T: Trait> Fn<(<T as Trait<'a>>::Assoc,)> for FooFnDef<T> {
    type Output = &'a ();
    // oh no `'a` isnt constrained wah wah waaaah *trumbone noises*
    // i think, idk what musical instrument that is
}
```

## solution

The PR solves this by having the hir visitor that checks for lifetimes in constraining uses check if the path is a `DefKind::Alias`. If it is we ""normalize"" it by calling `type_of` and walking the returned type. This is a bit hacky as it requires a mapping between the substs on the path in hir, and the generics of the `type Alias<...>` which is on the ty layer.

Alternative solutions may involve calculating the "late boundness" of lifetimes after/during astconv rather than relying on hir at all. We already have code to determine whether a lifetime SHOULD be late bound or not as this is currently how the error for `fn foo<'a, T: Trait>(_: Alias<'a, T>) -> &'a ();` gets emitted.

It is probably not possible to do this right now, late boundness is used by `generics_of` and `gather_explicit_predicates_of` as we currently do not put late bound lifetimes in `Generics`. Although this seems sus to me as the long term goal is to make all generics late bound which would result in `generics_of(function)` being empty? [#103448](https://github.com/rust-lang/rust/pull/103448) places all lifetimes in `Generics` regardless of late boundness so that may be a good step towards making this possible.
2022-11-08 21:03:51 -05:00
bors
bc2504a83c Auto merge of #103171 - jackh726:gen-interior-hrtb-error, r=cjgillot
Better error for HRTB error from generator interior

cc #100013

This is just a first pass at an error. It could be better, and shouldn't really be emitted in the first place. But this is better than what was being emitted before.
2022-11-09 02:02:28 +00:00
Boxy
49be827dca comment 2022-11-08 21:59:58 +00:00
CastilloDel
755ca4b9aa Reduce the scope of allow(rustc::potential_query_instability) in rustc_trait_selection
Make InferCtxtExt use a FxIndexMap

This should be faster, because the map is only being used to iterate,
which is supposed to be faster with the IndexMap

Make the user_computed_preds use an IndexMap

It is being used mostly for iteration, so the change shouldn't result in
a perf hit

Make the RegionDeps fields use an IndexMap

This change could be a perf hit. Both `larger` and `smaller` are used
for iteration, but they are also used for insertions.

Make types_without_default_bounds use an IndexMap

It uses extend, but it also iterates and removes items. Not sure if
this will be a perf hit.

Make InferTtxt.reported_trait_errors use an IndexMap

This change brought a lot of other changes. The map seems to have been
mostly used for iteration, so the performance shouldn't suffer.

Add FIXME to change ProvisionalEvaluationCache.map to use an IndexMap

Right now this results in a perf hit. IndexMap doesn't have
the `drain_filter` API, so in `on_completion` we now need to iterate two
times over the map.
2022-11-08 19:41:48 +01:00
Oli Scherer
1d93b35855 Remove overloaded_span argument from new, where it is usually redundant with the main span 2022-11-08 15:49:29 +00:00
Dylan DPC
c23068c8c6
Rollup merge of #104094 - lcnr:on_unimplemented-move, r=wesleywiser
fully move `on_unimplemented` to `error_reporting`

the `traits` module has a few too many submodules in my opinion.
2022-11-08 11:23:53 +05:30
Dylan DPC
77a44ab568
Rollup merge of #103865 - compiler-errors:fallback-has-occurred-tracking, r=eholk
Move `fallback_has_occurred` state tracking to `FnCtxt`

Removes a ton of callsites that defaulted to `false`
2022-11-08 11:23:51 +05:30
yukang
1f21b96dce add 'ty_error_with_guaranteed' and 'const_error_with_guaranteed' 2022-11-08 11:17:46 +08:00
Jack Huey
00e314d5ed Add an optional Span to BrAnon and use it to print better error for HRTB error from generator interior 2022-11-07 17:39:29 -05:00
lcnr
80e4e72fcd fully move on_unimplemented to error reporting 2022-11-07 08:10:25 +01:00
bors
7eef946fc0 Auto merge of #99943 - compiler-errors:tuple-trait, r=jackh726
Implement `std::marker::Tuple`, use it in `extern "rust-call"` and `Fn`-family traits

Implements rust-lang/compiler-team#537

I made a few opinionated decisions in this implementation, specifically:
1. Enforcing `extern "rust-call"` on fn items during wfcheck,
2. Enforcing this for all functions (not just ones that have bodies),
3. Gating this `Tuple` marker trait behind its own feature, instead of grouping it into (e.g.) `unboxed_closures`.

Still needing to be done:
1. Enforce that `extern "rust-call"` `fn`-ptrs are well-formed only if they have 1/2 args and the second one implements `Tuple`. (Doing this would fix ICE in #66696.)
2. Deny all explicit/user `impl`s of the `Tuple` trait, kinda like `Sized`.
3. Fixing `Tuple` trait built-in impl for chalk, so that chalkification tests are un-broken.

Open questions:
1. Does this need t-lang or t-libs signoff?

Fixes #99820
2022-11-06 17:48:33 +00:00
Boxy
c0889a6005 fixyfixfix 2022-11-06 13:39:18 +00:00
Michael Goulet
bc345d7bd0 Move fallback_has_occurred to FnCtxt 2022-11-06 02:40:25 +00:00
Michael Goulet
2257ba92db Adjust diagnostics, bless tests 2022-11-05 18:05:44 +00:00
Michael Goulet
99b3454d37 Enforce rust-check ABI in signatures, calls 2022-11-05 18:05:25 +00:00
Matthias Krüger
cf2d88db38
Rollup merge of #103972 - oli-obk:unoptional, r=fee1-dead
Remove an option and choose a behaviour-preserving default instead.

r? ``@fee1-dead``
2022-11-05 18:06:07 +01:00
Dylan DPC
3450aa38d0
Rollup merge of #103621 - fee1-dead-contrib:iat-fix-use, r=cjgillot
Correctly resolve Inherent Associated Types

I don't know if this is the best way to do this, but at least it is one way.
2022-11-05 11:31:28 +05:30
Mateusz
c97fd8183a
Refactor tcx mk_const parameters. 2022-11-04 20:33:32 +00:00
Oli Scherer
a2325fe3a9 Remove an option and choose a behaviour-preserving default instead. 2022-11-04 16:28:01 +00:00
Matthias Krüger
d10187f040
Rollup merge of #103780 - compiler-errors:bound-closure-lifetimes, r=jackh726
Fix late-bound lifetime closure ICEs in HIR typeck and MIR borrowck

During HIR typeck, we need to teach astconv to treat late-bound regions within a closure body as free, fixing escaping bound vars ICEs in both of the issues below.

However, this then gets us to MIR borrowck, which itself needs to be taught how to instantiate free region vids for late-bound regions that come from items that _aren't_ the typeck root (for now, just closures).

Fixes #103771
Fixes #103736
2022-11-04 12:18:01 +01:00
Matthias Krüger
61c6cdb5f4
Rollup merge of #103915 - chenyukang:yukang/fix-103874, r=lcnr
Improve use of ErrorGuaranteed and code cleanup

Part of #103874
2022-11-04 06:40:32 +01:00
Deadbeef
30b6fe37a6 Correctly resolve Inherent Associated Types 2022-11-03 15:09:02 +00:00
Matthias Krüger
bb201b5d95
Rollup merge of #103875 - oli-obk:ast_conv_simplification, r=spastorino
Simplify astconv item def id handling
2022-11-02 22:06:28 +01:00
Matthias Krüger
5784a038fb
Rollup merge of #103870 - TaKO8Ki:fix-103790, r=fee1-dead
Fix `inferred_kind` ICE

Fixes #103790
2022-11-02 22:06:27 +01:00
Matthias Krüger
214d6b6836
Rollup merge of #99801 - Neo-Zhixing:fix/generic_const_exprs_parent_opaque_predicates, r=oli-obk
fix(generic_const_exprs): Fix predicate inheritance for children of opaque types

Fixes #99705

We currently have a special case to perform predicate inheritance when the const item is in the generics. I think we're also going to need this for opaque return types. When evaluating the predicates applied to the associated item, it'll inherit from its parent, the opaque type, which will never have predicates applied. This PR bypass the opaque typed parent and inherit predicates directly from the function itself.
2022-11-02 22:06:26 +01:00
yukang
ab22f5521b change error_reported to use Result instead of an option 2022-11-03 04:57:44 +08:00
Oli Scherer
ecea616052 Simplify astconv item def id handling 2022-11-02 12:03:59 +00:00
Takayuki Maeda
b96ad1c096 return const_error when ty has errors 2022-11-02 14:47:48 +09:00
Manish Goregaokar
69e705564d
Rollup merge of #103575 - Xiretza:suggestions-style-attr, r=davidtwco
Change #[suggestion_*] attributes to use style="..."

As discussed [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20tool_only_span_suggestion), this changes `#[(multipart_)suggestion_{short,verbose,hidden}(...)]` attributes to plain `#[(multipart_)suggestion(...)]` attributes with a `style = "{short,verbose,hidden}"` parameter.

It also adds a new style, `tool-only`, that corresponds to `tool_only_span_suggestion`/`tool_only_multipart_suggestion` and causes the suggestion to not be shown in human-readable output at all.

Best reviewed commit-by-commit, there's a bit of noise in there.

cc #100717 `@compiler-errors`
r? `@davidtwco`
2022-11-01 20:00:38 -04:00
Zhixing Zhang
744fa610eb fix(generic_const_exprs): Fix predicate inheritance for children of opaque types 2022-11-01 15:41:16 -07:00
bors
11ebe6512b Auto merge of #103217 - mejrs:track, r=eholk
Track where diagnostics were created.

This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`.

For example, the following code...

```rust
struct A;
struct B;

fn main(){
    let _: A = B;
}
```
...now emits the following error message:

```
error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31
```
2022-11-01 21:09:45 +00:00
bors
e70cbef0c5 Auto merge of #103590 - compiler-errors:ocx-more, r=lcnr
(almost) Always use `ObligationCtxt` when dealing with canonical queries

Hope this is a step in the right direction. cc rust-lang/types-team#50.

r? `@lcnr`
2022-11-01 12:15:10 +00:00
Dylan DPC
09f4f7c8f0
Rollup merge of #103759 - cjgillot:adt-collect, r=davidtwco
Use `adt_def` during type collection.

This removes a wrapper which is close to what `adt_def` does.
2022-11-01 14:12:27 +05:30
mejrs
cbeb244b05 Add more track_caller 2022-10-31 16:14:29 +01:00
Camille GILLOT
abc1ad7106 Use AdtDef to check enum. 2022-10-31 11:21:46 +00:00