Commit graph

614 commits

Author SHA1 Message Date
bors
feac2ecf1c Auto merge of #94088 - oli-obk:revert, r=jackh726
Revert #91403

fixes #94004

r? `@pnkfelix` `@cjgillot`
2022-02-18 07:35:37 +00:00
Matthias Krüger
637d8b89e8
Rollup merge of #94011 - est31:let_else, r=lcnr
Even more let_else adoptions

Continuation of #89933, #91018, #91481, #93046, #93590.
2022-02-17 23:00:59 +01:00
Jack Huey
3d19c8defd Suggest copying trait associated type bounds on lifetime error 2022-02-17 14:09:21 -05:00
Oli Scherer
86d17b98f2 Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"
This reverts commit 3cfa4def7c, reversing
changes made to 5d8767cb22.
2022-02-17 16:00:04 +00:00
est31
60f969a4f2 Adopt let_else in even more places 2022-02-16 22:43:39 +01:00
lcnr
1b7c3bcef9 allow special behavior when printing const infer 2022-02-16 13:37:56 +01:00
Tomasz Miąsko
cd37638c14 Inline UnifyKey::index and UnifyKey::from_index 2022-02-15 19:07:06 +01:00
Nicholas Nethercote
a95fb8b150 Overhaul Const.
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as
this:
```
pub struct Const<'tcx>(&'tcx Interned<ConstS>);
```
This now matches `Ty` and `Predicate` more closely, including using
pointer-based `eq` and `hash`.

Notable changes:
- `mk_const` now takes a `ConstS`.
- `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a
  we need separate arena for it, because we can't use the `Dropless` one any
  more.
- Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes
- Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes.
- Lots of tedious sigil fiddling.
2022-02-15 16:19:59 +11:00
Nicholas Nethercote
7eb15509ce Remove unnecessary RegionKind:: quals.
The variant names are exported, so we can use them directly (possibly
with a `ty::` qualifier). Lots of places already do this, this commit
just increases consistency.
2022-02-15 16:14:24 +11:00
Nicholas Nethercote
7024dc523a Overhaul RegionKind and Region.
Specifically, change `Region` from this:
```
pub type Region<'tcx> = &'tcx RegionKind;
```
to this:
```
pub struct Region<'tcx>(&'tcx Interned<RegionKind>);
```

This now matches `Ty` and `Predicate` more closely.

Things to note
- Regions have always been interned, but we haven't been using pointer-based
  `Eq` and `Hash`. This is now happening.
- I chose to impl `Deref` for `Region` because it makes pattern matching a lot
  nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`.
- Various methods are moved from `RegionKind` to `Region`.
- There is a lot of tedious sigil changes.
- A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a
  `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`.
- A couple of test outputs change slightly, I'm not sure why, but the new
  outputs are a little better.
2022-02-15 16:08:52 +11:00
Nicholas Nethercote
e9a0c429c5 Overhaul TyS and Ty.
Specifically, change `Ty` from this:
```
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
```
to this
```
pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>);
```
There are two benefits to this.
- It's now a first class type, so we can define methods on it. This
  means we can move a lot of methods away from `TyS`, leaving `TyS` as a
  barely-used type, which is appropriate given that it's not meant to
  be used directly.
- The uniqueness requirement is now explicit, via the `Interned` type.
  E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather
  than via `TyS`, which wasn't obvious at all.

Much of this commit is boring churn. The interesting changes are in
these files:
- compiler/rustc_middle/src/arena.rs
- compiler/rustc_middle/src/mir/visit.rs
- compiler/rustc_middle/src/ty/context.rs
- compiler/rustc_middle/src/ty/mod.rs

Specifically:
- Most mentions of `TyS` are removed. It's very much a dumb struct now;
  `Ty` has all the smarts.
- `TyS` now has `crate` visibility instead of `pub`.
- `TyS::make_for_test` is removed in favour of the static `BOOL_TY`,
  which just works better with the new structure.
