Commit graph

920 commits

Author SHA1 Message Date
Oli Scherer
1fc9ef1edd tracing::instrument cleanup 2022-09-01 14:54:27 +00:00
Oli Scherer
d3b22c7267 Directly use the instrument macro instead of its full path 2022-09-01 14:53:46 +00:00
Dezhi Wu
b1430fb7ca Fix a bunch of typo
This PR will fix some typos detected by [typos].

I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.

[typos]: https://github.com/crate-ci/typos
2022-08-31 18:24:55 +08:00
Yuki Okushi
42a1901cf4
Rollup merge of #101192 - TaKO8Ki:remove-path-string, r=compiler-errors
Remove path string
2022-08-31 08:47:20 +09:00
Dylan DPC
15e2e5185a
Rollup merge of #100473 - compiler-errors:normalize-the-fn-def-sig-plz, r=lcnr
Attempt to normalize `FnDef` signature in `InferCtxt::cmp`

Stashes a normalization callback in `InferCtxt` so that the signature we get from `tcx.fn_sig(..).subst(..)` in `InferCtxt::cmp` can be properly normalized, since we cannot expect for it to have normalized types since it comes straight from astconv.

This is kind of a hack, but I will say that `@jyn514` found the fact that we present unnormalized types to be very confusing in real life code, and I agree with that feeling. Though altogether I am still a bit unsure about whether this PR is worth the effort, so I'm open to alternatives and/or just closing it outright.

On the other hand, this isn't a ridiculously heavy implementation anyways -- it's less than a hundred lines of changes, and half of that is just miscellaneous cleanup.

This is stacked onto #100471 which is basically unrelated, and it can be rebased off of that when that lands or if needed.

---

The code:
```rust
trait Foo { type Bar; }

impl<T> Foo for T {
    type Bar = i32;
}

fn foo<T>(_: <T as Foo>::Bar) {}

fn needs_i32_ref_fn(f: fn(&'static i32)) {}

fn main() {
    needs_i32_ref_fn(foo::<()>);
}
```

