Commit Graph

17659 Commits

Author SHA1 Message Date
Dylan DPC
33553e1a28
Rollup merge of #102385 - sunfishcode:sunfishcode/wasm-no-export-heap-base, r=davidtwco
Don't export `__heap_base` and `__data_end` on wasm32-wasi.

`__heap_base` and `__data_end` are exported for use by wasm-bindgen, which uses the wasm32-unknown-unknown target. On wasm32-wasi, as a step toward implementing the Canonical ABI, and as an aid to building speicalized WASI API polyfill wrappers, don't export `__heap_base` and `__data_end` on wasm32-wasi.
2022-09-29 18:13:20 +05:30
Dylan DPC
1be9ec5443
Rollup merge of #102336 - compiler-errors:issue-102333, r=jackh726
Fix associated type bindings with anon const in GAT position

The first commit formats `type_of.rs`, which is really hard to maintain since it uses a bunch of features like `let`-chains and `if let` match arm bindings. Best if you just review the second two diffs.

Fixes #102333
2022-09-29 18:13:19 +05:30
bors
c5bbf36a31 Auto merge of #102461 - oli-obk:split_collect_rs, r=lcnr
Split collect.rs

This file was way too big (adding a few lines of code caused tidy to trigger)
2022-09-29 10:44:29 +00:00
Oli Scherer
f22f149dbd Some path updates 2022-09-29 09:33:30 +00:00
Oli Scherer
6367e69929 Split collect.rs 2022-09-29 09:31:46 +00:00
bors
8a497b7181 Auto merge of #102328 - cuviper:ibm-stack-probes, r=nagisa
Enable inline stack probes on PowerPC and SystemZ

The LLVM PowerPC and SystemZ targets have both supported `"probe-stack"="inline-asm"` for longer than our current minimum LLVM 13 requirement, so we can turn this on for all `powerpc`, `powerpc64`, `powerpc64le`, and `s390x` targets in Rust. These are all tier-2 or lower, so CI does not run their tests, but I have confirmed that their `linux-gnu` variants do pass on RHEL.

cc #43241
2022-09-29 08:00:54 +00:00
Yuki Okushi
80e009ceba
Rollup merge of #102416 - lcnr:specialization-fixme, r=compiler-errors
remove FIXME, improve documentation

r? types
2022-09-29 11:42:06 +09:00
Yuki Okushi
039e9e2160
Rollup merge of #102399 - b-naber:binder-print-ice, r=lcnr
Account for use of index-based lifetime names in print of binder

Fixes https://github.com/rust-lang/rust/issues/102374

r? ```@lcnr```

cc ```@steffahn```
2022-09-29 11:42:06 +09:00
Yuki Okushi
19e84b91e5
Rollup merge of #102351 - Rageking8:improve-E0585, r=wesleywiser
Improve E0585 help
2022-09-29 11:42:04 +09:00
Yuki Okushi
852a152206
Rollup merge of #102085 - chenyukang:code-refactor, r=cjgillot
Code refactoring smart_resolve_report_errors

`smart_resolve_report_errors` 4ecfdfac51/compiler/rustc_resolve/src/late/diagnostics.rs (L143)
is almost 600 lines of code, we should do some code refactoring.
2022-09-29 11:42:03 +09:00
Ellis Hoag
01439c93b8 print <signal> when ranlib failed without an exit code 2022-09-28 19:02:38 -07:00
Nicholas Nethercote
269ff92975 Use let-chaining in WhileTrue::check_expr.
This has been bugging me for a while.
2022-09-29 09:10:57 +10:00
Nicholas Nethercote
f07d4efc45 Shrink hir::def::Res.
`Res::SelfTy` currently has two `Option`s. When the second one is `Some`
the first one is never consulted. So we can split it into two variants,
`Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res`
from 24 bytes to 12. This then shrinks `hir::Path` and
`hir::PathSegment`, which are the HIR types that take up the most space.
2022-09-29 08:44:52 +10:00
bors
b30c88623c Auto merge of #102384 - camelid:extrainfo, r=GuillaumeGomez
rustdoc: Remove `clean::TraitWithExtraInfo` and queryify `is_notable_trait`

cc `@notriddle` `@GuillaumeGomez`
2022-09-28 22:15:28 +00:00
Dan Gohman
297c908fee Change declare_cfn to use the C visibility for all C ABI functions. 2022-09-28 14:50:58 -07:00
Dan Gohman
bc5443a603 Use the existing set_visibility function. 2022-09-28 14:43:58 -07:00
Nicholas Nethercote
a8d5c00d46 Inline two Ident methods. 2022-09-29 07:05:34 +10:00
Nicholas Nethercote
2aa028d30d Inline <Token as PartialEq<TokenKind>>::eq. 2022-09-29 07:05:34 +10:00
Nicholas Nethercote
5f29a13a5b Change the "dummy self type".
Because this is the only occurrence of a `Res::SelfTy` with `None` and
`None` fields, and the next commit will rely on those not being present.
2022-09-29 06:57:53 +10:00
Cassaundra Smith
e5096d4cba
Fix span of byte-escaped left format args brace
Fix #102057.
2022-09-28 13:47:17 -07:00
bors
ce7f0f1aa0 Auto merge of #100719 - CohenArthur:rust-safe-intrinsic-attribute, r=wesleywiser
Add `#[rustc_safe_intrinsic]`

