Commit Graph

1422 Commits

Author SHA1 Message Date
Matthias Krüger
bfefd587c0
Rollup merge of #98028 - aticu:master, r=estebank
Add E0790 as more specific variant of E0283

Fixes #81701

I think this should be good to go, there are only two things where I am somewhat unsure:
- Is there a better way to get the fully-qualified path for the suggestion? I tried `self.tcx.def_path_str`, but that didn't seem to always give a correct path for the context.
- Should all this be extracted into it's own method or is it fine where it is?

r? `@estebank`
2022-07-19 13:30:44 +02:00
aticu
1cbacc0c8a Add E0790 as more specific variant of E0283 2022-07-19 10:16:10 +02:00
Oli Scherer
f40326027a Check generators for well formedness 2022-07-18 17:20:55 +00:00
bors
144227dae9 Auto merge of #99232 - lcnr:no-bound-vars-check, r=jackh726
`replace_bound_vars` fast path: check predicates, don't check consts

split out from #98900

`ty::Const` doesn't have precomputed type flags, so
computing `has_vars_bound_at_or_above` for constants
requires us to visit the const and its contained types
and constants. A noop fold should be pretty much equally as
fast so removing it prevents us from walking the constant twice
in case it contains bound vars.

r? `@jackh726`
2022-07-18 13:59:05 +00:00
bors
880416180b Auto merge of #99181 - lcnr:arenaGTrc, r=wesleywiser
`arena > Rc` for query results

The `Rc`s have to live for the whole duration as their count cannot go below 1 while stored as part of the query results.

By storing them in an arena we should save a bit of memory because we don't have as many independent allocations and also don't have to clone the `Rc` anymore.
2022-07-18 05:50:54 +00:00
Takayuki Maeda
a22934bea1 avoid Symbol to &str conversions 2022-07-18 14:25:34 +09:00
bors
2fa64d0e53 Auto merge of #99137 - jackh726:wf-no-infcx, r=estebank
Don't pass InferCtxt to WfPredicates

Simple cleanup. Infer vars will get passed up as obligations and shallowed resolved later. This actually improves one test output.
2022-07-18 03:07:26 +00:00
Caio
3266460749 Stabilize let_chains 2022-07-16 20:17:58 -03:00
Matthias Krüger
69e4f21f2e
Rollup merge of #99290 - compiler-errors:revert-98794, r=lcnr
Revert "Highlight conflicting param-env candidates"

This reverts #98794, commit 08135254dc.

Seems to have caused an incremental compilation bug. The root cause of the incr comp bug is somewhat unrelated but is triggered by this PR, so I don't feel comfortable with having this PR in the codebase until it can be investigated further. Fixes #99233.
2022-07-16 22:30:52 +02:00
Will Crichton
2f15dfab0b Fix suggestion regression with incorrect syntactic combination of trait bounds 2022-07-15 18:06:20 -07:00
Will Crichton
e5bb7d80d6 Propagate Expectation around binop typeck code to construct more precise trait obligations for binops. 2022-07-15 18:06:18 -07:00
Michael Goulet
1c8f87e907 Revert "Highlight conflicting param-env candidates"
This reverts commit 08135254dc.
2022-07-15 17:21:55 +00:00
lcnr
16b2acc7c0 hir typeck: fulfillment_cx ignore regions 2022-07-15 17:01:32 +02:00
lcnr
5bd8c960f5 provide generic_param_scope for region errors 2022-07-15 16:53:20 +02:00
lcnr
4b56fd9341 try to avoid FnCtxt during wf 2022-07-15 16:53:18 +02:00
lcnr
7808f69ad7 QueryNormalizer bug on ambiguity 2022-07-15 16:40:39 +02:00
Michael Goulet
fcfb3e92a0 Remove some more usages of guess_head_span 2022-07-15 05:23:47 +00:00
Michael Goulet
78efaf43e4 remove tcx from ObligationCauseCode::span 2022-07-15 03:17:20 +00:00
Michael Goulet
27b6ab9129 Remove some more usages of guess_head_span 2022-07-15 03:17:20 +00:00
Dylan DPC
39936fd0b7
Rollup merge of #99222 - atsuzaki:generic_const_err, r=lcnr
Better error message for generic_const_exprs inference failure

Fixes #90531

This code:
```rs
#![feature(generic_const_exprs)]

fn foo<const N: usize>(_arr: [u64; N + 1]) where [u64; N + 1]: {}

fn main() {
  let arr = [5; 5];
  foo(arr);
}
```

Will now emit the following error:
```rs
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> test.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information

error[E0284]: type annotations needed
 --> test.rs:8:7
  |
8 |       foo(arr);
  |       ^^^ cannot infer the value of the const parameter `N` declared on the function `foo`
  |
note: required by a bound in `foo`
 --> test.rs:3:56
  |
3 | fn foo<const N: usize>(_arr: [u64; N + 1]) where [u64; N + 1]: {}
  |                                                        ^^^^^ required by this bound in `foo`
help: consider specifying the generic argument
  |
8 |       foo::<N>(arr);
  |          +++++

error: aborting due to previous error; 1 warning emitted
```

