Commit Graph

12884 Commits

Author SHA1 Message Date
Camille GILLOT
94449e6101 Store all generic bounds as where predicates. 2022-04-30 13:55:13 +02:00
Camille GILLOT
05b29f9a92 Inline WhereClause into Generics. 2022-04-30 13:51:49 +02:00
Camille GILLOT
71b4e2d852 Box HIR Generics and Impl. 2022-04-30 13:51:49 +02:00
bors
76d4862fdd Auto merge of #95776 - cjgillot:ast-lifetimes-static, r=petrochenkov
Enforce static lifetimes in consts during late resolution

This PR moves the handling of implicitly and explicitly static lifetimes in constants from HIR to the AST.
2022-04-30 07:52:18 +00:00
bors
9a98c63b30 Auto merge of #96500 - SparrowLii:rpo, r=tmiasko
Reduce duplication of RPO calculation of mir

Computing the RPO of mir is not a low-cost thing, but it is duplicate in many places. In particular the `iterate_to_fixpoint` method which is called multiple times when computing the data flow.
This PR reduces the number of times the RPO is recalculated as much as possible, which should save some compile time.
2022-04-30 05:06:47 +00:00
Esteban Kuber
bce5ab2c78 Use newtype enums instead of bool 2022-04-30 02:40:36 +00:00
Esteban Kuber
09f3ea1692 When encountering a binding that could be a const or unit variant, suggest the right path 2022-04-30 02:27:25 +00:00
Camille GILLOT
865d0fef2f Ban non-static lifetimes from AnonConst on AST.
The extra diagnostics come from the compiler no longer aborting before
typeck.
2022-04-30 00:28:42 +02:00
bors
05c07386b4 Auto merge of #96566 - Dylan-DPC:rollup-fo7rd98, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #96390 (Switch JS code to ES6 - part 2)
 - #96527 (RustWrapper: explicitly don't handle DXILPointerTyID)
 - #96536 (rustdoc: fix missing method list for primitive deref target)
 - #96559 (Use the correct lifetime binder for elided lifetimes in path.)
 - #96560 (Remove unnecessary environment variable in cf-protection documentation)
 - #96562 (Fix duplicate directory separator in --remap-path-prefix.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-29 22:27:10 +00:00
Dylan DPC
548fca6927
Rollup merge of #96562 - michaelwoerister:path-remapping-fixes, r=oli-obk
Fix duplicate directory separator in --remap-path-prefix.

The compiler will currently emit duplicate directory separators when `--remap-path-prefix` has an exact match of the working directory and it is invoked with a relative path to the main source file. For example

```bash
rustc src/main.rs -Cdebuginfo=2 --remap-path-prefix="$(pwd)=abc"
```

will produce the path `abc//src/main.rs` in debuginfo. This is because `some_path.join("")` will append a directory separator to `some_path` and then LLVM does not check if the working directory already ends a directory separator before concatenating it with the relative path.
2022-04-29 23:54:43 +02:00
Dylan DPC
2003d833a5
Rollup merge of #96559 - cjgillot:elided-path-fn, r=petrochenkov
Use the correct lifetime binder for elided lifetimes in path.

Fixes https://github.com/rust-lang/rust/issues/96540
2022-04-29 23:54:41 +02:00
Dylan DPC
041f3b64dd
Rollup merge of #96527 - durin42:llvm-15-werror-wswitch, r=nikic
RustWrapper: explicitly don't handle DXILPointerTyID

This new enum entry was introduced in https://reviews.llvm.org/D122268,
and if I'm reading correctly there's no case where we'd ever encounter
it in our uses of LLVM. To preserve the ability to compile this file
with -Werror -Wswitch we add an explicit case for this entry.

r? nikic
2022-04-29 23:54:38 +02:00
Camille GILLOT
6e349c7f07 Remove error variable. 2022-04-29 22:26:22 +02:00
bors
a707f40107 Auto merge of #95819 - oli-obk:mir_can't_hold_all_these_lifetimes, r=estebank
Enforce Copy bounds for repeat elements while considering lifetimes

fixes https://github.com/rust-lang/rust/issues/95477

