]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoAuto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov
bors [Wed, 4 May 2022 21:16:28 +0000 (21:16 +0000)]
Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov

Overhaul `MacArgs`

Motivation:
- Clarify some code that I found hard to understand.
- Eliminate one use of three places where `TokenKind::Interpolated` values are created.

r? `@petrochenkov`

2 years agoOverhaul `MacArgs::Eq`.
Nicholas Nethercote [Thu, 28 Apr 2022 20:52:01 +0000 (06:52 +1000)]
Overhaul `MacArgs::Eq`.

The value in `MacArgs::Eq` is currently represented as a `Token`.
Because of `TokenKind::Interpolated`, `Token` can be either a token or
an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a
literal or macro call AST fragment, and then is later lowered to a
literal token. But this is very non-obvious. `Token` is a much more
general type than what is needed.

This commit restricts things, by introducing a new type `MacArgsEqKind`
that is either an AST expression (pre-lowering) or an AST literal
(post-lowering). The downside is that the code is a bit more verbose in
a few places. The benefit is that makes it much clearer what the
possibilities are (though also shorter in some other places). Also, it
removes one use of `TokenKind::Interpolated`, taking us a step closer to
removing that variant, which will let us make `Token` impl `Copy` and
remove many "handle Interpolated" code paths in the parser.

Things to note:
- Error messages have improved. Messages like this:
  ```
  unexpected token: `"bug" + "found"`
  ```
  now say "unexpected expression", which makes more sense. Although
  arbitrary expressions can exist within tokens thanks to
  `TokenKind::Interpolated`, that's not obvious to anyone who doesn't
  know compiler internals.
- In `parse_mac_args_common`, we no longer need to collect tokens for
  the value expression.

2 years agoAuto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco
bors [Tue, 3 May 2022 20:03:54 +0000 (20:03 +0000)]
Auto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco

Make rustc_parse_format compile on stable

This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.

2 years agoMake rustc_parse_format compile on stable
bjorn3 [Fri, 29 Apr 2022 16:48:58 +0000 (18:48 +0200)]
Make rustc_parse_format compile on stable

This allows it to be used by lightweight formatting systems and may
allow it to be used by rust-analyzer.

2 years agorustc: Panic by default in `DefIdTree::parent`
Vadim Petrochenkov [Mon, 25 Apr 2022 19:08:45 +0000 (22:08 +0300)]
rustc: Panic by default in `DefIdTree::parent`

Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.

2 years agoFix the clippy build
Scott McMurray [Mon, 25 Apr 2022 02:08:23 +0000 (19:08 -0700)]
Fix the clippy build

2 years agoBless tests.
Camille GILLOT [Mon, 14 Mar 2022 14:56:37 +0000 (15:56 +0100)]
Bless tests.

2 years agoStore all generic bounds as where predicates.
Camille GILLOT [Mon, 7 Feb 2022 21:58:30 +0000 (22:58 +0100)]
Store all generic bounds as where predicates.

2 years agoInline WhereClause into Generics.
Camille GILLOT [Sat, 5 Feb 2022 14:48:02 +0000 (15:48 +0100)]
Inline WhereClause into Generics.

2 years agoBox HIR Generics and Impl.
Camille GILLOT [Sat, 5 Feb 2022 14:26:49 +0000 (15:26 +0100)]
Box HIR Generics and Impl.

2 years agoerrors: `span_suggestion` takes `impl ToString`
David Wood [Tue, 26 Apr 2022 05:17:33 +0000 (06:17 +0100)]
errors: `span_suggestion` takes `impl ToString`

Change `span_suggestion` (and variants) to take `impl ToString` rather
than `String` for the suggested code, as this simplifies the
requirements on the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoMake clippy inspector more precise.
Camille GILLOT [Mon, 14 Feb 2022 12:20:47 +0000 (13:20 +0100)]
Make clippy inspector more precise.

2 years agoDrop vis in Item.
Camille GILLOT [Sun, 13 Feb 2022 10:30:48 +0000 (11:30 +0100)]
Drop vis in Item.

2 years agoDrop vis in ImplItem.
Camille GILLOT [Sun, 13 Feb 2022 09:54:07 +0000 (10:54 +0100)]
Drop vis in ImplItem.

2 years agoDrop vis in FieldDef.
Camille GILLOT [Sun, 13 Feb 2022 00:54:13 +0000 (01:54 +0100)]
Drop vis in FieldDef.

2 years agoStop visiting visibility.
Camille GILLOT [Sun, 13 Feb 2022 14:40:08 +0000 (15:40 +0100)]
Stop visiting visibility.