- The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls
  of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned`
  (pointer-based, for the `Equal` case) and partly on `TyS`
  (contents-based, for the other cases).
- There are many tedious sigil adjustments, i.e. adding or removing `*`
  or `&`. They seem to be unavoidable.
2022-02-15 16:03:24 +11:00
Santiago Pastorino
3c7fa0bcf3
reveal_defining_opaque_types field doesn't exist after rebase 2022-02-14 13:02:22 -03:00
Santiago Pastorino
f4bb4500dd
Call the method fork instead of clone and add proper comments 2022-02-14 12:57:20 -03:00
bors
b321742c6c Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnr
Make `Res::SelfTy` a struct variant and update docs

I found pattern matching on a `(Option<DefId>, Option<(DefId, bool)>)` to not be super readable, additionally the doc comments on the types in a tuple variant aren't visible anywhere at use sites as far as I can tell (using rust analyzer + vscode)

The docs incorrectly assumed that the `DefId` in `Option<(DefId, bool)>` would only ever be for an impl item and I also found the code examples to be somewhat unclear about which `DefId` was being talked about.

r? `@lcnr` since you reviewed the last PR changing these docs
2022-02-14 12:26:43 +00:00
Matthias Krüger
aff74a1697
Rollup merge of #93810 - matthewjasper:chalk-and-canonical-universes, r=jackh726
Improve chalk integration

- Support subtype bounds in chalk lowering
- Handle universes in canonicalization
- Handle type parameters in chalk responses
- Use `chalk_ir::LifetimeData::Empty` for `ty::ReEmpty`
- Remove `ignore-compare-mode-chalk` for tests that no longer hang (they may still fail or ICE)

This is enough to get a hello world program to compile with `-Zchalk` now. Some of the remaining issues that are needed to get Chalk integration working on larger programs are:

- rust-lang/chalk#234
- rust-lang/chalk#548
- rust-lang/chalk#734
- Generators are handled differently in chalk and rustc

r? `@jackh726`
2022-02-13 06:44:14 +01:00
Matthew Jasper
030c50824c Address review comment
canonicalize_chalk_query -> canonicalize_query_preserving_universes
2022-02-12 13:39:52 +00:00
Ellen
e81e09a24e change to a struct variant 2022-02-12 11:23:53 +00:00
Camille GILLOT
a4da6308b7 Inherit lifetimes for async fn instead of duplicating them. 2022-02-12 01:26:11 +01:00
Matthew Jasper
caa10dc572 Renumber universes when canonicalizing for Chalk
This is required to avoid creating large numbers of universes from each
Chalk query, while still having enough universe information for lifetime
errors.
2022-02-11 21:38:17 +00:00
bors
6499c5e7fc Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk
Revert lazy TAIT PR

Revert https://github.com/rust-lang/rust/pull/92306 (sorry `@Aaron1011,` will include your changes in the fix PR)
Revert https://github.com/rust-lang/rust/pull/93783
Revert https://github.com/rust-lang/rust/pull/92007

fixes https://github.com/rust-lang/rust/issues/93788
fixes https://github.com/rust-lang/rust/issues/93794
fixes https://github.com/rust-lang/rust/issues/93821
fixes https://github.com/rust-lang/rust/issues/93831
fixes https://github.com/rust-lang/rust/issues/93841
2022-02-11 17:39:34 +00:00
Oli Scherer
d54195db22 Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"
This reverts commit e7cc3bddbe, reversing
changes made to 734368a200.
2022-02-11 07:18:06 +00:00
Oli Scherer
2d8b8f3593 Revert "Auto merge of #92306 - Aaron1011:opaque-type-op, r=oli-obk"
This reverts commit 1f0a96862a, reversing
changes made to bf242bb119.
2022-02-11 07:17:16 +00:00
Michael Goulet
784c7a6cad only mark projection as ambiguous if GAT substs are constrained 2022-02-10 22:55:00 -08:00
Frank Steffahn
7eff2feb62 Remove further usage of &hir::Map 2022-02-10 13:04:59 +01:00
bors
1f0a96862a Auto merge of #92306 - Aaron1011:opaque-type-op, r=oli-obk
Improve opaque type higher-ranked region error message under NLL

Currently, any higher-ranked region errors involving opaque types
fall back to a generic "higher-ranked subtype error" message when
run under NLL. This PR adds better error message handling for this
case, giving us the same kinds of error messages that we currently
get without NLL:

```
error: implementation of `MyTrait` is not general enough
  --> $DIR/opaque-hrtb.rs:12:13
   |
