Commit Graph

134 Commits

Author SHA1 Message Date
Matthias Krüger
15c3abde1f
Rollup merge of #119417 - compiler-errors:closure-checking, r=davidtwco
Uplift some miscellaneous coroutine-specific machinery into `check_closure`

This PR uplifts some of the logic in `check_fn` that is specific to checking coroutines, which always flows through `check_closure`.

This is just some miscellaneous clean up that I've wanted to do, especially because I'm poking around this code to make it work for async closures.
2024-01-04 08:33:25 +01:00
León Orell Valerian Liehr
8bce6fc35e
Rollup merge of #119505 - fmease:no-host-param-for-trait-fns, r=fee1-dead
Don't synthesize host effect params for trait associated functions marked const

Fixes #113378.

r? fee1-dead or compiler
2024-01-03 16:08:30 +01:00
León Orell Valerian Liehr
aa799049d7
E0379: Provide suggestions 2024-01-02 13:49:48 +01:00
León Orell Valerian Liehr
ae8e401c9f
E0379: Make diagnostic more precise 2024-01-02 13:49:47 +01:00
Gary Guo
86bd81fe83 Update tracking issue of naked_functions
The original tracking issue was superseded by a new one
(constrainted naked functions) and therefore is closed.
2023-12-31 17:09:46 +00:00
Michael Goulet
7eeaaa2dc0 Compute yield and return types outside of check_fn 2023-12-29 19:59:58 +00:00
Martin Nordholts
7ca4e9fcb2 rustc_lint: Prevent triplication of 'unknown lint' lint 2023-12-28 19:46:51 +01:00
Michael Goulet
50e380c8f3
Rollup merge of #119235 - Urgau:missing-feature-gate-sanitizer-cfi-cfgs, r=Nilstrieb
Add missing feature gate for sanitizer CFI cfgs

Found during the review of https://github.com/rust-lang/rust/pull/118494 in https://github.com/rust-lang/rust/pull/118494#discussion_r1416079288.

cc `@rcvalle`
2023-12-26 13:29:13 -05:00
bors
f8fe517144 Auto merge of #116274 - RalfJung:soft_unstable, r=cjgillot
make soft_unstable show up in future breakage reports

If we want to break these in the future, let's warn users of affected crates.
2023-12-25 16:26:15 +00:00
Urgau
cc6cbaad4b Add missing CFI sanitizer cfgs feature gate 2023-12-23 00:52:42 +01:00
Esteban Küber
9d846fcc11 Tweak short_ty_string to reduce number of files
When shortening types and writing them to disk, make `short_ty_string`
capable of reusing the same file, instead of writing a file per
shortened type.
2023-12-13 23:07:10 +00:00
Jubilee
f9078a40ee
Rollup merge of #118891 - compiler-errors:async-gen-blocks, r=eholk
Actually parse async gen blocks correctly

1. I got the control flow in `parse_expr_bottom` messed up, and obviously forgot a test for `async gen`, so we weren't actually ever parsing it correctly.
2. I forgot to gate the span for `async gen {}`, so even if we did parse it, we wouldn't have correctly denied it in `cfg(FALSE)`.

r? eholk
2023-12-12 18:48:55 -08:00
Michael Goulet
1d78ce681e Actually parse async gen blocks correctly 2023-12-12 20:13:37 +00:00
Nadrieril
19e0c984d3 Don't gate the feature twice 2023-12-12 14:52:05 +01:00
Nadrieril
e274372689 Correctly gate the parsing of match arms without body 2023-12-12 14:42:04 +01:00
bors
d86d65bbc1 Auto merge of #118368 - GuillaumeGomez:env-flag, r=Nilstrieb
Implement `--env` compiler flag (without `tracked_env` support)

Part of https://github.com/rust-lang/rust/issues/80792.
Implementation of https://github.com/rust-lang/compiler-team/issues/653.
Not an implementation of https://github.com/rust-lang/rfcs/pull/2794.

