Commit Graph

241858 Commits

Author SHA1 Message Date
Michael Goulet
ae0a6e8537
Rollup merge of #119198 - compiler-errors:desugaring, r=eholk
Split coroutine desugaring kind from source

What a coroutine is desugared from (gen/async gen/async) should be separate from where it comes (fn/block/closure).
2023-12-22 21:41:04 -05:00
Michael Goulet
e0d7a72c46
Rollup merge of #119171 - nnethercote:cleanup-errors-4, r=compiler-errors
Cleanup error handlers: round 4

More `rustc_errors` cleanups. A sequel to #118933.

r? `@compiler-errors`
2023-12-22 21:41:03 -05:00
Michael Goulet
7dd095598b
Rollup merge of #119077 - tmiasko:lint, r=cjgillot
Separate MIR lints from validation

Add a MIR lint pass, enabled with -Zlint-mir, which identifies undefined or
likely erroneous behaviour.

The initial implementation mostly migrates existing checks of this nature from
MIR validator, where they did not belong (those checks have false positives and
there is nothing inherently invalid about MIR with undefined behaviour).

Fixes #104736
Fixes #104843
Fixes #116079
Fixes #116736
Fixes #118990
2023-12-22 21:41:03 -05:00
Michael Goulet
aaff415322
Rollup merge of #119012 - workingjubilee:extract-enum-layout-fn, r=b-naber
Extract `layout_of_{struct,enum}` fn

While writing #118974 I noticed it was annoying to navigate a huge, several hundred line function, which handles many subcases, and make confident declarations about what part of the flow of execution the compiler would be in. To help with that, this breaks out `layout_of_struct_or_enum`'s fundamental logic into a pair of functions, one for each case. It changes essentially none of that logic, merely moves it around.

Because "the layout of an ADT" feels like a somewhat nebulous subject, I chose to deliberately avoid any expansions to LayoutCalculator's public API, though such does feel like a possible logical next step. There are, indeed, many logical next steps. I'm not taking any of them here, yet, because this comparatively tiny refactor is a prerequisite for all of them.
2023-12-22 21:41:02 -05:00
Nicholas Nethercote
2cd14bc939 Remove DiagnosticBuilder::forget_guarantee.
It's unused. And this means `DiagnosticBuilderInner` no longer needs to
be separate from `DiagnosticBuilder`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
00e8485057 Remove all uses of DiagnosticBuilder::forget_guarantee().
There are only three. It's simpler to make the type
`DiagnosticBuilder<'_, ()>` from the start, no matter the level, than to
change the guarantee later.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
3db58e636f Fix a comment.
There are quite a few hand-written `IntoDiagnostic` impls.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
81f50fd7e3 Fix weird code setting in create_feature_err. 2023-12-23 13:23:28 +11:00
Nicholas Nethercote
394430166e Use pub(crate) in a couple of places. 2023-12-23 13:23:28 +11:00
Nicholas Nethercote
e0461f93c9 Take full advantage of a use Level::*;.
Some of the `Level::` qualifiers in this file are omitted. This commit
removes the remainder.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
49040d088a Remove LabelKind.
It has three variants, but only `LabelKind::Label` is ever used. This
means `SingleLabelManySpans::kind` can also be removed.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
ce0f703554 Remove SubDiagnostic::render_span.
It's only ever set to `None`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
125337bd68 Remove render_span args from Diagnostic::{sub,sub_with_highlight}.
They're always `None`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
824667f753 Improve some names.
Lots of vectors of messages called `message` or `msg`. This commit
pluralizes them.

