Commit Graph

15327 Commits

Author SHA1 Message Date
Maybe Waffle
2edad7d77c Apply suggestions from the review
- Use `expr.hir_id.owner` instead of `self.tcx.parent_module(expr.hir_id)`
- Use `.type_at()` instead of `.first()` + `.expect_ty()`
- Use single `.find()` with `&&` condition

Co-authored-by: Michael Goulet <michael@errs.io>
2022-07-19 02:15:56 +04:00
Maybe Waffle
da2752e00f check accessibility before suggesting wrapping expressions 2022-07-19 01:16:25 +04:00
bors
f8588549c3 Auto merge of #99422 - Dylan-DPC:rollup-htjofm6, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #98839 (Add assertion that `transmute_copy`'s U is not larger than T)
 - #98998 (Remove branch target prologues from `#[naked] fn`)
 - #99198 (add missing null ptr check in alloc example)
 - #99344 (rustdoc: avoid inlining items with duplicate `(type, name)`)
 - #99351 (Use `typeck_results` to get accurate qpath res for arg mismatch error)
 - #99378 (interpret/visitor: add missing early return)
 - #99394 (Add regression test for #95230)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-18 20:39:24 +00:00
Maybe Waffle
7163e7ff65 Suggest a fix for NonZero* <- * coercion error 2022-07-19 00:13:29 +04:00
Christopher Durham
c0569f2aa7 Revert "Stabilize $$ in Rust 1.63.0"
This reverts commit 9edaa76adc.
2022-07-18 15:22:01 -04:00
Ralf Jung
213a25d975 interpret: make some large types not Copy 2022-07-18 13:57:35 -04:00
Maybe Waffle
37c21d6fc7 Do not suggest "wrapping the expression in std::num::NonZeroU64" 2022-07-18 21:55:47 +04:00
Ralf Jung
388971b05d interpret: remove some unused trait impls 2022-07-18 13:51:11 -04:00
Oli Scherer
f40326027a Check generators for well formedness 2022-07-18 17:20:55 +00:00
Nika Layzell
c4acac6443 proc_macro: Move subspan to be a method on Span in the bridge
This method is still only used for Literal::subspan, however the
implementation only depends on the Span component, so it is simpler and
more efficient for now to pass down only the information that is needed.
In the future, if more information about the Literal is required in the
implementation (e.g. to validate that spans line up as expected with
source text), that extra information can be added back with extra
arguments.
2022-07-18 13:06:51 -04:00
Nika Layzell
b34c79f8f1 proc_macro: stop using a remote object handle for Literal
This builds on the symbol infrastructure built for `Ident` to replicate
the `LitKind` and `Lit` structures in rustc within the `proc_macro`
client, allowing literals to be fully created and interacted with from
the client thread. Only parsing and subspan operations still require
sync RPC.
2022-07-18 13:06:51 -04:00
Nika Layzell
491fccfbe3 proc_macro: stop using a remote object handle for Ident
Doing this for all unicode identifiers would require a dependency on
`unicode-normalization` and `rustc_lexer`, which is currently not
possible for `proc_macro` due to it being built concurrently with `std`
and `core`. Instead, ASCII identifiers are validated locally, and an RPC
message is used to validate unicode identifiers when needed.

String values are interned on the both the server and client when
deserializing, to avoid unnecessary copies and keep Ident cheap to copy and
move. This appears to be important for performance.

The client-side interner is based roughly on the one from rustc_span, and uses
an arena inspired by rustc_arena.

RPC messages passing symbols always include the full value. This could
potentially be optimized in the future if it is revealed to be a
performance bottleneck.

Despite now having a relevant implementaion of Display for Ident, ToString is
still specialized, as it is a hot-path for this object.

The symbol infrastructure will also be used for literals in the next
part.
2022-07-18 12:59:14 -04:00
Dylan DPC
a47a090d51
Rollup merge of #99378 - RalfJung:box-early-return, r=oli-obk
interpret/visitor: add missing early return

I forgot to add this when adding the special `Box` handling branch.

r? ```@oli-obk```
2022-07-18 21:14:48 +05:30
Dylan DPC
60c1068c92
Rollup merge of #99351 - compiler-errors:arg-mismatch-blame, r=davidtwco
Use `typeck_results` to get accurate qpath res for arg mismatch error

Improves error message from "function"  to actually what we're calling (e.g. enum variant constrcutor) in a few cases 😸
2022-07-18 21:14:47 +05:30
Dylan DPC
a027b01f33
Rollup merge of #98998 - workingjubilee:naked-means-no-clothes-enforcement-technology, r=Amanieu
Remove branch target prologues from `#[naked] fn`

This patch hacks around rust-lang/rust#98768 for now via injecting appropriate attributes into the LLVMIR we emit for naked functions. I intend to pursue this upstream so that these attributes can be removed in general, but it's slow going wading through C++ for me.
2022-07-18 21:14:43 +05:30
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
Tomasz Miąsko
45afc214af Update invalid atomic ordering lint
The restriction that success ordering must be at least as strong as its
failure ordering in compare-exchange operations was lifted in #98383.
2022-07-18 12:02:11 +02:00
Jordan McQueen
38f090b5e9 Use span_bug for unexpected field projection type
Improves the compiler error backtrace information, as shown in #99363,
by using `span_bug` instead of `bug`.

New output:

```
build/aarch64-apple-darwin/stage1/bin/rustc /tmp/test.rs --edition=2021
error: internal compiler error: compiler/rustc_middle/src/ty/closure.rs:185:25: Unexpected type Opaque(DefId(0:5 ~ test[db0f]::main::T::{opaque#0}), []) for `Field` projection
  --> /tmp/test.rs:11:27
   |
11 |         let Foo((a, b)) = foo;
   |                           ^^^

thread 'rustc' panicked at 'Box<dyn Any>', /Users/jmq/src/forked/rust/compiler/rustc_errors/src/lib.rs:1331:9
stack backtrace:
```