cc: `@lcnr` thanks a lot again for the help on this
2022-07-14 19:24:06 +05:30
Dylan DPC
ecae3d74e2
Rollup merge of #99000 - JulianKnodt:allow_resolve_no_substs, r=lcnr
Move abstract const to middle

Moves AbstractConst (and all associated methods) to rustc middle for use in `rustc_infer`.
This allows for const resolution in infer to use abstract consts to walk consts and check if
they are resolvable.

This attempts to resolve the issue where `Foo<{ concrete const }, generic T>` is incorrectly marked as conflicting, and is independent from the other issue where nested abstract consts must be resolved.

r? `@lcnr`
2022-07-14 19:24:04 +05:30
bors
f1a8854f9b Auto merge of #99231 - Dylan-DPC:rollup-0tl8c0o, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97720 (Always create elided lifetime parameters for functions)
 - #98315 (Stabilize `core::ffi:c_*` and rexport in `std::ffi`)
 - #98705 (Implement `for<>` lifetime binder for closures)
 - #99126 (remove allow(rustc::potential_query_instability) in rustc_span)
 - #99139 (Give a better error when `x dist` fails for an optional tool)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-14 11:00:30 +00:00
lcnr
864d2f3528 eagerly check for bound vars of predicates 2022-07-14 12:48:50 +02:00
lcnr
39a990d2f1 remove ct.has_vars_bound_at_or_above calls
`ty::Const` doesn't have precomputed type flags, so
computing `has_vars_bound_at_or_above` for constants
requires us to visit the const and its contained types
and constants. A noop fold should be pretty much equally as
fast so removing it prevents us from walking the constant twice
in case it contains bound vars.
2022-07-14 12:35:09 +02:00
kadmin
20fb8aba8f Fix overlapping impls 2022-07-14 09:01:17 +00:00
Dylan DPC
e5a86d7358
Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillot
Implement `for<>` lifetime binder for closures

This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following:

```rust
let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) };
//       ^^^^^^^^^^^--- new!
```

cc ``@Aaron1011`` ``@cjgillot``
2022-07-14 14:14:21 +05:30
Katherine Philip
083bd7cb1d Remove predicate note 2022-07-13 16:29:05 -07:00
Katherine Philip
b33955a0ef Add checks & fallback branch 2022-07-13 16:29:05 -07:00
Katherine Philip
82ab171673 Use emit_inference_failure_err for ConstEvaluatable predicates 2022-07-13 16:29:00 -07:00
Joshua Nelson
3c9765cff1 Rename debugging_opts to unstable_opts
This is no longer used only for debugging options (e.g. `-Zoutput-width`, `-Zallow-features`).
Rename it to be more clear.
2022-07-13 17:47:06 -05:00
Dylan DPC
0083cd2fd4
Rollup merge of #98574 - dingxiangfei2009:let-else-thir, r=oli-obk
Lower let-else in MIR

This MR will switch to lower let-else statements in MIR building instead.

To lower let-else in MIR, we build a mini-switch two branches. One branch leads to the matching case, and the other leads to the `else` block. This arrangement will allow temporary lifetime analysis running as-is so that the temporaries are properly extended according to the same rule applied to regular `let` statements.

cc https://github.com/rust-lang/rust/issues/87335

Fix #98672
2022-07-13 19:32:33 +05:30
Maybe Waffle
df4fee9841 Add an indirection for closures in hir::ExprKind
This helps bring `hir::Expr` size down, `Closure` was the biggest
variant, especially after `for<>` additions.
2022-07-12 21:00:13 +04:00
lcnr
0fc5296876 remove outdated comment 2022-07-12 15:29:32 +02:00
lcnr
baefd42861 arena > Rc for query results 2022-07-12 15:27:24 +02:00
Dylan DPC
c0bcbe8a6e
Rollup merge of #99038 - jackh726:earlybinder-cleanup, r=lcnr
Some more `EarlyBinder` cleanups

First commit has a couple unrelated cleanups, but otherwise each commit is self-explanatory

r? rust-lang/types
2022-07-12 17:06:34 +05:30
kadmin
e612e2603c Move abstract const to rustc_middle::ty 2022-07-12 02:21:31 +00:00
Ding Xiang Fei
1cd30e7b32
move else block into the Local struct 2022-07-11 23:20:37 +02:00
Ding Xiang Fei
6c529ded86
lower let-else in MIR instead 2022-07-11 23:20:36 +02:00
Matthias Krüger
d89c183554
Rollup merge of #99075 - danobi:dup_type_hint_sugg, r=petrochenkov
Fix duplicated type annotation suggestion

Before, there was more or less duplicated suggestions to add type hints.
Fix by clearing more generic suggestions when a more specific suggestion
is possible.

This fixes #93506 .
2022-07-11 22:39:05 +02:00
lcnr
bf183101dd cg_fulfill_obligation: expect erased regions 2022-07-11 16:26:12 +02:00
Dylan DPC
93f71d4e01
Rollup merge of #99091 - compiler-errors:private-types-should-stay-private, r=lcnr
Do not mention private types from other crates as impl candidates