LL | fn foo() -> impl for<'a> MyTrait<&'a str> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `MyTrait` is not general enough
   |
   = note: `impl MyTrait<&'2 str>` must implement `MyTrait<&'1 str>`, for any lifetime `'1`...
   = note: ...but it actually implements `MyTrait<&'2 str>`, for some specific lifetime `'2`

error: aborting due to previous error
```

To accomplish this, several different refactoring needed to be made:

* We now have a dedicated `InstantiateOpaqueType` struct which
implements `TypeOp`. This is used to invoke `instantiate_opaque_types`
during MIR type checking.
* `TypeOp` is refactored to pass around a `MirBorrowckCtxt`, which is
needed to report opaque type region errors.
* We no longer assume that all `TypeOp`s correspond to canonicalized
queries. This allows us to properly handle opaque type instantiation
(which does not occur in a query) as a `TypeOp`.
A new `ErrorInfo` associated type is used to determine what
additional information is used during higher-ranked region error
handling.
* The body of `try_extract_error_from_fulfill_cx`
has been moved out to a new function `try_extract_error_from_region_constraints`.
This allows us to re-use the same error reporting code between
canonicalized queries (which can extract region constraints directly
from a fresh `InferCtxt`) and opaque type handling (which needs to take
region constraints from the pre-existing `InferCtxt` that we use
throughout MIR borrow checking).
2022-02-09 09:41:48 +00:00
Aaron Hill
48a48fd1b8
Improve opaque type higher-ranked region error message under NLL
Currently, any higher-ranked region errors involving opaque types
fall back to a generic "higher-ranked subtype error" message when
run under NLL. This PR adds better error message handling for this
case, giving us the same kinds of error messages that we currently
get without NLL:

```
error: implementation of `MyTrait` is not general enough
  --> $DIR/opaque-hrtb.rs:12:13
   |
LL | fn foo() -> impl for<'a> MyTrait<&'a str> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `MyTrait` is not general enough
   |
   = note: `impl MyTrait<&'2 str>` must implement `MyTrait<&'1 str>`, for any lifetime `'1`...
   = note: ...but it actually implements `MyTrait<&'2 str>`, for some specific lifetime `'2`

