Commit Graph

20005 Commits

Author SHA1 Message Date
Michael Goulet
d0db3279ab Don't bug if we're trying to cast dyn* to a nother type 2022-12-14 18:00:56 +00:00
bors
7bdda8f801 Auto merge of #105686 - matthiaskrgr:rollup-bedfk3j, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #103644 (Add docs for question mark operator for Option)
 - #105161 (Refine when invalid prefix case error arises)
 - #105491 (Illegal sized bounds: only suggest mutability change if needed)
 - #105502 (Suggest impl in the scenario of typo with fn)
 - #105523 (Suggest `collect`ing into `Vec<_>`)
 - #105595 (Suggest dereferencing receiver arguments properly)
 - #105611 (fold instead of obliterating args)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-14 09:33:57 +00:00
Matthias Krüger
01469693de
Rollup merge of #105611 - BoxyUwU:more_granular_placeholderification, r=wesleywiser
fold instead of obliterating args

Fixes #105608

we call `const_eval_resolve` on the following constant:
```
def: playground::{impl#0}::and::{constant#0},
substs: [
  ConstKind::Unevaluated {
    def: playground::{impl#0}::and::{constant#0},
    substs: [
      ConstKind::Value(0x0),
      _,
    ]
  }
  _,
],
```
when expanded out to `ConstKind::Expr` there are no infer vars so we attempt to evaluate it after replacing infer vars with garbage, however the current logic for replacing with garbage replaces _the whole arg containing the infer var_ rather than just the infer var. This means that after garbage replacement has occured we attempt to evaluate:
```
def: playground::{impl#0}::and::{constant#0},
substs: [
  PLACEHOLDER,
  PLACEHOLDER,
],
```
Which then leads to ctfe being unable to evaluate the const. With this PR we attempt to evaluate:
```
def: playground::{impl#0}::and::{constant#0},
substs: [
  ConstKind::Unevaluated {
    def: playground::{impl#0}::and::{constant#0},
    substs: [
      ConstKind::Value(0x0),
      PLACEHOLDER,
    ]
  }
  PLACEHOLDER,
],
```
which ctfe _can_ handle.

I am not entirely sure why this function is supposed to replace params with placeholders rather than just inference vars 🤔
2022-12-14 10:31:08 +01:00
Matthias Krüger
939880ab72
Rollup merge of #105595 - TaKO8Ki:suggest-dereferencing-receiver-argument, r=compiler-errors
Suggest dereferencing receiver arguments properly

Fixes #105429
2022-12-14 10:31:07 +01:00
Matthias Krüger
e5fde968db
Rollup merge of #105523 - estebank:suggest-collect-vec, r=compiler-errors
Suggest `collect`ing into `Vec<_>`

Fix #105510.
2022-12-14 10:31:07 +01:00
Matthias Krüger
c8fd654d7c
Rollup merge of #105502 - chenyukang:yukang/fix-105366-impl, r=estebank
Suggest impl in the scenario of typo with fn

Fixes #105366
2022-12-14 10:31:06 +01:00
Matthias Krüger
49b99078b0
Rollup merge of #105491 - sulami:master, r=compiler-errors
Illegal sized bounds: only suggest mutability change if needed

In a scenario like

```rust
struct Type;

pub trait Trait {
    fn function(&mut self)
    where
        Self: Sized;
}

impl Trait for Type {
    fn function(&mut self) {}
}

fn main() {
    (&mut Type as &mut dyn Trait).function();
}
```

the problem is Sized, not the mutability of self. Thus don't emit the "you need &T instead of &mut T" note, or the other way around, as all it does is just invert the mutability of whatever was supplied.

Fixes #103622.
2022-12-14 10:31:05 +01:00
Matthias Krüger
8ed0384ca4
Rollup merge of #105161 - cassaundra:numeric-literal-error, r=nnethercote
Refine when invalid prefix case error arises

Fix cases where the "invalid base prefix for number literal" error arises with suffixes that look erroneously capitalized but which are actually invalid.
2022-12-14 10:31:05 +01:00
bors
dc30b92cc5 Auto merge of #105221 - alex:fat-archive-cleanup, r=bjorn3
Avoid a temporary file when processing macOS fat archives

r? `@bjorn3`
2022-12-14 06:51:50 +00:00
bors
309c469eec Auto merge of #104875 - chenyukang:yukang/fix-104867-inc, r=estebank
Properly handle postfix inc/dec in standalone and subexpr scenarios

Fixes #104867
r? `@estebank`
2022-12-14 04:00:05 +00:00
bors
918d0ac38e Auto merge of #104986 - compiler-errors:opaques, r=oli-obk
Combine `ty::Projection` and `ty::Opaque` into `ty::Alias`