It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`.

Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value.

As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR.

r? rust-lang/compiler
2023-12-10 21:48:53 +00:00
bors
b9068315db Auto merge of #116952 - compiler-errors:lifetime_capture_rules_2024, r=TaKO8Ki
Implement 2024-edition lifetime capture rules RFC

Implements rust-lang/rfcs#3498.
2023-12-10 15:51:39 +00:00
Guillaume Gomez
d2b1f94f05 Add feature gate test for --env flag 2023-12-10 14:25:57 +01:00
bors
2b399b5275 Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errors
never_patterns: Parse match arms with no body

Never patterns are meant to signal unreachable cases, and thus don't take bodies:
```rust
let ptr: *const Option<!> = ...;
match *ptr {
    None => { foo(); }
    Some(!),
}
```
This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser).

~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit

r? `@compiler-errors`
2023-12-08 17:08:52 +00:00
bors
5ea62560f2 Auto merge of #118668 - fmease:resolve-assoc-item-bindings-by-namespace, r=compiler-errors
Resolve associated item bindings by namespace

This is the 3rd commit split off from #118360 with tests reblessed (they no longer contain duplicated diags which were caused by 4c0addc80a) & slightly adapted (removed supertraits from a UI test, cc #118040).

> * Resolve all assoc item bindings (type, const, fn (feature `return_type_notation`)) by namespace instead of trying to resolve a type first (in the non-RTN case) and falling back to consts afterwards. This is consistent with RTN. E.g., for `Tr<K = {…}>` we now always try to look up assoc consts (this extends to supertrait bounds). This gets rid of assoc tys shadowing assoc consts in assoc item bindings which is undesirable & inconsistent (types and consts live in different namespaces after all)
> * Consolidate the resolution of assoc {ty, const} bindings and RTN (dedup, better diags for RTN)
> * Fix assoc consts being labeled as assoc *types* in several diagnostics
> * Make a bunch of diagnostics translatable

Fixes #112560 (error → pass).

As discussed
r? `@compiler-errors`

---

**Addendum**: What I call “associated item bindings” are commonly referred to as “type bindings” for historical reasons. Nowadays, “type bindings” include assoc type bindings, assoc const bindings and RTN (return type notation) which is why I prefer not to use this outdated term.
2023-12-08 09:30:52 +00:00
León Orell Valerian Liehr
55559d93e7
Resolve assoc item bindings by namespace
If a const is expected, resolve a const.
If a type is expected, resolve a type.
Don't try to resolve a type first falling back to consts.
2023-12-07 22:33:56 +01:00
Matthias Krüger
f546b44ecd
Rollup merge of #117981 - Urgau:check-cfg-remove-deprecated-syntax, r=b-naber
Remove deprecated `--check-cfg` syntax

This PR removes the deprecated `--check-cfg` `names(...)` and `values(...)` syntax.

Follow up to https://github.com/rust-lang/rust/pull/111072
Part of https://github.com/rust-lang/compiler-team/issues/636

r? compiler
2023-12-06 21:52:30 +01:00
Michael Goulet
0ad160a585 Add lifetime_capture_rules_2024 2023-12-05 19:53:59 +00:00
Urgau
3f0369e0f2 Remove deprecated --check-cfg names() and values() syntax 2023-12-05 13:25:11 +01:00
Nadrieril
5e470db05c Remove the precise_pointer_size_matching feature gate 2023-12-04 11:56:21 +01:00
Nadrieril
70deb9a57f Disallow arm bodies on never patterns 2023-12-03 12:25:46 +01:00
zetanumbers
f7617c1cd4 Enable link-arg link kind inside of #[link] attribute
- Implement link-arg as an attribute
- Apply suggestions from review
  - Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
- Add unstable book entry
2023-11-30 08:26:13 -08:00
Nadrieril
a3838c8550 Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
Nilstrieb
41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Vadim Petrochenkov
edf6c9c223 Add an experimental feature gate for function delegation
In accordance with the [process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md).

Detailed description of the feature can be found in the RFC repo - https://github.com/rust-lang/rfcs/pull/3530.
2023-11-23 17:27:31 +03:00
bors
360bafad68 Auto merge of #118065 - estebank:core-not-found-404, r=TaKO8Ki
When failing to import `core`, suggest `std`
2023-11-23 02:26:52 +00:00
Esteban Küber
ec50f1c90b When failing to import core, suggest std 2023-11-22 19:30:47 +00:00
Urgau
4c2d6de70e Stabilize RFC3324 dyn upcasting coercion
Aka trait_upcasting feature.

And also adjust the `deref_into_dyn_supertrait` lint.
2023-11-22 13:56:36 +01:00
bors
992943dbae Auto merge of #117537 - GKFX:offset-of-enum-feature, r=cjgillot
Feature gate enums in offset_of

As requested at https://github.com/rust-lang/rust/issues/106655#issuecomment-1790815262, put enums in offset_of behind their own feature gate.

`@rustbot` label F-offset_of
2023-11-05 13:44:59 +00:00
Nadrieril
746197c08a Tweak spans for "adt defined here" note 2023-11-03 18:26:16 +01:00
George Bateman
7c09b99ebb
Feature gate enums in offset_of 2023-11-03 13:16:47 +00:00
bors
7fc6365570 Auto merge of #116692 - Nadrieril:half-open-ranges, r=cjgillot
Match usize/isize exhaustively with half-open ranges

The long-awaited finale to the saga of [exhaustiveness checking for integers](https://github.com/rust-lang/rust/pull/50912)!

```rust
match 0usize {
    0.. => {} // exhaustive!
}
match 0usize {
    0..usize::MAX => {} // helpful error message!
}
```

Features:
- Half-open ranges behave as expected for `usize`/`isize`;
- Trying to use `0..usize::MAX` will tell you that `usize::MAX..` is missing and explain why. No more unhelpful "`_` is missing";
- Everything else stays the same.

This should unblock https://github.com/rust-lang/rust/issues/37854.

Review-wise:
- I recommend looking commit-by-commit;
- This regresses perf because of the added complexity in `IntRange`; hopefully not too much;
- I measured each `#[inline]`, they all help a bit with the perf regression (tho I don't get why);
- I did not touch MIR building; I expect there's an easy PR there that would skip unnecessary comparisons when the range is half-open.
2023-11-01 03:17:19 +00:00
Esteban Küber
8c04999226 On object safety error, mention new enum as alternative
When we encounter a `dyn Trait` that isn't object safe, look for its
implementors. If there's one, mention using it directly If there are
less than 9, mention the possibility of creating a new enum and using
that instead.