This PR adds the `#[rustc_safe_intrinsic]` attribute as mentionned on Zulip. The goal of this attribute is to avoid keeping a list of symbols as the source for stable intrinsics, and instead rely on an attribute. This is similar to `#[rustc_const_stable]` and `#[rustc_const_unstable]`, which among other things, are used to mark the constness of intrinsic functions.
2022-09-28 19:07:50 +00:00
Dan Gohman
284c94257f Don't export __wasm_init_memory on WebAssembly.
Since #72889, the Rust wasm target doesn't use --passive-segments, so
remove the `--export=__wasm_init_memory`.

As documented in the [tool-conventions Linking convention],
`__wasm_init_memory` is not intended to be exported.

[tool-conventions Linking convention]: 7c064f3048/Linking.md (shared-memory-and-passive-segments)
2022-09-28 11:13:51 -07:00
Dan Gohman
3c3bf76ce0 Declare main as visibility hidden on targets that default to hidden.
On targets with `default_hidden_visibility` set, which is currrently
just WebAssembly, declare the generated `main` function with visibility
hidden. This makes it consistent with clang's WebAssembly target, where
`main` is just a user function that gets the same visibility as any
other user function, which is hidden on WebAssembly unless explicitly
overridden.

This will help simplify use cases which in the future may want to
automatically wasm-export all visibility-"default" symbols. `main` isn't
intended to be wasm-exported, and marking it hidden prevents it from
being wasm-exported in that scenario.
2022-09-28 10:42:30 -07:00
Rageking8
2ee2ffa9a7 improve E0585 help 2022-09-29 00:34:31 +08:00
lcnr
9ccb851182 update fixme 2022-09-28 17:04:29 +02:00
bors
307dd938d7 Auto merge of #101454 - cjgillot:concat-binders, r=estebank
Do not overwrite lifetime binders for another HirId.

This PR makes higher-ranked bounds in where clauses a bit more principled.
We used to conflate `for<'a> T: Trait` with `(for<'a> T): Trait`.
This PR separates both binders.

This caused issued with fn types, which have their own binder, causing us to overwrite the predicates's binders with `fn`'s binders, ICEing.

Fixes https://github.com/rust-lang/rust/issues/98594
2022-09-28 14:42:55 +00:00
bors
09ae7846a2 Auto merge of #101619 - Xiretza:rustc_parse-session-diagnostics, r=davidtwco
Migrate more of rustc_parse to SessionDiagnostic

Still far from complete, but I thought I'd add a checkpoint here because rebasing was starting to get annoying.
2022-09-28 11:11:42 +00:00
b-naber
4fdc78e6bf account for use of index-based lifetime names in print of binder 2022-09-28 12:31:08 +02:00
bors
6201eabde8 Auto merge of #102302 - nnethercote:more-lexer-improvements, r=matklad
More lexer improvements

A follow-up to #99884.

r? `@matklad`
2022-09-28 08:14:04 +00:00
Arthur Cohen
37bf8f888c rustc_safe_intrinsic: Keep list of safe intrinsics within the compiler 2022-09-28 09:40:02 +02:00
bors
837bf370de Auto merge of #102388 - JohnTitor:rollup-mbyw6fl, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #100747 (Add long description and test for E0311)
 - #102232 (Stabilize bench_black_box)
 - #102288 (Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`.)
 - #102338 (Deny associated type bindings within associated type bindings)
 - #102347 (Unescaping cleanups)
 - #102348 (Tweak `FulfillProcessor`.)
 - #102378 (Use already resolved `self_ty` in `confirm_fn_pointer_candidate`)
 - #102380 (rustdoc: remove redundant mobile `.source > .sidebar` CSS)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-28 04:18:19 +00:00
Yuki Okushi
ae2028817a
Rollup merge of #102378 - compiler-errors:issue-102289, r=jackh726
Use already resolved `self_ty` in `confirm_fn_pointer_candidate`

Fixes #102289
2022-09-28 13:07:20 +09:00
Yuki Okushi
bf54cfe2b2
Rollup merge of #102348 - nnethercote:tweak-FulfillProcessor, r=jackh726
Tweak `FulfillProcessor`.

Avoids some unnecessary references and lifetimes.

