Commit Graph

15077 Commits

Author SHA1 Message Date
Yuki Okushi
cc35c787aa
Rollup merge of #99350 - compiler-errors:issue-99240, r=fee1-dead
Be more precise when suggesting removal of parens on unit ctor

* Fixes #99240 by only suggesting to remove parens on path exprs, not arbitrary expressions with enum type
* Generalizes by suggesting removal of parens on unit struct, too, because why not?
2022-07-18 08:39:58 +09:00
bors
263edd43c5 Auto merge of #99033 - 5225225:interpreter-validity-checks, r=oli-obk
Use constant eval to do strict mem::uninit/zeroed validity checks

I'm not sure about the code organisation here, I just dumped the check in rustc_const_eval at the root. Not hard to move it elsewhere, in any case.

Also, this means cranelift codegen intrinsics lose the strict checks, since they don't seem to depend on rustc_const_eval, and I didn't see a point in keeping around two copies.

I also left comments in the is_zero_valid methods about "uhhh help how do i do this", those apply to both methods equally.

Also rustc_codegen_ssa now depends on rustc_const_eval... is this okay?

Pinging `@RalfJung` since you were the one who mentioned this to me, so I'm assuming you're interested.

Haven't had a chance to run full tests on this since it's really warm, and it's 1AM, I'll check out any failures/comments in the morning :)
2022-07-17 19:28:01 +00:00
Michael Goulet
7a45a60418 use rustc_hir_pretty::qpath_to_string to avoid span_to_snippet when rendering path 2022-07-17 04:58:38 +00:00
Caio
3266460749 Stabilize let_chains 2022-07-16 20:17:58 -03:00
Michael Goulet
04c590b7ef Be more precise when suggesting removal of parens on unit adt ctor 2022-07-16 22:15:41 +00:00
Matthias Krüger
6277ac2fb8
Rollup merge of #99342 - TaKO8Ki:avoid-symbol-to-string-conversions, r=compiler-errors
Avoid some `Symbol` to `String` conversions

This patch removes some Symbol to String conversions.
2022-07-16 22:30:56 +02:00
Matthias Krüger
4805c215c8
Rollup merge of #99316 - tshepang:clearer, r=compiler-errors
docs: add missing word
2022-07-16 22:30:53 +02: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
Matthias Krüger
fa298beb79
Rollup merge of #99259 - RalfJung:visit-a-place, r=oli-obk
interpret/visitor: support visiting with a PlaceTy

Finally we can visit a `PlaceTy` in a way that will only do `force_allocation` when needed ti visit a field. :)

r? `@oli-obk`
2022-07-16 22:30:51 +02:00
Matthias Krüger
984ef421fd
Rollup merge of #99258 - estebank:suggest-let, r=wesleywiser
Provide structured suggestion for dropped temp value
2022-07-16 22:30:49 +02:00
Matthias Krüger
79857a740e
Rollup merge of #99213 - davidtwco:translation-migrate-passes, r=compiler-errors
migrate some of `rustc_passes::check_attr`'s diagnostics and derive improvements

- Implements `IntoDiagnosticArg` for `char` using its `Debug` implementation and introduces a macro for those types which just delegate the implementation to `ToString`.
- Apply the `#[rustc_lint_diagnostics]` attribute to `LintDiagnosticBuilder::build` so that diagnostic migration lints will trigger for it - some diagnostics in `rustc_privacy` need updated after this since the lints apply to that crate.
- Add support for `MultiSpan` with any of the attributes that work on a `Span` in the diagnostic derive (`SessionDiagnostic` + `LintDiagnostic`). Requires that diagnostic logic generated for these attributes are emitted in the by-move block rather than the by-ref block that they would normally have been generated in.
- Both diagnostic and subdiagnostic derives were missing the ability to add warnings to diagnostics - this is made more difficult by the `warn` attribute already existing, so this name being unavailable for the derives to use. `#[warn_]` is used instead, which requires special-casing so that `{span_,}warn` is called instead of `{span_,}warn_`.
- Migrate half of the `rustc_passes::check_attr` diagnostics to using diagnostic derives and being translatable. I got tired after a while. I modified some diagnostic output for consistency while doing this, nothing too crazy.

r? `@compiler-errors`
2022-07-16 22:30:48 +02:00
Matthias Krüger
6f8fb911ad
Rollup merge of #98582 - oli-obk:unconstrained_opaque_type, r=estebank
Allow destructuring opaque types in their defining scopes

fixes #96572

Before this PR, the following code snippet failed with an incomprehensible error, and similar code just ICEd in mir borrowck.

```rust
    type T = impl Copy;
    let foo: T = (1u32, 2u32);
    let (a, b) = foo;
```