Fixes #99080
2022-07-11 15:19:31 +05:30
Dylan DPC
92b8adf8e0
Rollup merge of #98907 - compiler-errors:plz-no-float, r=oli-obk
Deny float const params even when `adt_const_params` is enabled

Supersedes #98825
Fixes #98813

r? ``@oli-obk``
2022-07-11 15:19:30 +05:30
Michael Goulet
913023b6b4 Use Visibility::is_accessible_from to make suggestion more specific 2022-07-11 07:06:18 +00:00
Michael Goulet
f2d8af10c2 Do not mention private Self types from other crates 2022-07-11 06:57:48 +00:00
Michael Goulet
a1634642e0 Deny floats even when adt_const_params is enabled 2022-07-11 00:04:00 +00:00
Matthias Krüger
16d0d0b7f1
Rollup merge of #99095 - rhysd:issue-99092, r=compiler-errors
Remove duplicate notes from error on inter-crate ambiguous impl of traits

Fixes #99092
2022-07-11 00:33:49 +02:00
Jack Huey
a479f23f37 Don't pass InferCtxt to WfPredicates 2022-07-10 15:52:19 -04:00
Jack Huey
2d15f1ca42 Don't try to resolve inference variables in WF computation, just register 2022-07-10 15:25:33 -04:00
Matthias Krüger
86af7135ae
Rollup merge of #99103 - TaKO8Ki:avoid-&str-to-string-conversions, r=oli-obk
Avoid some `&str` to `String` conversions