r? `@jackh726`
2022-09-28 13:07:19 +09:00
Yuki Okushi
f0daff20ca
Rollup merge of #102347 - nnethercote:unescaping-cleanups, r=matklad
Unescaping cleanups

Some minor improvements.

r? `@matklad`
2022-09-28 13:07:18 +09:00
Yuki Okushi
b263b7e64c
Rollup merge of #102338 - compiler-errors:assoc-ty-binding-in-assoc-ty-binding, r=cjgillot
Deny associated type bindings within associated type bindings

Fixes #102335

This was made worse by #100865, which unified the way we generate substs for GATs and non-generic associated types. However, the issue was not _caused_ by #100865, evidenced by the test I added for GATs:

```rust
trait T {
    type A: S<C<(), i32 = ()> = ()>;
    //~^ ERROR associated type bindings are not allowed here
}

trait Q {}

trait S {
    type C<T>: Q;
}

fn main() {}
```

^ which passes on beta (where GATs are stable) and presumably ever since GATs support was added to `create_substs_for_associated_item` in astconv.
2022-09-28 13:07:18 +09:00
Yuki Okushi
9436ffc226
Rollup merge of #102288 - mejrs:inner, r=compiler-errors
Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`.

This suggests various ways to get inside wrapper types if the method cannot be found on the wrapper type, but is present on the wrappee.

For this PR, those wrapper types include `Localkey`, `MaybeUninit`, `RefCell`, `RwLock` and `Mutex`.
2022-09-28 13:07:17 +09:00
Yuki Okushi
07bb2e6527
Rollup merge of #102232 - Urgau:stabilize-bench_black_box, r=TaKO8Ki
Stabilize bench_black_box

This PR stabilize `feature(bench_black_box)`.

```rust
pub fn black_box<T>(dummy: T) -> T;
```

The FCP was completed in https://github.com/rust-lang/rust/issues/64102.

`@rustbot` label +T-libs-api -T-libs
2022-09-28 13:07:17 +09:00
Yuki Okushi
49bc668493
Rollup merge of #100747 - MatthewPeterKelly:mpk/add-long-error-message-for-E0311, r=MatthewPeterKelly
Add long description and test for E0311

Adds a long description and unit test for the E0311 compiler error.

Fixes one line-item in https://github.com/rust-lang/rust/issues/61137.
2022-09-28 13:07:16 +09:00
bors
d6734be398 Auto merge of #100996 - m-ou-se:format-args-2, r=estebank
Rewrite and refactor format_args!() builtin macro.

This is a near complete rewrite of `compiler/rustc_builtin_macros/src/format.rs`.

This gets rid of the massive unmaintanable [`Context` struct](76531befc4/compiler/rustc_builtin_macros/src/format.rs (L176-L263)), and splits the macro expansion into three parts:

1. First, `parse_args` will parse the `(literal, arg, arg, name=arg, name=arg)` syntax, but doesn't parse the template (the literal) itself.
2. Second, `make_format_args` will parse the template, the format options, resolve argument references, produce diagnostics, and turn the whole thing into a `FormatArgs` structure.
3. Finally, `expand_parsed_format_args` will turn that `FormatArgs` structure into the expression that the macro expands to.

In other words, the `format_args` builtin macro used to be a hard-to-maintain 'single pass compiler', which I've split into a three phase compiler with a parser/tokenizer (step 1), semantic analysis (step 2), and backend (step 3). (It's compilers all the way down. ^^)

This can serve as a great starting point for https://github.com/rust-lang/rust/issues/99012, which will only need to change the implementation of 3, while leaving step 1 and 2 unchanged.

It also makes https://github.com/rust-lang/compiler-team/issues/541 easier, which could then upgrade the new `FormatArgs` struct to an `ast` node and remove step 3, moving that step to later in the compilation process.

It also fixes a few diagnostics bugs.

This also [significantly reduces](https://gist.github.com/m-ou-se/b67b2d54172c4837a5ab1b26fa3e5284) the amount of generated code for cases with arguments in non-default order without formatting options, like `"{1} {0}"` or `"{a} {}"`, etc.
2022-09-28 01:36:28 +00:00
Nicholas Nethercote
d0a26acb2a Address review comments. 2022-09-28 11:15:23 +10:00
Noah Lev
4bf789fba7 rustdoc: Queryify is_notable_trait
This might help with #102375.
2022-09-27 17:44:54 -07:00
Dan Gohman
7f06d513fb Don't export __heap_base and __data_end on wasm32-wasi.
`__heap_base` and `__data_end` are exported for use by wasm-bindgen, which
uses the wasm32-unknown-unknown target. On wasm32-wasi, as a step toward
implementing the Canonical ABI, and as an aid to building speicalized WASI
API polyfill wrappers, don't export `__heap_base` and `__data_end` on
wasm32-wasi.
2022-09-27 17:42:33 -07:00
mejrs
4ff83cee95 Deduplicate some logic 2022-09-28 02:36:58 +02:00
Matthew Kelly
c0d32fd2cc review updates 2022-09-27 19:23:59 -04:00
Nicholas Nethercote
94cb5e86ea Small cleanups in unescaping code.
- Rename `unescape_raw_str_or_raw_byte_str` as
  `unescape_raw_str_or_byte_str`, which is more accurate.
- Remove the unused `Mode::in_single_quotes` method.
- Make some assertions more precise, and add a missing one to
  `unescape_char_or_byte`.
- Change all the assertions to `debug_assert!`, because this code is
  reasonably hot, and the assertions aren't required for memory safety,
  and any violations are likely to be sufficiently obvious that normal
  tests will trigger them.
2022-09-28 08:31:24 +10:00
Josh Stone
fb5002d68a Manually order DefId on 64-bit big-endian
`DefId` uses different field orders on 64-bit big-endian vs. others, in
order to optimize its `Hash` implementation. However, that also made it
derive different lexical ordering for `PartialOrd` and `Ord`. That
caused spurious differences wherever `DefId`s are sorted, like the
candidate sources list in `report_method_error`.

Now we manually implement `PartialOrd` and `Ord` on 64-bit big-endian to
match the same lexical ordering as other targets, fixing at least one
test, `src/test/ui/methods/method-ambig-two-traits-cross-crate.rs`.
2022-09-27 15:21:31 -07:00
Michael Goulet
e5776c6903 Use already resolved self_ty in confirm_fn_pointer_candidate 2022-09-27 20:00:24 +00:00
Matthias Krüger
3ca0cd0f94
Rollup merge of #102356 - davidtwco:translation-bootstrap-bump-allow-lint, r=lcnr
session: remove now-unnecessary lint `#[allow]`s