The problem was that the last line created MIR projections of the form `foo.0` and `foo.1`, but `foo`'s type is `T`, which doesn't have fields (only its hidden type does). But the pattern supplies enough type information (a tuple of two different inference types) to bind a hidden type.
2022-07-16 22:30:47 +02:00
Takayuki Maeda
c54d4ada26 avoid some Symbol to String conversions 2022-07-17 04:09:20 +09:00
bors
7210e46dc6 Auto merge of #99315 - JohnTitor:rollup-77wzoc1, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #98387 (Add new unstable API `downcast` to `std::io::Error`)
 - #98662 (Add std::fs::write documentation precision)
 - #99253 (Remove FIXME from MIR `always_storage_live_locals`)
 - #99264 (Fix typo in mod.rs)
 - #99270 (Add `#[must_use]` to `Box::from_raw`)
 - #99277 (Stabilize `core::ffi::CStr`, `alloc::ffi::CString`, and friends)
 - #99307 (Add regression test for #64401)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-16 16:30:25 +00:00
bors
56351589f8 Auto merge of #99263 - compiler-errors:issue-99261, r=jyn514
Fix ICE in `named_arguments_used_positionally` lint

Fixes #99261
Fixes #99289
Fixes #99284
Fixes #99273
Fixes #99297
Fixes #99271

This match pattern:

```
 FormatSpec { width: Count::CountIsName(s, _), .. }
| FormatSpec { precision: Count::CountIsName(s, _), .. }
```

does not account for when both `width` and `precision` are both `Count::CountIsName`, so split the check for these two fields into two separate `if let`.

Also, remove any future potential for ICEs by removing the index operator altogether.

---

It is still suspicious that this indexing was broken and caused the ICE, as opposed to just causing a spurious lint message.

cc `@PrestonFrom,` who may be familiar with this code because of implementing the lint this touches, perhaps you'd like to look into why named arguments in `FormatSpec.precision` seem to have indices that don't correspond to a span in `Context.arg_spans`?

Edit: Opened #99265 to track a (related?) incorrect argument indexing issue.
2022-07-16 14:05:52 +00:00
bors
d695a497bb Auto merge of #96482 - willcrichton:fix-trait-suggestion-for-binops, r=estebank
Add Output = expected type trait obligation for known binary operators

This PR is a follow-on to #94034 that addresses #96442. That is, after replacing the trait-suggestion logic in `op.rs` with a more generic path that analyzes a general set of `Obligation`s, then we lost some specificity in the suggestions where the bounds on the associated type `Output=` would not get suggested.

This PR fixes this issue by changing `FnCtxt::construct_obligation_for_trait` to include a new `ProjectionPredicate` obligation for binary operators that obliges that `Output` is the same as the expected type of the expression. Additionally, to get the expected type of the expression, this PR threads the `Expectation<'tcx>` structure throughout several functions.

See src/test/ui/generic-associated-types/missing-bounds.stderr for an example of how this works.

One side effect of this change is it causes type-check failures with binops to include additional information. Specifically, many now say

```
error: type mismatch resolving `<Lhs as TheBinop>::Output == ExpectedTy`
```

It's up for discussion whether this added context is worth it to the user.

r? `@estebank`
2022-07-16 11:36:19 +00:00
Tshepang Mbambo
653a214632 docs: add missing word 2022-07-16 12:11:43 +02:00
Yuki Okushi
b538d5acaf
Rollup merge of #99253 - pierwill:pierwill/rm-storage-fixme, r=oli-obk
Remove FIXME from MIR `always_storage_live_locals`

See discussion in https://github.com/rust-lang/rust/pull/99025#issuecomment-1183347428.
2022-07-16 17:53:01 +09: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
bors
e6c43cf8b9 Auto merge of #95685 - oxidecomputer:restore-static-dwarf, r=pnkfelix
Revert "Work around invalid DWARF bugs for fat LTO"

Since September, the toolchain has not been generating reliable DWARF
information for static variables when LTO is on. This has affected
projects in the embedded space where the use of LTO is typical. In our
case, it has kept us from bumping past the 2021-09-22 nightly toolchain
lest our debugger break. This has been a pretty dramatic regression for
people using debuggers and static variables. See #90357 for more info
and a repro case.

This commit is a mechanical revert of
d5de680e20 from PR #89041, which caused
the issue. (Note on that PR that the commit's author has requested it be
reverted.)

I have locally verified that this fixes #90357 by restoring the
functionality of both the repro case I posted on that bug, and debugger
behavior on real programs. There do not appear to be test cases for this
in the toolchain; if I've missed them, point me at 'em and I'll update
them.
2022-07-16 00:18:54 +00:00
Esteban Küber
3ee4e5f704 Fix rebase 2022-07-15 11:14:06 -07:00
Esteban Küber
635c38187b Avoid incorrect suggestion
We check that there's a single level of block nesting to ensure always
correct suggestions. If we don't, then we only provide a free-form
message to avoid misleading users in cases like
`src/test/ui/nll/borrowed-temporary-error.rs`.