2 years agoRollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Dylan DPC [Tue, 19 Apr 2022 12:43:21 +0000 (14:43 +0200)]
Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov

Stop using CRATE_DEF_INDEX outside of metadata encoding.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.  We should not manipulate raw `DefIndex` outside of metadata encoding.

2 years agoAuto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov
bors [Sun, 17 Apr 2022 12:56:19 +0000 (12:56 +0000)]
Auto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov

Report undeclared lifetimes during late resolution.

First step in https://github.com/rust-lang/rust/pull/91557

We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes.

r? `@petrochenkov`

2 years agoStop using CRATE_DEF_INDEX.
Camille GILLOT [Fri, 15 Apr 2022 17:27:53 +0000 (19:27 +0200)]
Stop using CRATE_DEF_INDEX.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.

2 years agoBless clippy.
Camille GILLOT [Fri, 1 Apr 2022 17:18:10 +0000 (19:18 +0200)]
Bless clippy.

2 years agoAuto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
bors [Sun, 17 Apr 2022 08:06:53 +0000 (08:06 +0000)]
Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot

Refactor HIR item-like traversal (part 1)

Issue  #95004

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
cc `@cjgillot`

2 years agoAuto merge of #94468 - Amanieu:global_asm_sym, r=nagisa
bors [Sat, 16 Apr 2022 04:46:01 +0000 (04:46 +0000)]
Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisa

Implement sym operands for global_asm!

Tracking issue: #93333

This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are:
- At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`.
- At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails).
  - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`.
  - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to.
- The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression.
- At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details.
  - On Mach-O, all symbols have a leading underscore.
  - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall.
  - No mangling is needed on other platforms.

r? `@nagisa`
cc `@eddyb`

2 years agoRollup merge of #94849 - ouz-a:master4, r=oli-obk
Dylan DPC [Fri, 15 Apr 2022 18:50:44 +0000 (20:50 +0200)]
Rollup merge of #94849 - ouz-a:master4, r=oli-obk

Check var scope if it exist

Fixes #92893.

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error

2 years agoclippy: Update full path to `CString`
Vadim Petrochenkov [Fri, 15 Apr 2022 13:52:58 +0000 (16:52 +0300)]
clippy: Update full path to `CString`

2 years agoUpdate issue-92893.stderr
ouz-a [Thu, 14 Apr 2022 20:42:15 +0000 (23:42 +0300)]
Update issue-92893.stderr

2 years agoReimplement lowering of sym operands for asm! so that it also works with global_asm!
Amanieu d'Antras [Tue, 1 Mar 2022 00:50:56 +0000 (00:50 +0000)]
Reimplement lowering of sym operands for asm! so that it also works with global_asm!

2 years agoAuto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk
bors [Wed, 13 Apr 2022 21:04:19 +0000 (21:04 +0000)]
Auto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk

errors: lazily load fallback fluent bundle

Addresses (hopefully) https://github.com/rust-lang/rust/pull/95667#issuecomment-1094794087.

Loading the fallback bundle in compilation sessions that won't go on to emit any errors unnecessarily degrades compile time performance, so lazily create the Fluent bundle when it is first required.

r? `@ghost` (just for perf initially)

2 years agoAuto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk
bors [Wed, 13 Apr 2022 07:50:56 +0000 (07:50 +0000)]
Auto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk

Use mir constant in thir instead of ty::Const

This is blocked on https://github.com/rust-lang/rust/pull/94059 (does include its changes, the first two commits in this PR correspond to those changes) and https://github.com/rust-lang/rust/pull/93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`.

Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? `@oli-obk`

2 years agoerrors: lazily load fallback fluent bundle
David Wood [Tue, 12 Apr 2022 08:34:40 +0000 (09:34 +0100)]
errors: lazily load fallback fluent bundle

Loading the fallback bundle in compilation sessions that won't go on to
emit any errors unnecessarily degrades compile time performance, so
lazily create the Fluent bundle when it is first required.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoAdd new `Deinit` statement kind
Jakob Degen [Tue, 5 Apr 2022 21:14:59 +0000 (17:14 -0400)]
Add new `Deinit` statement kind

2 years agoAuto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote
bors [Sat, 9 Apr 2022 02:31:24 +0000 (02:31 +0000)]
Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote

Cached stable hash cleanups

r? `@nnethercote`

Add a sanity assertion in debug mode to check that the cached hashes are actually the ones we get if we compute the hash each time.

Add a new data structure that bundles all the hash-caching work to make it easier to re-use it for different interned data structures