In #101230, the internal diagnostic migration lints - `diagnostic_outside_of_impl` and `untranslatable_diagnostic` - were modified so that they wouldn't trigger on functions annotated with `#[rustc_lint_diagnostics]`. However, this change has to make it into the bootstrap compiler before the `#[allow]` annotations that it aims to remove can be removed, which is possible now that #102051 has landed.
2022-09-27 21:42:24 +02:00
Matthias Krüger
e1fb698c44
Rollup merge of #102337 - cuviper:llvm-optional-bool, r=nikic
Avoid LLVM-deprecated `Optional::hasValue`

LLVM 15 added `Optional::has_value`, and LLVM `main` (16) has deprecated
`hasValue`. However, its `explicit operator bool` does the same thing,
and was added long ago, so we can use that across our full LLVM range of
compatibility.
2022-09-27 21:42:24 +02:00
Matthias Krüger
8b635cba1d
Rollup merge of #102284 - compiler-errors:missing-type-in-raw-ptr, r=davidtwco
Structured suggestion for missing `mut`/`const` in raw pointer

Fixes #102261
2022-09-27 21:42:23 +02:00
Matthias Krüger
8d2faa2ae8
Rollup merge of #102281 - RalfJung:invalid-enums, r=cjgillot
make invalid_value lint a bit smarter around enums

