Commit graph

4574 commits

Author SHA1 Message Date
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 b5618bc222
Rollup merge of #119494 - fmease:deny-hr-param-defaults, r=compiler-errors
Deny defaults for higher-ranked generic parameters

Fixes #119489 (incl. https://github.com/rust-lang/rust/issues/119489#issuecomment-1873399208).
Partially reverts #119042.

cc ```@bvanjoi```
r? ```@compiler-errors``` or compiler
2024-01-03 16:08:29 +01:00
León Orell Valerian Liehr b41b16971c
Rollup merge of #119476 - fmease:pp-always-const-trait-preds, r=compiler-errors
Pretty-print always-const trait predicates correctly

Follow-up to #119099.

r? fee1-dead
2024-01-03 16:08:27 +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
León Orell Valerian Liehr ba860344e1
Don't synthesize host effect params for trait assoc fns marked const 2024-01-02 13:49:47 +01:00
León Orell Valerian Liehr 3d0297a1e1
Deny defaults for higher-ranked generic parameters 2024-01-01 21:58:25 +01:00
León Orell Valerian Liehr 01ac44a664
Pretty-print always-const trait predicates correctly 2024-01-01 14:02:42 +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
bors d868bc2842 Auto merge of #119284 - Nadrieril:fix-bodiless-arm-parse, r=cjgillot
Don't drop a hir node after lowering

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

It seems that all hir nodes that get allocated an id must be placed within the hir on pain of ICEs. In https://github.com/rust-lang/rust/pull/118527 I dropped guards on never patterns since they're not useful, which caused the ICE.
2023-12-30 22:44:33 +00:00
Nilstrieb ffafcd8819 Update to bitflags 2 in the compiler
This involves lots of breaking changes. There are two big changes that
force changes. The first is that the bitflag types now don't
automatically implement normal derive traits, so we need to derive them
manually.

Additionally, bitflags now have a hidden inner type by default, which
breaks our custom derives. The bitflags docs recommend using the impl
form in these cases, which I did.
2023-12-30 18:17:28 +01:00
bors d59f06fc64 Auto merge of #119437 - matthiaskrgr:rollup-esf96p6, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #119158 (Clean up alloc::sync::Weak Clone implementation)
 - #119386 (fix typo in `IpAddr::to_canonical`)
 - #119413 (solaris support on bootstrap lock)
 - #119424 (Primitive docs: fix confusing `Send` in `&T`'s list)
 - #119425 (Fix invalid check-cfg Cargo feature diagnostic help)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-30 11:40:42 +00:00
Matthias Krüger e930ea274e
Rollup merge of #119425 - Urgau:check-cfg-fix-cargo-diag-bug, r=Nilstrieb
Fix invalid check-cfg Cargo feature diagnostic help

#118213 added specialized diagnostic for Cargo `feature` cfg. However when providing an empty `#[cfg(feature)]` condition the suggestion would suggest adding `feature` as a feature in `Cargo.toml` (wtf!).

This PR removes the invalid logic, which even brings a nice improvement.

```diff
   --> $DIR/cargo-feature.rs:18:7
    |
 LL | #[cfg(feature)]
-   |       ^^^^^^^
+   |       ^^^^^^^- help: specify a config value: `= "bitcode"`
    |
    = note: expected values for `feature` are: `bitcode`
-   = help: consider defining `feature` as feature in `Cargo.toml`
```

The first commit add a test showing the bug and the second commit fixes the bug.

`@rustbot` label +F-check-cfg
2023-12-30 11:42:04 +01:00
bors c2354aabea Auto merge of #119377 - tmiasko:after, r=cjgillot
Don't validate / lint MIR before each pass

To avoid redundant work and verbose output in case of failures.
2023-12-30 09:42:05 +00:00
bors 8d76d07666 Auto merge of #116012 - cjgillot:gvn-const, r=oli-obk
Implement constant propagation on top of MIR SSA analysis

This implements the idea I proposed in https://github.com/rust-lang/rust/pull/110719#issuecomment-1718324700

Based on https://github.com/rust-lang/rust/pull/109597

The value numbering "GVN" pass formulates each rvalue that appears in MIR with an abstract form (the `Value` enum), and assigns an integer `VnIndex` to each. This abstract form can be used to deduplicate values, reusing an earlier local that holds the same value instead of recomputing. This part is proposed in #109597.

From this abstract representation, we can perform more involved simplifications, for example in https://github.com/rust-lang/rust/pull/111344.

With the abstract representation `Value`, we can also attempt to evaluate each to a constant using the interpreter. This builds a `VnIndex -> OpTy` map. From this map, we can opportunistically replace an operand or a rvalue with a constant if their value has an associated `OpTy`.