Account for object unsafe `impl Trait on dyn Trait {}`.  Make a
distinction between public and sealed traits.

Fix #80194.
2023-10-29 23:55:46 +00:00
bors
2cad938a81 Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errors
Implement `gen` blocks in the 2024 edition

Coroutines tracking issue https://github.com/rust-lang/rust/issues/43122
`gen` block tracking issue https://github.com/rust-lang/rust/issues/117078

This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically.

An example usage of `gen` blocks is

```rust
fn foo() -> impl Iterator<Item = i32> {
    gen {
        yield 42;
        for i in 5..18 {
            if i.is_even() { continue }
            yield i * 2;
        }
    }
}
```

The limitations (to be resolved) of the implementation are listed in the tracking issue
2023-10-29 00:03:52 +00:00
Nadrieril
a4875ae1e2 Match usize/isize exhaustively 2023-10-27 19:56:12 +02:00
Oli Scherer
cece90c65f Feature gate coroutine yield usage 2023-10-27 13:05:48 +00:00
Oli Scherer
638d2d6fc1 Feature gate gen blocks, even in 2024 edition 2023-10-27 13:05:48 +00:00
Esteban Küber
27919ceba7 Tweak suggestion spans for invalid crate-level inner attribute
CC #89566.
2023-10-26 18:35:09 +00:00
David Tolnay
6a02e20fb5
Update since stability attributes in tests 2023-10-23 13:04:47 -07:00
bors
786c94a4eb Auto merge of #116734 - Nadrieril:lint-per-column, r=cjgillot
Lint `non_exhaustive_omitted_patterns` by columns

This is a rework of the `non_exhaustive_omitted_patterns` lint to make it more consistent. The intent of the lint is to help consumers of `non_exhaustive` enums ensure they stay up-to-date with all upstream variants. This rewrite fixes two cases we didn't handle well before:

First, because of details of exhaustiveness checking, the following wouldn't lint `Enum::C` as missing:
```rust
match Some(x) {
    Some(Enum::A) => {}
    Some(Enum::B) => {}
    _ => {}
}
```

Second, because of the fundamental workings of exhaustiveness checking, the following would treat the `true` and `false` cases separately and thus lint about missing variants:
```rust
match (true, x) {
    (true, Enum::A) => {}
    (true, Enum::B) => {}
    (false, Enum::C) => {}
    _ => {}
}
```
Moreover, it would correctly not lint in the case where the pair is flipped, because of asymmetry in how exhaustiveness checking proceeds.

A drawback is that it no longer makes sense to set the lint level per-arm. This will silently break the lint for current users of it (but it's behind a feature gate so that's ok).

The new approach is now independent of the exhaustiveness algorithm; it's a separate pass that looks at patterns column by column. This is another of the motivations for this: I'm glad to move it out of the algorithm, it was akward there.

This PR is almost identical to https://github.com/rust-lang/rust/pull/111651. cc `@eholk` who reviewed it at the time. Compared to then, I'm more confident this is the right approach.
2023-10-21 11:04:19 +00:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Nadrieril
ca869e3334 Lint non_exhaustive_omitted_patterns per column 2023-10-14 19:39:18 +02:00
Nadrieril
2d45df3caa Add and prepare tests 2023-10-14 19:39:18 +02:00
Michael Goulet
59315b8a63 Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00