Fixes https://github.com/rust-lang/rust/issues/102043
2022-09-27 21:42:22 +02:00
mejrs
f3ac328d58 Address feedback 2022-09-27 21:42:09 +02:00
mejrs
c4c9415132 Wrapper suggestions 2022-09-27 21:42:09 +02:00
Nilstrieb
8a96884981
Flush delayed bugs before codegen
Sometimes it can happen that invalid code like a TyKind::Error makes
its way through the compiler without triggering any errors (this is
always a bug in rustc but bugs do happen sometimes :)). These ICEs
will manifest in the backend like as cg_llvm not being able to get
the layout of `[type error]`, which makes it hard to debug. By flushing
before codegen, we display all the delayed bugs, making it easier to
trace it to the root of the problem.
2022-09-27 20:56:05 +02:00
Xiretza
d7c64574e0 Implement IntoDiagnosticArg for rustc_ast::token::Token(Kind) 2022-09-27 20:29:19 +02:00
Xiretza
37fdcb4b36 Don't unnecessarily stringify paths in diagnostics 2022-09-27 20:29:19 +02:00
Xiretza
caefac034e Document use of Symbol::to_string() 2022-09-27 20:29:19 +02:00
Xiretza
00f95468c4 Migrate even more diagnostics in rustc_parse to diagnostic structs 2022-09-27 20:29:19 +02:00
Xiretza
760c4352d6 Migrate "struct literal body without path" error to diagnostic struct 2022-09-27 20:29:19 +02:00
Xiretza
ba10f2c0f2 Migrate "expected semicolon" diagnostics to diagnostic structs 2022-09-27 20:29:19 +02:00
Xiretza
7507ee29fc Migrate "expected identifier" diagnostics to diagnostic structs 2022-09-27 20:29:19 +02:00
Xiretza
21b5194a3a Rework "inner attribute not permitted" errors 2022-09-27 20:29:19 +02:00
Xiretza
4d0519a4e7 Remove error condition in parse_attribute
This function is only ever called when the `#` has already been
consumed, no need to produce an error message here.
2022-09-27 20:29:19 +02:00
Xiretza
e1b1d7b029 Migrate more rustc_parse diagnostics to diagnostic structs 2022-09-27 20:29:18 +02:00
Xiretza
e56d6a68db Move rustc_parse diagnostic structs to separate module 2022-09-27 20:29:18 +02:00
Xiretza
6ae7a30927 Migrate "invalid literal suffix" diagnostic to diagnostic structs 2022-09-27 20:29:18 +02:00
Xiretza
ab7c7dc7ce Migrate more diagnostics in rustc_parse to diagnostic structs 2022-09-27 20:29:18 +02:00
Xiretza
4d02892acf Allow raw identifiers to be used as fluent arguments 2022-09-27 20:29:18 +02:00
Xiretza
8489a67f0b Implement IntoDiagnosticArg for rustc_ast::Path 2022-09-27 20:29:18 +02:00
Xiretza
495e271883 Migrate rustc_session::expr_parentheses_needed to Subdiagnostic struct 2022-09-27 20:29:18 +02:00
Michael Goulet
92561f43f1 Support bindings with anon consts in generics 2022-09-27 17:42:15 +00:00
Michael Goulet
05267b5a50 Make type_of work correctly for const arg bindings 2022-09-27 17:42:14 +00:00
Michael Goulet
cca48285b8 Format type_of 2022-09-27 17:42:13 +00:00
Michael Goulet
ca2e0bb51a Deny associated type bindings within associated type bindings 2022-09-27 17:41:34 +00:00
Camille GILLOT
337a73da6e Do not overwrite binders for another HirId. 2022-09-27 18:58:37 +02:00
Takayuki Maeda
d7b6bd8f13 improve errors for incomplete functions in struct definitions 2022-09-28 01:03:18 +09:00
Urgau
9ad2f00f6a Stabilize bench_black_box 2022-09-27 17:38:51 +02:00
Ralf Jung
67fd09d3b8 also query type_uninhabited_from 2022-09-27 16:20:23 +02:00
Arthur Cohen
99d57ee23d core: Mark all safe intrinsics with #[rustc_safe_intrinsic] 2022-09-27 15:55:42 +02:00
Arthur Cohen
0ab2c91a2d attributes: Add #[rustc_safe_intrinsic] builtin 2022-09-27 15:55:42 +02:00
Deadbeef
27b280e1b5 Fix ICE in const_trait check code
This fixes #102156.
2022-09-27 13:47:32 +00:00
Mara Bos
20bb600849 Remove confusing drop. 2022-09-27 13:31:52 +02:00
Mara Bos
ba7bf1d8ef Update doc comments. 2022-09-27 13:31:52 +02:00
Mara Bos
cf53fef0d6 Turn format arguments Vec into its own struct.
With efficient lookup through a hash map.
2022-09-27 13:31:52 +02:00
Mara Bos
c1c6e3ae7c Add clarifying comments. 2022-09-27 13:31:51 +02:00
Mara Bos
8d9a5881ea Flatten if-let and match into one. 2022-09-27 13:31:51 +02:00
Mara Bos
15754f5ea1 Move enum definition closer to its usage. 2022-09-27 13:31:51 +02:00
Mara Bos
df7fd119d2 Use if let chain. 2022-09-27 13:31:51 +02:00
Mara Bos
e65c96e4ad Tweak comments. 2022-09-27 13:31:51 +02:00
Mara Bos
ae238efe91 Prefer new_v1_formatted instead of new_v1 with duplicates. 2022-09-27 13:31:51 +02:00
Mara Bos
00074926bb Fix typo. 2022-09-27 13:31:51 +02:00
Mara Bos
8efc383047 Move FormatArgs structure to its own module. 2022-09-27 13:31:51 +02:00
Mara Bos
9bec0de397 Rewrite and refactor format_args!() builtin macro. 2022-09-27 13:13:08 +02:00
bors
57ee5cf5a9 Auto merge of #102306 - lcnr:rustc_hir_analysis, r=compiler-errors
rename rustc_typeck to rustc_hir_analysis

first part of https://github.com/rust-lang/compiler-team/issues/529