Before:
```
   = note: expected fn pointer `fn(&'static i32)`
                 found fn item `fn(<() as Foo>::Bar) {foo::<()>}`
```

After:
```
   = note: expected fn pointer `fn(&'static i32)`
                 found fn item `fn(i32) {foo::<()>}`
```
2022-08-30 16:56:08 +05:30
Dylan DPC
9cfd161cd5
Rollup merge of #99928 - compiler-errors:issue-99914, r=oli-obk
Do not leak type variables from opaque type relation

The "root cause" is that we call `InferCtxt::resolve_vars_if_possible` (3d9dd681f5) on the types we get back in `TypeError::Sorts` since I added a call to it in `InferCtxt::same_type_modulo_infer`. However if this `TypeError` comes from a `InferCtxt::commit_if_ok`, then it may reference type variables that do not exist anymore, which is problematic.

We avoid this by substituting the `TypeError` with the types we had before being generalized while handling opaques.

This is kinda gross, and I feel like we can get the same issue from other places where we generalize type/const inference variables. Maybe not? I don't know.

Fixes #99914
Fixes #99970
Fixes #100463
2022-08-30 16:56:07 +05:30
Takayuki Maeda
f6252a4862 remove path string 2022-08-30 19:06:19 +09:00
bors
0631ea5d73 Auto merge of #101183 - Dylan-DPC:rollup-6kewixv, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #95376 (Add `vec::Drain{,Filter}::keep_rest`)
 - #100092 (Fall back when relating two opaques by substs in MIR typeck)
 - #101019 (Suggest returning closure as `impl Fn`)
 - #101022 (Erase late bound regions before comparing types in `suggest_dereferences`)
 - #101101 (interpret: make read-pointer-as-bytes a CTFE-only error with extra information)
 - #101123 (Remove `register_attr` feature)
 - #101175 (Don't --bless in pre-push hook)
 - #101176 (rustdoc: remove unused CSS selectors for `.table-display`)
 - #101180 (Add another MaybeUninit array test with const)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-30 08:29:42 +00:00
Dylan DPC
1ea84961e8
Rollup merge of #101022 - compiler-errors:issue-101020, r=jackh726
Erase late bound regions before comparing types in `suggest_dereferences`

Fixes #101020
2022-08-30 11:26:50 +05:30
Dylan DPC
e63424db19
Rollup merge of #100092 - compiler-errors:issue-100075, r=oli-obk
Fall back when relating two opaques by substs in MIR typeck

This is certainly _one_ way to fix #100075. Not really confident it's the _best_ way to do it, though.

The root cause of this issue is that during MIR type-check, we end up trying to equate an opaque against the same opaque def-id but with different substs. Because of the way that we replace RPITs during (HIR) typeck with an inference variable, we don't end up emitting a type-checking error, so the delayed MIR bug causes an ICE.

See the `src/test/ui/impl-trait/issue-100075-2.rs` test below to make that clear -- in that example, we try to equate `{impl Sized} substs=[T]` and `{impl Sized} substs=[Option<T>]`, which causes an ICE. This new logic will instead cause us to infer `{impl Sized} substs=[Option<T>]` as the hidden type for `{impl Sized} substs=[T]`, which causes a proper error to be emitted later on when we check that an opaque isn't recursive.

I'm open to closing this in favor of something else. Ideally we'd fix this in typeck, but the thing we do to ensure backwards compatibility with weird RPIT cases makes that difficult. Also open to discussing this further.
2022-08-30 11:26:48 +05:30
bors
a0d07093f8 Auto merge of #100812 - Nilstrieb:revert-let-chains-nightly, r=Mark-Simulacrum
Revert let_chains stabilization

This is the revert against master, the beta revert was already done in #100538.

Bumps the stage0 compiler which already has it reverted.
2022-08-30 05:48:22 +00:00
bors
9f4d5d2a28 Auto merge of #101167 - matthiaskrgr:rollup-yt3jdmp, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #100898 (Do not report too many expr field candidates)
 - #101056 (Add the syntax of references to their documentation summary.)
 - #101106 (Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items)
 - #101131 (CTFE: exposing pointers and calling extern fn is just impossible)
 - #101141 (Simplify `get_trait_ref` fn used for `virtual_function_elimination`)
 - #101146 (Various changes to logging of borrowck-related code)
 - #101156 (Remove `Sync` requirement from lint pass objects)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-29 22:49:04 +00:00
Matthias Krüger
7b84298f1b
Rollup merge of #101146 - jackh726:borrowck-logging, r=compiler-errors
Various changes to logging of borrowck-related code

Cleanups found when doing other changes

r? `@compiler-errors`
2022-08-29 21:12:59 +02:00
Nilstrieb
d1ef8180f9 Revert let_chains stabilization
This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
Jack Huey
8033c3c27d Various changes to logging of borrowck-related code 2022-08-29 10:59:21 -04:00
Dylan DPC
5555e13a6e
Rollup merge of #99821 - cjgillot:ast-lifetimes-2, r=compiler-errors
Remove separate indexing of early-bound regions

~Based on https://github.com/rust-lang/rust/pull/99728.~

This PR copies some modifications from https://github.com/rust-lang/rust/pull/97839 around object lifetime defaults.
These modifications allow to stop counting generic parameters during lifetime resolution, and rely on the indexing given by `rustc_typeck::collect`.
2022-08-29 16:49:39 +05:30
Matthias Krüger
a3c965f5fe
Rollup merge of #100843 - IntQuant:issue-100717-infer, r=compiler-errors
Migrate part of rustc_infer to session diagnostic
2022-08-29 06:34:45 +02:00
Matthias Krüger
26c86c6993
Rollup merge of #100437 - compiler-errors:better-const-mismatch-err, r=oli-obk
Improve const mismatch `FulfillmentError`

Fixes #100414
2022-08-29 06:34:44 +02:00
Michael Goulet
48b3d8aa82 Drive-by: same_type_modulo_infer should handle ReVar == ReVar 2022-08-26 04:42:53 +00:00
Michael Goulet
075b3ce89d Attempt to normalize FnDef signature in InferCtxt::cmp 2022-08-25 23:32:46 +00:00
Yuki Okushi
f4550a6edf
Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkov
Stabilize `#![feature(label_break_value)]`

See the stabilization report in https://github.com/rust-lang/rust/issues/48594#issuecomment-1186213313.
2022-08-25 08:50:54 +09:00
Michael Goulet
4e976262a1 Call them constants instead of types 2022-08-24 17:53:35 +00:00
IQuant
e1765a9c56
Remove commented lines 2022-08-24 17:09:07 +03:00
Nikita Tomashevich
3fae3904b1
Use IntoDiagnosticArg where it makes sense 2022-08-24 15:46:29 +03:00
Joshua Nelson
31e39446ec Stabilize #![feature(label_break_value)]
# Stabilization proposal

The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now).
There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`.

There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed).
1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234
2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176
3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630

Many different examples of code that's simpler using this feature have been provided:
- A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014
- A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251. This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize).
- Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395
- Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733
- An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569
- Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006

Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249

nrc later resolved their concern, mostly because of the aforementioned macro problems.
joshtriplett suggested that macros could be able to generate IR directly
(https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983) but there are no open RFCs,
and the design space seems rather speculative.

joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804

withoutboats has regrettably left the language team.

joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353

[issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+

 ## Report

+ Feature gate:
    - d695a497bb/src/test/ui/feature-gates/feature-gate-label_break_value.rs
+ Diagnostics:
    - 6b2d3d5f3c/compiler/rustc_parse/src/parser/diagnostics.rs (L2629)
    - f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L749)
    - f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L1001)
    - 111df9e6ed/compiler/rustc_passes/src/loops.rs (L254)
    - d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L2079)
    - d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L1569)
+ Tests:
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs

 ## Interactions with other features

Labels follow the hygiene of local variables.

label-break-value is permitted within `try` blocks:
```rust
let _: Result<(), ()> = try {
    'foo: {
        Err(())?;
        break 'foo;
    }
};
```

label-break-value is disallowed within closures, generators, and async blocks:
```rust
'a: {
    || break 'a
    //~^ ERROR use of unreachable label `'a`
    //~| ERROR `break` inside of a closure
}
```

label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]:
```rust
fn labeled_match() {
    match false 'b: { //~ ERROR block label not supported here
        _ => {}
    }
}