2 years agoremove CheckVisitor, CollectExternCrateVisitor and ItemLikeVisitor impls
Miguel Guarniz [Thu, 7 Apr 2022 20:47:40 +0000 (16:47 -0400)]
remove CheckVisitor, CollectExternCrateVisitor and ItemLikeVisitor impls

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2 years agoRefactor HIR item-like traversal (part 1)
Miguel Guarniz [Sun, 3 Apr 2022 19:50:33 +0000 (15:50 -0400)]
Refactor HIR item-like traversal (part 1)

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- add par_items(impl Fn(hir::ItemId)) to traverse all items in parallel

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2 years agoAvoid looking at the internals of Interned directly
Oli Scherer [Fri, 8 Apr 2022 15:57:44 +0000 (15:57 +0000)]
Avoid looking at the internals of Interned directly

2 years agoUpdate Cargo.lock
flip1995 [Fri, 8 Apr 2022 09:41:55 +0000 (10:41 +0100)]
Update Cargo.lock

2 years agoMerge commit '984330a6ee3c4d15626685d6dc8b7b759ff630bd' into clippyup
flip1995 [Thu, 7 Apr 2022 17:39:59 +0000 (18:39 +0100)]
Merge commit '984330a6ee3c4d15626685d6dc8b7b759ff630bd' into clippyup

2 years agoget rid of visit_constant in thir visitor
b-naber [Wed, 6 Apr 2022 08:12:42 +0000 (10:12 +0200)]
get rid of visit_constant in thir visitor

2 years agosession: opt for enabling directionality markers
David Wood [Sun, 3 Apr 2022 03:53:01 +0000 (04:53 +0100)]
session: opt for enabling directionality markers

Add an option for enabling and disabling Fluent's directionality
isolation markers in output. Disabled by default as these can render in
some terminals and applications.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: implement sysroot/testing bundle loading
David Wood [Mon, 28 Mar 2022 08:36:20 +0000 (09:36 +0100)]
errors: implement sysroot/testing bundle loading

Extend loading of Fluent bundles so that bundles can be loaded from the
sysroot based on the language requested by the user, or using a nightly
flag.

Sysroot bundles are loaded from `$sysroot/share/locale/$locale/*.ftl`.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: implement fallback diagnostic translation
David Wood [Sat, 26 Mar 2022 07:27:43 +0000 (07:27 +0000)]
errors: implement fallback diagnostic translation

This commit updates the signatures of all diagnostic functions to accept
types that can be converted into a `DiagnosticMessage`. This enables
existing diagnostic calls to continue to work as before and Fluent
identifiers to be provided. The `SessionDiagnostic` derive just
generates normal diagnostic calls, so these APIs had to be modified to
accept Fluent identifiers.

In addition, loading of the "fallback" Fluent bundle, which contains the
built-in English messages, has been implemented.

Each diagnostic now has "arguments" which correspond to variables in the
Fluent messages (necessary to render a Fluent message) but no API for
adding arguments has been added yet. Therefore, diagnostics (that do not
require interpolation) can be converted to use Fluent identifiers and
will be output as before.

2 years agospan: move `MultiSpan`
David Wood [Thu, 24 Mar 2022 02:03:04 +0000 (02:03 +0000)]
span: move `MultiSpan`

`MultiSpan` contains labels, which are more complicated with the
introduction of diagnostic translation and will use types from
`rustc_errors` - however, `rustc_errors` depends on `rustc_span` so
`rustc_span` cannot use types like `DiagnosticMessage` without
dependency cycles. Introduce a new `rustc_error_messages` crate that can
contain `DiagnosticMessage` and `MultiSpan`.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agorebase and use ty::Const in patterns again
b-naber [Fri, 25 Mar 2022 09:06:10 +0000 (10:06 +0100)]
rebase and use ty::Const in patterns again

2 years agoAuto merge of #95501 - Dylan-DPC:rollup-arx6sdc, r=Dylan-DPC
bors [Thu, 31 Mar 2022 00:29:54 +0000 (00:29 +0000)]
Auto merge of #95501 - Dylan-DPC:rollup-arx6sdc, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #93901 (Stabilize native library modifier syntax and the `whole-archive` modifier specifically)
 - #94806 (Fix `cargo run tidy`)
 - #94869 (Add the generic_associated_types_extended feature)
 - #95011 (async: Give predictable name to binding generated from .await expressions.)
 - #95251 (Reduce max hash in raw strings from u16 to u8)
 - #95298 (Fix double drop of allocator in IntoIter impl of Vec)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoRollup merge of #95251 - GrishaVar:hashes-u16-to-u8, r=dtolnay
