Commit Graph

12090 Commits

Author SHA1 Message Date
lcnr
afbecc0f68 remove now unnecessary lang items 2022-03-30 11:23:58 +02:00
lcnr
bef6f3e895 rework implementation for inherent impls for builtin types 2022-03-30 11:23:58 +02:00
lcnr
4558a125b6 remove NoMatchData::new 2022-03-30 11:23:58 +02:00
lcnr
975162d1be update comment 2022-03-30 11:23:58 +02:00
bors
f132bcf3bd Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis
Lazy type-alias-impl-trait take two

### user visible change 1: RPIT inference from recursive call sites

Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned.

```rust
fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return 42
    }
    let x: u32 = bar(false); // this errors on stable
    99
}
```

The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type.

### user visible change 2: divergence between RPIT and TAIT in return statements

Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So

```rust
#![feature(type_alias_impl_trait)]
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![42];
    }
    std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![42]
    }
    std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended)
}
```

But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same:

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![];
    }
    let mut x = foo(false);
    x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator
    vec![]
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![];
    }
    let mut x = bar(false);
    x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator
    vec![]
}
```

### user visible change 3: TAIT does not merge types across branches

In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile.

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        vec![42_i32]
    } else {
        std::iter::empty().collect()
        //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_`
    }
}
```

It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this).

### PR formalities

previous attempt: #92007

This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893

fixes #93411
fixes #88236
fixes #89312
fixes #87340
fixes #86800
fixes #86719
fixes #84073
fixes #83919
fixes #82139
fixes #77987
fixes #74282
fixes #67830
fixes #62742
fixes #54895
2022-03-30 05:04:45 +00:00
Dylan DPC
a0d2862ca4
Rollup merge of #95386 - compiler-errors:try-wrapping, r=oli-obk
Suggest wrapping patterns in enum variants

Structured suggestion to wrap a pattern in a single-field enum or struct:

```diff
 struct A;

 enum B {
   A(A),
 }

 fn main(b: B) {
   match b {
-    A => {}
+    B::A(A) => {}
   }
 }