macro_rules! m {
    ($b:block) => {
        'lab: $b; //~ ERROR cannot use a `block` macro fragment here
        unsafe $b; //~ ERROR cannot use a `block` macro fragment here
        |x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here
    }
}

fn foo() {
    m!({});
}
```

[_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html
[_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html
2022-08-23 21:14:12 -05:00
Dylan DPC
f42cdf76e1
Rollup merge of #100368 - chenyukang:fix-100321, r=lcnr
InferCtxt tainted_by_errors_flag should be Option<ErrorGuaranteed>

Fixes #100321.
Use Cell<Option<ErrorGuaranteed>> to guarantee that we emit an error when that flag is set.
2022-08-23 20:40:03 +05:30
Nikita Tomashevich
f50d1713fd
Migrate note_region_origin function 2022-08-23 14:47:08 +03:00
Nikita Tomashevich
3f6cb475f7
Use GeneratorKind::descr() instead of it's Display impl
Those are basically the same but the first one seems to fit better
2022-08-23 14:47:08 +03:00
Nikita Tomashevich
7e4f433720
Actually migrate OpaqueHiddenType 2022-08-23 14:47:08 +03:00
Nikita Tomashevich
313d474b35
Migrate OpaqueHiddenType, E0282, E0283, E0284, E0698 2022-08-23 14:47:07 +03:00
yukang
8be37644db InferCtxt emit error when incorrectly tainted by errors 2022-08-22 22:15:23 +08:00
SparrowLii
a01ac5a699 re-base and use OutlivesEnvironment::with_bounds 2022-08-22 18:36:02 +08:00
SparrowLii
d037f1843e add with_bounds to OutlivesEnvironment and implied_bounds_tys to outlives_bounds::InferCtxtExt 2022-08-22 18:09:59 +08:00
SparrowLii
5d9e4d07fc get rid of RefCell in TransitiveRelation 2022-08-22 18:08:46 +08:00
Michael Goulet
c005e760f5 Rework point-at-arg 2022-08-21 02:34:52 +00:00
Matthias Krüger
51769af6ea
Rollup merge of #100691 - compiler-errors:issue-100690, r=estebank
Make `same_type_modulo_infer` a proper `TypeRelation`

Specifically, this fixes #100690 because we no longer consider a `ReLateBound` and a `ReVar` to be equal. `ReVar` can only be equal to free regions or static.
2022-08-20 19:32:11 +02:00
Matthias Krüger
61a529d902
Rollup merge of #100617 - chenyukang:fix-100605, r=compiler-errors
Suggest the right help message for as_ref

Fixes #100605
2022-08-20 07:09:00 +02:00
yukang
3de74f7e2b Suggest the right help message for as_ref 2022-08-20 09:43:37 +08:00
bors
8064a49508 Auto merge of #99860 - oli-obk:revert_97346, r=pnkfelix
Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, …

…r=oli-obk"

This reverts commit c703d11dcc, reversing
changes made to 64eb9ab869.

it didn't apply cleanly, so now it works the same for RPIT and for TAIT instead of just working for RPIT, but we should keep those in sync anyway. It also exposed a TAIT bug (see the feature gated test that now ICEs).

r? `@pnkfelix`

fixes #99536
2022-08-18 15:41:30 +00:00
Michael Goulet
64bd8c1dc4 Make same_type_modulo_infer a proper TypeRelation 2022-08-17 19:02:55 +00:00
Michael Goulet
fc7fc0fae5 ty::Error does not match other types for region constraints 2022-08-17 17:23:52 +00:00
Michael Goulet
8b64988575 Fix error message with non-tupled bare fn trait 2022-08-16 01:21:11 +00:00
Michael Goulet
75dfe55a5d TypeError can be Copy 2022-08-14 19:58:46 +00:00
Michael Goulet
aa1a07f114 Do not inline non-simple argument type errors into labels 2022-08-13 18:24:36 +00:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Michael Goulet
534426d0f3 Delay a bug if we try and fail to relate an opaque to itself in TypeRelating 2022-08-10 03:36:05 +00:00
Michael Goulet
28b6373b1d Fall back when relating two opaques by substs in MIR typeck 2022-08-10 03:27:41 +00:00
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
Matthias Krüger
6919a07eb8
Rollup merge of #100102 - b-naber:typo-higher-ranked-sub, r=Dylan-DPC
Fix typo

r? ```@jackh726```
2022-08-03 22:30:46 +02:00
Camille GILLOT
421bb6ac62 Remove index from Region::EarlyBound. 2022-08-03 18:44:18 +02:00