Dylan DPC [Wed, 30 Mar 2022 22:26:31 +0000 (00:26 +0200)]
Rollup merge of #95251 - GrishaVar:hashes-u16-to-u8, r=dtolnay

Reduce max hash in raw strings from u16 to u8

[Relevant discussion](https://rust-lang.zulipchat.com/#narrow/stream/237824-t-lang.2Fdoc/topic/Max.20raw.20string.20delimiters)

2 years agoAuto merge of #95436 - cjgillot:static-mut, r=oli-obk
bors [Wed, 30 Mar 2022 22:09:56 +0000 (22:09 +0000)]
Auto merge of #95436 - cjgillot:static-mut, r=oli-obk

Remember mutability in `DefKind::Static`.

This allows to compute the `BodyOwnerKind` from `DefKind` only, and
removes a direct dependency of some MIR queries onto HIR.

As a side effect, it also simplifies metadata, since we don't need 4
flavours of `EntryKind::*Static` any more.

2 years agoclippy: nameres for primitive type impls
lcnr [Wed, 30 Mar 2022 09:57:53 +0000 (11:57 +0200)]
clippy: nameres for primitive type impls

2 years agoget clippy to compile again
lcnr [Fri, 18 Mar 2022 12:33:40 +0000 (13:33 +0100)]
get clippy to compile again

2 years agoRemember mutability in `DefKind::Static`.
Camille GILLOT [Tue, 29 Mar 2022 15:11:12 +0000 (17:11 +0200)]
Remember mutability in `DefKind::Static`.

This allows to compute the `BodyOwnerKind` from `DefKind` only, and
removes a direct dependency of some MIR queries onto HIR.

As a side effect, it also simplifies metadata, since we don't need 4
flavours of `EntryKind::*Static` any more.

2 years agoRemove opaque type obligation and just register opaque types as they are encountered.
Oli Scherer [Thu, 17 Feb 2022 13:28:06 +0000 (13:28 +0000)]
Remove opaque type obligation and just register opaque types as they are encountered.

This also registers obligations for the hidden type immediately.

2 years agoRevert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"
Oli Scherer [Mon, 14 Feb 2022 16:10:22 +0000 (16:10 +0000)]
Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"

This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing
changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.

2 years agoAuto merge of #95274 - jendrikw:slice-must-use, r=Dylan-DPC
bors [Sat, 26 Mar 2022 20:17:04 +0000 (20:17 +0000)]
Auto merge of #95274 - jendrikw:slice-must-use, r=Dylan-DPC

add #[must_use] to functions of slice and its iterators.

Continuation of #92853.

Tracking issue: #89692.

2 years agoadd #[must_use] to functions of slice and its iterators.
Jendrik [Sat, 26 Mar 2022 15:19:47 +0000 (16:19 +0100)]
add #[must_use] to functions of slice and its iterators.

2 years agoadd #[must_use] to functions of slice and its iterators.
Jendrik [Sat, 26 Mar 2022 14:37:48 +0000 (15:37 +0100)]
add #[must_use] to functions of slice and its iterators.

2 years agoAuto merge of #95149 - cjgillot:once-diag, r=estebank
bors [Sat, 26 Mar 2022 00:54:54 +0000 (00:54 +0000)]
Auto merge of #95149 - cjgillot:once-diag, r=estebank

Remove `Session::one_time_diagnostic`

This is untracked mutable state, which modified the behaviour of queries.
It was used for 2 things: some full-blown errors, but mostly for lint declaration notes ("the lint level is defined here" notes).

It is replaced by the diagnostic deduplication infra which already exists in the diagnostic emitter.
A new diagnostic level `OnceNote` is introduced specifically for lint notes, to deduplicate subdiagnostics.

As a drive-by, diagnostic emission takes a `&mut` to allow dropping the `SubDiagnostic`s.

2 years agoUpdate clippy helper function types
Grisha Vartanyan [Fri, 25 Mar 2022 14:05:27 +0000 (15:05 +0100)]
Update clippy helper function types

2 years agoAuto merge of #95273 - flip1995:clippyup, r=manishearth
bors [Thu, 24 Mar 2022 22:52:34 +0000 (22:52 +0000)]
Auto merge of #95273 - flip1995:clippyup, r=manishearth

Update Clippy

r? `@Manishearth`

2 years agoMerge commit 'd0cf3481a84e3aa68c2f185c460e282af36ebc42' into clippyup
flip1995 [Thu, 24 Mar 2022 13:50:04 +0000 (14:50 +0100)]
Merge commit 'd0cf3481a84e3aa68c2f185c460e282af36ebc42' into clippyup

2 years agoupdate clippy stderr file
Oli Scherer [Thu, 24 Mar 2022 11:27:07 +0000 (11:27 +0000)]
update clippy stderr file

2 years agoTake &mut Diagnostic in emit_diagnostic.
Camille GILLOT [Sun, 20 Mar 2022 17:26:09 +0000 (18:26 +0100)]
Take &mut Diagnostic in emit_diagnostic.

Taking a Diagnostic by move would break the usual pattern
`diag.label(..).emit()`.

2 years agoRollup merge of #94960 - codehorseman:master, r=oli-obk
Dylan DPC [Thu, 17 Mar 2022 21:55:05 +0000 (22:55 +0100)]
Rollup merge of #94960 - codehorseman:master, r=oli-obk

Fix many spelling mistakes

Signed-off-by: codehorseman <cricis@yeah.net>
2 years agoRollup merge of #94309 - eholk:issue-57017, r=tmandry
Dylan DPC [Thu, 17 Mar 2022 21:55:02 +0000 (22:55 +0100)]
Rollup merge of #94309 - eholk:issue-57017, r=tmandry

[generator_interior] Be more precise with scopes of borrowed places

Previously the generator interior type checking analysis would use the nearest temporary scope as the scope of a borrowed value. This ends up being overly broad for cases such as:

```rust
fn status(_client_status: &Client) -> i16 {
    200
}

fn main() {
    let client = Client;
    let g = move || match status(&client) {
        _status => yield,
    };
    assert_send(g);
}
```

In this case, the borrow `&client` could be considered in scope for the entirety of the `match` expression, meaning it would be viewed as live across the `yield`, therefore making the generator not `Send`.

In most cases, we want to use the enclosing expression as the scope for a borrowed value which will be less than or equal to the nearest temporary scope. This PR changes the analysis to use the enclosing expression as the scope for most borrows, with the exception of borrowed RValues which are true temporary values that should have the temporary scope. There's one further exception where borrows of a copy such as happens in autoref cases also should be ignored despite being RValues.

Joint work with `@nikomatsakis`

Fixes #57017

r? `@tmandry`

2 years agoresolve the conflict in compiler/rustc_session/src/parse.rs
codehorseman [Wed, 16 Mar 2022 12:12:30 +0000 (20:12 +0800)]
resolve the conflict in compiler/rustc_session/src/parse.rs

Signed-off-by: codehorseman <cricis@yeah.net>
2 years agofix typos
Dylan DPC [Tue, 15 Mar 2022 01:00:08 +0000 (02:00 +0100)]
fix typos

2 years agoMerge commit 'dc5423ad448877e33cca28db2f1445c9c4473c75' into clippyup
flip1995 [Mon, 14 Mar 2022 11:02:53 +0000 (12:02 +0100)]
Merge commit 'dc5423ad448877e33cca28db2f1445c9c4473c75' into clippyup

2 years agoImprove `AdtDef` interning.
Nicholas Nethercote [Fri, 4 Mar 2022 20:28:41 +0000 (07:28 +1100)]
Improve `AdtDef` interning.

This commit makes `AdtDef` use `Interned`. Much the commit is tedious
changes to introduce getter functions. The interesting changes are in
`compiler/rustc_middle/src/ty/adt.rs`.

2 years agoRemove is_autoref parameter
Eric Holk [Fri, 11 Mar 2022 01:24:08 +0000 (17:24 -0800)]
Remove is_autoref parameter

2 years agoadd `#[rustc_pass_by_value]` to more types
lcnr [Tue, 8 Mar 2022 14:39:52 +0000 (15:39 +0100)]
add `#[rustc_pass_by_value]` to more types

2 years agoAuto merge of #94706 - matthiaskrgr:rollup-l5erynr, r=matthiaskrgr
bors [Mon, 7 Mar 2022 18:06:31 +0000 (18:06 +0000)]
Auto merge of #94706 - matthiaskrgr:rollup-l5erynr, r=matthiaskrgr

Rollup of 4 pull requests

Successful merges:

 - #93350 (libunwind: readd link attrs to _Unwind_Backtrace)
 - #93827 (Stabilize const_fn_fn_ptr_basics, const_fn_trait_bound, and const_impl_trait)
 - #94696 (Remove whitespaces and use CSS to align line numbers to the right instead)
 - #94700 (rustdoc: Update minifier version)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoUpdate clippy to new ExprUseVisitor delegate
Eric Holk [Sat, 26 Feb 2022 01:13:53 +0000 (17:13 -0800)]
Update clippy to new ExprUseVisitor delegate

2 years agoUpdate and fix clippy tests
Eric Holk [Fri, 11 Feb 2022 03:23:43 +0000 (19:23 -0800)]
Update and fix clippy tests

2 years agoStabilize const_fn_fn_ptr_basics and const_fn_trait_bound
Eric Holk [Wed, 9 Feb 2022 00:33:15 +0000 (16:33 -0800)]
Stabilize const_fn_fn_ptr_basics and const_fn_trait_bound

2 years agoClarify `Layout` interning.
Nicholas Nethercote [Fri, 4 Mar 2022 02:46:56 +0000 (13:46 +1100)]
Clarify `Layout` interning.

`Layout` is another type that is sometimes interned, sometimes not, and
we always use references to refer to it so we can't take any advantage
of the uniqueness properties for hashing or equality checks.

This commit renames `Layout` as `LayoutS`, and then introduces a new
`Layout` that is a newtype around an `Interned<LayoutS>`. It also
interns more layouts than before. Previously layouts within layouts
(via the `variants` field) were never interned, but now they are. Hence
the lifetime on the new `Layout` type.

Unlike other interned types, these ones are in `rustc_target` instead of
`rustc_middle`. This reflects the existing structure of the code, which
does layout-specific stuff in `rustc_target` while `TyAndLayout` is
generic over the `Ty`, allowing the type-specific stuff to occur in
`rustc_middle`.

The commit also adds a `HashStable` impl for `Interned`, which was
needed. It hashes the contents, unlike the `Hash` impl which hashes the
pointer.

2 years agoIntroduce `ConstAllocation`.
Nicholas Nethercote [Tue, 1 Mar 2022 20:15:04 +0000 (07:15 +1100)]
Introduce `ConstAllocation`.

Currently some `Allocation`s are interned, some are not, and it's very
hard to tell at a use point which is which.

This commit introduces `ConstAllocation` for the known-interned ones,
which makes the division much clearer. `ConstAllocation::inner()` is
used to get the underlying `Allocation`.

In some places it's natural to use an `Allocation`, in some it's natural
to use a `ConstAllocation`, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring `ConstAllocation`, which is the type that embodies more
information. This does require quite a few calls to `inner()`.

The commit also tweaks how `PartialOrd` works for `Interned`. The
previous code was too clever by half, building on `T: Ord` to make the
code shorter. That caused problems with deriving `PartialOrd` and `Ord`
for `ConstAllocation`, so I changed it to build on `T: PartialOrd`,
which is slightly more verbose but much more standard and avoided the
problems.

2 years agoRollup merge of #94617 - pierwill:update-itertools, r=Mark-Simulacrum
Matthias Krüger [Sun, 6 Mar 2022 14:41:26 +0000 (15:41 +0100)]
Rollup merge of #94617 - pierwill:update-itertools, r=Mark-Simulacrum

Update `itertools`

Update to 0.10.1

2 years agoChange syntax for TyAlias where clauses
Jack Huey [Tue, 19 Oct 2021 22:45:48 +0000 (18:45 -0400)]
Change syntax for TyAlias where clauses

2 years agoDo not point at whole file missing `fn main`
Esteban Kuber [Fri, 21 Jan 2022 00:15:39 +0000 (00:15 +0000)]
Do not point at whole file missing `fn main`

Only point at the end of the crate. We could try making it point at the
beginning of the crate, but that is confused with `DUMMY_SP`, causing
the output to be *worse*.

This change will make it so that VSCode will *not* underline the whole
file when `main` is missing, so other errors will be visible.

2 years agoUpdate `itertools`
pierwill [Fri, 4 Mar 2022 17:54:28 +0000 (11:54 -0600)]
Update `itertools`

Update to 0.10.1

2 years agoAuto merge of #94512 - RalfJung:sdiv-ub, r=oli-obk
bors [Thu, 3 Mar 2022 12:56:24 +0000 (12:56 +0000)]
Auto merge of #94512 - RalfJung:sdiv-ub, r=oli-obk

Miri/CTFE: properly treat overflow in (signed) division/rem as UB

To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine.

r? `@oli-obk`

2 years agobless clippy
Ralf Jung [Thu, 3 Mar 2022 00:20:27 +0000 (19:20 -0500)]
bless clippy

2 years agoMove transmute_undefined_repr back to nursery
flip1995 [Tue, 15 Feb 2022 09:54:38 +0000 (10:54 +0100)]
Move transmute_undefined_repr back to nursery

There's still open discussion if this lint is ready to be enabled by
default. We want to give us more time to figure this out and prevent
this lint from getting to stable as an enabled-by-default lint.

2 years agoMerge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup
flip1995 [Sat, 26 Feb 2022 13:26:21 +0000 (14:26 +0100)]
Merge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup

2 years agoSwitch bootstrap cfgs
Mark Rousskov [Wed, 23 Feb 2022 13:06:22 +0000 (08:06 -0500)]
Switch bootstrap cfgs

2 years agoAuto merge of #93368 - eddyb:diagbld-guarantee, r=estebank
bors [Fri, 25 Feb 2022 00:46:04 +0000 (00:46 +0000)]
Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebank

rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".

That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have:
* `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics
  * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation
  * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`)
  * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called
    (though note that this isn't a real guarantee until after completing the work on
     #69426)
* `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.)
  * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()`

This PR is a companion to other ongoing work, namely:
* #69426
  and it's ongoing implementation:
  #93222
  the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes
* #93244
  would make the choices of API changes (esp. naming) in this PR fit better overall

In order to be able to let `.emit()` return anything trustable, several changes had to be made:
* `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail)
  * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()`
* `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic
  * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user
  * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it
  * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early)
  * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`)