```

Half of #94942, the other half I'm not exactly sure how to fix.

Also includes two drive-by changes (that I am open to splitting out into another PR, but thought they could be rolled up into this one):
- 07776c111f: Makes sure not to suggest wrapping if it doesn't have tuple field constructor (i.e. has named fields)
- 8f2bbb18fd53e5008bb488302dbd354577698ede: Also suggest wrapping expressions in a tuple struct (not just enum variants)
2022-03-29 22:46:34 +02:00
Dylan DPC
564c583162
Rollup merge of #95422 - TaKO8Ki:use-format-args-capture-and-remove-unnecessary-nesting-in-rustc-typeck, r=petrochenkov
Refactor: Use `format-args-capture` and remove an unnecessary nested block
2022-03-29 17:11:54 +02:00
Dylan DPC
eceb173de9
Rollup merge of #95415 - notriddle:notriddle/issue-82081, r=Dylan-DPC
diagnostics: regression test for HashMap iter_mut suggestion

Closes #82081
2022-03-29 17:11:52 +02:00
Michael Goulet
ac95e80186 Suggest function borrow ignoring needs_note
`needs_note` is false if we've already suggested why the type is Copy...
but that has nothing to do with the diagnostic.
2022-03-28 22:27:07 -07:00
Michael Goulet
a9b02e13a6 drive-by: move Copy bound suggestion to its own function 2022-03-28 22:27:07 -07:00
Michael Goulet
0f3c2933e0 Add suggestion to borrow opaque Fn and FnMut instead of move 2022-03-28 22:27:06 -07:00
Takayuki Maeda
f2506c911b use format-args-capture and remove an unnecessary nested block 2022-03-29 12:18:22 +09:00
Michael Howell
a063b3a4b6 diagnostics: do not suggest map.iter_mut()() 2022-03-28 11:48:14 -07:00
Dylan DPC
ce319ac1a2
Rollup merge of #95328 - DrMeepster:box_gep_err, r=oli-obk
Fix yet another Box<T, A> ICE

Fixes #95036.

This widens the special case from #94414 to make sure that boxes with a custom allocator are never directly dereferenced.
2022-03-28 20:41:51 +02:00
Dylan DPC
e10d5039bc
Rollup merge of #95318 - rust-lang:notriddle/issue-95208, r=wesleywiser
diagnostics: correct generic bounds with doubled colon

Fixes #95208
2022-03-28 20:41:50 +02:00
Dylan DPC
72770efcb0
Rollup merge of #93787 - klensy:really-not-a-features, r=wesleywiser
parallel_compiler: hide dependencies behind feature

Separate dependencies for `parallel_compiler` feature, so they will not be compiled if feature not selected, reducing number of compiled crates from 238 to 224.
2022-03-28 20:41:49 +02:00
Oli Scherer
360edd611d Also use the RPIT back compat hack in trait projection 2022-03-28 17:09:00 +00:00
Oli Scherer
2aa49d4005 Fix mixing lazy TAIT and RPIT in their defining scopes 2022-03-28 17:02:21 +00:00
Oli Scherer
6596e9dfcf Test that TAIT and RPIT are in sync 2022-03-28 17:01:23 +00:00
Oli Scherer
1f46f771a6 Remove some special code handling TAIT being passed through if and match
This is not necessary for RPIT anymore, since we reverted that to using inference vars.
2022-03-28 17:00:29 +00:00
Oli Scherer
02536fe18b The hack isn't necessary for back compat anymore 2022-03-28 16:59:56 +00:00
Oli Scherer
7f933de194 Merge two duplicates of the same logic into a common function 2022-03-28 16:59:11 +00:00
Oli Scherer
1163aa7e72 Remove opaque type obligation and just register opaque types as they are encountered.
This also registers obligations for the hidden type immediately.
2022-03-28 16:57:45 +00:00
Oli Scherer
86e1860495 Revert to inference variable based hidden type computation for RPIT 2022-03-28 16:53:47 +00:00
Oli Scherer
3136bfef93 Special case the situation where the previous span is the same as the new one 2022-03-28 16:31:52 +00:00
Oli Scherer
d5b6510bfb Have the spans of TAIT type conflict errors point to the actual site instead of the owning function 2022-03-28 16:30:59 +00:00
Oli Scherer
4b249b062b Remove some dead code 2022-03-28 16:30:34 +00:00
Oli Scherer
4cfaf9a931 Normalize all projections in mir validation again 2022-03-28 16:30:16 +00:00
Oli Scherer
1c5bfb1770 Don't bind hidden types when searching for matching impls 2022-03-28 16:29:54 +00:00
Oli Scherer
f42a6793ce Fail more aggressively 2022-03-28 16:29:31 +00:00
Oli Scherer
264cd05b16 Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"
This reverts commit 6499c5e7fc, reversing
changes made to 78450d2d60.
2022-03-28 16:27:14 +00:00
Dylan DPC
1c8b7412d4
Rollup merge of #95390 - nnethercote:allow-doc-comments-in-macros, r=petrochenkov
Ignore doc comments in a declarative macro matcher.

Fixes #95267. Reverts to the old behaviour before #95159 introduced a
regression.

r? `@petrochenkov`
2022-03-28 16:08:11 +02:00
Dylan DPC
4dd9567cf6
Rollup merge of #95350 - petrochenkov:qpathregr, r=cjgillot
resolve: Simplify some diagnostic code to avoid an ICE

No need to resolve those paths, they are already resolved, we just need to take the results from `partial_res_map`.

Fixes https://github.com/rust-lang/rust/issues/95327
2022-03-28 16:08:09 +02:00
Dylan DPC
4651c8df02
Rollup merge of #95314 - c410-f3r:aqui-vamos-nos, r=lcnr
Tell users that `||` operators are not currently supported in let chain expressions

Tells that `||` operators are not currently supported instead of not allowed. See https://github.com/rust-lang/rust/issues/53667#issuecomment-1066075876

In other words, this PR is pretty much trivial.
2022-03-28 16:08:08 +02:00
Dylan DPC
ae037a86f9
Rollup merge of #95301 - nnethercote:rm-NtTT, r=petrochenkov
Remove `Nonterminal::NtTT`.

It's only needed for macro expansion, not as a general element in the
AST. This commit removes it, adds `NtOrTt` for the parser and macro
expansion cases, and renames the variants in `NamedMatch` to better
match the new type.

r? `@petrochenkov`
2022-03-28 16:08:07 +02:00
bors
0e4524e5b4 Auto merge of #94789 - compiler-errors:fatal-never, r=eddyb
Make fatal DiagnosticBuilder yield `!`

Fatal errors should really be fatal, so emitting them should cause us to exit at the same time.

Fine with just throwing away these changes if they're not worthwhile. Also, maybe we want to use an uninhabited enum instead of `!`.

r? `@eddyb` who has been working on `DiagnosticBuilder` stuff, feel free to reassign.
2022-03-28 11:08:23 +00:00
bors
b3e46a9763 Auto merge of #95396 - TaKO8Ki:suggest-replacing-field-when-using-the-same-type, r=compiler-errors
Suggest replacing a field when using the same type

closes #89166
2022-03-28 08:40:25 +00:00
bors
13c9fc38c9 Auto merge of #95300 - workingjubilee:less-bitsets, r=eddyb
Skip needless bitset for debuginfo

Found this while digging around looking at the inlining logic.
Seemed obvious enough so I decided to try to take care of it.
Is this what you had in mind, `@eddyb?`
2022-03-28 05:48:25 +00:00
klensy
008fc79dcd Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
klensy
78fbcca3e1 use cfg attribute instead of macro 2022-03-28 08:37:32 +03:00
Michael Goulet
928388bad2 Make fatal DiagnosticBuilder yield never 2022-03-27 22:25:32 -07:00
Takayuki Maeda
c26cfd1c53 use can_coerce instead of same_type_modulo_infer 2022-03-28 13:43:33 +09:00
Takayuki Maeda
9e4d019fee suggest replacing field when using the same type 2022-03-28 12:38:10 +09:00
bors
3badf5c51c Auto merge of #95333 - GuillaumeGomez:auto-trait-perf-issue, r=oli-obk
Fix perf issue for auto trait selection

Follow-up of https://github.com/rust-lang/rust/pull/95069 which fixes the perf issue introduced by it.

r? `@oli-obk`
2022-03-28 00:01:01 +00:00
Nicholas Nethercote
9967594346 Ignore doc comments in a declarative macro matcher.
Fixes #95267. Reverts to the old behaviour before #95159 introduced a
regression.
2022-03-28 10:45:24 +11:00
Michael Goulet
fc289a0796 suggest wrapping in struct tuples as well 2022-03-27 16:44:55 -07:00
Michael Goulet
07776c111f do not suggest enum tuple variant for named field variant 2022-03-27 16:10:02 -07:00
Michael Goulet
dd6683fcda suggest wrapping patterns with compatible enum variants 2022-03-27 16:10:02 -07:00
Nicholas Nethercote
364b908d57 Remove Nonterminal::NtTT.
It's only needed for macro expansion, not as a general element in the
AST. This commit removes it, adds `NtOrTt` for the parser and macro
expansion cases, and renames the variants in `NamedMatch` to better
match the new type.
2022-03-28 10:03:02 +11:00
bors
62523045ec Auto merge of #95382 - Dylan-DPC:rollup-bebyfd1, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #94939 (diagnostics: suggest missing comma in bad FRU syntax)
 - #95120 (Implement `apply_switch_int_edge_effects` for backward analyses)
 - #95364 (Add long error explanation for E0667)
 - #95366 (Remove test files with duplicated checksums)
 - #95368 (Fix typo in `String::try_reserve_exact` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-27 21:36:42 +00:00