error: aborting due to previous error
```

To accomplish this, several different refactoring needed to be made:

* We now have a dedicated `InstantiateOpaqueType` struct which
implements `TypeOp`. This is used to invoke `instantiate_opaque_types`
during MIR type checking.
* `TypeOp` is refactored to pass around a `MirBorrowckCtxt`, which is
needed to report opaque type region errors.
* We no longer assume that all `TypeOp`s correspond to canonicalized
queries. This allows us to properly handle opaque type instantiation
(which does not occur in a query) as a `TypeOp`.
A new `ErrorInfo` associated type is used to determine what
additional information is used during higher-ranked region error
handling.
* The body of `try_extract_error_from_fulfill_cx`
has been moved out to a new function `try_extract_error_from_region_constraints`.
This allows us to re-use the same error reporting code between
canonicalized queries (which can extract region constraints directly
from a fresh `InferCtxt`) and opaque type handling (which needs to take
region constraints from the pre-existing `InferCtxt` that we use
throughout MIR borrow checking).
2022-02-08 12:35:42 -05:00
Matthias Krüger
8429dcdb79
Rollup merge of #92715 - chordtoll:empty-string, r=davidtwco
Do not suggest char literal for zero-length strings

PR #92507 adds a hint to switch to single quotes when a char is expected and a single-character string literal is provided.

The check to ensure the string literal is one character long missed the 0-char case, and would incorrectly offer the hint.

This PR adds the missing check, and a test case to confirm the new behavior.
2022-02-08 16:40:47 +01:00
Matthias Krüger
25ce315c76
Rollup merge of #93728 - JulianKnodt:toterm, r=oli-obk
Add in ValuePair::Term

This adds in an enum when matching on positions which can either be types or consts.
It will default to emitting old special cased error messages for types.

r? `@oli-obk`
cc `@matthiaskrgr`
Fixes #93578
2022-02-08 06:47:38 +01:00
bors
e7cc3bddbe Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis
Lazy type-alias-impl-trait

Previously opaque types were processed by

1. replacing all mentions of them with inference variables
2. memorizing these inference variables in a side-table
3. at the end of typeck, resolve the inference variables in the side table and use the resolved type as the hidden type of the opaque type

This worked okayish for `impl Trait` in return position, but required lots of roundabout type inference hacks and processing.

This PR instead stops this process of replacing opaque types with inference variables, and just keeps the opaque types around.
Whenever an opaque type `O` is compared with another type `T`, we make the comparison succeed and record `T` as the hidden type. If `O` is compared to `U` while there is a recorded hidden type for it, we grab the recorded type (`T`) and compare that against `U`. This makes implementing

* https://github.com/rust-lang/rfcs/pull/2515

much simpler (previous attempts on the inference based scheme were very prone to ICEs and general misbehaviour that was not explainable except by random implementation defined oddities).

r? `@nikomatsakis`

fixes #93411
fixes #88236
2022-02-07 23:40:26 +00:00
kadmin
be236d7fc2 Rm ValuePairs::Ty/Const
Remove old value pairs which is a strict subset of Terms.
2022-02-07 16:42:37 +00:00
Mara Bos
557d300e1b
Rollup merge of #91530 - bobrippling:suggest-1-tuple-parens, r=camelid
Suggest 1-tuple parentheses on exprs without existing parens

A follow-on from #86116, split out from #90677.

This alters the suggestion to add a trailing comma to create a 1-tuple - previously we would only apply this if the relevant expression was parenthesised. We now make the suggestion regardless of parentheses, which reduces the fragility of the check (w.r.t formatting).

e.g.
```rust
let a: Option<(i32,)> = Some(3);
```

gets the below suggestion:

```rust
let a: Option<(i32,)> = Some((3,));
//                           ^ ^^
```

This change also improves the suggestion in other ways, such as by only making the suggestion if the types would match after the suggestion is applied and making the suggestion a multipart suggestion.
2022-02-07 14:08:31 +00:00
kadmin
fdd6f4e56c Add in ValuePair::Term
This adds in an enum when matching on positions which can either be types or consts.
It will default to emitting old special cased error messages for types.
2022-02-07 05:53:22 +00:00
Rob Pilling
82a012299d Merge duplicate suggestion string 2022-02-06 20:58:24 +00:00
Rob Pilling
344ea6e0e5 Factor out emit_tuple_wrap_err, improve Applicability 2022-02-06 20:58:24 +00:00
Oli Scherer
d526a8d594 Clean up opaque type obligations in query results 2022-02-03 13:44:29 +00:00
Oli Scherer
be153f0976 Only prevent TAITs from defining each other, RPIT and async are fine, they only ever have one defining site, and it is ordered correctly around expected and actual type in type comparisons 2022-02-02 15:40:12 +00:00
Oli Scherer
7f608eb9ed Prevent two opaque types in their defining scopes from being defined via the other 2022-02-02 15:40:12 +00:00
Oli Scherer
ee2158f1ee run rustfmt 2022-02-02 15:40:12 +00:00
Oli Scherer
d8c29b3e28 Simplify diff 2022-02-02 15:40:11 +00:00
Oli Scherer
dbda675419 Undo a diff 2022-02-02 15:40:11 +00:00
Oli Scherer
b45fabddfd Inline a function that is only used once 2022-02-02 15:40:11 +00:00
Oli Scherer
d35d1ef4f5 Remove unnecessary field 2022-02-02 15:40:11 +00:00
Oli Scherer
5b49b8e2d5 Remove unnecessary closure in favour of just passing the argument directly 2022-02-02 15:40:11 +00:00
Oli Scherer
fcba8d31c4 Remove the Instantiator now that we don't recurse within it anymore 2022-02-02 15:40:11 +00:00
Oli Scherer
e03edd287e Inline a function that is only ever used in one place 2022-02-02 15:40:11 +00:00
Oli Scherer
edaf9625fb Clean up leftovers from eager hidden type merging 2022-02-02 15:40:11 +00:00
Oli Scherer
38f50d1ecb Eagerly merge hidden types. 2022-02-02 15:40:11 +00:00
Oli Scherer
a745797142 Stop generating inference vars for nested impl trait and let type equality handle it.
This means we stop supporting the case where a locally defined trait has only a single impl so we can always use that impl (see nested-tait-inference.rs).
2022-02-02 15:40:11 +00:00
Oli Scherer
7bce50c01a Register member constraints on the final merged hidden type
Previously we did this per hidden type candiate, which didn't always have all the information available.
2022-02-02 15:40:11 +00:00
Oli Scherer
0f6e06b7c0 Lazily resolve type-alias-impl-trait defining uses
by using an opaque type obligation to bubble up comparisons between opaque types and other types

Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-02-02 15:40:11 +00:00
Oli Scherer
8d2b598459 More sanity checks 2022-02-02 15:40:10 +00:00
Oli Scherer
f7abc1b6f8 Expose current span to type equality checking in nll 2022-02-02 15:40:10 +00:00
Oli Scherer
a4c1cec4f8 Add some sanity assertions to make sure we use the opaque types correctly 2022-02-02 15:40:10 +00:00
Oli Scherer
d49b0746f6 Add roll back infrastructure for opaque type caches 2022-02-02 15:40:10 +00:00
bors
1ea4851715 Auto merge of #93285 - JulianKnodt:const_eq_2, r=oli-obk
Continue work on associated const equality

This actually implements some more complex logic for assigning associated consts to values.
Inside of projection candidates, it now defers to a separate function for either consts or
types. To reduce amount of code, projections are now generic over T, where T is either a Type or
a Const. I can add some comments back later, but this was the fastest way to implement it.

It also now finds the correct type of consts in type_of.

---

The current main TODO is finding the const of the def id for the LeafDef.

Right now it works if the function isn't called, but once you use the trait impl with the bound it fails inside projection.
I was hoping to get some help in getting the `&'tcx ty::Const<'tcx>`, in addition to a bunch of other `todo!()`s which I think may not be hit.

r? `@oli-obk`

Updates #92827
2022-02-01 23:18:01 +00:00
kadmin
78fb74a600 Fix w/ comments 2022-02-01 20:19:54 +00:00
lcnr
a1a30f7548 add a rustc::query_stability lint 2022-02-01 10:15:59 +01:00
kadmin
c654e4d6f4 Add ValuePairs::Terms & Fix compile error
And use correct substs.
2022-01-31 18:30:33 +00:00
Matthias Krüger
6749f32c33
Rollup merge of #90277 - pierwill:fix-70258-inference-terms, r=jackh726
Improve terminology around "after typeck"

Closes #70258.
2022-01-31 06:58:26 +01:00
Rob Pilling
91a43f0423 Only suggest 1-tuple if expected and found types match 2022-01-28 23:43:47 +00:00
Rob Pilling
18cea90d4a Handle existing parentheses when suggesting trailing-tuple-comma 2022-01-28 23:42:30 +00:00
Rob Pilling
c734c32776 Replace span suggestion with multipart 2022-01-28 23:17:57 +00:00
Rob Pilling
4738ce463e Suggest 1-tuple parentheses, without existing parens 2022-01-28 22:44:06 +00:00
kadmin
bd03d8167f Remove generalization over projection
Instead, just use a term everywhere.
2022-01-28 00:25:36 +00:00
Michael Goulet
c6f6e3e0e9 do not register infer var for GAT projection in opaque 2022-01-26 22:45:12 -08:00
bors
8cdb3cd94e Auto merge of #93095 - Aaron1011:remove-assoc-ident, r=cjgillot
Store a `Symbol` instead of an `Ident` in `AssocItem`

This is the same idea as #92533, but for `AssocItem` instead
of `VariantDef`/`FieldDef`.

With this change, we no longer have any uses of
`#[stable_hasher(project(...))]`
2022-01-25 18:53:45 +00:00
Cameron Steffen
b11733534d Remove a span from hir::ExprKind::MethodCall 2022-01-21 07:48:10 -06:00
Aaron Hill
c8941d3e48
Store a Symbol instead of an Ident in AssocItem
This is the same idea as #92533, but for `AssocItem` instead
of `VariantDef`/`FieldDef`.