Note that `emit_message_default` and `emit_messages_default` both
already existed, and both process a vector, so I renamed the former
`emit_messages_default_inner` because it's called by the latter.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
d7a3b6291c Remove Diagnostic::new_with_code.
Its single use can be replaced with `Diagnostic::new_with_messages`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
3a1b8e643a Rename EarlyDiagCtxt methods to match DiagCtxt.
- `early_error_no_abort` -> `early_err`
- `early_error` -> `early_fatal`
- `early_struct_error` -> `early_struct_fatal`
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
1f08bfa383 Remove DiagCtxtInner::span_bug.
`DiagCtxt::span_bug` is different to the other `DiagCtxt::span_*`
methods. This commit makes it the same, which requires changing
`DiagCtxt::span_delayed_bug` to not do everything within the
`inner.borrow_mut()`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
1502596ca2 Introduce DiagCtxt::treat_next_err_as_bug.
To fix a FIXME.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
6f147afea9 Remove unnecessary line breaks from two string literals. 2023-12-23 13:23:28 +11:00
Nicholas Nethercote
a108a3bd8e Tweak flush_delayed.
- Take a `Vec` instead of an iterator, because that's all that is
  needed.
- Do an early return for the "no bugs" case.
- Use `enumerate` and an `i == 0` test to identify the first bug.

Those changes mean the `no_bug` variable can be removed, which I found
hard to read.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
757d6f6ef8 Give DiagnosticBuilder a default type.
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the
most common diagnostic level. It makes sense to do likewise for the
closely-related (and much more widely used) `DiagnosticBuilder` type,
letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just
`DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many
multi-line things becoming single line things.
2023-12-23 13:23:10 +11:00
Nicholas Nethercote
6257f3bf1f Use IntoDiagnostic default.
`IntoDiagnostic` defaults to `G = ErrorGuaranteed`. Take advantage of
this in one place that currently doesn't.
2023-12-23 13:18:50 +11:00
Nicholas Nethercote
aec78dd695 Fix a couple of left-over references to Handler. 2023-12-23 13:18:50 +11:00
Nicholas Nethercote
1b3695887f Improve use items in compiler/rustc_errors/src/lib.rs.
There are a bunch of them about 400 lines down, which is weird and
annoying. This commit moves them up and puts them in a more sensible
order.
2023-12-23 13:18:50 +11:00
Nicholas Nethercote
de303b87c9 Streamline struct_lint_level.
We can just get the error level in the `match` and then use
`DiagnosticBuilder::new`. This then means a number of `DiagCtxt`
functions are no longer needed, because this was the one place that used
them.

Note: the commit changes the treatment of spans for `Expect`, which was
different to all the other cases, but this has no apparent effect.
2023-12-23 13:18:50 +11:00
Nicholas Nethercote
c8c1615df0 Add comments to Level.
There is room for improvement on some of these, but something is better
than nothing.
2023-12-23 13:18:50 +11:00
bors
495203bf61 Auto merge of #119211 - rust-lang:pa-master-1.77, r=Mark-Simulacrum
Bump stage0 to 1.76 beta

r? `@Mark-Simulacrum`
2023-12-23 00:26:47 +00:00
Michael Goulet
004450506e Split coroutine desugaring kind from source 2023-12-22 23:58:29 +00:00
bors
467d1d97d4 Auto merge of #119227 - weihanglo:update-cargo, r=weihanglo
Update cargo

10 commits in 1a2666ddd14cf0a255d4ddb61c63531c259a7b39..363a2d11320faf531f6aacd1ea067c6bc08343b9
2023-12-17 17:53:53 +0000 to 2023-12-22 03:12:42 +0000
- refactor: centralize git checkouts and db paths (rust-lang/cargo#13187)
- Bump to 0.78.0; update changelog (rust-lang/cargo#13192)
- refactor: custom error types for `cargo-util-schemas` (rust-lang/cargo#13186)
- chore(deps): update rust crate handlebars to `v4.5.0` (rust-lang/cargo#13168)
- Hold the mutate exclusive lock when vendoring (rust-lang/cargo#12509)
- refactor: clean up package metadata (rust-lang/cargo#13184)
- ci: check SemVer for cargo-util-schemas on CI (rust-lang/cargo#13185)
- refactor(schemas): Pull out as `cargo-util-schemas` (rust-lang/cargo#13178)
- chore(rustfix): rename Readme.md to README.md (rust-lang/cargo#13181)
- chore(rustfix): remove useless clippy rules and fix a typo (rust-lang/cargo#13182)

r? ghost
2023-12-22 22:27:35 +00:00
Weihang Lo
e6412f277a
bootstrap: build doc for `cargo-util-schemas 2023-12-22 17:13:35 -05:00
Weihang Lo
b94cc35f38
Update cargo 2023-12-22 17:02:31 -05:00
bors
d6d7a93866 Auto merge of #118824 - aliemjay:perf-region-cons, r=compiler-errors
use Vec for region constraints instead of BTreeMap