The most relevant commit is [Evaluated computed values to constants.](2767c4912e)"

r? `@oli-obk`
2023-12-30 03:45:58 +00:00
Urgau a25e0236df Fix invalid check-cfg Cargo feature diagnostic help 2023-12-30 01:06:03 +01:00
Urgau 621e241748 Add check-cfg test for Cargo feature without value 2023-12-30 01:04:15 +01:00
Matthias Krüger bfc1643071
Rollup merge of #119410 - est31:fix_if_guard_unused, r=Nilstrieb
Rename test to be more descriptive

As suggested in https://github.com/rust-lang/rust/pull/119402#discussion_r1438171079

r? ``@Nilstrieb``
2023-12-29 21:40:24 +01:00
Matthias Krüger 7c5c948f2e
Rollup merge of #119406 - lqd:issue-114325, r=compiler-errors
Add non-regression test for ATPIT ICE #114325

ATPIT issue #114325 had been unknowingly fixed by https://github.com/rust-lang/rust/pull/107421, so this PR adds its [MCVE](https://github.com/rust-lang/rust/issues/114325#issuecomment-1721561552) as a non-regression test.

Closes #114325.
2023-12-29 21:40:23 +01:00
Matthias Krüger c8d42740c5
Rollup merge of #119388 - Enselic:prevent-lint-triplication, r=cjgillot
rustc_lint: Prevent triplication of various lints

Prevent triplication of various lints. The triplication happens because we run the same lint three times (or less in some cases):
* In `BuiltinCombinedPreExpansionLintPass`
* In `BuiltinCombinedEarlyLintPass`
* In `shallow_lint_levels_on()`

Only run the lints one time by checking the `lint_added_lints` bool.

Set your GitHub diff setting to ignore whitespaces changes when reviewing this PR, since I had to enclose a block inside an if.

Closes #73301