r? `@compiler-errors`
2022-09-27 10:45:57 +00:00
David Wood
2286888ef9 session: remove now-unnecessary lint #[allow]s
In #101230, the internal diagnostic migration lints -
`diagnostic_outside_of_impl` and `untranslatable_diagnostic` - were
modified so that they wouldn't trigger on functions annotated with
`#[rustc_lint_diagnostics]`. However, this change has to make it into
the bootstrap compiler before the `#[allow]` annotations that it aims to
remove can be removed, which is possible now that #102051 has landed.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-27 11:01:49 +01:00
lcnr
1fc86a63f4 rustc_typeck to rustc_hir_analysis 2022-09-27 10:37:23 +02:00
bors
d9297d22ad Auto merge of #102314 - TaKO8Ki:add-label-to-struct-enum-union-ident, r=estebank
Add a label to struct/enum/union ident name

Based on https://github.com/rust-lang/rust/pull/94996#discussion_r831694150
cc: `@estebank`
2022-09-27 07:30:11 +00:00
Nicholas Nethercote
b69c335327 Tweak FulfillProcessor.
Avoids some unnecessary references and lifetimes.
2022-09-27 16:37:00 +10:00
Nicholas Nethercote
c91c64708b Fix an incorrect comment.
If a `\x` escape occurs in a non-byte literals (e.g. char literal,
string literal), it must be <= 0xff.
2022-09-27 15:25:34 +10:00
bors
de0b511daa Auto merge of #102189 - davidtwco:translation-derive-enums, r=compiler-errors
macros: diagnostic derive on enums

Part of #100717.

Extends `#[derive(Diagnostic)]` to work on enums too where each variant acts like a distinct diagnostic - being able to represent diagnostics this way can be quite a bit simpler for some parts of the compiler.

r? `@compiler-errors`
cc `@Xiretza`
2022-09-27 04:39:25 +00:00
Ellis Hoag
6d01c6d9c8 lint and remove unused diagnostic 2022-09-26 19:57:40 -07:00
Michael Goulet
594134d873 Structured suggestion for missing mut/const in pointer 2022-09-27 02:47:07 +00:00
Nicholas Nethercote
7f7e2165b1 Rename some variables.
These make the delimiter processing clearer.
2022-09-27 12:04:03 +10:00
Takayuki Maeda
4f44dee501 add a label to struct/enum/union ident name 2022-09-27 10:28:50 +09:00
Takayuki Maeda
e123a61297 create a new local var 2022-09-27 10:22:46 +09:00
Matthew Kelly
0d9c01480b remove implied link bound per review
also update .stderr outputs
2022-09-26 20:50:33 -04:00
Matthew Kelly
24aab524cb Merge remote-tracking branch 'origin/master' into mpk/add-long-error-message-for-E0311 2022-09-26 19:59:52 -04:00
Nicholas Nethercote
880ebb657a Minor improvements.
Add some comments, and mark one path as unreachable.
2022-09-27 09:53:04 +10:00
Josh Stone
35adb36779 Avoid LLVM-deprecated Optional::hasValue
LLVM 15 added `Optional::has_value`, and LLVM `main` (16) has deprecated
`hasValue`. However, its `explicit operator bool` does the same thing,
and was added long ago, so we can use that across our full LLVM range of
compatibility.
2022-09-26 16:51:18 -07:00
Josh Stone
ad8f519ed7 Enable inline stack probes on PowerPC and SystemZ 2022-09-26 13:40:24 -07:00
bors
8b705839cd Auto merge of #102324 - matthiaskrgr:rollup-6l70oz3, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #101875 (Allow more `!Copy` impls)
 - #101996 (Don't duplicate region names for late-bound regions in print of Binder)
 - #102181 (Add regression test)
 - #102273 (Allow `~const` bounds on non-const functions)
 - #102286 (Recover some items that expect braces and don't take semicolons)

Failed merges:

 - #102314 (Add a label to struct/enum/union ident name)

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-26 19:57:51 +00:00
Matthias Krüger
6f5e8c2ed4
Rollup merge of #102286 - compiler-errors:recover-semi-in-block-item, r=davidtwco
Recover some items that expect braces and don't take semicolons

Fixes #102262
2022-09-26 19:19:21 +02:00
Matthias Krüger
e9bec2fdd4
Rollup merge of #102273 - woppopo:relax_const_bound, r=fee1-dead
Allow `~const` bounds on non-const functions

Makes the behavior of bound of trait-associated functions and non-associated functions consistent.
2022-09-26 19:19:21 +02:00
Matthias Krüger
b02062e886
Rollup merge of #101996 - b-naber:binder-print, r=lcnr
Don't duplicate region names for late-bound regions in print of Binder

Fixes https://github.com/rust-lang/rust/issues/101280
2022-09-26 19:19:20 +02:00
Matthias Krüger
4d4a3691e9
Rollup merge of #101875 - fmease:allow-more-negative-copy-impls, r=lcnr
Allow more `!Copy` impls

You can already implement `!Copy` for a lot of types (with `#![feature(negative_impls)]`). However, before this PR you could not implement `!Copy` for ADTs whose fields don't implement `Copy` which didn't make any sense. Further, you couldn't implement `!Copy` for types impl'ing `Drop` (equally nonsensical).