* since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>,
  we have to make `.emit()` idempotent wrt the guarantees it returns
  * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission
* `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic)
  * the APIs were already mostly identical, allowing for low-effort porting to this new setup
  * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259)
  * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective)
  * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same)

This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each.

r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`

2 years agoRollup merge of #93714 - compiler-errors:can-type-impl-copy-error-span, r=jackh726
Dylan DPC [Thu, 24 Feb 2022 20:42:12 +0000 (21:42 +0100)]
Rollup merge of #93714 - compiler-errors:can-type-impl-copy-error-span, r=jackh726

better ObligationCause for normalization errors in `can_type_implement_copy`

Some logic is needed so we can point to the field when given totally nonsense types like `struct Foo(<u32 as Iterator>::Item);`

Fixes #93687

2 years agoUpdate clippy tests
Vadim Petrochenkov [Sat, 5 Feb 2022 02:07:13 +0000 (10:07 +0800)]
Update clippy tests

2 years agoresolve: Fix incorrect results of `opt_def_kind` query for some built-in macros
Vadim Petrochenkov [Sat, 11 Dec 2021 11:52:23 +0000 (19:52 +0800)]
resolve: Fix incorrect results of `opt_def_kind` query for some built-in macros

Previously it always returned `MacroKind::Bang` while some of those macros are actually attributes and derives