With this change, we no longer have any uses of
`#[stable_hasher(project(...))]`
2022-01-19 17:13:21 -05:00
Tyler Mandry
698631e16c Simplify error reporting code, remove await point wording 2022-01-19 21:33:57 +00:00
Tyler Mandry
5c15ad7fca NiceRegionError: Use written return type for async fn 2022-01-19 21:33:57 +00:00
Tyler Mandry
6487845884 Properly account for binders in get_impl_future_output_ty 2022-01-19 21:33:57 +00:00
bors
7bc7be860f Auto merge of #87648 - JulianKnodt:const_eq_constrain, r=oli-obk
allow eq constraints on associated constants

Updates #70256

(cc `@varkor,` `@Centril)`
2022-01-18 09:58:39 +00:00
Matthias Krüger
cb5ecff8b2
Rollup merge of #92640 - compiler-errors:array-deref-on-newtype, r=lcnr
Fix ICEs related to `Deref<Target=[T; N]>` on newtypes

1. Stash a const infer's type into the canonical var during canonicalization, so we can recreate the fresh const infer with that same type.
    For example, given `[T; _]` we know `_` is a `usize`. If we go from infer => canonical => infer, we shouldn't forget that variable is a usize.
Fixes #92626
Fixes #83704

2. Don't stash the autoderef'd slice type that we get from method lookup, but instead recreate it during method confirmation. We need to do this because the type we receive back after picking the method references a type variable that does not exist after probing is done.
Fixes #92637

... A better solution for the second issue would be to actually _properly_ implement `Deref` for `[T; N]` instead of fixing this autoderef hack to stop leaking inference variables. But I actually looked into this, and there are many complications with const impls.
2022-01-18 04:41:58 +01:00
kadmin
1c1ce2fbda Add term to ExistentialProjection
Also prevent ICE when adding a const in associated const equality.
2022-01-17 20:01:22 +00:00
kadmin
e7529d6a38 Update term for use in more places
Replace use of `ty()` on term and use it in more places. This will allow more flexibility in the
future, but slightly worried it allows items which are consts which only accept types.
2022-01-17 19:59:40 +00:00
kadmin
67f56671d0 Use Term in ProjectionPredicate
ProjectionPredicate should be able to handle both associated types and consts so this adds the
first step of that. It mainly just pipes types all the way down, not entirely sure how to handle
consts, but hopefully that'll come with time.
2022-01-17 17:44:56 +00:00
chordtoll
9622a42776
Only suggest char literal for single-character strings 2022-01-16 19:09:35 -08:00
Cameron Steffen
45db716902 Replace NestedVisitorMap with NestedFilter 2022-01-16 16:02:36 -06:00
Matthias Krüger
9835b90c91
Rollup merge of #92710 - jackh726:issue-92280, r=nikomatsakis
Include Projections when elaborating TypeOutlives

Fixes #92280

In `Elaborator`, we elaborate that `Foo<<Bar as Baz>::Assoc>: 'a` -> `<Bar as Baz>::Assoc: 'a`. This is the same rule that would be applied to any other `Param`. If there are escaping vars, we continue to do nothing.

r? `@nikomatsakis`
2022-01-16 16:58:17 +01:00
bors
7be8693984 Auto merge of #92805 - BoxyUwU:revert-lazy-anon-const-substs, r=lcnr
partially revertish `lazily "compute" anon const default substs`

reverts #87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted
why revert: <https://github.com/rust-lang/rust/pull/92805#issuecomment-1010736049>

r? `@lcnr`
2022-01-16 11:19:21 +00:00
Camille GILLOT
67727aa7c3 Reduce use of local_def_id_to_hir_id. 2022-01-15 21:26:25 +01:00
Camille GILLOT
60064726ae Return a LocalDefId in get_parent_item. 2022-01-15 21:26:20 +01:00
Matthias Krüger
8326f3f317
Rollup merge of #92743 - bjorn3:less_symbol_intern, r=camelid
Use pre-interned symbols in a couple of places

Re-open of https://github.com/rust-lang/rust/pull/92733 as bors glitched.
2022-01-15 02:25:17 +01:00
Matthias Krüger
64716825b0
Rollup merge of #92191 - jackh726:issue-89352, r=nikomatsakis
Prefer projection candidates instead of param_env candidates for Sized predicates

Fixes #89352

Also includes some drive by logging and verbose printing changes that I found useful when debugging this, but I can remove this if needed.

This is a little hacky - but imo no more than the rest of `candidate_should_be_dropped_in_favor_of`. Importantly, in a Chalk-like world, both candidates should be completely compatible.

r? ```@nikomatsakis```
2022-01-15 02:25:14 +01:00
Ellen
dec8ed438c attempt to re-add ty::Unevaluated visitor and friends 2022-01-15 01:16:55 +00:00
Ellen
71bbb603f4 initial revert 2022-01-15 01:16:55 +00:00
Matthias Krüger
f13e871ac5
Rollup merge of #92045 - oli-obk:cleanup, r=petrochenkov
Don't fall back to crate-level opaque type definitions.

That would just hide bugs, as it works accidentally if the opaque type is defined at the crate level.

Only works after #90948 which worked by accident for our entire test suite.
2022-01-14 07:47:31 +01:00
Matthias Krüger
b45a819bef
Rollup merge of #92006 - oli-obk:welcome_opaque_types_into_the_fold, r=nikomatsakis
Welcome opaque types into the fold

r? ```@nikomatsakis``` because idk who else to bug on the type_op changes

The commits have explanations in them. The TLDR is that

* 5c46002273 stops the "recurse and replace" scheme that replaces opaque types with their canonical inference var by just doing that ahead of time
* bdeeb07bf6 does not affect anything on master afaict, but since opaque types generate obligations when instantiated, and lazy TAIT instantiates opaque types *everywhere*, we need to properly handle obligations here instead of just hoping no problematic obligations ever come up.
2022-01-13 08:11:19 +01:00
Michael Goulet
012910dab2 Canonicalize const variables correctly 2022-01-12 08:27:41 -08:00
Oli Scherer
956db072a8 Don't fall back to crate-level opaque type definitions.
That would just hide bugs, as it works accidentally if the opaque type
is defined at the crate level.
2022-01-12 14:06:11 +00:00
bors
72e74d7b9c Auto merge of #92533 - Aaron1011:variant-symbol, r=petrochenkov
Store a `Symbol` instead of an `Ident` in `VariantDef`/`FieldDef`

The field is also renamed from `ident` to `name`. In most cases,
we don't actually need the `Span`. A new `ident` method is added
to `VariantDef` and `FieldDef`, which constructs the full `Ident`
using `tcx.def_ident_span()`. This method is used in the cases
where we actually need an `Ident`.

This makes incremental compilation properly track changes
to the `Span`, without all of the invalidations caused by storing
a `Span` directly via an `Ident`.
2022-01-11 21:02:01 +00:00
Aaron Hill
450ef8613c
Store a Symbol instead of an Ident in VariantDef/FieldDef
The field is also renamed from `ident` to `name. In most cases,
we don't actually need the `Span`. A new `ident` method is added
to `VariantDef` and `FieldDef`, which constructs the full `Ident`
using `tcx.def_ident_span()`. This method is used in the cases
where we actually need an `Ident`.

This makes incremental compilation properly track changes
to the `Span`, without all of the invalidations caused by storing
a `Span` directly via an `Ident`.
2022-01-11 10:16:22 -05:00
bjorn3
ec9c949946 Use pre-interned symbols in a couple of places 2022-01-10 17:13:33 +01:00
Jack Huey
ad57295fc9 Elaborate param_env predicates when checking if type outlives involving projection holds 2022-01-10 00:29:06 -05:00
Lucas Kent
08829853d3 eplace usages of vec![].into_iter with [].into_iter 2022-01-09 14:09:25 +11:00
chordtoll
3087c4dfb7
Suggest changing quotes when str/char type mismatch 2022-01-03 22:08:08 -08:00
Aaron Hill
b15cb29a4a
Refactor variance diagnostics to work with more types
Instead of special-casing mutable pointers/references, we
now support general generic types (currently, we handle
`ty::Ref`, `ty::RawPtr`, and `ty::Adt`)

When a `ty::Adt` is involved, we show an additional note
explaining which of the type's generic parameters is
invariant (e.g. the `T` in `Cell<T>`). Currently, we don't
explain *why* a particular generic parameter ends up becoming
invariant. In the general case, this could require printing
a long 'backtrace' of types, so doing this would be
more suitable for a follow-up PR.

We still only handle the case where our variance switches
to `ty::Invariant`.
2021-12-29 18:53:40 -05:00
Jack Huey
d3aecc1001 When obligation is a sized predicate, prefer projection or object candidates instead of param_env candidates 2021-12-22 04:14:20 -05:00
Nicholas Nethercote
f09b1facd0 Eliminate ObligationCauseData.
This makes `Obligation` two words bigger, but avoids allocating a lot of
the time.

I previously tried this in #73983 and it didn't help much, but local
timings look more promising now.
2021-12-20 09:29:20 +11:00
Matthias Krüger
d576f7d42d
Rollup merge of #91878 - LegionMammal978:less-inband-infer, r=Aaron1011
Remove `in_band_lifetimes` from `rustc_infer`

See #91867 for more information.

This crate actually had a typo `'ctx` in one of its functions:
```diff
-pub fn same_type_modulo_infer(a: Ty<'tcx>, b: Ty<'ctx>) -> bool {
+pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
```
Also, I wasn't entirely sure about the lifetimes in `suggest_new_region_bound`:
```diff
 pub fn suggest_new_region_bound(
-    tcx: TyCtxt<'tcx>,
+    tcx: TyCtxt<'_>,
     err: &mut DiagnosticBuilder<'_>,
     fn_returns: Vec<&rustc_hir::Ty<'_>>,
```
Should all of those lifetimes really be distinct?
2021-12-19 17:38:33 +01:00