this is a breaking change in order to fix a soundness bug.

Before this PR we only checked whether the repeat element type had an `impl Copy`, but not whether that impl also had the appropriate lifetimes. E.g. if the impl was for `YourType<'static>` and not a general `'a`, then copying any type other than a `'static` one should have been rejected, but wasn't.

r? `@lcnr`
2022-04-29 20:00:47 +00:00
SparrowLii
7149bbcdc5 Eliminate duplication of RPO calculation for mir
add `postorder_cache` to mir Body

add `ReversePostorderCache` struct

correct struct name and comments
2022-04-30 03:42:57 +08:00
Michael Woerister
3614bd3c45 Fix duplicate directory separator in --remap-path-prefix. 2022-04-29 21:09:12 +02:00
Oli Scherer
67ce547f47 Refactor and document the repeat length check 2022-04-29 18:56:57 +00:00
Oli Scherer
be54947315 Extract copy bound check into a function 2022-04-29 18:49:02 +00:00
bors
1c8966e5e9 Auto merge of #96474 - SparrowLii:langcall, r=lcnr
Eliminate duplication code of building panic langcall during codegen

From the FIXME in the `codegen_panic_intrinsic` func.
2022-04-29 17:20:00 +00:00
Camille GILLOT
f66de50f8a Use the correct lifetime binder for elided lifetimes in path. 2022-04-29 18:51:21 +02:00
bors
683c582c1e Auto merge of #96468 - davidtwco:diagnostic-translation-subdiagnostic, r=oli-obk
macros: subdiagnostic derive

Add a new macro, `#[derive(SessionSubdiagnostic)]`, which can be applied to structs that represent subdiagnostics, such as labels, notes, helps or suggestions.

`#[derive(SessionSubdiagnostic)]` can be used with the existing `#[derive(SessionDiagnostic)]`. All diagnostics implemented using either derive are translatable, and this new derive should make it easier to port existing diagnostics to using these derives.

For example, consider the following subdiagnostic types...

```rust
#[derive(SessionSubdiagnostic)]
pub enum ExpectedIdentifierLabel<'tcx> {
    #[label(slug = "parser-expected-identifier")]
    WithoutFound {
        #[primary_span]
        span: Span,
    }
    #[label(slug = "parser-expected-identifier-found")]
    WithFound {
        #[primary_span]
        span: Span,
        found: String,
    }
}

#[derive(SessionSubdiagnostic)]
#[suggestion_verbose(slug = "parser-raw-identifier")]
pub struct RawIdentifierSuggestion<'tcx> {
    #[primary_span]
    span: Span,
    #[applicability]
    applicability: Applicability,
    ident: Ident,
}
```

...and the corresponding Fluent messages:

```fluent
parser-expected-identifier = expected identifier

parser-expected-identifier-found = expected identifier, found {$found}

parser-raw-identifier = escape `{$ident}` to use it as an identifier
```

These can be emitted using the new `subdiagnostic` function on `Diagnostic`...

```rust
diag.subdiagnostic(ExpectedIdentifierLabel::WithoutFound { span });
diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident });
```

...or as part of a larger `#[derive(SessionDiagnostic)]`:

```rust
#[derive(SessionDiagnostic)]
#[error(slug = "parser-expected-identifier")]
pub struct ExpectedIdentifier {
    #[primary_span]
    span: Span,
    token_descr: String,
    #[subdiagnostic]
    label: ExpectedIdentifierLabel,
    #[subdiagnostic]
    raw_identifier_suggestion: Option<RawIdentifierSuggestion>,
}
```

```rust
sess.emit_err(ExpectedIdentifier { ... });
```

r? `@oli-obk`
cc `@pvdrz`
2022-04-29 11:58:24 +00:00
Dylan DPC
48199e0e3f
Rollup merge of #96523 - nbdd0121:windows, r=petrochenkov
Add `@feat.00` symbol to symbols.o for COFF

Fix #96498

This is based on top of #96444.