Implements https://github.com/rust-lang/types-team/issues/79.

This PR consolidates `ty::Projection` and `ty::Opaque` into a single `ty::Alias`, with an `AliasKind` and `AliasTy` type (renamed from `ty::ProjectionTy`, which is the inner data of `ty::Projection`) defined as so:

```
enum AliasKind {
  Projection,
  Opaque,
}

struct AliasTy<'tcx> {
  def_id: DefId,
  substs: SubstsRef<'tcx>,
}
```

Since we don't have access to `TyCtxt` in type flags computation, and because repeatedly calling `DefKind` on the def-id is expensive, these two types are distinguished with `ty::AliasKind`, conveniently glob-imported into `ty::{Projection, Opaque}`. For example:

```diff
  match ty.kind() {
-   ty::Opaque(..) =>
+   ty::Alias(ty::Opaque, ..) => {}
    _ => {}
  }
```

This PR also consolidates match arms that treated `ty::Opaque` and `ty::Projection` identically.

r? `@ghost`
2022-12-14 01:19:24 +00:00
bors
21ee03e062 Auto merge of #105667 - matthiaskrgr:rollup-fexlc0b, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #105147 (Allow unsafe through inline const)
 - #105438 (Move some codegen-y methods from `rustc_hir_analysis::collect` -> `rustc_codegen_ssa`)
 - #105464 (Support #[track_caller] on async closures)
 - #105476 (Change pattern borrowing suggestions to be verbose and remove invalid suggestion)
 - #105500 (Make some diagnostics not depend on the source of what they reference being available)
 - #105628 (Small doc fixes)
 - #105659 (Don't require owned data in `MaybeStorageLive`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-12-13 22:05:28 +00:00
Esteban Küber
40a62758a7 rename argument 2022-12-13 13:23:19 -08:00
Esteban Küber
165efabbee review comments 2022-12-13 11:36:43 -08:00
Matthias Krüger
e0e9f3a7b7
Rollup merge of #105659 - JakobDegen:storage-live-borrow, r=davidtwco
Don't require owned data in `MaybeStorageLive`

Small improvement that avoids a clone. I don't expect this to have any noticeable perf effects, but better to have it than not to.

r? ``@tmiasko``
2022-12-13 19:57:12 +01:00
Matthias Krüger
1c86de25f1
Rollup merge of #105628 - spastorino:small-doc-fixes, r=compiler-errors
Small doc fixes

r? `@compiler-errors`
2022-12-13 19:57:12 +01:00
Matthias Krüger
15b9e20640
Rollup merge of #105500 - oli-obk:unhide_unknown_spans, r=estebank
Make some diagnostics not depend on the source of what they reference being available

r? `@estebank`

follow up to https://github.com/rust-lang/rust/pull/104449
2022-12-13 19:57:11 +01:00
Matthias Krüger
dcdbbd0471
Rollup merge of #105476 - estebank:moves-n-borrows, r=compiler-errors
Change pattern borrowing suggestions to be verbose and remove invalid suggestion

Synthesize a more accurate span and use verbose suggestion output to
make the message clearer.

Do not suggest borrowing binding in pattern in let else. Fix #104838.
2022-12-13 19:57:11 +01:00
Matthias Krüger
5e38e702aa
Rollup merge of #105464 - nbdd0121:hir, r=compiler-errors
Support #[track_caller] on async closures

Follow up on #105180

r? ```@compiler-errors```
cc ```@cjgillot```
2022-12-13 19:57:10 +01:00
Matthias Krüger
51375dd7a8
Rollup merge of #105438 - compiler-errors:move-methods, r=estebank
Move some codegen-y methods from `rustc_hir_analysis::collect` -> `rustc_codegen_ssa`

Unclear if they should live here, but they seem codegen-y enough, and `rustc_hir_analysis::collect` is extremely long, so it should probably lose some methods.
2022-12-13 19:57:10 +01:00
Matthias Krüger
7357cfbf3d
Rollup merge of #105147 - nbdd0121:inline_const_unsafe, r=oli-obk
Allow unsafe through inline const

Handle similar to closures.

Address https://github.com/rust-lang/rust/pull/104087#issuecomment-1324173328

Note that this PR does not fix the issue for `unsafe { [0; function_requiring_unsafe()] }`. This is fundamentally unfixable for MIR unsafeck IMO.