We could expand the analysis to suggest hoising all of the relevant
parts of the users' code to make the code compile, but that could be
too much.
2022-07-15 11:04:45 -07:00
Esteban Küber
20b5aaf111 Provide structured suggestion for dropped temp value 2022-07-15 11:04:45 -07:00
Michael Goulet
2902b92769 Only suggest if span is not erroneous 2022-07-15 17:32:34 +00:00
Michael Goulet
b71a09fda0 Fix ICE in named_arguments_used_positionally lint 2022-07-15 17:32:34 +00:00
Michael Goulet
1c8f87e907 Revert "Highlight conflicting param-env candidates"
This reverts commit 08135254dc.
2022-07-15 17:21:55 +00:00
bors
23e21bdd25 Auto merge of #99015 - lcnr:fn-ctxt-no-more, r=compiler-errors
stop using `FnCtxt` outside of hir typeck

the requirements between **hir typeck**™, and **not hir typeck**™ are different enough to warrant a full split. with this PR `FnCtxt` is now only used for hir typeck (and for one clippy lint which seems to be emulating hir typeck).

Once this PR has landed I intend to move `FnCtxt` into a new crate. This should also allow some further general improvements here.

r? rust-lang/types
2022-07-15 17:11:07 +00:00
Oli Scherer
57e9f7a556 Infer wildcard type from other patterns at every pattern level 2022-07-15 15:56:17 +00:00
Oli Scherer
92e470a1de Move constructor into the branch that actually uses it 2022-07-15 15:56:17 +00:00
Oli Scherer
ea68ce7fac Revert a hack that only ever worked on level deep 2022-07-15 15:56:17 +00:00
Oli Scherer
6b33d5bfa9 Make destructuring a defining use 2022-07-15 15:56:17 +00:00
Oli Scherer
728c7e8bda Allow destructuring opaque types, since the patterns constrain the opaque types 2022-07-15 15:56:17 +00:00
Oli Scherer
12457f814c Some tracing helpers 2022-07-15 15:56:16 +00:00
Oli Scherer
0c6918fe21 Reuse a helper method instead of manually rolling it 2022-07-15 15:56:16 +00:00
Oli Scherer
7a8a048b58 Remove early return that would likely have caused miscompilations if it ever happened 2022-07-15 15:56:16 +00:00
Oli Scherer
eeb10335ce Pass one argument instead of fetching two fields of it at every call site 2022-07-15 15:56:16 +00:00
Oli Scherer
a034446fae Add some tracing instrumentation 2022-07-15 15:56:16 +00:00
Ralf Jung
c4cb043f06 interpret/visitor: support visiting with a PlaceTy 2022-07-15 11:54:20 -04:00
Oli Scherer
84a444a1f4 Introduce opaque type to hidden type projection 2022-07-15 15:49:22 +00:00
David Wood
78b19a90b7 passes: migrate half of check_attr
Migrate half of the `rustc_passes::check_attr` diagnostics to using
diagnostic derives and being translatable.
2022-07-15 16:13:49 +01:00
David Wood
81cf2294b4 macros: support adding warnings to diags
Both diagnostic and subdiagnostic derives were missing the ability to
add warnings to diagnostics - this is made more difficult by the `warn`
attribute already existing, so this name being unavailable for the
derives to use. `#[warn_]` is used instead, which requires
special-casing so that `{span_,}warn` is called instead of
`{span_,}warn_`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15 16:13:49 +01:00
David Wood
88c11c5bff macros: support MultiSpan in diag derives
Add support for `MultiSpan` with any of the attributes that work on a
`Span` - requires that diagnostic logic generated for these attributes
are emitted in the by-move block rather than the by-ref block that they
would normally have been generated in.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15 16:13:49 +01:00
David Wood
c3fdf74885 errors: lint on LintDiagnosticBuilder::build
Apply the `#[rustc_lint_diagnostics]` attribute to
`LintDiagnosticBuilder::build` so that diagnostic migration lints will
trigger for it.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15 16:13:47 +01:00
David Wood
06f480661f errors: impl IntoDiagnosticArg for char
Implements `IntoDiagnosticArg` for `char` using its `Debug`
implementation and introduces a macro for those types which just
delegate the implementation to `ToString`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15 16:12:46 +01: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
b955fa7dd0 don't require FnCtxt to check global asm 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
29d0390b97 remove unnecessary select_obligations_where_possible
this was previously used for opaque types but became unnecessary
after #89024
2022-07-15 16:40:39 +02:00