r? ``@petrochenkov``
2022-04-29 11:23:16 +02:00
Dylan DPC
109008a1c1
Rollup merge of #96516 - oli-obk:impl_trait_inference_accidental_permitted, r=jackh726
Revert diagnostic duplication and accidental stabilization

fixes #96460

this is an accidental stabilization that we should put into the beta. I believe it is low-risk, because it was literally what we had before #94081

The effect on tests is massive, but mostly deduplication of diagnostics and some minor span changes.
2022-04-29 11:23:15 +02:00
Dylan DPC
31693cbef7
Rollup merge of #96477 - alexcrichton:update-wasm64-data-layout, r=wesleywiser
Update data layout string for wasm64-unknown-unknown

Looks like this changed in a recent LLVM update but wasm64 isn't built
on CI so it wasn't caught until now.

Closes #96463
2022-04-29 11:23:12 +02:00
bors
5560c51738 Auto merge of #96444 - nbdd0121:used2, r=petrochenkov
Use decorated names for linked_symbols on Windows

Fix #96423

r? `@petrochenkov`
2022-04-29 05:34:29 +00:00
David Wood
dca88612b9 macros: add interop between diagnostic derives
Add `#[subdiagnostic]` field attribute to the diagnostic derive which
is applied to fields that have types which use the subdiagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:12:10 +01:00
David Wood
e5d9371b30 macros: allow setting applicability in attribute
In the initial implementation of the `SessionSubdiagnostic`, the
`Applicability` of a suggestion can be set both as a field and as part
of the attribute, this commit adds the same support to the original
`SessionDiagnostic` derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:12:10 +01:00
David Wood
e8ee0d7a20 macros: add more documentation comments
Documentation comments are always good.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:12:10 +01:00
David Wood
2647a4812c macros: reuse SetOnce trait in diagnostic derive
`SetOnce` trait was introduced in the subdiagnostic derive to simplify
the code a little bit, re-use it in the diagnostic derive too.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:12:10 +01:00
David Wood
36a396ce51 macros: add helper functions for invalid attrs
Remove some duplicated code between both diagnostic derives by
introducing helper functions for reporting an error in case of a invalid
attribute.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:12:10 +01:00
David Wood
071f07274b macros: split diagnostic derives into modules
Split `SessionDiagnostic` and `SessionSubdiagnostic` derives and the
various helper functions into multiple modules.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:12:08 +01:00
David Wood
49ec909ca7 macros: subdiagnostic derive
Add a new derive, `#[derive(SessionSubdiagnostic)]`, which enables
deriving structs for labels, notes, helps and suggestions.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:05:20 +01:00
David Wood
73fa217bc1 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>
2022-04-29 02:05:20 +01:00
Camille GILLOT
a87ab48099 Ban non-static in const generics in AST. 2022-04-29 00:02:49 +02:00
Gary Guo
0fce0db96f Add @feat.00 symbol to symbols.o for COFF 2022-04-28 21:33:23 +01:00
Dylan DPC
0cbf3b2b30
Rollup merge of #96433 - petrochenkov:delim, r=nnethercote
rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`

Compiler cannot reuse `proc_macro::Delimiter` directly due to extra impls, but can at least use the same naming.

After this PR the only difference between these two enums is that `proc_macro::Delimiter::None` is turned into `token::Delimiter::Invisible`.
It's my mistake that the invisible delimiter is called `None` on stable, during the stabilization I audited the naming and wrote the docs, but missed the fact that the `None` naming gives a wrong and confusing impression about what this thing is.

cc https://github.com/rust-lang/rust/pull/96421
r? ``@nnethercote``
2022-04-28 20:13:02 +02:00
Dylan DPC
cbfbc3be7d
Rollup merge of #96409 - marmeladema:fix-nll-introduce-named-lifetime-suggestion, r=jackh726
Recover suggestions to introduce named lifetime under NLL

Fixes #96157

r? ```@jackh726```

Built on top of #96385 so only the second commit is relevant
2022-04-28 20:13:01 +02:00
Dylan DPC
b3329f84f4
Rollup merge of #96405 - pvdrz:ambiguous-plus-diagnostic, r=davidtwco
Migrate ambiguous plus diagnostic to the new derive macro

r? ````@davidtwco```` ````@jyn514````
2022-04-28 20:12:59 +02:00
Augie Fackler
e8ae06a31b RustWrapper: explicitly don't handle DXILPointerTyID
This new enum entry was introduced in https://reviews.llvm.org/D122268,
and if I'm reading correctly there's no case where we'd ever encounter
it in our uses of LLVM. To preserve the ability to compile this file
with -Werror -Wswitch we add an explicit case for this entry.
2022-04-28 13:53:52 -04:00
Oli Scherer
d22c439989 Revert diagnostic duplication and accidental stabilization 2022-04-28 13:25:36 +00:00
bors
b2c2a32870 Auto merge of #95976 - b-naber:valtree-constval-conversion, r=oli-obk
Implement Valtree to ConstValue conversion

Once we start to use `ValTree`s in the type system we will need to be able to convert them into `ConstValue` instances, which we want to continue to use after MIR construction.

r? `@oli-obk`

cc `@RalfJung`
2022-04-28 13:18:22 +00:00
SparrowLii
cf00142b4d use tcx.require_lang_item() instead 2022-04-28 20:18:01 +08:00
Oli Scherer
018f9347fc Update the diagnostic message to match the new span 2022-04-28 09:40:42 +00:00
Oli Scherer
4e6e68e27a Check that repeat expression elements are Copy (ignoring lifetimes) in typeck and that they are Copy (with proper lifetime checks) in borrowck 2022-04-28 09:19:42 +00:00
Vadim Petrochenkov
2733ec1be3 rustc_ast: Harmonize delimiter naming with proc_macro::Delimiter 2022-04-28 10:04:29 +03:00
bors
0e7915d11f Auto merge of #96085 - jsgf:deny-unused-deps, r=compiler-errors
Make sure `-Dunused-crate-dependencies --json unused-externs` makes rustc exit with error status

This PR:
- fixes compiletest to understand unused extern notifications
- adds tests for `--json unused-externs`
- makes sure that deny-level unused externs notifications are treated as compile errors
  - refactors the `emit_unused_externs` callstack to plumb through the level as an enum as a string, and adds `Level::is_error`

Update: adds `--json unused-externs-silent` with the original behaviour since Cargo needs it. Should address `@est31's` concerns.