This patch removes some `&str` to `String` conversions.
2022-07-10 11:52:17 +02:00
rhysd
d5aed20f47 Remove duplicate notes from error on inter-crate ambiguous impl of traits (fix #99092) 2022-07-10 16:39:12 +09:00
Takayuki Maeda
bda83e6543 avoid some &str to String conversions 2022-07-10 03:18:56 +09:00
Ralf Jung
a422b42159 don't allow ZST in ScalarInt
There are several indications that we should not ZST as a ScalarInt:
- We had two ways to have ZST valtrees, either an empty `Branch` or a `Leaf` with a ZST in it.
  `ValTree::zst()` used the former, but the latter could possibly arise as well.
- Likewise, the interpreter had `Immediate::Uninit` and `Immediate::Scalar(Scalar::ZST)`.
- LLVM codegen already had to special-case ZST ScalarInt.

So instead add new ZST variants to those types that did not have other variants
which could be used for this purpose.
2022-07-09 07:27:29 -04:00
Daniel Xu
34e9e6dff1 Fix duplicated type annotation suggestion
Before, there was more or less duplicated suggestions to add type hints.
Fix by clearing more generic suggestions when a more specific suggestion
is possible.

This fixes #93506 .
2022-07-08 21:03:03 -05:00
bors
47575bb066 Auto merge of #98816 - estebank:implicit-sized, r=oli-obk
Track implicit `Sized` obligations in type params

When we evaluate `ty::GenericPredicates` we introduce the implicit
`Sized` predicate of type params, but we do so with only the `Predicate`
its `Span` as context, we don't have an `Obligation` or
`ObligationCauseCode` we could influence. To try and carry this
information through, we add a new field to `ty::GenericPredicates` that
tracks both which predicates come from a type param and whether that
param has any bounds already (to use in suggestions).

We also suggest adding a `?Sized` bound if appropriate on E0599.

Address part of #98539.
2022-07-08 23:17:34 +00:00
bors
052495d001 Auto merge of #98614 - oli-obk:take_unsound_opaque_types, r=wesleywiser
don't succeed `evaluate_obligation` query if new opaque types were registered

fixes #98608
fixes #98604

The root cause of all this is that in type flag computation we entirely ignore nongeneric things like struct fields and the signature of function items. So if a flag had to be set for a struct if it is set for a field, that will only happen if the field is generic, as only the generic parameters are checked.

I now believe we cannot use type flags to handle opaque types. They seem like the wrong tool for this.

Instead, this PR replaces the previous logic by adding a new variant of `EvaluatedToOk`: `EvaluatedToOkModuloOpaqueTypes`, which says that there were some opaque types that got hidden types bound, but that binding may not have been legal (because we don't know if the opaque type was in its defining scope or not).
2022-07-08 17:55:26 +00:00
Dylan DPC
54dde8678b
Rollup merge of #98794 - compiler-errors:conflicting-param-env, r=michaelwoerister
Highlight conflicting param-env candidates

This could probably be further improved by noting _why_ equivalent param-env candidates (modulo regions) leads to ambiguity.

Fixes #98786
2022-07-08 18:25:51 +05:30
Dylan DPC
fe87923b54
Rollup merge of #98654 - nnethercote:pest-2.1.3-opt, r=pnkfelix
An optimization for `pest-2.1.3`

An easy win I found while looking at a profile of `pest-2.1.3`. It's also a small code cleanup.

r? `@pnkfelix`
2022-07-08 18:25:49 +05:30
Michael Goulet
08135254dc Highlight conflicting param-env candidates 2022-07-08 03:51:08 +00:00
Jack Huey
ad9e1e377f Use map_bound 2022-07-07 22:14:01 -04:00
Jack Huey
31e1a777e7 Move code from rustc_trait_selection/opaque_types to better places 2022-07-07 21:45:40 -04:00
Esteban Küber
385c79379c Track WellFormed obligations with an appropriate cause, instead of MiscObligation 2022-07-07 12:15:18 -07:00
Guillaume Gomez
d712f67897
Rollup merge of #98519 - TaKO8Ki:add-head-span-field-to-item-and-impl-item, r=cjgillot
Replace some `guess_head_span` with `def_span`

This patch fixes a part of #97417.
r? `@cjgillot`
2022-07-06 20:43:24 +02:00
Takayuki Maeda
0541b4e034 use named_span in case of tuple variant 2022-07-06 19:09:50 +09:00
Takayuki Maeda
83dea35384 replace guess_head_span with def_span 2022-07-06 19:09:47 +09:00
Dylan DPC
df1f415305
Rollup merge of #98884 - davidtwco:translation-on-lints-derive, r=oli-obk
macros: `LintDiagnostic` derive

- Move `LintDiagnosticBuilder` into `rustc_errors` so that a diagnostic derive can refer to it.
- Introduce a `DecorateLint` trait, which is equivalent to `SessionDiagnostic` or `AddToDiagnostic` but for lints. Necessary without making more changes to the lint infrastructure as `DecorateLint` takes a `LintDiagnosticBuilder` and re-uses all of the existing logic for determining what type of diagnostic a lint should be emitted as (e.g. error/warning).
- Various refactorings of the diagnostic derive machinery (extracting `build_field_mapping` helper and moving `sess` field out of the `DiagnosticDeriveBuilder`).
- Introduce a `LintDiagnostic` derive macro that works almost exactly like the `SessionDiagnostic` derive macro  except that it derives a `DecorateLint` implementation instead. A new derive is necessary for this because `SessionDiagnostic` is intended for when the generated code creates the diagnostic. `AddToDiagnostic` could have been used but it would have required more changes to the lint machinery.

~~At time of opening this pull request, ignore all of the commits from #98624, it's just the last few commits that are new.~~

r? `@oli-obk`
2022-07-06 14:49:10 +05:30
bors
5b8cf49c51 Auto merge of #98206 - eggyal:align-to-chalk-folding-api, r=jackh726
Split TypeVisitable from TypeFoldable

Impl of rust-lang/compiler-team#520 following MCP approval.

r? `@ghost`
2022-07-06 05:48:11 +00:00
Alan Egerton
4f0a64736b
Update TypeVisitor paths 2022-07-06 06:41:53 +01:00
Alan Egerton
e9e5d0685b
Relax constrained generics to TypeVisitable 2022-07-05 22:25:43 +01:00
Alan Egerton
e4b9625b87
Add #[derive(TypeVisitable)] 2022-07-05 22:25:15 +01:00
bors
41ad4d9b2d Auto merge of #98936 - matthiaskrgr:rollup-dvr0ucm, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #98860 (adjust dangling-int-ptr error message)
 - #98888 (interpret: fix CheckedBinOp behavior when overflow checking is disabled)
 - #98889 (Add regression test for #79467)
 - #98895 (bootstrap.py: Always use `.exe` for Windows)
 - #98920 (adapt issue-37945 codegen test to accept any order of ops)
 - #98921 (Refactor: remove a redundant mutable variable)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-05 17:46:53 +00:00
Matthias Krüger
720eb123af
Rollup merge of #98921 - TaKO8Ki:refactor-fulfillment-context-select, r=Dylan-DPC
Refactor: remove a redundant mutable variable
2022-07-05 17:08:15 +02:00
David Wood
2874f09534 lint: LintDiagnosticBuilder into rustc_errors
Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05 16:00:20 +01:00
bors
efb171e235 Auto merge of #98584 - lcnr:region-stuff-more-beans, r=oli-obk
continue nll transition by removing stuff

r? `@jackh726` for now

building on #98641
2022-07-05 14:58:31 +00:00
Takayuki Maeda
c9e2aa4d7f refactor: remove a redundant mutable variable 2022-07-05 18:28:36 +09:00
lcnr
9f95c605f8 region obligations, remove body_id 2022-07-04 14:35:20 +02:00
lcnr
a0d2d9f315 implied bounds byebye nested hir ids 2022-07-04 14:35:20 +02:00
lcnr
e78e0e2ad0 rip out RegionCtxt from hir typeck 2022-07-04 14:35:20 +02:00
lcnr
24799e3720 remove an unused DefId 2022-07-04 14:35:19 +02:00
lcnr
c2ed08715b remove unused function argument 2022-07-04 13:58:28 +02:00
Michael Goulet
6711313f76 Move Sized check before first error is created 2022-07-01 17:38:34 +00:00
Michael Goulet
12ab6bfafd Don't point at Self type if we can't find an infer variable in ambiguous trait predicate 2022-07-01 17:38:34 +00:00
Michael Goulet
ca0105ba4e Show source of ambiguity in a few more places 2022-07-01 17:38:34 +00:00
Michael Goulet
f44ae98cee Only label place where type is needed if span is meaningful 2022-07-01 17:38:34 +00:00
Oli Scherer
84fc551664 Make evaluate_obligation not succeed unconditionally if it registered new hidden types for opaque types 2022-06-30 14:23:31 +00:00
Matthias Krüger
d34c4ca9be
Rollup merge of #98668 - TaKO8Ki:avoid-many-&str-to-string-conversions, r=Dylan-DPC
Avoid some `&str` to `String` conversions with `MultiSpan::push_span_label`

This patch removes some`&str` to `String` conversions with `MultiSpan::push_span_label`.
2022-06-29 20:35:07 +02:00
Dylan DPC
7b9a7ef218
Rollup merge of #98499 - JulianKnodt:erase_lifetime, r=lcnr
Erase regions in New Abstract Consts

When an abstract const is constructed, we previously included lifetimes in the set of substitutes, so it was not able to unify two abstract consts if their lifetimes did not match but the values did, despite the values not depending on the lifetimes. This caused code that should have compiled to not compile.

Fixes #98452

r? ```@lcnr```
2022-06-29 17:59:33 +05:30
Takayuki Maeda
6212e6b339 avoid many &str to String conversions with MultiSpan::push_span_label 2022-06-29 21:16:43 +09:00
bors
66c83ffca1 Auto merge of #98558 - nnethercote:smallvec-1.8.1, r=lqd
Update `smallvec` to 1.8.1.

This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.

r? `@lqd`
2022-06-29 09:11:29 +00:00
bors
493c960a3e Auto merge of #98656 - Dylan-DPC:rollup-hhytn0c, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #97423 (Simplify memory ordering intrinsics)
 - #97542 (Use typed indices in argument mismatch algorithm)
 - #97786 (Account for `-Z simulate-remapped-rust-src-base` when resolving remapped paths)
 - #98277 (Fix trait object reborrow suggestion)
 - #98525 (Add regression test for #79224)
 - #98549 (interpret: do not prune requires_caller_location stack frames quite so early)
 - #98603 (Some borrowck diagnostic fixes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-29 05:47:42 +00:00
kadmin
1e40200b35 Erase regions in new abstract consts 2022-06-29 03:44:11 +00:00
bors
116edb6800 Auto merge of #98542 - jackh726:coinductive-wf, r=oli-obk
Make empty bounds lower to `WellFormed` and make `WellFormed` coinductive

r? rust-lang/types
2022-06-29 03:22:47 +00:00
Nicholas Nethercote
687e391bc3 Avoid constructing an unnecessary InferCtxt.
Currently, `search_for_structural_match_violation` constructs an `infcx`
from a `tcx` and then only uses the `tcx` within the `infcx`. This is
wasteful because `infcx` is a big type.

This commit changes it to use the `tcx` directly. When compiling
`pest-2.1.3`, this changes the memcpy stats reported by DHAT for a `check full`
build from this:
```
433,008,916 bytes (100%, 99,787.93/Minstr) in 2,148,668 blocks (100%, 495.17/Minstr), avg size 201.52 bytes
```
to this:
```
101,422,347 bytes (99.98%, 25,243.59/Minstr) in 1,318,407 blocks (99.96%, 328.15/Minstr), avg size 76.93 bytes
```
This translates to a 4.3% reduction in instruction counts.
2022-06-29 12:16:03 +10:00
Nicholas Nethercote
9e76fcc468 Change Search::infcx to tcx.
Because the `infcx` isn't needed. This removes one lifetime from
`Search`.
2022-06-29 12:16:00 +10:00
Michael Goulet
862873d20b Note concrete type being coerced into object 2022-06-28 21:56:18 +00:00
Michael Goulet
6c0a591dee Fix trait object reborrow suggestion 2022-06-28 21:42:52 +00:00
Dylan DPC
c703d11dcc
Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, r=oli-obk
Remove a back-compat hack on lazy TAIT

This PR's motivation is here: https://github.com/rust-lang/rust/issues/72614#issuecomment-1134595446
~~But removing a hack doesn't seem to reject the code on the issue, there're some more hacks?~~
r? ``@oli-obk``
2022-06-28 15:30:00 +05:30
Jack Huey
bd298adcd4 Take into account trait predicate coinductiveness 2022-06-28 00:18:06 -04:00
Jack Huey
e16dbb5076 Make empty bounds lower to WellFormed and make WellFormed coinductive 2022-06-28 00:17:40 -04:00
Matthias Krüger
950934801e
Rollup merge of #98576 - lcnr:region-stuff-cool-beans, r=jackh726
small regions refactoring

these commits should be fairly self-contained

r? rust-lang/types
2022-06-27 22:35:09 +02:00
Matthias Krüger
6391f239c8
Rollup merge of #98506 - compiler-errors:object-safety-suggestions, r=oli-obk
Fix span issues in object safety suggestions

Fixes #98500
2022-06-27 22:35:07 +02:00
lcnr
4dbf9ba0ab outside of borrowck, do not provide an implicit_region_bound
see comment added to the field in `VerifyBoundCx`.
2022-06-27 15:48:54 +02:00
Yuki Okushi
c24f06354a
Remove a back-compat hack on lazy TAIT 2022-06-27 20:43:44 +09:00
bors
7702ae16a2 Auto merge of #98221 - cjgillot:single-coh, r=lcnr
Perform coherence checking per impl.

r? `@ghost`
2022-06-27 02:56:06 +00:00
Nicholas Nethercote
7c40661ddb Update smallvec to 1.8.1.
This pulls in https://github.com/servo/rust-smallvec/pull/282, which
gives some small wins for rustc.
2022-06-27 08:48:55 +10:00
Michael Goulet
eff865ca76 Fix span issues in object safety suggestions 2022-06-25 14:59:45 -07:00
Matthias Krüger
65187f51dc
Rollup merge of #98311 - eggyal:reverse-folder-hierarchy, r=jackh726
Reverse folder hierarchy

#91318 introduced a trait for infallible folders distinct from the fallible version.  For some reason (completely unfathomable to me now that I look at it with fresh eyes), the infallible trait was a supertrait of the fallible one: that is, all fallible folders were required to also be infallible.  Moreover the `Error` associated type was defined on the infallible trait!  It's so absurd that it has me questioning whether I was entirely sane.

This trait reverses the hierarchy, so that the fallible trait is a supertrait of the infallible one: all infallible folders are required to also be fallible (which is a trivial blanket implementation).  This of course makes much more sense!  It also enables the `Error` associated type to sit on the fallible trait, where it sensibly belongs.

There is one downside however: folders expose a `tcx` accessor method.  Since the blanket fallible implementation for infallible folders only has access to a generic `F: TypeFolder`, we need that trait to expose such an accessor to which we can delegate.  Alternatively it's possible to extract that accessor into a separate `HasTcx` trait (or similar) that would then be a supertrait of both the fallible and infallible folder traits: this would ensure that there's only one unambiguous `tcx` method, at the cost of a little additional boilerplate.  If desired, I can submit that as a separate PR.

r? ````@jackh726````
2022-06-25 15:14:11 +02:00
Michael Goulet
667a54623d
Rollup merge of #98365 - jyn514:improve-obligation-errors-review-comments, r=eholk
Address review comments from #98259

It got approved so fast I didn't have time to make changes xD

r? ``@eholk``
2022-06-23 14:39:14 -07:00
Michael Goulet
413e350f87
Rollup merge of #98259 - jyn514:improve-obligation-errors, r=estebank
Greatly improve error reporting for futures and generators in `note_obligation_cause_code`

Most futures don't go through this code path, because they're caught by
`maybe_note_obligation_cause_for_async_await`. But all generators do,
and `maybe_note` is imperfect and doesn't catch all futures. Improve the error message for those it misses.

At some point, we may want to consider unifying this with the code for `maybe_note_async_await`,
so that `async_await` notes all parent constraints, and `note_obligation` can point to yield points.
But both functions are quite complicated, and it's not clear to me how to combine them;
this seems like a good incremental improvement.

Helps with https://github.com/rust-lang/rust/issues/97332.

r? ``@estebank`` cc ``@eholk`` ``@compiler-errors``
2022-06-23 14:39:06 -07:00
Camille GILLOT
0ff8c65d6f Perform coherence checking per impl. 2022-06-22 21:18:46 +02:00
Michael Goulet
52409c4c90 Point at return expression for RPIT-related error 2022-06-21 18:23:37 -07:00
Joshua Nelson
b052d76586 Address review comments from #98259
It got merged so fast I didn't have time to make changes xD
2022-06-21 19:44:53 -05:00
Alan Egerton
6ac6866bec
Reverse folder hierarchy
#91318 introduced a trait for infallible folders distinct from the fallible version.  For some reason (completely unfathomable to me now that I look at it with fresh eyes), the infallible trait was a supertrait of the fallible one: that is, all fallible folders were required to also be infallible.  Moreover the `Error` associated type was defined on the infallible trait!  It's so absurd that it has me questioning whether I was entirely sane.

This trait reverses the hierarchy, so that the fallible trait is a supertrait of the infallible one: all infallible folders are required to also be fallible (which is a trivial blanket implementation).  This of course makes much more sense!  It also enables the `Error` associated type to sit on the fallible trait, where it sensibly belongs.

There is one downside however: folders expose a `tcx` accessor method.  Since the blanket fallible implementation for infallible folders only has access to a generic `F: TypeFolder`, we need that trait to expose such an accessor to which we can delegate.  Alternatively it's possible to extract that accessor into a separate `HasTcx` trait (or similar) that would then be a supertrait of both the fallible and infallible folder traits: this would ensure that there's only one unambiguous `tcx` method, at the cost of a little additional boilerplate.  If desired, I can submit that as a separate PR.

r? @jackh726
2022-06-21 17:38:22 +01:00
Yuki Okushi
9c800ec4e9
Rollup merge of #97805 - coolreader18:trace-suggestions, r=oli-obk
Add proper tracing spans to rustc_trait_selection::traits::error_reporting

While I was trying to figure out #97704 I did some of this to make the logs more legible, so I figured I'd do the whole module and open a PR with it. afaict this is an ongoing process in the compiler from the log->tracing transition? but lmk if there was a reason for the more verbose forms of logging as they are.

Also, for some of the functions with only one log in them, I put the function name as a message for that log instead of `#[instrument]`-ing the whole function with a span? but maybe the latter would actually be preferable, I'm not actually sure.
2022-06-21 20:08:09 +09:00
bors
1d6010816c Auto merge of #97674 - nnethercote:oblig-forest-tweaks, r=nikomatsakis
Obligation forest tweaks

A few minor improvements to the code.

r? `@nikomatsakis`
2022-06-20 10:58:56 +00:00
Peter Hebden
3ce6e125fa
Fix minor documentation typo
Incorrect pluralisation of `crate`
2022-06-20 03:30:21 +01:00
Joshua Nelson
1deca0425d Greatly improve error reporting for futures and generators in note_obligation_cause_code
Most futures don't go through this code path, because they're caught by
`maybe_note_obligation_cause_for_async_await`. But all generators do,
and `maybe_note` is imperfect and doesn't catch all futures. Improve the error message for those it misses.

At some point, we may want to consider unifying this with the code for `maybe_note_async_await`,
so that `async_await` notes all parent constraints, and `note_obligation` can point to yield points.
But both functions are quite complicated, and it's not clear to me how to combine them;
this seems like a good incremental improvement.
2022-06-19 15:31:22 -05:00
Dylan DPC
6e8f541fff
Rollup merge of #98136 - fee1-dead-contrib:rename_impl_constness, r=oli-obk
Rename `impl_constness` to `constness`

The current code is a basis for `is_const_fn_raw`, and `impl_constness`
is no longer a valid name, which is previously used for determining the
constness of impls, and not items in general.

r? `@oli-obk`
2022-06-19 15:26:28 +02:00
Deadbeef
26ac45614b Rename impl_constness to constness
The current code is a basis for `is_const_fn_raw`, and `impl_constness`
is no longer a valid name, which is previously used for determining the
constness of impls, and not items in general.
2022-06-15 20:54:43 +10:00
Yuki Okushi
87e373e82f
Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011
Make `ExprKind::Closure` a struct variant.

Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`.

r? ``@Aaron1011``
2022-06-15 19:37:14 +09:00
b-naber
15c1c06522 rebase 2022-06-14 17:57:51 +02:00
b-naber
705d818bd5 implement valtrees as the type-system representation for constant values 2022-06-14 16:07:11 +02:00
Dylan DPC
9e5c5c57e9
Rollup merge of #97935 - nnethercote:rename-ConstS-val-as-kind, r=lcnr
Rename the `ConstS::val` field as `kind`.

And likewise for the `Const::val` method.

Because its type is called `ConstKind`. Also `val` is a confusing name
because `ConstKind` is an enum with seven variants, one of which is
called `Value`. Also, this gives consistency with `TyS` and `PredicateS`
which have `kind` fields.

The commit also renames a few `Const` variables from `val` to `c`, to
avoid confusion with the `ConstKind::Value` variant.

r? `@BoxyUwU`
2022-06-14 10:35:29 +02:00
bors
4e02a9281d Auto merge of #98041 - jackh726:remove-regionckmode, r=oli-obk
Remove RegionckMode in favor of calling new skip_region_resolution

Simple cleanup. We can skip a bunch of stuff for places where NLL does the region checking, so skip earlier.

r? rust-lang/types
2022-06-14 05:07:11 +00:00
Nicholas Nethercote
93e4b6ef06 Rename the ConstS::val field as kind.
And likewise for the `Const::val` method.

Because its type is called `ConstKind`. Also `val` is a confusing name
because `ConstKind` is an enum with seven variants, one of which is
called `Value`. Also, this gives consistency with `TyS` and `PredicateS`
which have `kind` fields.

The commit also renames a few `Const` variables from `val` to `c`, to
avoid confusion with the `ConstKind::Value` variant.
2022-06-14 13:06:44 +10:00
Takayuki Maeda
77d6176e69 remove unnecessary to_string and String::new 2022-06-13 15:48:40 +09:00
Jack Huey
d716245aa6 Remove RegionckMode in favor of calling new skip_region_resolution 2022-06-13 01:15:04 -04:00
Michael Goulet
5f7474e6dc Address comments 2022-06-11 16:38:48 -07:00
Michael Goulet
38d7e2734f Properly replace impl Trait in fn args, turn {integer} to i32 2022-06-11 16:38:48 -07:00
Michael Goulet
55805ab473 Make is_suggestable work on all TypeFoldable 2022-06-11 16:38:48 -07:00
Michael Goulet
9c47afe9fa Handle empty where-clause better 2022-06-11 16:27:01 -07:00
Camille GILLOT
3039cfeb6a Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
lcnr
cc013e05b4 bound_vars -> infer: don't return lt map 2022-06-10 10:09:50 +02:00
bors
e45d9973b2 Auto merge of #97860 - Dylan-DPC:rollup-t3vxos8, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97595 (Remove unwrap from get_vtable)
 - #97597 (Preserve unused pointer to address casts)
 - #97819 (Recover `import` instead of `use` in item)
 - #97823 (Recover missing comma after match arm)
 - #97851 (Use repr(C) when depending on struct layout in ptr tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-08 08:05:47 +00:00
Dylan DPC
148a44a001
Rollup merge of #97595 - ouz-a:issue-97381, r=compiler-errors
Remove unwrap from get_vtable

This avoids ICE on issue #97381 I think the bug is a bit deeper though, it compiles fine when `v` is `&v` which makes me think `Deref` is causing some issue with borrowck but it's fine I guess since this thing crashes since `nightly-2020-09-17` 😅
2022-06-08 07:37:29 +02:00
bors
64a7aa7016 Auto merge of #97447 - nnethercote:improve-folding, r=jackh726
Folding revamp

r? `@ghost`
2022-06-08 05:36:40 +00:00
Nicholas Nethercote
90db033955 Folding revamp.
This commit makes type folding more like the way chalk does it.

Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods.
- `fold_with` is the standard entry point, and defaults to calling
  `super_fold_with`.
- `super_fold_with` does the actual work of traversing a type.
- For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead
  calls into a `TypeFolder`, which can then call back into
  `super_fold_with`.

With the new approach, `TypeFoldable` has `fold_with` and
`TypeSuperFoldable` has `super_fold_with`.
- `fold_with` is still the standard entry point, *and* it does the
  actual work of traversing a type, for all types except types of
  interest.
- `super_fold_with` is only implemented for the types of interest.

Benefits of the new model.
- I find it easier to understand. The distinction between types of
  interest and other types is clearer, and `super_fold_with` doesn't
  exist for most types.
- With the current model is easy to get confused and implement a
  `super_fold_with` method that should be left defaulted. (Some of the
  precursor commits fixed such cases.)
- With the current model it's easy to call `super_fold_with` within
  `TypeFolder` impls where `fold_with` should be called. The new
  approach makes this mistake impossible, and this commit fixes a number
  of such cases.
- It's potentially faster, because it avoids the `fold_with` ->
  `super_fold_with` call in all cases except types of interest. A lot of
  the time the compile would inline those away, but not necessarily
  always.
2022-06-08 09:24:03 +10:00
Nicholas Nethercote
465d198c74 Rename TypeVisitor::visit_unevaluated_const.
To match the corresponding type name.
2022-06-08 09:22:23 +10:00
bors
b17e9d76f2 Auto merge of #97081 - oli-obk:outlives_query_fast_path, r=jackh726
Re-use the type op instead of calling the implied_outlives_bounds query directly

r? `@ghost`
2022-06-07 21:44:40 +00:00
Noa
976336dab0
Add proper tracing spans to rustc_trait_selection::traits::error_reporting 2022-06-06 14:47:49 -05:00
Matthias Krüger
df86d04977
Rollup merge of #97721 - compiler-errors:issue-97704, r=jackh726
Do `suggest_await_before_try` with infer variables in self, and clean up binders

Fixes #97704

Also cleans up binders in this fn, since everything is a `Poly*` and we really shouldn't have stray escaping late-bound regions everywhere. That's why the function changed so much. This isn't necessary, so I can revert if necessary.
2022-06-06 08:37:01 +02:00
Michael Goulet
d268b34da4 Do suggest_await_before_try with infer in self, clean up binders 2022-06-05 18:46:48 -07:00
Nicholas Nethercote
32741d5d16 Split process_obligation in two.
Because it really has two halves:
- A read-only part that checks if further work is needed.
- The further work part, which is much less hot.

This makes things a bit clearer and nicer.
2022-06-06 08:47:49 +10:00
Nicholas Nethercote
281229a6d3 Handle stalling within ObligationForest.
It is simpler if `ObligationForest` does this itself, rather than the
caller having to manage it.
2022-06-06 08:47:49 +10:00
ouz-a
8f1fff04a7 get_vtable returns opt instd of unwrpping 2022-06-05 16:35:02 +03:00
bors
4322a785cc Auto merge of #97697 - WaffleLapkin:no_ref_vec, r=WaffleLapkin
Replace `&Vec<_>`s with `&[_]`s

It's generally preferable to use `&[_]` since it's one less indirection and it can be created from types other that `Vec`.

I've left `&Vec` in some locals where it doesn't really matter, in cases where `TypeFoldable` is expected (`TypeFoldable: Clone` so slice can't implement it) and in cases where it's `&TypeAliasThatIsActiallyVec`. Nothing important, really, I was just a little annoyed by `visit_generic_param_vec` :D

r? `@compiler-errors`
2022-06-05 09:30:53 +00:00
Michael Goulet
4c6a6bc3f9 Tighten spans for bad fields in Copy struct 2022-06-03 19:17:12 -07:00
Maybe Waffle
afaa9854fa Replace &Vec<_>s with &[_]s 2022-06-03 20:42:42 +04:00
Takayuki Maeda
28988902a2 fix wrong suggestion for adding where clauses 2022-06-02 20:50:01 +09:00
Yuki Okushi
85fdef087c
Rollup merge of #97616 - TaKO8Ki:remove-unnecessary-option, r=Dylan-DPC
Remove an unnecessary `Option`
2022-06-01 23:36:53 +09:00
Takayuki Maeda
8d007aa06d remove an unnecessary Option 2022-06-01 17:06:07 +09:00