(Remainder of output truncated.)
2022-07-18 16:24:08 +09: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
Yuki Okushi
f3a458f735
Rollup merge of #99360 - compiler-errors:issue-99331, r=fee1-dead
Do not ICE when we have `-Zunpretty=expanded` with invalid ABI

Fixes #99331
2022-07-18 08:40:00 +09:00
Yuki Okushi
3c2175b8a2
Rollup merge of #99356 - compiler-errors:tait-in-assoc-ty-supertraits, r=oli-obk
Do not constraint TAITs when checking impl/trait item compatibility

Check out the UI test for the example.

Open to other approaches to fix this issue -- ideally we _would_ be able to collect this opaque type constraint in a way to use it in `find_opaque_ty_constraints`, so we can report a better mismatch error in the incompatible case, and just allow it in the compatible case. But that seems like a bigger refactor, so I wouldn't want to start it unless someone else thought it was a good idea.

cc #99348
r? ``@oli-obk``
2022-07-18 08:39:59 +09:00
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
Michael Howell
1169832f2f rustdoc: extend #[doc(tuple_variadic)] to fn pointers
The attribute is also renamed `fake_variadic`.
2022-07-17 16:32:06 -07: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
6d2bd541e0 use body's param-env when checking if type needs drop 2022-07-17 10:56:12 -07:00
Ralf Jung
e6be52bbbd interpret/visitor: add missing early return 2022-07-17 10:47:34 -04:00
Amanieu d'Antras
931a8f81fe Upgrade hashbrown to 0.12.3
This fixes a double-free in the `clone_from` function if dropping an
existing element in the table panics. See
https://github.com/rust-lang/hashbrown/pull/348 for more details.
2022-07-17 07:05:58 -07:00
Josh Stone
daa7c14a44 Upgrade indexmap and thorin-dwp to use hashbrown 0.12
This removes the last dependencies on hashbrown 0.11.
2022-07-17 07:05:58 -07: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
Michael Goulet
26ecd44160 Do not ICE when we have -Zunpretty=expand with invalid ABI 2022-07-16 20:35:54 -07:00
Michael Goulet
23cb89ea38 Do not constraint TAITs when checking impl/trait item compatibility 2022-07-16 18:36:08 -07:00
Caio
3266460749 Stabilize let_chains 2022-07-16 20:17:58 -03:00
Michael Goulet
d672fea64a Use typeck_results to avoid duplicate ast_ty_to_ty call 2022-07-16 22:54:46 +00:00
Michael Goulet
75a1b1cf06 Use typeck_results to get accurate qpath res for arg mismatch error 2022-07-16 22:29:52 +00: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
Niklas Jonsson
b47a934194 rustc_expand: Switch FxHashMap to FxIndexMap where iteration is used 2022-07-16 13:23:05 +02: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
lcnr
2b730a3610 remove impl_implied_bounds from FnCtxt 2022-07-15 16:40:39 +02:00
lcnr
7808f69ad7 QueryNormalizer bug on ambiguity 2022-07-15 16:40:39 +02:00
bors
0fe5390a88 Auto merge of #99046 - nnethercote:final-derive-output-improvements, r=Mark-Simulacrum
Final derive output improvements

With all these changes, the derive output in `deriving-all-codegen.stdout` is pretty close to optimal, i.e. very similar to what you'd write by hand.

r? `@ghost`
2022-07-15 14:30:14 +00:00
bors
116819f54f Auto merge of #99278 - Dylan-DPC:rollup-fcln6st, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #88991 (Add Nintendo Switch as tier 3 target)
 - #98869 (Remove some usages of `guess_head_span`)
 - #99119 (Refactor: remove a string matching about methods)
 - #99209 (Correctly handle crate level page on docs.rs as well)
 - #99246 (Update RLS)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-15 11:44:20 +00:00
Dylan DPC
24f0e1499e
Rollup merge of #99119 - TaKO8Ki:remove-string-matching-about-methods, r=cjgillot
Refactor: remove a string matching about methods

This patch remove a string matching about methods and adds some rustfix tests.
2022-07-15 15:53:38 +05:30
Dylan DPC
e0e6f1d1cb
Rollup merge of #98869 - compiler-errors:stop_guessing_head_span, r=cjgillot
Remove some usages of `guess_head_span`

No need to pass things through `guess_head_span` if they already point to the head span.

Only major change is that we point to the head span of `enum`s on some errors now, which I prefer.

r? `@cjgillot`
2022-07-15 15:53:37 +05:30
Dylan DPC
a6d3ee3247
Rollup merge of #88991 - libstd-switch:aarch64-nintendo-switch, r=wesleywiser
Add Nintendo Switch as tier 3 target

[Relevant Zulip Discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Upstreaming.20Nintendo.20Switch.20Support/near/253445503)

This is the first step towards working on incrementally adding support for the Nintendo Switch. After this lands `@leo60228` and I will work on ensuring further work is cleared from a legal perspective before continuing on to work on an allocator and porting libstd.