(I found this while exploring the code related to [this](https://github.com/rust-lang/rust/pull/119251#discussion_r1435677330) comment.)
2023-12-29 21:40:23 +01:00
bors 3cdd004e55 Auto merge of #118911 - Young-Flash:fix_issue_118819, r=fmease
fix: correct the args for `disambiguate the associated function` diagnostic

This is somehow silimar to https://github.com/rust-lang/rust/pull/118502, we shouldn't take receiver as first arg all the cases.

close https://github.com/rust-lang/rust/issues/118819
2023-12-29 18:39:23 +00:00
est31 740378cdde Rename test 2023-12-29 13:49:23 +01:00
Rémy Rakic 21e8710ed3 add non-regression test for issue 114325 2023-12-29 10:01:53 +00:00
est31 ab60a7df64 Also walk bindings created by if-let guards 2023-12-29 03:38:09 +01:00
Martin Nordholts 7ca4e9fcb2 rustc_lint: Prevent triplication of 'unknown lint' lint 2023-12-28 19:46:51 +01:00
Martin Nordholts 741884dab2 rustc_lint: Prevent multiple 'incompatible with previous forbid' lints 2023-12-28 19:46:40 +01:00
Martin Nordholts e0c626fbbc rustc_lint: Prevent multiple 'lint ignored' lints
Prevent multiple 'ignored unless specified at crate level' lints. The
multiplication happens because we run the same lint three times:
* In BuiltinCombinedEarlyLintPass
* In BuiltinCombinedPreExpansionLintPass
* In shallow_lint_levels_on

Only run the lint one time by checking the `lint_added_lints` bool.
2023-12-28 19:46:40 +01:00
Matthias Krüger e8831b6df8
Rollup merge of #119380 - ShE3py:match-never-pat, r=petrochenkov
Don't suggest writing a bodyless arm if the pattern can never be a never pattern

#118527 enabled arms to be bodyless for never patterns ; this PR removes the `,` and `}` suggestions for patterns that could never be never patterns.
2023-12-28 18:48:02 +01:00
Matthias Krüger 77c23b3e94
Rollup merge of #119376 - msrd0:regression-test-106630, r=petrochenkov
Add regression test for #106630

This PR adds a regression test for #106630. I was unsure where exactly to place the test or how to test it locally so please let me know if I should change something.
2023-12-28 18:48:01 +01:00
Tomasz Miąsko 8d77c2eab8 Don't validate / lint MIR before each pass
To avoid redundant work and verbose output in case of failures.
2023-12-28 15:32:54 +01:00
Lieselotte 7d6cd6bf1f
Don't expect bodyless arms if the pattern can never be a never pattern 2023-12-28 15:02:17 +01:00
Dominic a88c9a644c
Add regression test for #106630 2023-12-28 14:53:23 +01:00
bors 89e2160c4c Auto merge of #119105 - dtolnay:paren, r=WaffleLapkin
Fix parenthesization of subexprs containing statement boundary

This PR fixes a multitude of false negatives and false positives in the AST pretty printer's parenthesis insertion related to statement boundaries — statements which terminate unexpectedly early if there aren't parentheses.

Without this fix, the AST pretty printer (including both `stringify!` and `rustc -Zunpretty=expanded`) is prone to producing output which is not syntactically valid Rust. Invalid output is problematic because it means Rustfmt is unable to parse the output of `cargo expand`, for example, causing friction by forcing someone trying to debug a macro into reading poorly formatted code.

I believe the set of bugs fixed in this PR account for the most prevalent reason that `cargo expand` produces invalid output in real-world usage.

Fixes #98790.

## False negatives

The following is a correct program — `cargo check` succeeds.

```rust
macro_rules! m {
    ($e:expr) => {
        match () { _ => $e }
    };
}

fn main() {
    m!({ 1 } - 1);
}
```

But `rustc -Zunpretty=expanded main.rs` produces output that is invalid Rust syntax, because parenthesization is needed and not being done by the pretty printer.

```rust
fn main() { match () { _ => { 1 } - 1, }; }
```

Piping this expanded code to rustfmt, it fails to parse.

```console
error: unexpected `,` in pattern
 --> <stdin>:1:38
  |
1 | fn main() { match () { _ => { 1 } - 1, }; }
  |                                      ^
  |
help: try adding parentheses to match on a tuple...
  |
1 | fn main() { match () { _ => { 1 } (- 1,) }; }
  |                                   +    +
help: ...or a vertical bar to match on multiple alternatives
  |
1 | fn main() { match () { _ => { 1 } - 1 | }; }
  |                                   ~~~~~
```

Fixed output after this PR:

```rust
fn main() { match () { _ => ({ 1 }) - 1, }; }
```

## False positives

Less problematic, but worth fixing (just like #118726).

```rust
fn main() {
    let _ = match () { _ => 1 } - 1;
}
```

Output of `rustc -Zunpretty=expanded lib.rs` before this PR. There is no reason parentheses would need to be inserted there.

```rust
fn main() { let _ = (match () { _ => 1, }) - 1; }
```

After this PR:

```rust
fn main() { let _ = match () { _ => 1, } - 1; }
```

## Alternatives considered

In this PR I opted to parenthesize only the leading subexpression causing the statement boundary, rather than the entire statement. Example:

```rust
macro_rules! m {
    ($e:expr) => {
        $e
    };
}

fn main() {
    m!(loop { break [1]; }[0] - 1);
}
```

This PR produces the following pretty-printed contents for fn main:

```rust
(loop { break [1]; })[0] - 1;
```

A different equally correct output would be:

```rust
(loop { break [1]; }[0] - 1);
```

I chose the one I did because it is the *only* approach used by handwritten code in the standard library and compiler. There are 4 places where parenthesization is being used to prevent a statement boundary, and in all 4, the developer has chosen to parenthesize the smallest subexpression rather than the whole statement:

b37d43efd9/compiler/rustc_codegen_cranelift/example/alloc_system.rs (L102)

b37d43efd9/compiler/rustc_parse/src/errors.rs (L1021-L1029)

b37d43efd9/library/core/src/future/poll_fn.rs (L151)

b37d43efd9/library/core/src/ops/range.rs (L824-L828)
2023-12-27 21:27:26 +00:00
bors 88d69b72b4 Auto merge of #119099 - fmease:always-const-trait-bounds, r=fee1-dead
Introduce `const Trait` (always-const trait bounds)

Feature `const_trait_impl` currently lacks a way to express “always const” trait bounds. This makes it impossible to define generic items like fns or structs which contain types that depend on const method calls (\*). While the final design and esp. the syntax of effects / keyword generics isn't set in stone, some version of “always const” trait bounds will very likely form a part of it. Further, their implementation is trivial thanks to the `effects` backbone.

Not sure if this needs t-lang sign-off though.

(\*):

```rs
#![feature(const_trait_impl, effects, generic_const_exprs)]

fn compute<T: const Trait>() -> Type<{ T::generate() }> { /*…*/ }

struct Store<T: const Trait>
where
    Type<{ T::generate() }>:,
{
    field: Type<{ T::generate() }>,
}
```

Lastly, “always const” trait bounds are a perfect fit for `generic_const_items`.

```rs
#![feature(const_trait_impl, effects, generic_const_items)]

const DEFAULT<T: const Default>: T = T::default();
```

Previously, we (oli, fee1-dead and I) wanted to reinterpret `~const Trait` as `const Trait` in generic const items which would've been quite surprising and not very generalizable.
Supersedes #117530.

---

cc `@oli-obk`

As discussed
r? fee1-dead (or compiler)
2023-12-27 19:24:31 +00:00
bors a861c8965e Auto merge of #117303 - sjwang05:issue-117245, r=estebank
Suggest `=>` --> `>=` in comparisons

Fixes #117245
2023-12-27 17:26:12 +00:00
León Orell Valerian Liehr 3eb48a35c8
Introduce const Trait (always-const trait bounds) 2023-12-27 12:51:32 +01:00
Matthias Krüger d6382c785f
Rollup merge of #119175 - veera-sivarajan:fix-cast-to-slice, r=WaffleLapkin
fix: diagnostic for casting reference to slice

fixes:  #118790

Removes `if self.cast_ty.is_trait()` to produce the same diagnostic for cast to slice and trait.
2023-12-27 09:11:35 +01:00
Young-Flash 9e9353c0da fix broken CI and code review 2023-12-27 15:47:57 +08:00
sjwang05 97cf1c87bd
Suggest => --> >= in conditions 2023-12-26 20:59:14 -08:00
Esteban Küber dc30eb1967 Suggest = to == in more cases, even in the face of reference mismatch
Given `foo: &String` and `bar: str`, suggest `==` when given `if foo = bar {}`:

```
error[E0308]: mismatched types
  --> $DIR/assignment-expected-bool.rs:37:8
   |
LL |     if foo = bar {}
   |        ^^^^^^^^^ expected `bool`, found `()`
   |
help: you might have meant to compare for equality
   |
LL |     if foo == bar {}
   |             +
```
2023-12-26 23:48:55 +00:00
bors 2df6406b88 Auto merge of #118431 - sjwang05:issue-44695, r=estebank
Emit better suggestions for `&T == T` and `T == &T`

Fixes #40660
Fixes #44695
2023-12-26 21:34:24 +00:00
bors deace71034 Auto merge of #119324 - compiler-errors:rollup-c6eqcg9, r=compiler-errors
Rollup of 5 pull requests

Successful merges:

 - #119235 (Add missing feature gate for sanitizer CFI cfgs)
 - #119240 (Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s)
 - #119297 (Pass DeadItem and lint as consistent group in dead-code.)
 - #119307 (Clean up some lifetimes in `rustc_pattern_analysis`)
 - #119323 (add test for coercing never to infinite type)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-26 19:28:49 +00:00
Michael Goulet a5b3d139b3
Rollup merge of #119323 - lukas-code:test-never-to-infinite, r=compiler-errors
add test for coercing never to infinite type

Closes https://github.com/rust-lang/rust/issues/113197.

This was fixed in https://github.com/rust-lang/rust/pull/118308, probably 1978168c13.
2023-12-26 13:29:14 -05:00
Michael Goulet 65aaece6c0
Rollup merge of #119297 - cjgillot:issue-119267, r=petrochenkov
Pass DeadItem and lint as consistent group in dead-code.

Fixes https://github.com/rust-lang/rust/issues/119267
2023-12-26 13:29:13 -05:00
Michael Goulet e7bd402a38
Rollup merge of #119240 - compiler-errors:lang-item-more, r=petrochenkov
Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s

The rest of 'em affect diagnostics, so leave them alone... for now.

cc #115178
2023-12-26 13:29:13 -05: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 a75fed74b6 Auto merge of #119042 - bvanjoi:fix-118697-2, r=compiler-errors
fallback `default` to `None` during ast-lowering for lifetime binder

Fixes #118697

This is another attempt. It has a fallback, setting `default` to `None` and emit an error for non-lifetime binders during ast lowering.

r? `@compiler-errors`
2023-12-26 17:30:42 +00:00
Lukas Markeffsky 29036045c3 add test for coercing never to infinite type 2023-12-26 17:57:33 +01:00
Lukas Markeffsky cb2fc0967f rename tests 2023-12-26 17:50:30 +01:00
bors e1fadb2c35 Auto merge of #119133 - scottmcm:assert-unchecked, r=thomcc
Add `hint::assert_unchecked`

Libs-API expressed interest, modulo bikeshedding, in https://github.com/rust-lang/libs-team/issues/315#issuecomment-1863159430

I think that means this is good for nightly, since we can always rename it before stabilization.

Tracking issue: https://github.com/rust-lang/rust/issues/119131
2023-12-26 15:31:44 +00:00