~1% perf gain

Diagnostic regressions need more investigation.

r? `@ghost`
2023-12-22 20:28:48 +00:00
bors
398fd92e17 Auto merge of #119221 - matthiaskrgr:rollup-dh9exqf, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #117601 (Add support for hexagon-unknown-none-elf as target)
 - #119169 (Rid the AST & HIR pretty printer of cruft)
 - #119194 (Run fuchsia tests only on nightly)
 - #119201 (tests: fix overaligned-constant to not over-specify getelementptr instr)
 - #119215 (Emits error if has bound regions)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-22 18:32:16 +00:00
Matthias Krüger
b24e8784de
Rollup merge of #119215 - mu001999:fix/119209, r=Nilstrieb
Emits error if has bound regions

Fixes #119209
2023-12-22 19:01:28 +01:00
Matthias Krüger
41fbd25b73
Rollup merge of #119201 - durin42:overaligned-constant, r=Mark-Simulacrum
tests: fix overaligned-constant to not over-specify getelementptr instr

On LLVM 18 we get slightly different arguments here, so it's easier to just regex those away. The important details are all still asserted as I understand things.

Fixes #119193.

`@rustbot` label: +llvm-main
2023-12-22 19:01:27 +01:00
Matthias Krüger
c1263be8ea
Rollup merge of #119194 - pietroalbini:pa-disable-fuchsia-non-nightly, r=tmandry
Run fuchsia tests only on nightly

We discovered in https://github.com/rust-lang/rust/pull/119187 that the Fuchsia tests only work on nightly, and so we cannot have the `x86_64-gnu-integration` job run on beta and stable. This PR gates the job to only run in the nightly channel.

r? `@tmandry`
2023-12-22 19:01:27 +01:00
Matthias Krüger
15dc9f5bee
Rollup merge of #119169 - fmease:pretty-yeet-syntactic-cruft, r=compiler-errors
Rid the AST & HIR pretty printer of cruft

Found while working on #119163.

For `trait Trait: ?Sized {}` (semantically malformed), we currently output `trait Trait for ? Sized {}` (sic!) / `trait Trait for ? Sized { }` (sic!) if `-Zunpretty=expanded` / `-Zunpretty=hir` is passed.

`trait Tr for Sized? {}` (#15521) and later also `trait Tr for ?Sized {}` (I guess, #20194) is former Rust syntax. Hence I'm removing these outdated branches.

~~This will conflict with #119163, therefore marking this PR as blocked.~~ Rebased
2023-12-22 19:01:26 +01:00
Matthias Krüger
09684d2d31
Rollup merge of #117601 - androm3da:hexagon_unknown_none_elf, r=petrochenkov
Add support for hexagon-unknown-none-elf as target

Still TODO: document usage details for new target
2023-12-22 19:01:26 +01:00
r0cky
d3f466a3a7 Update test 2023-12-23 00:09:37 +08:00
r0cky
4830325a14 Emits error if has bound regions 2023-12-22 23:25:54 +08:00
bors
208dd2032b Auto merge of #118847 - eholk:for-await, r=compiler-errors
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue.

r? `@compiler-errors`
2023-12-22 14:17:10 +00:00
León Orell Valerian Liehr
b09889b959
Rid the AST & HIR pretty printers of syntactic cruft 2023-12-22 14:32:40 +01:00
bors
c1fc1d18cd Auto merge of #116821 - Nadrieril:fix-opaque-ice, r=compiler-errors
Exhaustiveness: reveal opaque types properly

Previously, exhaustiveness had no clear policy around opaque types. In this PR I propose the following policy: within the body of an item that defines the hidden type of some opaque type, exhaustiveness checking on a value of that opaque type is performed using the concrete hidden type inferred in this body.

I'm not sure how consistent this is with other operations allowed on opaque types; I believe this will require FCP.

From what I can tell, this doesn't change anything for non-empty types.

The observable changes are:
- when the real type is uninhabited, matches within the defining scopes can now rely on that for exhaustiveness, e.g.:

```rust
#[derive(Copy, Clone)]
enum Void {}
fn return_never_rpit(x: Void) -> impl Copy {
    if false {
        match return_never_rpit(x) {}
    }
    x
}
```
- this properly fixes ICEs like https://github.com/rust-lang/rust/issues/117100 that occurred because a same match could have some patterns where the type is revealed and some where it is not.

Bonus subtle point: if `x` is opaque, a match like `match x { ("", "") => {} ... }` will constrain its type ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=901d715330eac40339b4016ac566d6c3)). This is not the case for `match x {}`: this will not constain the type, and will only compile if something else constrains the type to be empty.

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