2 years agobetter ObligationCause for normalization errors in can_type_implement_copy
Michael Goulet [Sun, 6 Feb 2022 21:03:28 +0000 (13:03 -0800)]
better ObligationCause for normalization errors in can_type_implement_copy

2 years agorustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.
Eduard-Mihai Burtescu [Wed, 26 Jan 2022 03:39:14 +0000 (03:39 +0000)]
rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.

2 years agoReplace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`.
Eduard-Mihai Burtescu [Sun, 23 Jan 2022 20:41:46 +0000 (20:41 +0000)]
Replace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`.

2 years agoupdate clippy
lcnr [Mon, 7 Feb 2022 15:06:55 +0000 (16:06 +0100)]
update clippy

2 years agoAuto merge of #94088 - oli-obk:revert, r=jackh726
bors [Fri, 18 Feb 2022 07:35:37 +0000 (07:35 +0000)]
Auto merge of #94088 - oli-obk:revert, r=jackh726

Revert #91403

fixes #94004

r? `@pnkfelix` `@cjgillot`

2 years agoRevert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"
Oli Scherer [Thu, 17 Feb 2022 16:00:04 +0000 (16:00 +0000)]
Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"

This reverts commit 3cfa4def7c87d571bd46d92fed608edf8fad236e, reversing
changes made to 5d8767cb229b097fedb1dd4bd9420d463c37774f.