``@rustbot`` label T-types F-negative_impls
Fixes #101836.

r? types
2022-09-26 19:19:19 +02:00
bors
1d1f142660 Auto merge of #102257 - cjgillot:let-else-lint, r=dingxiangfei2009
Fix lint scoping for let-else.

The scoping for let-else is inconsistent with HIR nesting.  This creates cases, in `ui/let-else/let-else-allow-unused.rs` for instance, where an `allow` lint attribute does not apply to the bindings created by `let-else`.

This PR is an attempt to correct this.

As there is no lint that currently relies on this, the test for this behaviour is https://github.com/rust-lang/rust/pull/101500.

cc `@dingxiangfei2009` as you filed https://github.com/rust-lang/rust/pull/101894
2022-09-26 17:17:07 +00:00
bors
e1d7dec558 Auto merge of #102051 - pietroalbini:pa-bootstrap-update, r=Mark-Simulacrum
Update bootstrap compiler to 1.65.0

This PR updates the bootstrap compiler to Rust 1.65.0, removing the various `cfg(bootstrap)`s.

r? `@Mark-Simulacrum`
2022-09-26 14:22:43 +00:00
b-naber
6118ee343f address review 2022-09-26 14:21:39 +02:00
bors
84946fe241 Auto merge of #102184 - chenyukang:fix-102087-add-binding-sugg, r=nagisa
Suggest Default::default() when binding isn't initialized

Fixes #102087
2022-09-26 11:41:58 +00:00
b-naber
456f4e8d22 don't duplicate late-bound region names in print of Binder 2022-09-26 13:10:55 +02:00
David Wood
f20c882b8b macros: support diagnostic derive on enums
Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-26 11:59:19 +01:00
lcnr
932f930d27 remove outdated coherence hack 2022-09-26 12:48:28 +02:00
Pietro Albini
3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Pietro Albini
d0305b3d00
replace stabilization placeholders 2022-09-26 10:13:44 +02:00
bors
21265dd0d2 Auto merge of #102224 - fee1-dead-contrib:const_trait_impl_specialization, r=oli-obk
Allow specializing on const trait bounds
2022-09-26 08:08:35 +00:00
Ralf Jung
c19daa472b make invalid_value lint a bit smarter around enums 2022-09-26 09:44:10 +02:00
bors
72f4923979 Auto merge of #102297 - fee1-dead-contrib:rollup-2np0cre, r=fee1-dead
Rollup of 5 pull requests

Successful merges:

 - #102143 (Recover from struct nested in struct)
 - #102178 (bootstrap: the backtrace feature is stable, no need to allow it any more)
 - #102197 (Stabilize const `BTree{Map,Set}::new`)
 - #102267 (Don't set RUSTC in the bootstrap build script)
 - #102270 (Remove benches from `rustc_middle`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-26 05:27:43 +00:00
fee1-dead
39c6bdc30d
Rollup merge of #102270 - Nilstrieb:delete-useless-benches, r=TaKO8Ki
Remove benches from `rustc_middle`

These benches benchmark rust langauge features and not the compiler, so they seem to be in the wrong place here. They also all take <1ns, making them pretty useless. Looking at their git history, they just seem to have been carried around for many, many years. This commit ends their journey.
2022-09-26 13:09:43 +08:00
fee1-dead
804c2c1ed9
Rollup merge of #102197 - Nilstrieb:const-new-🌲, r=Mark-Simulacrum
Stabilize const `BTree{Map,Set}::new`

The FCP was completed in #71835.

Since `len` and `is_empty` are not const stable yet, this also creates a new feature for them since they previously used the same `const_btree_new` feature.
2022-09-26 13:09:42 +08:00
fee1-dead
0adf293f87
Rollup merge of #102143 - Rageking8:fix-101540, r=TaKO8Ki
Recover from struct nested in struct

Fixes #101540

r? `@TaKO8Ki`

Not sure If I have done it right.
2022-09-26 13:09:41 +08:00
woppopo
e4b08ab241 Allow ~const bounds on non-const functions 2022-09-26 05:00:31 +00:00
Nicholas Nethercote
fb4dba0a17 Inline and remove cook_lexer_token.
This is a small performance win, alas.
2022-09-26 13:50:13 +10:00
Nicholas Nethercote
da84f0f4c3 Add rustc_lexer::TokenKind::Eof.
For alignment with `rust_ast::TokenKind::Eof`. Plus it's a bit faster,
due to less `Option` manipulation in `StringReader::next_token`.
2022-09-26 13:48:08 +10:00
Nicholas Nethercote
cc0022a363 Rename some things.
`Cursor` keeps track of the position within the current token. But it
uses confusing names that don't make it clear that the "length consumed"
is just within the current token.