r? `@oli-obk`

Edited for precision of the wording

[Included](https://github.com/rust-lang/rust/pull/116821#issuecomment-1813171764) in the FCP on this PR is this rule:

> Within the body of an item that defines the hidden type of some opaque type, exhaustiveness checking on a value of that opaque type is performed using the concrete hidden type inferred in this body.
2023-12-22 12:12:12 +00:00
Pietro Albini
f9f5840eb4
update cfg(bootstrap)s 2023-12-22 11:14:11 +01:00
Pietro Albini
bcdaa0d194
bump stage0 2023-12-22 11:04:31 +01:00
Pietro Albini
c00486c9bb
update version placeholders 2023-12-22 11:01:42 +01:00
bors
ef1b78eabe Auto merge of #119173 - compiler-errors:direct-coro-kind, r=TaKO8Ki
Encode `CoroutineKind` directly

Probably a quick optimization?

r? `@ghost`
2023-12-22 04:07:40 +00:00
bors
aaef5fe497 Auto merge of #119163 - fmease:refactor-ast-trait-bound-modifiers, r=compiler-errors
Refactor AST trait bound modifiers

Instead of having two types to represent trait bound modifiers in the parser / the AST (`parser::ty::BoundModifiers` & `ast::TraitBoundModifier`), only to map one to the other later, just use `parser::ty::BoundModifiers` (moved & renamed to `ast::TraitBoundModifiers`).

The struct type is more extensible and easier to deal with (see [here](https://github.com/rust-lang/rust/pull/119099/files#r1430749981) and [here](https://github.com/rust-lang/rust/pull/119099/files#r1430752116) for context) since it more closely models what it represents: A compound of two kinds of modifiers, constness and polarity. Modeling this as an enum (the now removed `ast::TraitBoundModifier`) meant one had to add a new variant per *combination* of modifier kind, which simply isn't scalable and which lead to a lot of explicit non-DRY matches.

NB: `hir::TraitBoundModifier` being an enum is fine since HIR doesn't need to worry representing invalid modifier kind combinations as those get rejected during AST validation thereby immensely cutting down the number of possibilities.
2023-12-22 02:00:55 +00:00
bors
cee794ee98 Auto merge of #119097 - nnethercote:fix-EmissionGuarantee, r=compiler-errors
Fix `EmissionGuarantee`

There are some problems with the `DiagCtxt` API related to `EmissionGuarantee`. This PR fixes them.

r? `@compiler-errors`
2023-12-22 00:03:57 +00:00
Augie Fackler
58fdbd1479 tests: fix overaligned-constant to not over-specify getelementptr instr
On LLVM 18 we get slightly different arguments here, so it's easier to
just regex those away. The important details are all still asserted as I
understand things.

Fixes #119193.

@rustbot label: +llvm-main
2023-12-21 15:53:28 -05:00