This PR also does not fix unsafety checking for inline const in pattern position. It actually breaks it, allowing unsafe functions to be used in inline const in pattern position without unsafe blocks. Inline const in pattern position is not visible in MIR so ignored by MIR unsafety checking (currently it is also not checked by borrow checker, which is the reason why it's considered an incomplete feature).

`@rustbot` label: +T-lang +F-inline_const
2022-12-13 19:57:09 +01:00
Takayuki Maeda
19fa5b381c suggest dereferencing receiver arguments properly
fix a stderr
2022-12-14 03:48:54 +09:00
bors
0f529f0f49 Auto merge of #102813 - Akida31:issue-64915/simpler_diagnostic_when_passing_arg_to_closure_and_missing_borrow, r=estebank
Simpler diagnostic when passing arg to closure and missing borrow

fixes #64915

I followed roughly the instructions and the older PR #76362.
The number of references for the expected and the found types will be compared and depending on which has more the diagnostic will be emitted.

I'm not quite sure if my approach with the many `span_bug!`s is good, it could lead to some ICEs. Would it be better if  those errors are ignored?

As far as I know the following code works similarly but in a different context. Is this probably reusable since it looks like it would emit better diagnostics?
a688a0305f/compiler/rustc_hir_analysis/src/check/demand.rs (L713-L1061)

When running the tests locally, a codegen test failed. Is there something I can/ should do about that?

If you have some improvements/ corrections please say so and I will happily include them.

r? `@estebank` (as you added the mentoring instructions to the issue)
2022-12-13 18:46:35 +00:00
Esteban Küber
7d1e47aeb0 Suggest : Type instead of : _ 2022-12-13 10:39:44 -08:00
Esteban Küber
3e25bcb020 Mention implementations that satisfy the trait 2022-12-13 10:39:44 -08:00
Esteban Küber
b3fba5e18a Remove unnecessary code and account for turbofish suggestion
Remove previously existing fallback that tried to give a good turbofish
suggestion, `need_type_info` is already good enough.

Special case `::<Vec<_>` suggestion for `Iterator::collect`.
2022-12-13 10:39:44 -08:00
Esteban Küber
9d5e7d3c04 Suggest collecting into Vec<_> 2022-12-13 10:39:44 -08:00
Esteban Küber
cf0b6b9337 Account for dereference expressions 2022-12-13 10:06:15 -08:00
Esteban Küber
b8bd1d0826 Fix span for &mut removal suggestion 2022-12-13 10:06:14 -08:00
Esteban Küber
dd72b1a0df Suggest ref for some patterns as a fallback 2022-12-13 10:06:14 -08:00
Esteban Küber
4f7c257fd8 Do not suggest borrowing binding in pattern in let else
Fix #104838.
2022-12-13 10:06:13 -08:00
Esteban Küber
e46416eed6 Change pattern borrowing suggestions to be verbose
Synthesize a more accurate span and use verbose suggestion output to
make the message clearer.
2022-12-13 10:06:13 -08:00
Michael Goulet
99417d54af Address a few more nits 2022-12-13 17:56:04 +00:00
Michael Goulet
fbe66a6ef3 Address nits
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-12-13 17:56:04 +00:00
Michael Goulet
7196973c3e Remove chalk lowering for AliasTy 2022-12-13 17:48:55 +00:00
Michael Goulet
0f9e414092 nit: docs 2022-12-13 17:48:55 +00:00
Michael Goulet
4b19a2c119 Combine OfOpaque and OfProjection 2022-12-13 17:48:55 +00:00
Michael Goulet
96cb18e864 Combine identical alias arms 2022-12-13 17:48:55 +00:00
Michael Goulet
61adaf8187 Combine projection and opaque into alias 2022-12-13 17:48:55 +00:00
Michael Goulet
c13bd83528 squash OpaqueTy and ProjectionTy into AliasTy 2022-12-13 17:40:27 +00:00
Michael Goulet
5c6afb850c ProjectionTy.item_def_id -> ProjectionTy.def_id 2022-12-13 17:34:44 +00:00
Michael Goulet
7f3af72606 Use ty::OpaqueTy everywhere 2022-12-13 17:29:26 +00:00
Michael Goulet
918ede6474 make Opaque have one field: OpaqueTy 2022-12-13 17:27:41 +00:00
akida31
757396f5fe
tidy: ignore filelength 2022-12-13 16:37:44 +01:00
akida31
f780faa8c4
reduce to single suggestion for all arguments 2022-12-13 16:30:04 +01:00
akida31
4d87fb5d11
remove manual fn_decl extraction 2022-12-13 16:29:13 +01:00
akida31
7822822d51
change error message 2022-12-13 16:29:10 +01:00
akida31
b1d7430657
move changes to an extra function 2022-12-13 16:28:34 +01:00
akida31
e326e8c885
Remove hint from help message 2022-12-13 16:28:31 +01:00
akida31
1e5d772417
Improve diagnostic when passing arg to closure and missing borrow.
This checks the number of references for the given and expected type and
shows hints to the user if the numbers don't match.
2022-12-13 16:24:38 +01:00