2 years agoDon't lint `needless_borrow` in method receiver positions
Jason Newcomb [Thu, 17 Feb 2022 04:14:39 +0000 (23:14 -0500)]
Don't lint `needless_borrow` in method receiver positions

2 years agoRollup merge of #94030 - ChayimFriedman2:issue-94010, r=petrochenkov
Matthias Krüger [Thu, 17 Feb 2022 05:30:02 +0000 (06:30 +0100)]
Rollup merge of #94030 - ChayimFriedman2:issue-94010, r=petrochenkov

Correctly mark the span of captured arguments in `format_args!()`

It should not include the braces, or misspelling suggestions will be wrong.

Fixes #94010.

2 years agoCorrectly mark the span of captured arguments in `format_args!()`
Chayim Refael Friedman [Wed, 16 Feb 2022 00:38:04 +0000 (00:38 +0000)]
Correctly mark the span of captured arguments in `format_args!()`

It should only include the identifier, or misspelling suggestions will be wrong.

2 years agoRollup merge of #94014 - flip1995:clippy_transmute_lint_regroup, r=dtolnay
Matthias Krüger [Tue, 15 Feb 2022 15:02:37 +0000 (16:02 +0100)]
Rollup merge of #94014 - flip1995:clippy_transmute_lint_regroup, r=dtolnay