The plan is to keep these changes small and incremental enough so as to not cause unneeded burden on reviewers by submitting a single large patch, as was felt to be the case last attempt at upstreaming (#74567).

All this specific patch does is add the target itself without and std support, which has been tested on-device and is working as expected.

Designated Target Maintainers:
* `@leo60228`
* `@jam1garner`
2022-07-15 15:53:36 +05:30
bors
6077b7cda4 Auto merge of #99013 - RalfJung:dont-poison-my-places, r=oli-obk
interpret: get rid of MemPlaceMeta::Poison

This is achieved by refactoring the projection code (`{mplace,place,operand}_{downcast,field,index,...}`) so that we no longer need to call `assert_mem_place` in the operand handling.
2022-07-15 08:57:59 +00:00
bors
522abf6d88 Auto merge of #99267 - Dylan-DPC:rollup-d8l7y1o, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #99113 (Simplify [a]rc code a little)
 - #99131 (Add label for generic arg (+ APIT) and RPIT callables in `label_fn_like`)
 - #99237 (removed unused CSS and unused HTML IDs)
 - #99239 (Add myself to the set of people notified when MIR changes.)
 - #99241 (Remove comment referring to constness.rs)
 - #99257 (Add regression test for #89436)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-15 06:14:51 +00:00
Takayuki Maeda
45b88aff10 simplify suggest_deref_ref_or_into 2022-07-15 14:29:15 +09:00
Michael Goulet
fcfb3e92a0 Remove some more usages of guess_head_span 2022-07-15 05:23:47 +00:00
Dylan DPC
6dae197afa
Rollup merge of #99241 - danbev:intrinsics-comment, r=fee1-dead
Remove comment referring to constness.rs

This commit removes the comment in emulate_intrinsic, which is
currently referring to `src/librustc_middle/ty/constness.rs`.
2022-07-15 10:39:46 +05:30
Dylan DPC
7b63058d13
Rollup merge of #99131 - compiler-errors:label-fn, r=cjgillot
Add label for generic arg (+ APIT) and RPIT callables in `label_fn_like`

Fixes #98308
2022-07-15 10:39:43 +05:30
bors
b90a0ede02 Auto merge of #97406 - aliemjay:verify-bounds-fix-master, r=oli-obk
Make outlives::{components,verify} agree

fixes #97405

cc `@oli-obk` this is should fix https://github.com/rust-lang/rust/pull/95474#discussion_r880660075

r? `@oli-obk`
2022-07-15 03:44:53 +00:00
Michael Goulet
4b890f3474 Remove some span_of_impl+unwrap 2022-07-15 03:17:21 +00:00
Michael Goulet
03bfbe1fb3 Move item_span from check_item_type into each function 2022-07-15 03:17:21 +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
Michael Goulet
57f7618f62 Remove some usages of guess_head_span from typeck 2022-07-15 03:17:20 +00:00
Michael Goulet
aad2334ecb Make item spans more consistent 2022-07-15 03:17:20 +00:00
bors
30243dd87e Auto merge of #98203 - kckeiks:gather-body-owners-in-hir-item-queries, r=cjgillot
gather body owners

Issue #96341
2022-07-15 01:03:55 +00:00
Michael Goulet
d25abdc0c5 Point out custom Fn-family trait impl 2022-07-14 23:36:46 +00:00
Michael Goulet
ddb7003b79 Add support for APIT and RPIT callables in label_fn_like 2022-07-14 23:29:03 +00:00
Ralf Jung
6c6cccdd9b interpret/validity: improve some comments 2022-07-14 19:19:15 -04:00
5225225
27412d1e3e Use constant eval to do strict validity checks 2022-07-14 22:55:17 +01:00
bors
1ba1fec234 Auto merge of #96544 - m-ysk:feature/issue-96358, r=cjgillot
Stop keeping metadata in memory before writing it to disk

Fixes #96358

I created this PR according with the instruction given in the issue except for the following points:

- While the issue says "Write metadata into the temporary file in `encode_and_write_metadata` even if `!need_metadata_file`", I could not do that. That is because though I tried to do that and run `x.py test`, I got a lot of test failures as follows.

<details>
<summary>List of failed tests</summary>
<pre>
<code>
failures:
    [ui] src/test/ui/json-multiple.rs
    [ui] src/test/ui/json-options.rs
    [ui] src/test/ui/rmeta/rmeta-rpass.rs
    [ui] src/test/ui/save-analysis/emit-notifications.rs
    [ui] src/test/ui/svh/changing-crates.rs
    [ui] src/test/ui/svh/svh-change-lit.rs
    [ui] src/test/ui/svh/svh-change-significant-cfg.rs
    [ui] src/test/ui/svh/svh-change-trait-bound.rs
    [ui] src/test/ui/svh/svh-change-type-arg.rs
    [ui] src/test/ui/svh/svh-change-type-ret.rs
    [ui] src/test/ui/svh/svh-change-type-static.rs
    [ui] src/test/ui/svh/svh-use-trait.rs

test result: FAILED. 12915 passed; 12 failed; 100 ignored; 0 measured; 0 filtered out; finished in 71.41s

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
Build completed unsuccessfully in 0:01:58
</code>
</pre>
</details>

- I could not resolve the extra tasks about `create_rmeta_file` and `create_compressed_metadata_file` for my lack of ability.
2022-07-14 21:50:14 +00:00
pierwill
0d45977aa5 Remove FIXME from MIR always_storage_live_locals 2022-07-14 15:30:36 -05:00
leo60228
62aafb01b1
Rename aarch64-nintendo-switch to aarch64-nintendo-switch-freestanding 2022-07-14 15:58:26 -04:00
leo60228
c690db4024
Remove obsolete crt0 references in linker script 2022-07-14 15:58:11 -04:00
jam1garner
7f8804915e
Remove unneeded options from Nintendo Switch target 2022-07-14 15:58:09 -04:00
leo60228
4bc8549cb3
Add linker script for switch 2022-07-14 15:57:19 -04:00
leo60228
f688a56ef6
Remove unnecessary linker args 2022-07-14 15:56:41 -04:00
jam1garner
e6aedf6056
Add Nintendo Switch tier 3 target 2022-07-14 15:55:58 -04:00
Ziv Dunkelman
724c91234d rustc: add ability to output regular LTO bitcode modules
Adding the option to control from rustc CLI
if the resulted ".o" bitcode module files are with
thinLTO info or regular LTO info.

Allows using "-lto-embed-bitcode=optimized" during linkage
correctly.

Signed-off-by: Ziv Dunkelman <ziv.dunkelman@nextsilicon.com>
2022-07-14 22:21:26 +03:00
bors
c2f428d2f3 Auto merge of #99252 - lqd:win-dwarf5, r=eddyb
fix dwarf debuginfo being used in addition to CodeView on windows

Tackles the debuginfo size increase regression on windows to [unblock clippy](https://github.com/rust-lang/rust/issues/99143#issuecomment-1184638573) -- introduced by the DWARF5 support in #98350 cc `@pcwalton.`

r? `@eddyb`
Fixes #99143
2022-07-14 19:03:58 +00:00
Rémy Rakic
97510f2128 fix dwarf debuginfo being used in addition to CodeView on windows
Fixes the debuginfo size increase regression introduced by the DWARF5 support.
2022-07-14 20:41:55 +02:00
bors
74621c764e Auto merge of #99242 - Dylan-DPC:rollup-34bqdh8, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #98072 (Add provider API to error trait)
 - #98580 (Emit warning when named arguments are used positionally in format)
 - #99000 (Move abstract const to middle)
 - #99192 (Fix spans for asm diagnostics)
 - #99222 (Better error message for generic_const_exprs inference failure)
 - #99236 (solaris: unbreak build on native platform)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-14 16:23:07 +00:00
Ralf Jung
e3ef4fdac9 rename MPlaceTy::dangling to fake_alloc_zst 2022-07-14 11:40:47 -04:00
Daniel Bevenius
ed73037661 Remove comment referring to constness.rs
This commit removes the comment in emulate_intrinsic, which is
currently referring to 'src/librustc_middle/ty/constness.rs'.
2022-07-14 16:30:48 +02: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
d3a1aa0b43
Rollup merge of #99192 - Amanieu:fix-asm-srcloc, r=petrochenkov
Fix spans for asm diagnostics

Line spans were incorrect if the first line of an asm statement was an
empty string.
2022-07-14 19:24:05 +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
Dylan DPC
8c5c983e5b
Rollup merge of #98580 - PrestonFrom:issue_98466, r=estebank
Emit warning when named arguments are used positionally in format

Addresses Issue 98466 by emitting an error if a named argument
is used like a position argument (i.e. the name is not used in
the string to be formatted).

Fixes rust-lang#98466
2022-07-14 19:24:03 +05:30
bors
24699bcbad Auto merge of #95956 - yaahc:stable-in-unstable, r=cjgillot
Support unstable moves via stable in unstable items

part of https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/moving.20items.20to.20core.20unstably and a blocker of https://github.com/rust-lang/rust/pull/90328.

The libs-api team needs the ability to move an already stable item to a new location unstably, in this case for Error in core. Otherwise these changes are insta-stable making them much harder to merge.

This PR attempts to solve the problem by checking the stability of path segments as well as the last item in the path itself, which is currently the only thing checked.
2022-07-14 13:42:09 +00:00
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
Amanieu d'Antras
f4e7813121 Fix spans for asm diagnostics
Line spans were incorrect if the first line of an asm statement was an
empty string.
2022-07-14 11:20:52 +02:00
kadmin
20fb8aba8f Fix overlapping impls 2022-07-14 09:01:17 +00:00
Dylan DPC
85159a4df8
Rollup merge of #99126 - NiklasJonsson:84447/rustc_span, r=petrochenkov
remove allow(rustc::potential_query_instability) in rustc_span

Also, avoid sorting before debug output as iteration order can now be
relied upon.

Related #84447
2022-07-14 14:14:22 +05:30
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
Dylan DPC
f5e9cb53ab
Rollup merge of #97720 - cjgillot:all-fresh, r=petrochenkov
Always create elided lifetime parameters for functions

Anonymous and elided lifetimes in functions are sometimes (async fns) --and sometimes not (regular fns)-- desugared to implicit generic parameters.

This difference of treatment makes it some downstream analyses more complicated to handle.  This step is a pre-requisite to perform lifetime elision resolution on AST.

There is currently an inconsistency in the treatment of argument-position impl-trait for functions and async fns:
```rust
trait Foo<'a> {}
fn foo(t: impl Foo<'_>) {} //~ ERROR missing lifetime specifier
async fn async_foo(t: impl Foo<'_>) {} //~ OK
fn bar(t: impl Iterator<Item = &'_ u8>) {} //~ ERROR missing lifetime specifier
async fn async_bar(t: impl Iterator<Item = &'_ u8>) {} //~ OK
```

The current implementation reports "missing lifetime specifier" on `foo`, but **accepts it** in `async_foo`.
This PR **proposes to accept** the anonymous lifetime in both cases as an extra generic lifetime parameter.
This change would be insta-stable, so let's ping t-lang.
Anonymous lifetimes in GAT bindings keep being forbidden:
```rust
fn foo(t: impl Foo<Assoc<'_> = Bar<'_>>) {}
                         ^^        ^^
                       forbidden   ok
```
I started a discussion here: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Anonymous.20lifetimes.20in.20universal.20impl-trait/near/284968606

r? ``@petrochenkov``
2022-07-14 14:14:19 +05:30
bors
0ed9c64c3e Auto merge of #98975 - jyn514:unstable_opts, r=wesleywiser
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.

cc https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Codegen.20options.20.2F.20debugging.20options

r? `@Amanieu` cc `@nikic` `@joshtriplett`
2022-07-14 08:14:31 +00:00
bors
8a392a5992 Auto merge of #98754 - jyn514:non-trivial-drop, r=compiler-errors
Fix drop-tracking ICE when a struct containing a field with a significant drop is used across an await

Previously, drop-tracking would incorrectly assume the struct would be dropped immediately, which was not true.

Fixes #98476. Also fixes https://github.com/rust-lang/rust/issues/98477, I think because the parent HIR node for type variables is the whole function instead of the expression where the variable is used.

r? `@eholk`
2022-07-14 02:22:48 +00:00
Ali MJ Al-Nasrawy
83c17887b7 Make outlives::{components,verify} agree 2022-07-14 03:12:44 +03:00
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
Ralf Jung
07fe9882cc add array tests, cleanup, tidy, and bless 2022-07-13 18:31:29 -04:00
Ralf Jung
e4593ef0f2 assigning to a union field can never drop now 2022-07-13 18:27:28 -04:00
Ralf Jung
5bf6017b87 remove untagged_union feature gate 2022-07-13 18:27:28 -04:00
Ralf Jung
6dfede3b9d also allow arrays of allowed types 2022-07-13 18:27:28 -04:00
Ralf Jung
ec7152cdf6 allow unions with mutable references and tuples of allowed types 2022-07-13 18:27:28 -04:00
Ralf Jung
848d23b57b factor 'is this type allowed as union field on stable' into separate function 2022-07-13 18:27:28 -04:00
Preston From
1219f72f90 Emit warning when named arguments are used positionally in format
Addresses Issue 98466 by emitting a warning if a named argument
is used like a position argument (i.e. the name is not used in
the string to be formatted).

Fixes rust-lang#98466
2022-07-13 15:34:10 -06:00
Miguel Guarniz
2d265b6f75 collect module item-likes in visit_items
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-13 13:54:45 -04:00
Niklas Jonsson
f94484fe7e reduce scope of allow(rustc::potential_query_instability) in rustc_span 2022-07-13 19:30:08 +02:00
bors
c80dde43f9 Auto merge of #99210 - Dylan-DPC:rollup-879cp1t, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #98574 (Lower let-else in MIR)
 - #99011 (`UnsafeCell` blocks niches inside its nested type from being available outside)
 - #99030 (diagnostics: error messages when struct literals fail to parse)
 - #99155 (Keep unstable target features for asm feature checking)
 - #99199 (Refactor: remove an unnecessary `span_to_snippet`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-13 17:13:27 +00:00
Miguel Guarniz
275497c35e merge visitors in queries
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-13 12:22:49 -04:00
Miguel Guarniz
b599cf45d6 inline associated_body
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-13 12:22:49 -04:00
Miguel Guarniz
c6e7c0514f use gathered body_owners in par_body_owners
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-07-13 12:22:25 -04:00
bors
42bd138126 Auto merge of #98145 - ouz-a:some_branch, r=oli-obk
Pull Derefer before ElaborateDrops

_Follow up work to #97025 #96549 #96116 #95887 #95649_

This moves `Derefer` before `ElaborateDrops` and creates a new `Rvalue` called `VirtualRef` that allows us to bypass many constraints for `DerefTemp`.

r? `@oli-obk`
2022-07-13 14:32:33 +00:00
Ralf Jung
874a130ca0 get rid of MemPlaceMeta::Poison
MPlaceTy::dangling still exists, but now it is only called in places that
actually conceptually allocate something new, so that's fine.
2022-07-13 10:22:59 -04:00
Dylan DPC
3933b2b310
Rollup merge of #99199 - TaKO8Ki:remove-unnecessary-span-to-snippet, r=cjgillot
Refactor: remove an unnecessary `span_to_snippet`

`span_suggestion_hidden` does not show the suggested code and the suggestion is used just for rustfix, so `span_to_snippet` is unnecessary here.
2022-07-13 19:32:37 +05:30
Dylan DPC
68cfdbb5c1
Rollup merge of #99155 - Amanieu:unstable-target-features, r=davidtwco
Keep unstable target features for asm feature checking

Inline assembly uses the target features to determine which registers
are available on the current target. However it needs to be able to
access unstable target features for this.

Fixes #99071
2022-07-13 19:32:36 +05:30
Dylan DPC
980579a5e9
Rollup merge of #99030 - rust-lang:notriddle/field-recovery, r=petrochenkov
diagnostics: error messages when struct literals fail to parse

If an expression is supplied where a field is expected, the parser can become convinced that it's a shorthand field syntax when it's not.

This PR addresses it by explicitly recording the permitted `:` token immediately after the identifier, and also adds a suggestion to insert the name of the field if it looks like a complex expression.

Fixes #98917
2022-07-13 19:32:35 +05:30
Dylan DPC
1e7d04b23b
Rollup merge of #99011 - oli-obk:UnsoundCell, r=eddyb
`UnsafeCell` blocks niches inside its nested type from being available outside

fixes #87341

This implements the plan by `@eddyb` in https://github.com/rust-lang/rust/issues/87341#issuecomment-886083646

Somewhat related PR (not strictly necessary, but that cleanup made this PR simpler): #94527
2022-07-13 19:32:34 +05:30
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
Camille GILLOT
5a20834884 Add feature gate. 2022-07-13 14:17:09 +02:00
Camille GILLOT
031b2c53cd Always use CreateParameter mode for function definitions. 2022-07-13 14:14:37 +02:00
Guillaume Gomez
f290811aaf
Rollup merge of #99185 - krasimirgg:llvm-wrapper-inlineasm, r=nikic
llvm-wrapper: adapt for LLVM API change

This adapts RustWrapper's ` LLVMRustInlineAsmVerify` for LLVM commit 00797b88e0.
2022-07-13 10:38:50 +02:00
Guillaume Gomez
8a48557261
Rollup merge of #99020 - fee1-dead-contrib:repr_transparent_non_exhaustive, r=oli-obk
check non_exhaustive attr and private fields for transparent types

Fixes #78586.
2022-07-13 10:38:43 +02:00
Deadbeef
1d260067f1 fix documentation 2022-07-13 04:49:32 +00:00
Takayuki Maeda
f65bf0b2bb avoid &str to String conversions 2022-07-13 13:24:38 +09:00
Takayuki Maeda
5188bdbccd remove an unnecessary span_to_snippet 2022-07-13 13:24:06 +09:00
bors
7b5715289f Auto merge of #99101 - RalfJung:interpret-projections, r=oli-obk
interpret: refactor projection handling code

Moves our projection handling code into a common file, and avoids the use of a
general mplace-based fallback function by have more specialized implementations.

mplace_index (and the other slice-related functions) could be more efficient by
copy-pasting the body of operand_index. Or we could do some trait magic to share
the code between them. But for now this is probably fine.

This is the common part of https://github.com/rust-lang/rust/pull/99013 and https://github.com/rust-lang/rust/pull/99097. I am seeing some strange perf results so this probably should be its own change so we know which diff caused which perf changes...

r? `@oli-obk`
2022-07-13 02:43:25 +00:00
Nicholas Nethercote
1cb1d63bd2 Use &{self.x} for packed Copy structs.
Because it's more concise than the `let` form.
2022-07-13 10:54:02 +10:00
Maybe Waffle
d2923b4007 Add back expr size checks 2022-07-12 21:00:13 +04:00
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
Maybe Waffle
3ebb852956 Add LifetimeBinderKind::Closure 2022-07-12 21:00:13 +04:00
Maybe Waffle
0c284843ba make for<> in closures a possible place to suggest adding named lifetime 2022-07-12 21:00:13 +04:00
Maybe Waffle
c2dbd62c7c Lower closure binders to hir & properly check them 2022-07-12 21:00:03 +04:00
Michael Howell
9fcb9c6648 Update compiler/rustc_parse/src/parser/expr.rs
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2022-07-12 09:51:20 -07:00
Krasimir Georgiev
a89d014a21 llvm-wrapper: adapt for LLVM API change 2022-07-12 16:00:52 +00: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
Maybe Waffle
f89ef3cf66 Comment out expr size check 2022-07-12 16:26:08 +04:00
Maybe Waffle
40ae7b5b8e Parse closure binders
This is first step in implementing RFC 3216.
- Parse `for<'a>` before closures in ast
  - Error in lowering
- Add `closure_lifetime_binder` feature
2022-07-12 16:25:16 +04:00
Dylan DPC
01c24213cb
Rollup merge of #99154 - rosehuds:master, r=cjgillot
use PlaceRef::iter_projections to fix old FIXME

I added this function in 53481a5a8f
2022-07-12 17:06:35 +05:30
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
Dylan DPC
99fc65bc49
Rollup merge of #98972 - TaKO8Ki:suggest-adding-missing-zero-to-floating-point-number, r=compiler-errors
Suggest adding a missing zero to a floating point number

fixes #98836
2022-07-12 17:06:33 +05:30
Dylan DPC
9997c51496
Rollup merge of #98633 - c410-f3r:yet-another-let-chain, r=estebank
Fix last `let_chains` blocker

In order to forbid things like `let x = (let y = 1);` or `if let a = 1 && { let x = let y = 1; } {}`, the parser **HAS** to know the context of `let`.

This context thing is not a surprise in the parser because you can see **a lot** of ad hoc fixes mixing parsing logic with validation logic creating code that looks more like spaghetti with tomato sauce.

To make things even greater, a new ad hoc fix was added to only allow `let`s in a valid `let_chains` context by checking the previously processed token. This was the only solution I could think of and believe me, I thought about it for a long time 👍

In the long term, it should be preferable to segregate different responsibilities or create a more robust and cleaner parser framework.

cc https://github.com/rust-lang/rust/pull/94927
cc https://github.com/rust-lang/rust/issues/53667
2022-07-12 17:06:33 +05:30
Dylan DPC
76153661dc
Rollup merge of #98622 - petrochenkov:executables, r=oli-obk
rustc_target: Flip the default for `TargetOptions::executables` to true

This flag is true for most targets and the remaining targets may be mistakes.
2022-07-12 17:06:32 +05:30
ouz-a
cb0017f2f8 add new rval, pull deref early 2022-07-12 14:26:41 +03:00
Ding Xiang Fei
947cbda5eb
fix the typo 2022-07-12 13:24:08 +02:00
Deadbeef
944c0e23b8 check non_exhaustive attr and private fields for transparent types 2022-07-12 10:20:55 +00:00
Takayuki Maeda
e03cb7fb9a implement a suggestion for a floating point number with a type suffix 2022-07-12 13:59:51 +09:00
Ralf Jung
04b3cd9f7c use a loop rather than try_fold 2022-07-11 22:51:33 -04:00
Ralf Jung
ab225ade1e interpret: refactor projection handling code
Moves our projection handling code into a common file, and avoids the use of a
general mplace-based fallback function by have more specialized implementations.

mplace_index (and the other slice-related functions) could be more efficient by
copy-pasting the body of operand_index. Or we could do some trait magic to share
the code between them. But for now this is probably fine.
2022-07-11 22:50:46 -04:00
kadmin
e612e2603c Move abstract const to rustc_middle::ty 2022-07-12 02:21:31 +00:00
Ding Xiang Fei
5374688e1d
add tests for async await 2022-07-11 23:20:39 +02:00
Ding Xiang Fei
8e4a971084
extract method to read scrutinee conditionally 2022-07-11 23:20:38 +02: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
5e223dc7b9
Rollup merge of #99146 - compiler-errors:issue-61525, r=lcnr
Do not error during method probe on `Sized` predicates for types that aren't the method receiver

Fixes #61525

This is safe even though we're skipping an error because we end up confirming the method, which means we're still checking the `Sized` predicate in the end. It just means that we don't emit an erroneous message as below:

```
error: the `query` method cannot be invoked on a trait object
  --> src/lib.rs:14:11
   |
14 |         1.query::<dyn ToString>("")
   |           ^^^^^
   |
   = note: another candidate was found in the following trait, perhaps add a `use` for it:
           `use crate::Example;`
```

Also fixes erroneously suggesting the same trait over again, as seen in the `issue-35976.rs` UI test.
2022-07-11 22:39:09 +02:00
Matthias Krüger
1679d1c622
Rollup merge of #99145 - jyn514:dont-rerun-build-script, r=wesleywiser
Don't rerun the build script for the compiler each time on non-windows platforms

In practice, this doesn't matter very much because the script takes ~no time to run.
But this makes `CARGO_LOG=info` easier to read, and theoretically saves a few milliseconds.
2022-07-11 22:39:08 +02:00
Matthias Krüger
7151aaf940
Rollup merge of #99124 - compiler-errors:issue-99122, r=oli-obk
Fix sized check ICE in asm check

Fixes (beta nominated, so doesn't close) #99122

1. Moves a check for unresolved inference variables to _before_ other checks that could possibly ICE. We're not changing behavior here, just doing the same thing earlier in the function.
2. Erases region variables in sized check (which are not resolved at this point) because rustc will also ICE when region vars are passed to a query which does not canonicalize them.
2022-07-11 22:39:06 +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
Vadim Petrochenkov
8d9fdb778e rustc_target: Flip the default for TargetOptions::executables to true
Also change `executables` to true for linux-kernel and windows-uwp-gnu targets
2022-07-11 23:23:51 +03:00
Michael Goulet
5c6560f2d5 Fix sized check ICE in intrisicck 2022-07-11 17:57:02 +00:00
bors
38b72154de Auto merge of #98637 - cjgillot:bare-trait-anon-lt, r=petrochenkov
Create fresh lifetime parameters for bare fn trait too

The current code fails to account for the equivalence between `dyn FnMut(&mut u8)` and bare `FnMut(&mut u8)`, and treated them differently.

This PR introduces a special case for `Fn` traits, which are always fully resolved.

Fixes #98616
Fixes #98726
This will require a beta-backport, as beta contains that bug.

r? `@petrochenkov`
2022-07-11 17:09:37 +00:00
Jack Huey
988e754691
placeholders -> inference vars in comment 2022-07-11 09:52:25 -04:00
Rose Hudson
d84f7394a4 use PlaceRef::iter_projections to fix old FIXME
I added this function in 53481a5a8f
2022-07-11 14:42:49 +01:00
Amanieu d'Antras
e51f1b7e27 Keep unstable target features for asm feature checking
Inline assembly uses the target features to determine which registers
are available on the current target. However it needs to be able to
access unstable target features for this.

Fixes #99071
2022-07-11 14:26:58 +01:00
Oli Scherer
984db78d77 Hide niches in SIMD types, too 2022-07-11 10:25:41 +00:00
Oli Scherer
423915590b More obvious closure name 2022-07-11 10:11:28 +00:00
Dylan DPC
21d6b1fc0e
Rollup merge of #99147 - compiler-errors:issue-55673, r=lcnr
Mention similarly named associated type even if it's not clearly in supertrait

Due to query cycle avoidance, we sometimes restrict the candidates in `complain_about_assoc_type_not_found` too much so that we can't detect typo replacements from just supertraits.

This creates a more general note of the existence of a similarly named associated type from _all_ visible traits when possible.

Fixes #55673
2022-07-11 15:19:33 +05:30
Dylan DPC
9fc297a2ae
Rollup merge of #99140 - TaKO8Ki:implement-is-accessible-span, r=fee1-dead
Implement `SourceMap::is_span_accessible`

This patch adds `SourceMap::is_span_accessible` and replaces `span_to_snippet(span).is_ok()` and `span_to_snippet(span).is_err()` with it. This removes a `&str` to `String` conversion.
2022-07-11 15:19:32 +05:30
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
Dylan DPC
943152008f
Rollup merge of #98882 - compiler-errors:explain-doc-comments-in-macros, r=davidtwco
explain doc comments in macros a bit

Open to suggestions on improving this... macro parsing is very foreign to me.

Should we have a structured suggestion to turn them into their regular non-doc comments?

Fixes #92846
Fixes #97850
2022-07-11 15:19:29 +05:30
Takayuki Maeda
018155c3a2 rename a method 2022-07-11 16:51:19 +09:00
Michael Goulet
913023b6b4 Use Visibility::is_accessible_from to make suggestion more specific 2022-07-11 07:06:18 +00:00
Nicholas Nethercote
10144e29af Handle tags better.
Currently, for the enums and comparison traits we always check the tag
for equality before doing anything else. This is a bit clumsy. This
commit changes things so that the tags are handled very much like a
zeroth field in the enum.

For `eq`/ne` this makes the code slightly cleaner.

For `partial_cmp` and `cmp` it's a more notable change: in the case
where the tags aren't equal, instead of having a tag equality check
followed by a tag comparison, it just does a single tag comparison.

The commit also improves how `Hash` works for enums: instead of having
duplicated code to hash the tag for every arm within the match, we do
it just once before the match.

All this required replacing the `EnumNonMatchingCollapsed` value with a
new `EnumTag` value.

For fieldless enums the new code is particularly improved. All the code
now produced is close to optimal, being very similar to what you'd write
by hand.
2022-07-11 16:58:32 +10:00
Michael Goulet
f2d8af10c2 Do not mention private Self types from other crates 2022-07-11 06:57:48 +00:00
Michael Goulet
680fef4d04 Mention similarly named associated type even if it's not clearly in supertrait 2022-07-11 06:53:11 +00:00
Michael Goulet
88f2140d87 Do not suggest same trait over again 2022-07-11 05:23:08 +00:00
Michael Goulet
0c39762dd6 Use fake substs to check for Self: Sized predicates on method receivers 2022-07-11 05:21:02 +00:00
Joshua Nelson
033a025b10 Don't rerun the build script for the compiler each time on linux
In practice, this doesn't matter very much because the script takes ~no time to run.
But this makes `CARGO_LOG=info` easier to read, and theoretically saves a few milliseconds.
2022-07-10 23:57:25 -05:00
Nicholas Nethercote
4bcbd76bc9 Move the no-variants handling code earlier in expand_enum_method_body.
To avoid computing a bunch of stuff that it doesn't need.
2022-07-11 14:09:53 +10:00
Nicholas Nethercote
f1d9e2b50c Avoid some unnecessary blocks in derive output. 2022-07-11 14:09:37 +10:00
Nicholas Nethercote
56178d4259 Rename tag-related things.
Use `tag` in names of things referring to tags, instead of the
mysterious `vi`.

Also change `arg_N` in output to `argN`, which has the same length as
`self` and so results in nicer vertical alignments.
2022-07-11 14:09:17 +10:00
Nicholas Nethercote
96f09d73cd Remove unnecessary &* sigil pairs in derived code.
By producing `&T` expressions for fields instead of `T`. This matches
what the existing comments (e.g. on `FieldInfo`) claim is happening, and
it's also what most of the trait-specific code needs.

The exception is `PartialEq`, which needs `T` expressions for lots of
special case error messaging to work. So we now convert the `&T` back to
a `T` for `PartialEq`.
2022-07-11 14:07:33 +10:00
Nicholas Nethercote
277bc9641d Remove unnecessary sigils and refs in derived code.
E.g. improving code like this:
```
match &*self {
    &Enum1::Single { x: ref __self_0 } => {
        ::core:#️⃣:Hash::hash(&*__self_0, state)
    }
}
```
to this:
```
match self {
    Enum1::Single { x: __self_0 } => {
        ::core:#️⃣:Hash::hash(&*__self_0, state)
    }
}
```
by removing the `&*`, the `&`, and the `ref`.

I suspect the current generated code predates deref-coercion.

The commit also gets rid of `use_temporaries`, instead passing around
`always_copy`, which makes things a little clearer. And it fixes up some
comments.
2022-07-11 14:04:42 +10:00
Takayuki Maeda
12d11e9a35 implement is_accessible_span 2022-07-11 11:36:15 +09:00
Michael Goulet
a1634642e0 Deny floats even when adt_const_params is enabled 2022-07-11 00:04:00 +00:00
Michael Goulet
d2e5a929b9 use subdiagnostic for message 2022-07-10 23:43:46 +00:00
Michael Goulet
2a973e2abc explain doc comments in macros a bit 2022-07-10 23:42:50 +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
Matthias Krüger
2cb7d1c933
Rollup merge of #98713 - nikomatsakis:issue-98693, r=jackh726
promote placeholder bounds to 'static obligations

In NLL, when we are promoting a bound out from a closure, if we have a requirement that `T: 'a` where `'a` is in a higher universe, we were previously ignoring that, which is totally wrong. We should be promoting those constraints to `'static`, since universes are not expressible across closure boundaries.

Fixes #98693

~~(Marking as WIP because I'm still running tests, haven't add the new test, etc)~~

r? ``@jackh726``
2022-07-11 00:33:47 +02:00
Nicholas Nethercote
f314ece275 Remove mutbl argument from create_struct_patterns.
It's always `ast::Mutability::Not`.
2022-07-11 07:30:27 +10:00
Joshua Nelson
b30315d64f Fix drop-tracking ICE when a struct containing a field with a Drop impl is used across an await
Previously, drop-tracking would incorrectly assume the struct would be dropped immediately, which
was not true: when the field had a type with a manual `Drop` impl, the drop becomes observable and
has to be dropped after the await instead.

For reasons I don't understand, this also fixes another error crater popped up related to type parameters.

 #98476
2022-07-10 15:39:07 -05: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
Takayuki Maeda
1599c5a821 remove a string matching about methods 2022-07-11 02:19:45 +09:00
bors
c6ff90b00e Auto merge of #98785 - compiler-errors:no-check-expr-in-check-compatible, r=estebank
Do not call `check_expr` in `check_compatible`, since it has side-effects

Fixes a weird suggestion in #98784

found later:
Fixes #98894
Fixes #98897
2022-07-10 16:45:17 +00:00
bors
29554c0a12 Auto merge of #98463 - mystor:expand_expr_bool, r=eddyb
proc_macro: Fix expand_expr expansion of bool literals

Previously, the expand_expr method would expand bool literals as a
`Literal` token containing a `LitKind::Bool`, rather than as an `Ident`.
This is not a valid token, and the `LitKind::Bool` case needs to be
handled seperately.

Tests were added to more deeply compare the streams in the expand-expr
test suite to catch mistakes like this in the future.
2022-07-10 14:02:45 +00: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
bors
95e77648e4 Auto merge of #97522 - xfix:stabilize-slice-from-raw-parts, r=dtolnay
Partially stabilize const_slice_from_raw_parts

This doesn't stabilize methods working on mutable pointers.

This pull request continues from #94946.

Pinging `@rust-lang/wg-const-eval` this because I use `rustc_allow_const_fn_unstable`. I believe this is justifiable as it's already possible to use `slice::from_raw_parts` in stable by abusing `transmute`. The stable alternative to this would be to provide a stable const implementation of `std::ptr::from_raw_parts` (as it can already be implemented in stable).

```rust
use std::mem;

#[repr(C)]
struct Slice<T> {
    data: *const T,
    len: usize,
}

fn main() {
    let data: *const i32 = [1, 2, 3, 4].as_ptr();
    let len = 4;
    println!("{:?}", unsafe {
        mem::transmute::<Slice<i32>, &[i32]>(Slice { data, len })
    });
}
```

`@rustbot` modify labels: +T-libs-api
2022-07-10 06:26:03 +00:00
Konrad Borowski
0753fd117b Partially stabilize const_slice_from_raw_parts
This doesn't stabilize methods working on mutable pointers.
2022-07-09 23:20:02 +02:00
Michael Goulet
6858fbc101 Do not call check_expr in check_compatible, since it has side-effects and we've already checked all args 2022-07-09 20:50:23 +00:00
bors
6dba4ed215 Auto merge of #99056 - lcnr:higher_ranked_sub, r=oli-obk
don't use `commit_if_ok` during `higher_ranked_sub`

This snapshot doesn't really do anything useful for us, especially once we deal with placeholder outlive bounds during trait solving.

I guess that currently the idea is that `higher_ranked_sub` could cause a later `leak_check` to fail even if the combine operation isn't actually relevant. But really, using combine outside of snapshot and ignoring its result is wrong anyways, as it can constrain inference variables.

r? rust-lang/types
2022-07-09 19:57:13 +00:00
Takayuki Maeda
bda83e6543 avoid some &str to String conversions 2022-07-10 03:18:56 +09:00
bors
f893495e3d Auto merge of #98957 - RalfJung:zst-are-different, r=lcnr,oli-obk
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 I propose we stop using ScalarInt to represent ZST (which are clearly not integers). Instead, we can add new ZST variants to those types that did not have other variants which could be used for this purpose.

Based on https://github.com/rust-lang/rust/pull/98831. Only the commits starting from "don't allow ZST in ScalarInt" are new.

r? `@oli-obk`
2022-07-09 17:16:00 +00:00
Ralf Jung
4e7aaf1f44 tweak names and output and bless 2022-07-09 07:43:56 -04:00