Fixes: https://github.com/rust-lang/rust/issues/96068
2022-04-28 04:17:52 +00:00
bors
81799cd8fd Auto merge of #96495 - Dylan-DPC:rollup-9lm4tpp, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #96377 (make `fn() -> _ { .. }` suggestion MachineApplicable)
 - #96397 (Make EncodeWide implement FusedIterator)
 - #96421 (Less `NoDelim`)
 - #96432 (not need `Option` for `dbg_scope`)
 - #96466 (Better error messages when collecting into `[T; n]`)
 - #96471 (replace let else with `?`)
 - #96483 (Add missing `target_feature` to the list of well known cfg names)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-04-28 01:37:03 +00:00
Dylan DPC
89db345859
Rollup merge of #96483 - Urgau:check-cfg-target_feature, r=petrochenkov
Add missing `target_feature` to the list of well known cfg names

This PR adds the missing `target_feature` cfg name to the list of well known cfg names.

It was notice missing in https://github.com/rust-lang/rust/issues/96472 thanks to `@bjorn3,` the reason being that `--check-cfg=names()` automatically inherit the names passed by `--cfg` (or internal to `rustc`) and is seems that the vast majority of targets have at least one target feature leading to `target_feature` being a well known name in most target but it should always be a well known name so this PR add it unconditionally to list.

r? `@petrochenkov`
2022-04-28 02:40:37 +02:00
Dylan DPC
4c628bbb1c
Rollup merge of #96471 - BoxyUwU:let_else_considered_harmful, r=lcnr
replace let else with `?`

r? `@oli-obk`
2022-04-28 02:40:36 +02:00
Dylan DPC
6f6fe3e651
Rollup merge of #96466 - compiler-errors:error-collect-array, r=davidtwco
Better error messages when collecting into `[T; n]`

Fixes #96461
2022-04-28 02:40:35 +02:00