This commit renames things to make this clearer.
2022-09-26 13:43:19 +10:00
Nicholas Nethercote
ceb25d125f Use less DRY in cook_lexer_token.
This is a case where a small amount of repetition results in code that
is faster and easier to read.
2022-09-26 13:41:58 +10:00
Nicholas Nethercote
aa6bfaf04b Make rustc_lexer::cursor::Cursor public.
`Cursor` is currently hidden, and the main tokenization path uses
`rustc_lexer::first_token` which involves constructing a new `Cursor`
for every single token, which is weird. Also, `first_token` also can't
handle empty input, so callers have to check for that first.

This commit makes `Cursor` public, so `StringReader` can contain a
`Cursor`, which results in a simpler structure. The commit also changes
`StringReader::advance_token` so it returns an `Option<Token>`,
simplifying the the empty input case.
2022-09-26 13:36:35 +10:00
Nicholas Nethercote
33516ac09a [ui] Rearrange StringReader/TokenTreesReader creation.
`TokenTreesReader` wraps a `StringReader`, but the `into_token_trees`
function obscures this. This commit moves to a more straightforward
control flow.
2022-09-26 13:35:46 +10:00
Nicholas Nethercote
33ba2776c9 Remove ast::Token::take.
Instead of replacing `TokenTreesReader::token` in two steps, we can just
do it in one, which is both simpler and faster.
2022-09-26 13:35:43 +10:00
Nicholas Nethercote
5b2075e03d Remove TokenTreesReader::bump.
It's an unnecessary layer that obfuscates when I am looking for
optimizations.
2022-09-26 13:34:04 +10:00
Nicholas Nethercote
d7928a92e5 Clarify spacing computation.
The spacing computation is done in two parts. In the first part
`next_token` and `bump` use `Spacing::Alone` to mean "preceded by
whitespace" and `Spacing::Joint` to mean the opposite. In the second
part `parse_token_tree_other` then adjusts the `spacing` value to mean
the usual thing (i.e. "is the following token joinable punctuation?").
This shift in meaning is very confusing and it took me some time to
understand what was going on.

This commit changes the first part to use a bool, and adds some
comments, which makes things much clearer.
2022-09-26 13:21:26 +10:00
Nicholas Nethercote
9640d1c023 Move #! checking.
Currently does the "is this a `#!` at the start of the file?" check for
every single token(!)

This commit moves it so it only happens once.
2022-09-26 13:19:14 +10:00
bors
fe217c28ff Auto merge of #102292 - fee1-dead-contrib:rollup-61ptdkt, r=fee1-dead
Rollup of 4 pull requests

Successful merges:

 - #101851 (Clean up (sub)diagnostic derives)
 - #102244 (Only generate closure def id for async fns with body)
 - #102263 (Clarify Iterator::rposition code example)
 - #102280 (rustdoc: clean up `.out-of-band`/`.in-band` CSS)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-26 02:45:13 +00:00
fee1-dead
c807277382
Rollup merge of #102244 - compiler-errors:issue-102219, r=cjgillot
Only generate closure def id for async fns with body

Fixes #102219
2022-09-26 09:27:37 +08:00
fee1-dead
1a93028bcc
Rollup merge of #101851 - Xiretza:diagnostic-derive-cleanups, r=davidtwco
Clean up (sub)diagnostic derives

The biggest chunk of this is unifying the parsing of subdiagnostic attributes (`#[error]`, `#[suggestion(...)]`, `#[label(...)]`, etc) between `Subdiagnostic` and `Diagnostic` type attributes as well as `Diagnostic` field attributes.

It also improves a number of proc macro diagnostics.

Waiting for #101558.
2022-09-26 09:27:36 +08:00
bors
3288d3a305 Auto merge of #101785 - jyn514:query-struct-fn-ptrs, r=cjgillot
Use function pointers instead of macro-unrolled loops in rustc_query_impl

By making these standalone functions, we
a) allow making them extensible in the future with a new `QueryStruct`
b) greatly decrease the amount of code in each individual function, avoiding exponential blowup in llvm

Helps with https://github.com/rust-lang/rust/issues/96524. Based on https://github.com/rust-lang/rust/pull/101173; only the last commit is relevant.

r? `@cjgillot`
2022-09-26 00:17:59 +00:00
yukang
672e3f4d77 fix #102087, Suggest Default::default() when binding isn't initialized 2022-09-26 07:56:26 +08:00
Michael Goulet
e99f6fee44 Only lower async fn body if it actually has a body 2022-09-25 23:03:15 +00:00
Michael Goulet
730ead8047 Only generate closure def id for async fns with body 2022-09-25 23:03:15 +00:00
Michael Goulet
4d0d688a3c Recover some items that expect braces and don't take semicolons 2022-09-25 22:34:25 +00:00
Nicholas Nethercote
14281e6147 Remove unnecessary spacing assignment.
It has no useful effect.
2022-09-26 08:28:45 +10:00