Move transmute_undefined_repr back to nursery

There's still open discussion if this lint is ready to be enabled by
default. We want to give us more time to figure this out and prevent
this lint from getting to stable as an enabled-by-default lint.

cc https://github.com/rust-lang/rust-clippy/pull/8432

r? `@Manishearth` `@dtolnay`

I think this is the way to go here. We can re-enable this lint with the next sync, if we should decide to do so. But I would hold of for this release.

We have until Friday (beta branching) to decide if we want to merge this.

2 years agoMove transmute_undefined_repr back to nursery
flip1995 [Tue, 15 Feb 2022 09:54:38 +0000 (10:54 +0100)]
Move transmute_undefined_repr back to nursery

There's still open discussion if this lint is ready to be enabled by
default. We want to give us more time to figure this out and prevent
this lint from getting to stable as an enabled-by-default lint.

2 years agoOverhaul `Const`.
Nicholas Nethercote [Wed, 2 Feb 2022 03:24:45 +0000 (14:24 +1100)]
Overhaul `Const`.

Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as
this:
```
pub struct Const<'tcx>(&'tcx Interned<ConstS>);
```
This now matches `Ty` and `Predicate` more closely, including using
pointer-based `eq` and `hash`.

Notable changes:
- `mk_const` now takes a `ConstS`.
- `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a
  we need separate arena for it, because we can't use the `Dropless` one any
  more.
- Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes
- Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes.
- Lots of tedious sigil fiddling.

2 years agoOverhaul `RegionKind` and `Region`.
Nicholas Nethercote [Fri, 28 Jan 2022 00:25:15 +0000 (11:25 +1100)]
Overhaul `RegionKind` and `Region`.

Specifically, change `Region` from this:
```
pub type Region<'tcx> = &'tcx RegionKind;
```
to this:
```
pub struct Region<'tcx>(&'tcx Interned<RegionKind>);
```

This now matches `Ty` and `Predicate` more closely.

Things to note
- Regions have always been interned, but we haven't been using pointer-based
  `Eq` and `Hash`. This is now happening.
- I chose to impl `Deref` for `Region` because it makes pattern matching a lot
  nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`.
- Various methods are moved from `RegionKind` to `Region`.
- There is a lot of tedious sigil changes.
- A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a
  `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`.
- A couple of test outputs change slightly, I'm not sure why, but the new
  outputs are a little better.

2 years agoOverhaul `TyS` and `Ty`.
Nicholas Nethercote [Tue, 25 Jan 2022 03:13:38 +0000 (14:13 +1100)]
Overhaul `TyS` and `Ty`.

Specifically, change `Ty` from this:
```
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
```
to this
```
pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>);
```
There are two benefits to this.
- It's now a first class type, so we can define methods on it. This
  means we can move a lot of methods away from `TyS`, leaving `TyS` as a
  barely-used type, which is appropriate given that it's not meant to
  be used directly.
- The uniqueness requirement is now explicit, via the `Interned` type.
  E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather
  than via `TyS`, which wasn't obvious at all.

Much of this commit is boring churn. The interesting changes are in
these files:
- compiler/rustc_middle/src/arena.rs
- compiler/rustc_middle/src/mir/visit.rs
- compiler/rustc_middle/src/ty/context.rs
- compiler/rustc_middle/src/ty/mod.rs

Specifically:
- Most mentions of `TyS` are removed. It's very much a dumb struct now;
  `Ty` has all the smarts.
- `TyS` now has `crate` visibility instead of `pub`.
- `TyS::make_for_test` is removed in favour of the static `BOOL_TY`,
  which just works better with the new structure.
- The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls
  of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned`
  (pointer-based, for the `Equal` case) and partly on `TyS`
  (contents-based, for the other cases).
- There are many tedious sigil adjustments, i.e. adding or removing `*`
  or `&`. They seem to be unavoidable.