Commit graph

7201 commits

Author SHA1 Message Date
Michael Goulet a2a6fe7e51 Inline get_node_fn_decl into get_fn_decl, simplify/explain logic in report_return_mismatched_types 2024-05-20 20:16:29 -04:00
Michael Goulet bc6b70f1d1 Adjust the method ambiguity lint too 2024-05-20 19:21:38 -04:00
Michael Goulet a502e7ac1d Implement BOXED_SLICE_INTO_ITER 2024-05-20 19:21:30 -04:00
Michael Goulet c86a4aa5ca Backticks 2024-05-20 19:16:36 -04:00
Matthias Krüger e97103ff6c
Rollup merge of #125308 - lcnr:search-graph-5, r=compiler-errors
track cycle participants per root

The search graph may have multiple roots, e.g. in
```
A :- B
B :- A, C
C :- D
D :- C
```
we first encounter the `A -> B -> A` cycle which causes `A` to be a root. We then later encounter the `C -> D -> C` cycle as a nested goal of `B`. This cycle is completely separate and `C` will get moved to the global cache. This previously caused us to use `[B, D]` as the `cycle_participants` for `C` and `[]` for `A`.

split off from #125167 as I would like to merge this change separately and will rebase that PR on top of this one. There is no test for this issue and I don't quite know how to write one. It is probably worth it to generalize the search graph to enable us to write unit tests for it.

r? `@compiler-errors`
2024-05-21 00:47:02 +02:00
Matthias Krüger 4b26045b92
Rollup merge of #125158 - Nilstrieb:block-indent, r=compiler-errors
hir pretty: fix block indent

before:
```rust
fn main() {
        {
                {
                        ::std::io::_print(format_arguments::new_const(&["Hello, world!\n"]));
                    };
            }
    }
```
after:
```rust
fn main() {
    {
        {
            ::std::io::_print(format_arguments::new_const(&["Hello, world!\n"]));
        };
    }
}
```

AST pretty does the same.
2024-05-21 00:47:02 +02:00
Matthias Krüger e275d2dad6
Rollup merge of #124283 - surechen:fix_123558, r=estebank
Note for E0599 if shadowed bindings has the method.

implement #123558

Use a visitor to find earlier shadowed bingings which has the method.

r? ``@estebank``
2024-05-21 00:47:01 +02:00
Matthias Krüger 8903de31ca
Rollup merge of #124050 - saethlin:less-sysroot-libc, r=ChrisDenton
Remove libc from MSVC targets

``@ChrisDenton`` started working on a project to remove libc from Windows MSVC targets. I'm completing that work here.

The primary change is to cfg out the dependency in `library/`. And then there's a lot of test patching. Happy to separate this more if people want.
2024-05-21 00:47:00 +02:00
lcnr f99c9ffd88 track cycle participants per entry 2024-05-20 20:57:14 +00:00
bors b92758a9ae Auto merge of #125219 - Urgau:check-cfg-cargo-config, r=fmease
Update `unexpected_cfgs` lint for Cargo new `check-cfg` config

This PR updates the diagnostics output of the `unexpected_cfgs` lint for Cargo new `check-cfg` config.

It's a simple and cost-less alternative to the build-script `cargo::rustc-check-cfg` instruction.

```toml
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo, values("bar"))'] }
```

This PR also adds a Cargo specific section regarding check-cfg and Cargo inside rustc's book (motivation is described inside the file, but mainly check-cfg is a rustc feature not a Cargo one, Cargo only enabled the feature, it does not own it; T-cargo even considers the `check-cfg` lint config to be an implementation detail).

This PR also updates the links to refer to that sub-page when using Cargo from rustc.

As well as updating the lint doc to refer to the check-cfg docs.

~**Not to be merged before https://github.com/rust-lang/cargo/pull/13913 reaches master!**~ (EDIT: merged in https://github.com/rust-lang/rust/pull/125237)

`@rustbot` label +F-check-cfg
r? `@fmease` *(feel free to roll)*
Fixes https://github.com/rust-lang/rust/issues/124800
cc `@epage` `@weihanglo`
2024-05-20 20:14:09 +00:00
ardi 972633f530 Fix parsing of erroneously placed semicolons 2024-05-20 21:36:20 +02:00
Nilstrieb 7b1527ff5f hir pretty: fix block indent 2024-05-20 20:30:44 +02:00
Matthias Krüger a79737c3f0
Rollup merge of #125314 - jdonszelmann:global-registration-feature-gate, r=pnkfelix
Add an experimental feature gate for global registration

See #125119 for the tracking issue.
2024-05-20 18:13:49 +02:00
Matthias Krüger ba1bb80b6b
Rollup merge of #124917 - cardigan1008:issue-124819, r=pnkfelix
Check whether the next_node is else-less if in get_return_block

Fix #124819
2024-05-20 18:13:47 +02:00
Matthias Krüger 29c603c1fa
Rollup merge of #124682 - estebank:issue-40990, r=pnkfelix
Suggest setting lifetime in borrowck error involving types with elided lifetimes

```
error: lifetime may not live long enough
  --> $DIR/ex3-both-anon-regions-both-are-structs-2.rs:7:5
   |
LL | fn foo(mut x: Ref, y: Ref) {
   |        -----       - has type `Ref<'_, '1>`
   |        |
   |        has type `Ref<'_, '2>`
LL |     x.b = y.b;
   |     ^^^^^^^^^ assignment requires that `'1` must outlive `'2`
   |
help: consider introducing a named lifetime parameter
   |
LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: Ref<'a, 'a>) {
   |       ++++           ++++++++        ++++++++
```

As can be seen above, it currently doesn't try to compare the `ty::Ty` lifetimes that diverged vs the `hir::Ty` to correctly suggest the following

```
help: consider introducing a named lifetime parameter
   |
LL | fn foo<'a>(mut x: Ref<'_, 'a>, y: Ref<'_, 'a>) {
   |       ++++           ++++++++        ++++++++
```

but I believe this to still be an improvement over the status quo.

Fix #40990.
2024-05-20 18:13:46 +02:00
Ben Kimock 39ef149a29 Undo accidental change to tests/ui/sanitizer/thread.rs 2024-05-20 11:13:33 -04:00
Ben Kimock f45a7a291c Fix feature-gates/rustc-private.rs 2024-05-20 11:13:10 -04:00
Ben Kimock 7a906e1af7 Port stdout-during-shutdown 2024-05-20 11:13:10 -04:00
Ben Kimock 70147cd3ab Patch up foreign-fn-linkname.rs 2024-05-20 11:13:10 -04:00
Ben Kimock 281178de42 Add a Windows version of foreign2.rs 2024-05-20 11:13:10 -04:00
Ben Kimock 18b0a07d49 Handle a few more simple tests 2024-05-20 11:13:10 -04:00
Ben Kimock e0632d7cec Add only-unix to sigpipe tests 2024-05-20 11:13:10 -04:00
Ben Kimock 8d3bc55904 Fix up a few more tests 2024-05-20 11:13:10 -04:00
surechen 4ebbb5f048 Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.
fixes #122714
2024-05-20 20:28:57 +08:00
surechen b092b5d02b Note for E0599 if shadowed bindings has the method.
implement #123558
2024-05-20 18:53:17 +08:00
Urgau ccd3e99a1a Fix quote escaping inside check-cfg value 2024-05-20 11:44:09 +02:00
jdonszelmann 1d9757cd84
add todo test for feature gate 2024-05-20 09:18:49 +02:00
Matthias Krüger ecbd110c7e
Rollup merge of #125302 - workingjubilee:prefer-my-stack-neat, r=compiler-errors
defrost `RUST_MIN_STACK=ice rustc hello.rs`

I didn't think too hard about testing my previous PR rust-lang/rust#122847 which makes our stack overflow handler assist people in discovering the `RUST_MIN_STACK` variable (which apparently is surprisingly useful for Really Big codebases). After it was merged, some useful comments left in a drive-by review led me to discover I had added an ICE. This reworks the code a bit to explain the rationale, remove the ICE that I introduced, and properly test one of the diagnostics.
2024-05-20 08:31:42 +02:00
Matthias Krüger 199d3bf3e4
Rollup merge of #125301 - jwong101:fix-static-coro-suggest, r=compiler-errors
fix suggestion in E0373 for !Unpin coroutines

Coroutines can be prefixed with the `static` keyword to make them
`!Unpin`.
However, given the following function:

```rust

fn check() -> impl Sized {
    let x = 0;
    #[coroutine]
    static || {
        yield;
        x
    }
}
```

We currently suggest prefixing `move` before `static`, which is
syntactically incorrect:

```
error[E0373]: coroutine may outlive the current function, but it borrows
...
 --> src/main.rs:6:5
  |
6 |     static || {
  |     ^^^^^^^^^ may outlive borrowed value `x`
7 |         yield;
8 |         x
  |         - `x` is borrowed here
  |
note: coroutine is returned here
 --> src/main.rs:6:5
  |
6 | /     static || {
7 | |         yield;
8 | |         x
9 | |     }
  | |_____^
help: to force the coroutine to take ownership of `x` (and any other
referenced variables), use the `move` keyword
  |     // this is syntactically incorrect, it should be `static move ||`
6 |     move static || {
  |     ++++

```

This PR suggests adding `move` after `static` for these coroutines.

I also added a UI test for this case.
2024-05-20 08:31:42 +02:00
Matthias Krüger 88552615e8
Rollup merge of #125282 - WaffleLapkin:never-type-unsafe-improvements, r=compiler-errors
Never type unsafe lint improvements

- Move linting code to a separate method
- Remove mentions of `core::convert::absurd` (#124311 was rejected)
- Make the lint into FCW

The last thing is a bit weird though. On one hand it should be `EditionSemanticsChange(2024)`, but on the other hand it shouldn't, because we also plan to break it on all editions some time later. _Also_, it's weird that we don't have `FutureReleaseSemanticsChangeReportInDeps`, IMO "this might cause UB in a future release" is important enough to be reported in deps...

IMO we ought to have three enums instead of [`FutureIncompatibilityReason`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/enum.FutureIncompatibilityReason.html#):

```rust
enum IncompatibilityWhen {
     FutureRelease,
     Edition(Edition),
}

enum IncompatibilyWhat {
    Error,
    SemanticChange,
}

enum IncompatibilityReportInDeps {
    No,
    Yes,
}
```

Tracking:
- https://github.com/rust-lang/rust/issues/123748
2024-05-20 08:31:41 +02:00
Caleb Zulawski 86158f581d Make repr(packed) vectors work with SIMD intrinsics 2024-05-20 01:09:29 -04:00
Michael Goulet 6b3058204a Force the inner coroutine of an async closure to move if the outer closure is move and FnOnce 2024-05-19 23:46:52 -04:00
Jubilee Young b6d0d6da55 note value of RUST_MIN_STACK and explain unsetting 2024-05-19 20:09:03 -07:00
Jubilee Young 9985821b2f defrost RUST_MIN_STACK=ice rustc hello.rs
An earlier commit included the change for a suggestion here.
Unfortunately, it also used unwrap instead of dying properly.
Roll out the ~~rice paper~~ EarlyDiagCtxt before we do anything that
might leave a mess.
2024-05-19 18:28:14 -07:00
Jubilee Young def6b99b4a move rustc-rust-log test into ui/rustc-env 2024-05-19 18:27:53 -07:00
Joshua Wong 371de042d9 add ui tests for E0373 suggestion 2024-05-19 19:23:38 -05:00
Matthias Krüger d5bef41ee5
Rollup merge of #124948 - blyxyas:remove-repeated-words, r=compiler-errors
chore: Remove repeated words (extension of #124924)

When I saw #124924 I thought "Hey, I'm sure that there are far more than just two typos of this nature in the codebase". So here's some more typo-fixing.

Some found with regex, some found with a spellchecker. Every single one manually reviewed by me (along with hundreds of false negatives by the tools)
2024-05-19 22:50:55 +02:00
Urgau 3b47f4c60c Refer to the Cargo specific doc in the check-cfg diagnostics 2024-05-19 20:12:41 +02:00
Urgau 7cb84fbf14 Prefer suggesting string-literal for Cargo check-cfg lint config 2024-05-19 20:04:32 +02:00
Waffle Lapkin 434221ba45 bless tests 2024-05-19 19:10:04 +02:00
Georg Semmler 9b45cfdbdd
Actually use the #[do_not_recommend] attribute if present
This change tweaks the error message generation to actually use the
`#[do_not_recommend]` attribute if present by just skipping the marked
trait impl in favour of the parent impl. It also adds a compile test for
this behaviour. Without this change the test would output the following
error:

```
error[E0277]: the trait bound `&str: Expression` is not satisfied
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:53:15
   |
LL |     SelectInt.check("bar");
   |               ^^^^^ the trait `Expression` is not implemented for `&str`, which is required by `&str: AsExpression<Integer>`
   |
   = help: the following other types implement trait `Expression`:
             Bound<T>
             SelectInt
note: required for `&str` to implement `AsExpression<Integer>`
  --> /home/weiznich/Documents/rust/rust/tests/ui/diagnostic_namespace/do_not_recommend.rs:26:13
   |
LL | impl<T, ST> AsExpression<ST> for T
   |             ^^^^^^^^^^^^^^^^     ^
LL | where
LL |     T: Expression<SqlType = ST>,
   |        ------------------------ unsatisfied trait bound introduced here
```

Note how that mentions `&str: Expression` before and now mentions `&str:
AsExpression<Integer>` instead which is much more helpful for users.

Open points for further changes before stabilization:

* We likely want to move the attribute to the `#[diagnostic]` namespace
to relax the guarantees given?
* How does it interact with the new trait solver?
2024-05-19 08:29:27 +02:00
Jubilee Young 1914c722b5 compiler: add simd_ctpop intrinsic 2024-05-18 18:11:20 -07:00
bors b1ec1bd65f Auto merge of #125257 - jieyouxu:rollup-11evnm9, r=jieyouxu
Rollup of 3 pull requests

Successful merges:

 - #125214 (Only make GAT ambiguous in `match_projection_projections` considering shallow resolvability)
 - #125236 (Add tests for `-Zunpretty=expanded` ported from stringify's tests)
 - #125251 (Clarify how String::leak and into_boxed_str differ )

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-18 21:45:06 +00:00
许杰友 Jieyou Xu (Joe) ffc04dfcc6
Rollup merge of #125236 - dtolnay:expandtest, r=nnethercote
Add tests for `-Zunpretty=expanded` ported from stringify's tests

This PR adds a new set of tests for the AST pretty-printer.

Previously, pretty-printer edge cases were tested by way of `stringify!` in [tests/ui/macros/stringify.rs](https://github.com/rust-lang/rust/blob/1.78.0/tests/ui/macros/stringify.rs), such as the tests added by 419b26931b and 527e2eac17.

Those tests will no longer provide effective coverage of the AST pretty-printer after #124141. `Nonterminal` and `TokenKind::Interpolated` are being removed, and a consequence is that `stringify!` will perform token stream pretty printing, instead of AST pretty printing, in all of the `stringify!` cases including $:expr and all other interpolations.

This PR adds 2 new ui tests with `compile-flags: -Zunpretty=expanded`:

- **tests/ui/unpretty/expanded-exhaustive.rs** &mdash; this test aims for exhaustive coverage of all the variants of `ExprKind`, `ItemKind`, `PatKind`, `StmtKind`, `TyKind`, and `VisibilityKind`. Some parts could use being fleshed out further, but the current state is roughly on par with what exists in the old stringify-based tests.

- **tests/ui/unpretty/expanded-interpolation.rs** &mdash; this test covers tricky macro metavariable edge cases that require the AST pretty printer to synthesize parentheses in order for the printed code to be valid Rust syntax.

r? `@nnethercote`
2024-05-18 20:38:05 +01:00
许杰友 Jieyou Xu (Joe) f08746a95d
Rollup merge of #125214 - compiler-errors:gat-guide, r=lcnr
Only make GAT ambiguous in `match_projection_projections` considering shallow resolvability

In #123537, I tweaked the hack from #93892 to use `resolve_vars_if_possible` instead of `shallow_resolve`. This considers more inference guidance ambiguous. This resulted in crater regressions in #125196.

I've effectively reverted the change to the old behavior. That being said, I don't *like* this behavior, but I'd rather keep it for now since #123537 was not meant to make any behavioral changes. See the attached example.

This also affects the new solver, for the record, which doesn't have any rules about not guiding inference from param-env candidates which may constrain GAT args as a side-effect.

r? `@lcnr` or `@jackh726`
2024-05-18 20:38:04 +01:00
bors eb1a5c9bb3 Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726
Rename Unsafe to Safety

Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks.

This leaves us today with:

```rust
enum ast::Safety {
    Unsafe(Span),
    Default,
    // Safe (going to be added for unsafe extern blocks)
}

enum hir::Safety {
    Unsafe,
    Safe,
}
```

We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-18 19:35:24 +00:00
David Tolnay 3e05be5466
Add tests for -Zunpretty=expanded ported from stringify's tests 2024-05-18 10:36:02 -07:00
Michael Goulet 5ee4db4e05 Warn/error on self ctor from outer item in inner item 2024-05-18 13:08:34 -04:00
Michael Goulet 2e97dae8d4 An async closure may implement FnMut/Fn if it has no self-borrows 2024-05-18 12:47:59 -04:00
Matthias Krüger f9bf759e83
Rollup merge of #125117 - dev-ardi:improve-parser, r=wesleywiser,fmease
Improve parser

Fixes #124935.

- Add a few more help diagnostics to incorrect semicolons
- Overall improved that function
- Addded a few comments
- Renamed diff_marker fns to git_diff_marker
2024-05-18 18:44:14 +02:00
blyxyas c5c820e7fb Fix typos (taking into account review comments) 2024-05-18 18:12:18 +02:00
bors 685a80f7a0 Auto merge of #125180 - mu001999-contrib:improve/macro-diag, r=fee1-dead
Improve error message: missing `;` in macro_rules

Fixes #124968
2024-05-18 13:02:48 +00:00
r0cky c2be1342b7 Improve error message: missing ; in macro_rules 2024-05-18 18:56:12 +08:00
bors 1c90b9fe6e Auto merge of #125004 - pymongo:issue-125002, r=estebank
Fix println! ICE when parsing percent prefix number

This PR fixes #125002 ICE occurring, for example, with `println!("%100000", 1)` or `println!("%    100000", 1)`.

## Test Case/Change Explanation

The return type of `Num::from_str` has been changed to `Option<Self>` to handle errors when parsing large integers fails.

1. The first `println!` in the test case covers the change of the first `Num::from_str` usage in `format_foreign.rs:426`.
2. The second `println!` in the test case covers the change of the second `Num::from_str` usage in line 460.
3. The 3rd to 5th `Num::from_str` usages behave the same as before.

The 3rd usage would cause an ICE when `num > u16::MAX` in the previous version, but this commit does not include a fix for the ICE in `println!("{:100000$}")`. I think we need to emit an error in the compiler and have more discussion in another issue/PR.
2024-05-18 08:44:01 +00:00
bors 36c0a6d40f Auto merge of #125105 - nnethercote:rustc_resolve-cleanups, r=estebank
`rustc_resolve` cleanups

Some improvements I found while looking through this code.

r? `@estebank`
2024-05-18 06:36:44 +00:00
wuaoxiang 582fd1fb53 Fix println! ICE when parsing percent prefix number 2024-05-18 01:05:56 +00:00
bors 9b75a43881 Auto merge of #123865 - eholk:expr_2021, r=fmease
Update `expr` matcher for Edition 2024 and add `expr_2021` nonterminal

This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag.

This change also updates `expr` so that on Edition 2024 it will also match `const { ... }` blocks, while `expr_2021` preserves the current behavior of `expr`, matching expressions without `const` blocks.

Joint work with `@vincenzopalazzo.`

Issue #123742
2024-05-17 21:54:14 +00:00
Santiago Pastorino 6b46a919e1
Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
Esteban Küber cf5702ee91 Detect when a lifetime is being reused in suggestion 2024-05-17 21:23:47 +00:00
Esteban Küber 1775e7b93d Tweak suggested lifetimes to modify return type instead of &self receiver
Do not suggest constraining the `&self` param, but rather the return type.
If that is wrong (because it is not sufficient), a follow up error will tell the
user to fix it. This way we lower the chances of *over* constraining, but still
get the cake of "correctly" contrained in two steps.

This is a correct suggestion:

```
error: lifetime may not live long enough
  --> $DIR/ex3-both-anon-regions-return-type-is-anon.rs:9:9
   |
LL |     fn foo<'a>(&self, x: &i32) -> &i32 {
   |                -         - let's call the lifetime of this reference `'1`
   |                |
   |                let's call the lifetime of this reference `'2`
LL |         x
   |         ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
   |
help: consider introducing a named lifetime parameter and update trait if needed
   |
LL |     fn foo<'a>(&self, x: &'a i32) -> &'a i32 {
   |                           ++          ++
```

While this is incomplete because it should suggestino `&'a self`

```
error: lifetime may not live long enough
  --> $DIR/ex3-both-anon-regions-self-is-anon.rs:7:19
   |
LL |     fn foo<'a>(&self, x: &Foo) -> &Foo {
   |                -         - let's call the lifetime of this reference `'1`
   |                |
   |                let's call the lifetime of this reference `'2`
LL |         if true { x } else { self }
   |                   ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
   |
help: consider introducing a named lifetime parameter and update trait if needed
   |
LL |     fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
   |                           ++          ++
```

but the follow up error is

```
error: lifetime may not live long enough
 --> tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-self-is-anon.rs:7:30
  |
6 |     fn foo<'a>(&self, x: &'a Foo) -> &'a Foo {
  |            --  - let's call the lifetime of this reference `'1`
  |            |
  |            lifetime `'a` defined here
7 |         if true { x } else { self }
  |                              ^^^^ method was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`
  |
help: consider introducing a named lifetime parameter and update trait if needed
  |
6 |     fn foo<'a>(&'a self, x: &'a Foo) -> &'a Foo {
  |                 ++
```
2024-05-17 20:31:13 +00:00
Esteban Küber ee5a157b4a Run rustfmt on modified tests 2024-05-17 20:31:13 +00:00
Esteban Küber d1d585d039 Account for owning item lifetimes in suggestion and annotate tests as run-rustfix
```
error: lifetime may not live long enough
  --> $DIR/lt-ref-self.rs:12:9
   |
LL |     fn ref_self(&self, f: &u32) -> &u32 {
   |                 -         - let's call the lifetime of this reference `'1`
   |                 |
   |                 let's call the lifetime of this reference `'2`
LL |         f
   |         ^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
   |
help: consider introducing a named lifetime parameter and update trait if needed
   |
LL |     fn ref_self<'b>(&'b self, f: &'b u32) -> &'b u32 {
   |                ++++  ++           ++          ++
```
2024-05-17 20:31:13 +00:00
Esteban Küber 120049fab4 Always constrain the return type in lifetime suggestion
```
error: lifetime may not live long enough
 --> f205.rs:8:16
  |
7 |     fn resolve_symbolic_reference(&self, reference: Option<Reference>) -> Option<Reference> {
  |                                   -      --------- has type `Option<Reference<'1>>`
  |                                   |
  |                                   let's call the lifetime of this reference `'2`
8 |         return reference;
  |                ^^^^^^^^^ method was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
  |
help: consider introducing a named lifetime parameter
  |
7 |     fn resolve_symbolic_reference<'a>(&'a self, reference: Option<Reference<'a>>) -> Option<Reference<'a>> {
  |                                  ++++  ++                                  ++++                      ++++
```

The correct suggestion would be

```
help: consider introducing a named lifetime parameter
  |
7 |     fn resolve_symbolic_reference<'a>(&self, reference: Option<Reference<'a>>) -> Option<Reference<'a>> {
  |                                  ++++                                   ++++                      ++++
```

but we are not doing the analysis to detect that yet. If we constrain `&'a self`, then the return type with a borrow will implicitly take its lifetime from `'a`, it is better to make it explicit in the suggestion, in case that `&self` *doesn't* need to be `'a`, but the return does.
2024-05-17 20:31:13 +00:00
Esteban Küber 9f730e92f2 Suggest setting lifetime in borrowck error involving types with elided lifetimes
```
error: lifetime may not live long enough
  --> $DIR/ex3-both-anon-regions-both-are-structs-2.rs:7:5
   |
LL | fn foo(mut x: Ref, y: Ref) {
   |        -----       - has type `Ref<'_, '1>`
   |        |
   |        has type `Ref<'_, '2>`
LL |     x.b = y.b;
   |     ^^^^^^^^^ assignment requires that `'1` must outlive `'2`
   |
help: consider introducing a named lifetime parameter
   |
LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: Ref<'a, 'a>) {
   |       ++++           ++++++++        ++++++++
```

As can be seen above, it currently doesn't try to compare the `ty::Ty` lifetimes that diverged vs the `hir::Ty` to correctly suggest the following

```
help: consider introducing a named lifetime parameter
   |
LL | fn foo<'a>(mut x: Ref<'_, 'a>, y: Ref<'_, 'a>) {
   |       ++++           ++++++++        ++++++++
```

but I believe this to still be an improvement over the status quo.

CC #40990.
2024-05-17 20:31:13 +00:00
Michael Goulet fa829feb2f Only make GAT ambiguous in match_projection_projections considering shallow resolvability 2024-05-17 12:51:21 -04:00
Matthias Krüger 3695449a89
Rollup merge of #125191 - compiler-errors:wf, r=lcnr
Report better WF obligation leaf obligations in new solver

r? lcnr
2024-05-17 07:20:59 +02:00
Matthias Krüger e62688eb96
Rollup merge of #123694 - Xiretza:expand-diagnostics, r=compiler-errors
expand: fix minor diagnostics bug

The error mentions `///`, when it's actually `//!`:

```
error[E0658]: attributes on expressions are experimental
 --> test.rs:4:9
  |
4 |         //! wah
  |         ^^^^^^^
  |
  = note: see issue https://github.com/rust-lang/rust/issues/15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = help: `///` is for documentation comments. For a plain comment, use `//`.
```
2024-05-17 07:20:56 +02:00
Michael Goulet 119c7bbef7 Report better WF obligation leaf obligations in new solver 2024-05-16 21:08:42 -04:00
Urgau 05f77d1b79 Update unexpected_cfgs lint for Cargo new check-cfg config 2024-05-16 20:58:22 +02:00
Michael Goulet d3e510eb9d Don't ICE because recomputing overflow goals during find_best_leaf_obligation causes inference side-effects 2024-05-16 10:00:11 -04:00
cardigan1008 c811acb1f3 feat: add unit test 2024-05-16 21:10:07 +08:00
bors b71e8cbaf2 Auto merge of #124987 - workingjubilee:macro-metavar-expr-with-a-shorter-len, r=c410-f3r,joshtriplett,joshtriplett
Rename `${length()}` to `${len()}`

Implements the rename suggested in https://github.com/rust-lang/rust/pull/122808#issuecomment-2047722187
> I brought this up in the doc PR but it belongs here – `length` should probably be renamed `len` before stabilization. The latter is de facto standard in the standard library, whereas the former is only used in a single unstable API. These metafunctions aren’t library items of course, but should presumably still be consistent with established names.

r? `@c410-f3r`
2024-05-16 00:26:20 +00:00
Zachary S 6b818ddac6 Fix article in test 2024-05-15 13:17:11 -05:00
Zachary S ea549fd176 Add tests for 'Also apply warn(for_loops_over_fallibles) to &T and &mut T, not just T = Result/Option.' 2024-05-15 11:53:40 -05:00
David Koloski 1b934f3e8c Sort mutually-exclusive pairs, update fixed tests 2024-05-15 15:40:52 +00:00
Alice Ryhl 7677ff2879 Remove aarch64 from revisions list 2024-05-15 13:09:02 +02:00
Alice Ryhl 0ce51f59ec Remove fixed_x18.aarch64.stderr 2024-05-15 12:35:39 +02:00
bors 3cb0030fe9 Auto merge of #123413 - petrochenkov:delegmulti2, r=fmease
delegation: Implement list delegation

```rust
reuse prefix::{a, b, c};
```

Using design described in https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2020869823 (the lists are desugared at macro expansion time).
List delegations are expanded eagerly when encountered, similarly to `#[cfg]`s, and not enqueued for later resolution/expansion like regular macros or glob delegation (https://github.com/rust-lang/rust/pull/124135).

Part of https://github.com/rust-lang/rust/issues/118212.
2024-05-15 10:35:31 +00:00
Alice Ryhl b780fa9219 Use an error struct instead of a panic 2024-05-15 11:14:45 +02:00
Matthias Krüger 5f1a120ee5
Rollup merge of #125135 - chenyukang:yukang-fix-116502, r=compiler-errors
Fix the dedup error because of spans from suggestion

Fixes #116502

I believe this kind of issue is supposed resolved by #118057, but the `==` in `span` respect syntax context, here we should only care that they point to the same bytes of source text, so should use `source_equal`.
2024-05-15 07:16:49 +02:00
Matthias Krüger f7c2934420
Rollup merge of #125132 - mejrs:diag, r=compiler-errors
Add `on_unimplemented" typo suggestions
2024-05-15 07:16:48 +02:00
yukang 75895f59b0 Fix the dedup error because of spans from suggestion 2024-05-15 10:28:44 +08:00
bors 0160bff4b1 Auto merge of #125084 - Jules-Bertholet:fix-125058, r=Nadrieril
`rustc_hir_typeck`: Account for `skipped_ref_pats` in `expr_use_visitor`

Fixes #125058

r? `@Nadrieril`

cc https://github.com/rust-lang/rust/issues/123076

`@rustbot` label A-edition-2024 A-patterns
2024-05-15 00:04:28 +00:00
Vadim Petrochenkov c30b41012d delegation: Implement list delegation
```rust
reuse prefix::{a, b, c}
```
2024-05-15 02:32:59 +03:00
mejrs 18d7411719 Add `on_unimplemented" typo suggestions 2024-05-15 00:49:33 +02:00
ardi 8dc6a5d145 improve maybe_consume_incorrect_semicolon 2024-05-14 23:07:40 +02:00
bors ac385a5af6 Auto merge of #125120 - compiler-errors:rollup-mnjybwv, r=compiler-errors
Rollup of 7 pull requests

Successful merges:

 - #119838 (style-guide: When breaking binops handle multi-line first operand better)
 - #124844 (Use a proper probe for shadowing impl)
 - #125047 (Migrate `run-make/issue-14500` to new `rmake.rs` format)
 - #125080 (only find segs chain for missing methods when no available candidates)
 - #125088 (Uplift `AliasTy` and `AliasTerm`)
 - #125100 (Don't do post-method-probe error reporting steps if we're in a suggestion)
 - #125118 (Use new utility functions/methods in run-make tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-14 14:40:20 +00:00
jdonszelmann 42119ff45c
create a feature gate 2024-05-14 16:11:26 +02:00
Michael Goulet d59f430eec
Rollup merge of #125100 - compiler-errors:faster, r=nnethercote
Don't do post-method-probe error reporting steps if we're in a suggestion

Currently in method probing, if we fail to pick a method, then we reset and try to collect relevant candidates for method errors:

34582118af/compiler/rustc_hir_typeck/src/method/probe.rs (L953-L993)

However, we do method lookups via `lookup_method_for_diagnostic` and only care about the result if the method probe was a *success*.

Namely, we don't need to do a bunch of other lookups on failure, since we throw away these results anyways, such as an expensive call to:

34582118af/compiler/rustc_hir_typeck/src/method/probe.rs (L959)

And:
34582118af/compiler/rustc_hir_typeck/src/method/probe.rs (L985)

---

This PR also renames some methods so it's clear that they're for diagnostics.

r? `@nnethercote`
2024-05-14 09:55:30 -04:00
Michael Goulet 8c64acdbdc
Rollup merge of #125080 - bvanjoi:fix-124946, r=nnethercote
only find segs chain for missing methods when no available candidates

Fixes #124946

This PR includes two changes:
- Extracting the lookup for the missing method in chains into a single function.
- Calling this function only when there are no candidates available.
2024-05-14 09:55:29 -04:00
bohan ade33b02f2 only find segs chain for missing methods when no available candidates 2024-05-14 20:28:55 +08:00
Trevor Gross 792a9bdd4b Enable v0 mangling tests and add checks for f16/f128 2024-05-14 06:16:48 -04:00
bors c45e831d8f Auto merge of #124228 - compiler-errors:lint-overcaptures, r=oli-obk
Warn against changes in opaque lifetime captures in 2024

Adds a (mostly[^1]) machine-applicable lint `IMPL_TRAIT_OVERCAPTURES` which detects cases where we will capture more lifetimes in edition 2024 than in edition <= 2021, which may lead to erroneous borrowck errors.

This lint is gated behind the `precise_capturing` feature gate and marked `Allow` for now.

[^1]: Except when there are APITs -- I may work on that soon

r? oli-obk
2024-05-14 07:44:16 +00:00
Michael Goulet 052de1da4f And finally add tests 2024-05-13 23:57:56 -04:00
Michael Goulet 1529c661e4 Warn against redundant use<...> 2024-05-13 23:57:56 -04:00
Michael Goulet 8f97a2588c Add test to make sure suggestions are still quick 2024-05-13 23:38:31 -04:00
bors fba5f44bd8 Auto merge of #125098 - jhpratt:rollup-2qm4gga, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - #116675 ([ptr] Document maximum allocation size)
 - #124997 (Fix ICE while casting a type with error)
 - #125072 (Add test for dynamic dispatch + Pin::new soundness)
 - #125090 (Migrate fuchsia docs from `pm` to `ffx`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-14 03:19:44 +00:00
Jacob Pratt 209703af85
Rollup merge of #125072 - Darksonn:pin-dyn-dispatch-sound, r=jhpratt
Add test for dynamic dispatch + Pin::new soundness

While working on [the `#[derive(SmartPointer)]` RFC][1], I realized that the soundness of <code>impl [DispatchFromDyn](https://doc.rust-lang.org/stable/std/ops/trait.DispatchFromDyn.html) for [Pin](https://doc.rust-lang.org/stable/std/pin/struct.Pin.html)</code> relies on the restriction that you can't implement [`Unpin`](https://doc.rust-lang.org/stable/std/marker/trait.Unpin.html) for trait objects.

As far as I can tell, the relevant error exists to solve some unrelated issues with coherence. To avoid cases where `Pin` is made unsound due to changes in the coherence-related errors, add a test that verifies that unsound use of `Pin` and `DispatchFromDyn` does not become allowed in the future.

[1]: https://github.com/rust-lang/rfcs/pull/3621
2024-05-13 21:14:16 -04:00
Jacob Pratt 18d9c039bb
Rollup merge of #124997 - gurry:124848-ice-should-be-sized, r=Nadrieril
Fix ICE while casting a type with error

Fixes #124848

The ICE originates here: f9a3fd9661/compiler/rustc_hir_typeck/src/cast.rs (L143) The underlying cause is that a type with error, `MyType` was involved in a cast. During cast checks the below method `pointer_kind` was called: f9a3fd9661/compiler/rustc_hir_typeck/src/cast.rs (L87-L91) Thanks to the changes in PR #123491, `type_is_sized_modulo_regions` in `pointer_kind` returned `false` which caused control to reach the `span_bug` here: f9a3fd9661/compiler/rustc_hir_typeck/src/cast.rs (L143) resulting in an ICE.

This PR fixes the issue by changing the `span_bug` to a `span_delayed_bug`.
2024-05-13 21:14:15 -04:00
bors 9105c57b7f Auto merge of #124256 - nnethercote:rm-NtIdent-NtLifetime, r=petrochenkov
Remove `NtIdent` and `NtLifetime`

This is one part of the bigger "remove `Nonterminal` and `TokenKind::Interpolated`" change drafted in #114647. More details in the individual commit messages.

r? `@petrochenkov`
2024-05-14 01:10:38 +00:00
Jules Bertholet fe8f66e4bc
rustc_hir_typeck: Account for skipped_ref_pats in expr_use_visitor
Fixes #125058
2024-05-13 18:36:49 -04:00
Michael Goulet fa84018c2e Apply nits 2024-05-13 16:55:58 -04:00
Eric Holk f364011955
Apply code review suggestions
- use feature_err to report unstable expr_2021
- Update downlevel expr_2021 diagnostics

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-05-13 11:55:38 -07:00
Vincenzo Palazzo a55d06323a
Macros: match const { ... } with expr nonterminal in edition 2024
Co-authored-by: Eric Holk <eric@theincredibleholk.org>
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-05-13 11:55:26 -07:00
Eric Holk 73303c3b45
expr_2021 should be allowed on edition 2021 and later 2024-05-13 11:27:41 -07:00
Eric Holk 65da4adfcd
Add test that expr_2021 only works on 2024 edition
Co-authored-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-05-13 11:27:40 -07:00
Eric Holk ef6478ba5f
Add expr_2021 nonterminal and feature flag
This commit adds a new nonterminal `expr_2021` in macro patterns, and
`expr_fragment_specifier_2024` feature flag. For now, `expr` and
`expr_2021` are treated the same, but in future PRs we will update
`expr` to match to new grammar.

Co-authored-by: Vincezo Palazzo <vincenzopalazzodev@gmail.com>
2024-05-13 11:27:26 -07:00
bjorn3 531dae1cdf Only allow immutable statics with #[linkage] 2024-05-13 14:34:32 +00:00
Alice Ryhl b3a78c1d09 Add test for dynamic dispatch + Pin::new soundness 2024-05-13 14:25:03 +02:00
Ralf Jung 5c33a5690d offset, offset_from: allow zero-byte offset on arbitrary pointers 2024-05-13 07:59:16 +02:00
David Tolnay a36b94d088
Disallow cast with trailing braced macro in let-else 2024-05-12 21:50:14 -07:00
Nicholas Nethercote 9a63a42cb7 Remove a Span from TokenKind::Interpolated.
This span records the declaration of the metavariable in the LHS of the macro.
It's used in a couple of error messages. Unfortunately, it gets in the way of
the long-term goal of removing `TokenKind::Interpolated`. So this commit
removes it, which degrades a couple of (obscure) error messages but makes
things simpler and enables the next commit.
2024-05-13 10:30:30 +10:00
bors ecbe3fd550 Auto merge of #125051 - dtolnay:printletelse, r=compiler-errors
Pretty-print let-else with added parenthesization when needed

Rustc used to produce invalid syntax for the following code, which is problematic because it means we cannot apply rustfmt to the output of `-Zunpretty=expanded`.

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

fn main() {
    let _ = expr!(loop {}) else { return; };
}
```

```console
$ rustc repro.rs -Zunpretty=expanded | rustfmt
error: `loop...else` loops are not supported
 --> <stdin>:9:29
  |
9 | fn main() { let _ = loop {} else { return; }; }
  |                     ----    ^^^^^^^^^^^^^^^^
  |                     |
  |                     `else` is attached to this loop
  |
  = note: consider moving this `else` clause to a separate `if` statement and use a `bool` variable to control if it should run
```
2024-05-12 22:06:34 +00:00
David Tolnay 94cc82c088
Pretty-print let-else with added parenthesization when needed 2024-05-12 13:42:37 -07:00
David Tolnay 68854b798e
Add AST pretty-printer tests for let-else 2024-05-12 13:37:00 -07:00
David Tolnay 75a34ca262
Add test of trailing brace in a cast expression 2024-05-12 13:07:11 -07:00
David Tolnay f4931437c2
Clean up unneeded warnings from let-else syntax test 2024-05-12 13:07:03 -07:00
bors ef0027897d Auto merge of #124639 - Jules-Bertholet:match-ergonomics-2024-migration-lint, r=Nadrieril
Match ergonomics 2024: migration lint

Depends on #124567

r? `@Nadrieril`

cc https://github.com/rust-lang/rust/issues/123076

`@rustbot` label A-edition-2024 A-patterns
2024-05-12 19:58:50 +00:00
Michael Goulet c697ec41f4 Propagate errors rather than using return_if_err 2024-05-12 12:50:18 -04:00
Michael Goulet fb298e80c3 Apply nits 2024-05-12 12:11:25 -04:00
Michael Goulet 5ab6dca6d3 Try structurally resolve 2024-05-12 12:11:25 -04:00
Jules Bertholet 9d92a7f355
Match ergonomics 2024: migration lint
Unfortunately, we can't always offer a machine-applicable suggestion when there are subpatterns from macro expansion.

Co-Authored-By: Guillaume Boisseau <Nadrieril@users.noreply.github.com>
2024-05-12 11:13:33 -04:00
bors 4fd98a4b1b Auto merge of #125012 - RalfJung:format-error, r=Mark-Simulacrum,workingjubilee
io::Write::write_fmt: panic if the formatter fails when the stream does not fail

Follow-up to https://github.com/rust-lang/rust/pull/124954
2024-05-12 08:34:32 +00:00
bors 8cc6f34653 Auto merge of #119427 - dtolnay:maccall, r=compiler-errors
Fix, document, and test parser and pretty-printer edge cases related to braced macro calls

_Review note: this is a deceptively small PR because it comes with 145 lines of docs and 196 lines of tests, and only 25 lines of compiler code changed. However, I recommend reviewing it 1 commit at a time because much of the effect of the code changes is non-local i.e. affecting code that is not visible in the final state of the PR. I have paid attention that reviewing the PR one commit at a time is as easy as I can make it. All of the code you need to know about is touched in those commits, even if some of those changes disappear by the end of the stack._

This is a follow-up to https://github.com/rust-lang/rust/pull/119105. One case that is not relevant to `-Zunpretty=expanded`, but which came up as I'm porting #119105 and #118726 into `syn`'s printer and `prettyplease`'s printer where it **is** relevant, and is also relevant to rustc's `stringify!`, is statement boundaries in the vicinity of braced macro calls.

Rustc's AST pretty-printer produces invalid syntax for statements that begin with a braced macro call:

```rust
macro_rules! stringify_item {
    ($i:item) => {
        stringify!($i)
    };
}

macro_rules! repro {
    ($e:expr) => {
        stringify_item!(fn main() { $e + 1; })
    };
}

fn main() {
    println!("{}", repro!(m! {}));
}
```

**Before this PR:** output is not valid Rust syntax.

```console
fn main() { m! {} + 1; }
```

```console
error: leading `+` is not supported
 --> <anon>:1:19
  |
1 | fn main() { m! {} + 1; }
  |                   ^ unexpected `+`
  |
help: try removing the `+`
  |
1 - fn main() { m! {} + 1; }
1 + fn main() { m! {}  1; }
  |
```

**After this PR:** valid syntax.

```console
fn main() { (m! {}) + 1; }
```
2024-05-12 04:18:20 +00:00
David Tolnay 78c8dc1234
Fix redundant parens around braced macro call in match arms 2024-05-11 18:18:20 -07:00
David Tolnay aedc1b6ad4
Remove MacCall special case from recovery after missing 'if' after 'else'
The change to the test is a little goofy because the compiler was
guessing "correctly" before that `falsy! {}` is the condition as opposed
to the else body. But I believe this change is fundamentally correct.
Braced macro invocations in statement position are most often item-like
(`thread_local! {...}`) as opposed to parenthesized macro invocations
which are condition-like (`cfg!(...)`).
2024-05-11 15:49:51 -07:00
David Tolnay 0f6a51d495
Add macro calls to else-no-if parser test 2024-05-11 15:49:51 -07:00
David Tolnay 4a80865437
Add parser tests for statement boundary insertion 2024-05-11 15:49:50 -07:00
David Tolnay 0ca322c774
Add test of unused_parens lint involving macro calls 2024-05-11 15:49:03 -07:00
David Tolnay 7f2ffbdbc6
Fix pretty printer statement boundaries after braced macro call 2024-05-11 15:49:01 -07:00
David Tolnay c5a0eb1246
Add ExprKind::MacCall statement boundary tests 2024-05-11 15:49:00 -07:00
bors fe03fb9569 Auto merge of #125028 - matthiaskrgr:rollup-3qk782d, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #124096 (Clean up users of rust_dbg_call)
 - #124829 (Enable profiler for armv7-unknown-linux-gnueabihf.)
 - #124939 (Always hide private fields in aliased type)
 - #124963 (Migrate `run-make/rustdoc-shared-flags` to rmake)
 - #124981 (Relax allocator requirements on some Rc/Arc APIs.)
 - #125008 (Add test for #122775)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-11 21:55:00 +00:00
Matthias Krüger d2b0555964
Rollup merge of #125008 - Dirbaio:test-issue-122775, r=compiler-errors
Add test for #122775

Closes #122775
2024-05-11 23:43:26 +02:00
Matthias Krüger 6e172c5fde
Rollup merge of #124096 - saethlin:rust-dbg-call, r=Nilstrieb
Clean up users of rust_dbg_call

`rust_dbg_call` is a C test helper that until this PR was declared in C with `void*` arguments and used in Rust _mostly_ with `libc::uintptr_t` arguments. Nearly every user just wants to pass integers around, so I've changed all users to `uint64_t` or `u64`.

The single test that actually used the pointer-ness of the argument is a test for ensuring that Rust can make extern calls outside of tasks. Rust hasn't had tasks for quite a few years now, so I'm deleting that test under the same logic as the test deleted in https://github.com/rust-lang/rust/pull/124073
2024-05-11 23:43:23 +02:00
bors 78a7751270 Auto merge of #124988 - compiler-errors:name-span, r=lcnr
Consolidate obligation cause codes for where clauses

Removes some unncessary redundancy between `SpannedWhereClause`/`WhereClause`

r? lcnr
2024-05-11 19:48:04 +00:00
León Orell Valerian Liehr 7faa879486
Pattern types: Prohibit generic args on const params 2024-05-11 16:12:43 +02:00
Ralf Jung e00f27b7be io::Write::write_fmt: panic if the formatter fails when the stream does not fail 2024-05-11 15:13:18 +02:00
bors 686bfc4c42 Auto merge of #125010 - matthiaskrgr:rollup-270pck3, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #124928 (Stabilize `byte_slice_trim_ascii` for `&[u8]`/`&str`)
 - #124954 (Document proper usage of `fmt::Error` and `fmt()`'s `Result`.)
 - #124969 (check if `x test tests` missing any test directory)
 - #124978 (Handle Deref expressions in invalid_reference_casting)
 - #125005 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-11 12:46:54 +00:00
Matthias Krüger 8eac6d2333
Rollup merge of #124978 - saethlin:ref-casting_derefs, r=Urgau,Nilstrieb
Handle Deref expressions in invalid_reference_casting

Similar to https://github.com/rust-lang/rust/pull/124908

See https://github.com/rust-lang/rust/issues/124951 for context; this PR fixes the last of the known false postiive cases with this lint that we encounter in Crater.
2024-05-11 13:16:41 +02:00
Dario Nieuwenhuis ebf574fb97 Add test for #122775 2024-05-11 12:59:06 +02:00
bors 35c5e67c69 Auto merge of #124567 - Jules-Bertholet:and-eats-andmut, r=Nadrieril
Match ergonomics 2024: let `&` patterns eat `&mut`

r? `@Nadrieril`

cc https://github.com/rust-lang/rust/issues/123076

`@rustbot` label A-edition-2024 A-patterns
2024-05-11 10:39:11 +00:00
Michael Goulet e444017b49 Consolidate obligation cause codes for where clauses 2024-05-11 02:10:45 -04:00
Gurinder Singh fb619ec208 FIx ICE while casting a type with error 2024-05-11 08:24:26 +05:30
许杰友 Jieyou Xu (Joe) e7bb090d0a
Rollup merge of #124930 - compiler-errors:consume-arg, r=petrochenkov
Make sure we consume a generic arg when checking mistyped turbofish

When recovering un-turbofish-ed args in expr position (e.g. `let x = a<T, U>();` in `check_mistyped_turbofish_with_multiple_type_params`, we used `parse_seq_to_before_end` to parse the fake generic args; however, it used `parse_generic_arg` which *optionally* parses a generic arg. If it doesn't end up parsing an arg, it returns `Ok(None)` and consumes no tokens. If we don't find a delimiter after this (`,`), we try parsing *another* element. In this case, we just infinitely loop looking for a subsequent element.

We can fix this by making sure that we either parse a generic arg or error in `parse_seq_to_before_end`'s callback.

Fixes #124897
2024-05-11 01:15:10 +01:00
许杰友 Jieyou Xu (Joe) 69122f1da4
Rollup merge of #124318 - bvanjoi:fix-123911, r=petrochenkov
ignore generics args in attribute paths

Fixes #97006
Fixes #123911
Fixes #123912

This patch ensures that we no longer have to handle invalid generic arguments in attribute paths.

r? `@petrochenkov`
2024-05-11 01:15:08 +01:00
Jubilee Young 6e74155b0b fix tests after s/${length()}/${len()}/ 2024-05-10 12:29:17 -07:00
Jules Bertholet f57b970de8
Comments and fixes 2024-05-10 13:47:37 -04:00
Jules Bertholet 91bbbaa0f7
Fix spans when macros are involved 2024-05-10 13:47:36 -04:00
Jules Bertholet ed96c655c6
Various fixes:
- Only show error when move-check would not be triggered
- Add structured suggestion
2024-05-10 13:47:36 -04:00
Jules Bertholet 4f76f1069a
Match ergonomics 2024: let & patterns eat &mut 2024-05-10 13:47:34 -04:00
Ben Kimock 2bb25d3f4a Handle Deref expressions in invalid_reference_casting 2024-05-10 12:33:07 -04:00
bohan f70f900036 ignore generics args in attribute paths 2024-05-11 00:13:27 +08:00
Matthias Krüger 1ae0d90b72
Rollup merge of #124797 - beetrees:primitive-float, r=davidtwco
Refactor float `Primitive`s to a separate `Float` type

Now there are 4 of them, it makes sense to refactor `F16`, `F32`, `F64` and `F128` out of `Primitive` and into a separate `Float` type (like integers already are). This allows patterns like `F16 | F32 | F64 | F128` to be simplified into `Float(_)`, and is consistent with `ty::FloatTy`.

As a side effect, this PR also makes the `Ty::primitive_size` method work with `f16` and `f128`.

Tracking issue: #116909

`@rustbot` label +F-f16_and_f128
2024-05-10 16:10:46 +02:00
Matthias Krüger f605174ea7
Rollup merge of #124778 - fmease:fix-diag-msg-parse-meta-item, r=nnethercote
Fix parse error message for meta items

Addresses https://github.com/rust-lang/rust/issues/122796#issuecomment-2010803906, cc [``@]Thomasdezeeuw.``

For attrs inside of a macro like `#[doc(alias = $ident)]` or `#[cfg(feature = $ident)]` where `$ident` is a macro metavariable of fragment kind `ident`, we used to say the following when expanded (with `$ident` ⟼ `ident`):

```
error: expected unsuffixed literal or identifier, found `ident`
  --> weird.rs:6:19
   |
6  |      #[cfg(feature = $ident)]
   |                      ^^^^^^
...
11 | m!(id);
   | ------ in this macro invocation
   |
   = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This was incorrect and caused confusion, justifiably so (see #122796).

In this position, we only accept/expect *unsuffixed literals* which consist of numeric & string literals as well as the boolean literals / the keywords / the reserved identifiers `false` & `true` **but not** arbitrary identifiers.

Furthermore, we used to suggest garbage when encountering unexpected non-identifier tokens:

```
error: expected unsuffixed literal, found `-`
  --> weird.rs:16:17
   |
16 | #[cfg(feature = -1)]
   |                 ^
   |
help: surround the identifier with quotation marks to parse it as a string
   |
16 | #[cfg(feature =" "-1)]
   |                + +
```

Now we no longer do.
2024-05-10 16:10:45 +02:00
León Orell Valerian Liehr 0ad3c5da72
Fix parse error message for meta items 2024-05-10 09:16:27 +02:00
Nicholas Nethercote 5134a04eaa Remove ordinalize.
Some minor (English only) heroics are performed to print error messages
like "5th rule of macro `m` is never used". The form "rule #5 of macro
`m` is never used" is just as good and much simpler to implement.
2024-05-10 16:42:09 +10:00
Matthias Krüger 43ddd1d963
Rollup merge of #124936 - lcnr:cool-beans, r=compiler-errors
analyse visitor: build proof tree in probe

see inline comments

fixes #124791
fixes #124702

r? ```@compiler-errors```
2024-05-10 07:30:21 +02:00
lcnr 83e6da0be5 analyse visitor: build proof tree in probe 2024-05-09 17:29:53 +00:00
Matthias Krüger 024881a36b
Rollup merge of #124923 - RalfJung:offset-from-errors, r=compiler-errors
interpret/miri: better errors on failing offset_from

Fixes https://github.com/rust-lang/miri/issues/3104
2024-05-09 19:09:30 +02:00
Michael Goulet dbdef68ddf Make sure we consume a generic arg when checking mistyped turbofish 2024-05-09 10:47:14 -04:00
bors 8c7c151a7a Auto merge of #124706 - Zalathar:revision-checker, r=jieyouxu
Tidy check for test revisions that are mentioned but not declared

If a `[revision]` name appears in a test header directive or error annotation, but isn't declared in the `//@ revisions:` header, that is almost always a mistake.

In cases where a revision needs to be temporarily disabled, adding it to an `//@ unused-revision-names:` header will suppress these checks for that name.

Adding the wildcard name `*` to the unused list will suppress these checks for the entire file.

(None of the tests actually use `*`; it's just there because it was easy to add and could be handy as an escape hatch when dealing with other problems.)

---

Most of the existing problems discovered by this check were fairly straightforward to fix (or ignore); the trickiest cases are in `borrowck` tests.
2024-05-09 13:06:40 +00:00
Ralf Jung 41d36a0951 interpret/miri: better errors on failing offset_from 2024-05-09 13:09:47 +02:00
bors cb93c24bf3 Auto merge of #124157 - wutchzone:partial_eq, r=estebank
Do not add leading asterisk in the `PartialEq`

I think we should address this issue, however I am not exactly sure, if this is the right way to do it. It is related to the #123056.

Imagine the simplified code:

```rust
trait MyTrait {}

impl PartialEq for dyn MyTrait {
    fn eq(&self, _other: &Self) -> bool {
        true
    }
}

#[derive(PartialEq)]
enum Bar {
    Foo(Box<dyn MyTrait>),
}
```

On the nightly compiler, the `derive` produces invalid code with the weird error message:
```
error[E0507]: cannot move out of `*__arg1_0` which is behind a shared reference
  --> src/main.rs:11:9
   |
9  | #[derive(PartialEq)]
   |          --------- in this derive macro expansion
10 | enum Things {
11 |     Foo(Box<dyn MyTrait>),
   |         ^^^^^^^^^^^^^^^^ move occurs because `*__arg1_0` has type `Box<dyn MyTrait>`, which does not implement the `Copy` trait
   |
   = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
```

It may be related to the perfect derive problem, although requiring the _type_ to be `Copy` seems unfortunate because it is not necessary. Besides, we are adding the extra dereference only for the diagnostics?
2024-05-09 08:34:14 +00:00
Zalathar 14d56e8338 Fix test problems discovered by the revision check
Most of these changes either add revision names that were apparently missing,
or explicitly mark a revision name as currently unused.
2024-05-09 14:47:09 +10:00
Matthias Krüger 48b1e1a280
Rollup merge of #124908 - saethlin:ref-casting_bigger_place_projection, r=fee1-dead
Handle field projections like slice indexing in invalid_reference_casting

r? `@Urgau`

I saw the implementation in https://github.com/rust-lang/rust/pull/124761, and I was wondering if we also need to handle field access. We do. Without this PR, we get this errant diagnostic:
```
error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
  --> /home/ben/rust/tests/ui/lint/reference_casting.rs:262:18
   |
LL |         let r = &mut v.0;
   |                      --- backing allocation comes from here
LL |         let ptr = r as *mut i32 as *mut Vec3<i32>;
   |                   ------------------------------- casting happend here
LL |         unsafe { *ptr = Vec3(0, 0, 0) }
   |                  ^^^^^^^^^^^^^^^^^^^^
   |
   = note: casting from `i32` (4 bytes) to `Vec3<i32>` (12 bytes)
```
2024-05-09 06:04:40 +02:00
Matthias Krüger c49436df4c
Rollup merge of #124875 - compiler-errors:more-diagnostics-ices, r=estebank
Fix more ICEs in `diagnostic::on_unimplemented`

There were 8 other calls to `expect_local` left in `on_unimplemented.rs` -- all of which (afaict) could be turned into ICEs.

I would really like to see validation of `on_unimplemented` separated from parsing, so we only emit errors here:
a60f077c38/compiler/rustc_hir_analysis/src/check/check.rs (L836-L839)
...And gracefully fail instead when emitting trait predicate failures, not *ever* even trying to emit an error or a lint. But that's left for a separate PR.

r? `@estebank`
2024-05-09 06:04:39 +02:00
Matthias Krüger 9b834d01e5
Rollup merge of #124777 - veera-sivarajan:bugfix-124495-identify-gen-block, r=compiler-errors
Fix Error Messages for `break` Inside Coroutines

Fixes #124495

Previously, `break` inside `gen` blocks and functions
were incorrectly identified to be enclosed by a closure.

This PR fixes it by displaying an appropriate error message
for async blocks, async closures, async functions, gen blocks,
gen closures, gen functions, async gen blocks, async gen closures
and async gen functions.

Note: gen closure and async gen closure are not supported by the
compiler yet but I have added an error message here assuming that
they might be implemented in the future.

~~Also, fixes grammar in a few places by replacing
`inside of a $coroutine` with `inside a $coroutine`.~~
2024-05-09 06:04:38 +02:00
Matthias Krüger 952f12ea7a
Rollup merge of #124869 - compiler-errors:keyword, r=Nilstrieb
Make sure we don't deny macro vars w keyword names

`$async:ident`, etc are all valid.

Fixes #124862
2024-05-08 23:33:26 +02:00
Matthias Krüger d8a3a69ad1
Rollup merge of #124587 - reitermarkus:use-generic-nonzero, r=dtolnay
Generic `NonZero` post-stabilization changes.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

r? ``@dtolnay``
2024-05-08 23:33:25 +02:00
Matthias Krüger d30af5e168
Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb
Remove braces when fixing a nested use tree into a single item

[Back in 2019](https://github.com/rust-lang/rust/pull/56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
2024-05-08 23:33:24 +02:00
Ben Kimock 0ca1a94b2b Handle field projections like slice indexing in invalid_reference_casting 2024-05-08 17:21:06 -04:00
Markus Reiter bd8e565e16
Use generic NonZero. 2024-05-08 21:37:55 +02:00
Markus Reiter 7531eafa7e
Simplify suggestion. 2024-05-08 21:37:54 +02:00
Matthias Krüger 9fce3dc685
Rollup merge of #124761 - Urgau:ref-casting_bigger_slice_index, r=jieyouxu
Fix insufficient logic when searching for the underlying allocation

This PR fixes the logic inside the `invalid_reference_casting` lint, when trying to lint on bigger memory layout casts.

More specifically when looking for the "underlying allocation" we were wrongly assuming that when we got `&mut slice[index]` that `slice[index]` was the allocation, but it's not.

Fixes https://github.com/rust-lang/rust/issues/124685
2024-05-08 17:03:09 +02:00
Matthias Krüger e997508ecb
Rollup merge of #124548 - gurry:113272-ice-failed-to-normalize, r=compiler-errors
Handle normalization failure in `struct_tail_erasing_lifetimes`

Fixes #113272

The ICE occurred because the struct being normalized had an error. This PR adds some defensive code to guard against that.
2024-05-08 17:03:08 +02:00
Michael Goulet 7dbdbaaa8e Fix ICEs in diagnostic::on_unimplemented 2024-05-07 23:13:44 -04:00
Michael Goulet a8f2e33eec Add more ICEs due to malformed diagnostic::on_unimplemented 2024-05-07 23:13:44 -04:00
bors a60f077c38 Auto merge of #124683 - estebank:issue-124651, r=compiler-errors
Do not ICE on foreign malformed `diagnostic::on_unimplemented`

Fix #124651.
2024-05-08 00:54:38 +00:00
Michael Goulet 1d9d6715ae Make sure we don't deny macro vars w keyword names 2024-05-07 19:13:33 -04:00
Esteban Küber 758e459427 Add test for #124651 2024-05-07 22:31:22 +00:00
Veera 4271383e1d Update Tests 2024-05-07 16:56:54 -04:00
bors faefc618cf Auto merge of #124219 - gurry:122989-ice-unexpected-anon-const, r=compiler-errors
Do not ICE on `AnonConst`s in `diagnostic_hir_wf_check`

Fixes #122989

Below is the snippet from #122989 that ICEs:
```rust
trait Traitor<const N: N<2> = 1, const N: N<2> = N> {
    fn N(&N) -> N<2> {
        M
    }
}

trait N<const N: Traitor<2> = 12> {}
```

The `AnonConst` that triggers the ICE is the `2` in the param `const N: N<2> = 1`. The currently existing code in `diagnostic_hir_wf_check` deals only with `AnonConst`s that are default values of some param, but  the `2` is not a default value. It is just an `AnonConst` HIR node inside a `TraitRef` HIR node corresponding to `N<2>`. Therefore the existing code cannot handle it and this PR ensures that it does.
2024-05-07 20:01:18 +00:00
bors b923ea4924 Auto merge of #124849 - matthiaskrgr:rollup-68humsk, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #124738 (rustdoc: dedup search form HTML)
 - #124827 (generalize hr alias: avoid unconstrainable infer vars)
 - #124832 (narrow down visibilities in `rustc_parse::lexer`)
 - #124842 (replace another Option<Span> by DUMMY_SP)
 - #124846 (Don't ICE when we cannot eval a const to a valtree in the new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-07 17:44:06 +00:00
Matthias Krüger 067f6327a5
Rollup merge of #124846 - compiler-errors:const-eval, r=lcnr
Don't ICE when we cannot eval a const to a valtree in the new solver

Use `const_eval_resolve` instead of `try_const_eval_resolve` because naming aside, the former doesn't ICE when a value can't be evaluated to a valtree.

r? lcnr
2024-05-07 18:12:56 +02:00
Matthias Krüger 4a5bf7b06e
Rollup merge of #124827 - lcnr:generalize-incomplete, r=compiler-errors
generalize hr alias: avoid unconstrainable infer vars

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/108

see inline comments for more details

r? `@compiler-errors` cc `@BoxyUwU`
2024-05-07 18:12:55 +02:00
lcnr 690d5aa417 generalize hr alias: avoid unconstrainable infer vars 2024-05-07 15:58:06 +00:00
Michael Goulet b58f5a7800 Don't ICE when we cannot eval a const to a valtree in the new solver 2024-05-07 11:14:25 -04:00
bors 0f40f14b61 Auto merge of #123332 - Nadrieril:testkind-never, r=matthewjasper
never patterns: lower never patterns to `Unreachable` in MIR

This lowers a `!` pattern to "goto Unreachable". Ideally I'd like to read from the place to make it clear that the UB is coming from an invalid value, but that's tricky so I'm leaving it for later.

r? `@compiler-errors` how do you feel about a lil bit of MIR lowering
2024-05-07 15:14:20 +00:00
Matthias Krüger 284b5530b8
Rollup merge of #124809 - lcnr:prepopulate-opaques, r=compiler-errors
borrowck: prepopulate opaque storage more eagerly

otherwise we ICE due to ambiguity when normalizing while computing implied bounds.

r? ``@compiler-errors``
2024-05-06 21:46:06 +02:00
Matthias Krüger f76c8f7f77
Rollup merge of #124759 - compiler-errors:impl-args, r=lcnr
Record impl args in the proof tree in new solver

Rather than rematching them during select.

Also use `ImplSource::Param` instead of `ImplSource::Builtin` for alias-bound candidates, so we don't ICE in `Instance::resolve`.

r? lcnr
2024-05-06 21:46:05 +02:00
Michael Goulet e34723997a Use correct ImplSource for alias bounds 2024-05-06 14:38:35 -04:00
bors 31110152e2 Auto merge of #124811 - matthiaskrgr:rollup-4zpov13, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #124520 (Document that `create_dir_all` calls `mkdir`/`CreateDirW` multiple times)
 - #124724 (Prefer lower vtable candidates in select in new solver)
 - #124771 (Don't consider candidates with no failing where clauses when refining obligation causes in new solver)
 - #124808 (Use `super_fold` in `RegionsToStatic` visitor)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-06 17:24:30 +00:00
Matthias Krüger ad73b1623d
Rollup merge of #124808 - compiler-errors:super, r=lcnr
Use `super_fold` in `RegionsToStatic` visitor

so as to avoid an infinite stack cycle

fixes #124805
r? lcnr
2024-05-06 18:50:36 +02:00
Matthias Krüger 43de8225dc
Rollup merge of #124771 - compiler-errors:cand-has-failing-wc, r=lcnr
Don't consider candidates with no failing where clauses when refining obligation causes in new solver

Improves error messages when we have param-env candidates that don't deeply unify (i.e. after alias-bounds).

r? lcnr
2024-05-06 18:50:35 +02:00
Matthias Krüger 2d557ba9f4
Rollup merge of #124724 - compiler-errors:prefer-lower, r=lcnr
Prefer lower vtable candidates in select in new solver

Also, adjust the select visitor to only winnow when the *parent* goal is `Certainty::Yes`. This means that we won't winnow in cases when we have any ambiguous inference guidance from two candidates.

r? lcnr
2024-05-06 18:50:35 +02:00
Michael Goulet 116f95bb46 Use super_fold in RegionsToStatic visitor 2024-05-06 12:22:15 -04:00
lcnr 24ee32cf70 borrowck: more eagerly prepopulate opaques 2024-05-06 16:04:57 +00:00
Michael Goulet 4e3350d43b Don't consider candidates with no failing where clauses 2024-05-06 11:32:50 -04:00
Michael Goulet a4ee20eb13 Prefer lower vtable candidates in select in new solver 2024-05-06 10:48:39 -04:00
bors fc47cf38e5 Auto merge of #123850 - tspiteri:f16_f128_consts, r=Amanieu
Add constants for f16 and f128

- Commit 1 adds associated constants for `f16`, excluding NaN and infinities as these are implemented using arithmetic for `f32` and `f64`.
- Commit 2 adds associated constants for `f128`, excluding NaN and infinities.
- Commit 3 adds constants in `std::f16::consts`.
- Commit 4 adds constants in `std::f128::consts`.
2024-05-06 14:45:28 +00:00
beetrees 3769fddba2
Refactor float Primitives to a separate Float type 2024-05-06 14:56:10 +01:00
bors 8cef37dbb6 Auto merge of #124497 - rytheo:move-std-tests-to-library, r=workingjubilee
Move some stdlib tests from `tests/ui` to `library/std/tests`

Related to #99417
2024-05-06 09:53:24 +00:00
bors 69f53f5e55 Auto merge of #124679 - Urgau:check-cfg-structured-cli-errors, r=nnethercote
Improve check-cfg CLI errors with more structured diagnostics

This PR improve check-cfg CLI errors with more structured diagnostics.

In particular it now shows the statement where the error occurred, what kind lit it is, as well as pointing users to the doc for more details.

`@rustbot` label +F-check-cfg
2024-05-06 07:46:27 +00:00
Urgau 228496e4f5 Improve check-cfg CLI errors with more structured diagnostics 2024-05-06 07:44:41 +02:00
Matthias Krüger 3d97660f40
Rollup merge of #124742 - Urgau:check-cfg-rustfmt, r=fmease
Add `rustfmt` cfg to well known cfgs list

This PR adds the `rustfmt` cfg to the well known cfgs list.

Related to https://github.com/rust-lang/rust/issues/124735
2024-05-06 06:21:03 +02:00
bors 80420a693f Auto merge of #124747 - MasterAwesome:master, r=davidtwco
Support Result<T, E> across FFI when niche optimization can be used (v2)

This PR is identical to #122253, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? ghost

Original PR description:

---

Allow allow enums like `Result<T, E>` to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe.

Implementation of https://github.com/rust-lang/rfcs/pull/3391
Tracking issue: https://github.com/rust-lang/rust/issues/110503

Additional ABI and codegen tests were added in https://github.com/rust-lang/rust/pull/115372
2024-05-06 00:55:49 +00:00
Urgau cd6a0c8c77 Fix insufficient logic when searching for the underlying allocation
in the `invalid_reference_casting` lint, when trying to lint on
bigger memory layout casts.
2024-05-05 19:14:20 +02:00
bors 7c4ac0603e Auto merge of #124752 - GuillaumeGomez:rollup-a4qagbd, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #124148 (rustdoc-search: search for references)
 - #124668 (Fix bootstrap panic when build from tarball)
 - #124736 (compiler: upgrade time from 0.3.34 to 0.3.36)
 - #124748 (Fix unwinding on 32-bit watchOS ARM (v2))
 - #124749 (Stabilize exclusive_range_pattern (v2))
 - #124750 (Document That `f16` And `f128` Hardware Support is Limited (v2))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-05 14:59:34 +00:00
Guillaume Gomez d3e042dc4e
Rollup merge of #124749 - RossSmyth:stable_range, r=davidtwco
Stabilize exclusive_range_pattern (v2)

This PR is identical to #124459, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? ghost

Original PR description:

---

Stabilization report: https://github.com/rust-lang/rust/issues/37854#issuecomment-1842398130
FCP: https://github.com/rust-lang/rust/issues/37854#issuecomment-1872520294

Stabilization was blocked by a lint that was merged here: #118879

Documentation PR is here: rust-lang/reference#1484

`@rustbot` label +F-exclusive_range_pattern +T-lang
2024-05-05 16:42:48 +02:00
bors 06e88c306a Auto merge of #123125 - gurry:122561-bad-note-non-zero-loop-iters-2, r=estebank
Remove suggestion about iteration count in coerce

Fixes #122561

The iteration count-centric suggestion was implemented in PR #100094, but it was based on the wrong assumption that the type mismatch error depends on the number of times the loop iterates. As it turns out, that is not true (see this comment for details: https://github.com/rust-lang/rust/pull/122679#issuecomment-2017432531)

This PR attempts to remedy the situation by changing the suggestion from the one centered on iteration count to a simple suggestion to add a return value.

It should also fix #100285 by simply making it redundant.
2024-05-05 12:51:37 +00:00
Urgau f90b15b7fc Add rustfmt cfg to well known cfgs list 2024-05-05 14:30:35 +02:00
Matthias Krüger 07dc4aa837
Rollup merge of #124718 - compiler-errors:record-impl-args, r=lcnr
Record impl args in the proof tree

Weren't recording these since they went through a different infcx method

r? lcnr
2024-05-04 22:27:33 +02:00
Matthias Krüger 79071ee3a9
Rollup merge of #124717 - compiler-errors:do-not-recomment-next-solver, r=lcnr
Implement `do_not_recommend` in the new solver

Put the test into `diagnostic_namespace` test folder even though it's not in the diagnostic namespace, because it should be soon.

r? lcnr
cc `@weiznich`
2024-05-04 22:27:32 +02:00
Matthias Krüger 6ece08f41f
Rollup merge of #124713 - Urgau:check-cfg-update-cargo-diagnostics, r=jieyouxu
Update Cargo specific diagnostics in check-cfg

This PR updates the Cargo specific diagnostics for check-cfg/`unexpected_cfgs` lint.

Specifically it update to new url and use the double-column (instead of one) in the Cargo directive suggestion.

`@rustbot` label +F-check-cfg
cc `@weihanglo`
2024-05-04 22:27:32 +02:00
Michael Goulet 50338aa59a Record impl args in the proof tree 2024-05-04 12:57:01 -04:00
Michael Goulet b33599485b Implement do_not_recommend in the new solver 2024-05-04 12:51:10 -04:00
Michael Goulet 6714216eaa Only consider ambiguous goals when finding best obligation for ambiguities 2024-05-04 12:05:36 -04:00
Urgau dcf6853693 Update Cargo diagnostics in check-cfg 2024-05-04 17:26:15 +02:00
Nadrieril 57e8aebb6c Lower never patterns to Unreachable in mir 2024-05-04 16:30:01 +02:00
Nadrieril 92d65a92e2 Add tests 2024-05-04 16:20:47 +02:00
bors d7ea27808d Auto merge of #124703 - matthiaskrgr:rollup-2lljptd, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #123356 (Reduce code size of `thread::set_current`)
 - #124159 (Move thread parking to `sys::sync`)
 - #124293 (Let miri and const eval execute intrinsics' fallback bodies)
 - #124677 (Set non-leaf frame pointers on Fuchsia targets)
 - #124692 (We do not coerce `&mut &mut T -> *mut mut T`)
 - #124698 (Rewrite `rustdoc-determinism` test in Rust)
 - #124700 (Remove an unnecessary cast)
 - #124701 (Docs: suggest `uN::checked_sub` instead of check-then-unchecked)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-04 12:41:40 +00:00
Matthias Krüger b0715b4e57
Rollup merge of #124692 - workingjubilee:document-no-double-pointer-coercion-happens, r=compiler-errors
We do not coerce `&mut &mut T -> *mut mut T`

Resolves #34117 by declaring it to be "working as intended" until someone RFCs it or whatever other lang proposal would be required. It seems a bit of a footgun, but perhaps there are strong reasons to allow it anyways. Seeing as how I often have to be mindful to not allow a pointer to coerce the wrong way in my FFI work, I am inclined to think not, but perhaps it's fine in some use-case and that's actually more common?
2024-05-04 12:37:23 +02:00
bors 7dd170fccb Auto merge of #124345 - Urgau:compiletest-check-cfg, r=jieyouxu
Enable `--check-cfg` by default in UI tests

This PR enables-by-default `--check-cfg` in UI tests, now that it has become stable.

To do so this PR does 2 main things:
 - it introduce the `no-auto-check-cfg` directive to `compiletest`, to prevent any `--check-cfg` args (only to be used for `--check-cfg` tests)
 - it updates the _remaining_[^1] UI tests by either:
     - allowing the lint when neither expecting the lint nor giving the check-cfg args make sense
     - give the appropriate check-cfg args
     - or expect the lint, when it useful

[^1]: some preparation work was done in #123577 #123702

I highly recommend reviewing this PR commit-by-commit.

r? `@jieyouxu`
2024-05-04 10:31:49 +00:00
Urgau d4e26fbb53 compiletest: add enable-by-default check-cfg 2024-05-04 11:30:38 +02:00
Urgau 517374150c compiletest: add no-auto-check-cfg directive
this directive prevents compiletest from adding any implicit and
automatic --check-cfg arguments
2024-05-04 11:30:38 +02:00
Urgau ed81578820 tests/ui: prepare some tests for --check-cfg by default 2024-05-04 11:30:38 +02:00
Michael Goulet 9dfd527c6f
Rollup merge of #124480 - Enselic:on-broken-pipe, r=jieyouxu
Change `SIGPIPE` ui from `#[unix_sigpipe = "..."]` to `-Zon-broken-pipe=...`

In the stabilization [attempt](https://github.com/rust-lang/rust/pull/120832) of `#[unix_sigpipe = "sig_dfl"]`, a concern was [raised ](https://github.com/rust-lang/rust/pull/120832#issuecomment-2007394609) related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward.

So as a first step towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature.

Another point was [also raised](https://github.com/rust-lang/rust/pull/120832#issuecomment-1987023484), namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization.

Tracking issue: https://github.com/rust-lang/rust/issues/97889
2024-05-03 23:34:22 -04:00
Michael Goulet e3bf0a13cf
Rollup merge of #124418 - compiler-errors:better-cause, r=lcnr
Use a proof tree visitor to refine the `Obligation` for error reporting in new solver

With the magic of `ProofTreeVisitor`, we can close the gap that we have on `ObligationCause`s being not as descriptive in the new trait solver.

r? lcnr

Needs some work and obviously documentation.
2024-05-03 23:34:21 -04:00
Jubilee Young e404e7a8bd We do not coerce &mut &mut T -> *mut mut T 2024-05-03 20:19:20 -07:00
bors 09cd00fea4 Auto merge of #124401 - oli-obk:some_hir_cleanups, r=cjgillot
Some hir cleanups

It seemed odd to not put `AnonConst` in the arena, compared with the other types that we did put into an arena. This way we can also give it a `Span` without growing a lot of other HIR data structures because of the extra field.

r? compiler
2024-05-04 00:32:27 +00:00
Matthias Krüger bd305e10c2
Rollup merge of #124510 - linyihai:raw-ident-in-typo-suggestion, r=fmease
Add raw identifier in a typo suggestion

Fixes #68962
2024-05-03 20:33:45 +02:00
Ralf Jung cbd682beeb turn pointer_structural_match into a hard error 2024-05-03 15:56:59 +02:00
Ralf Jung 179a6a08b1 remove IndirectStructuralMatch lint, emit the usual hard error instead 2024-05-03 15:56:59 +02:00
Michael Goulet 34e91ece90 Higher ranked goal source, do overflow handling less badly 2024-05-02 21:56:14 -04:00
Michael Goulet 3e03b1b190 Use a proof tree visitor to refine the Obligation for error reporting 2024-05-02 21:56:14 -04:00
Ross Smyth 6967d1c0fc Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
Martin Nordholts cde0cde151 Change SIGPIPE ui from #[unix_sigpipe = "..."] to -Zon-broken-pipe=...
In the stabilization attempt of `#[unix_sigpipe = "sig_dfl"]`, a concern
was raised related to using a language attribute for the feature: Long
term, we want `fn lang_start()` to be definable by any crate, not just
libstd. Having a special language attribute in that case becomes
awkward.

So as a first step towards towards the next stabilization attempt, this
PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag
`-Zon-broken-pipe=...` to remove that concern, since now the language
is not "contaminated" by this feature.

Another point was also raised, namely that the ui should not leak
**how** it does things, but rather what the **end effect** is. The new
flag uses the proposed naming. This is of course something that can be
iterated on further before stabilization.
2024-05-02 19:48:29 +02:00
Matthias Krüger f01e99f191
Rollup merge of #124138 - mati865:ignore-llvm-abi-in-dlltool-tests, r=davidtwco
Ignore LLVM ABI in dlltool tests since those targets don't use dlltool

Otherwise those two tests fail when running `./x.py test` with this target.
2024-05-02 19:42:47 +02:00
Trevor Spiteri d8e6b81b59 update error messages in ui tests 2024-05-02 15:13:30 +02:00
Guillaume Gomez 1b0972cc61
Rollup merge of #124597 - cuviper:x86-64-v3, r=workingjubilee
Use an explicit x86-64 cpu in tests that are sensitive to it

There are a few tests that depend on some target features **not** being
enabled by default, and usually they are correct with the default x86-64
target CPU. However, in downstream builds we have modified the default
to fit our distros -- `x86-64-v2` in RHEL 9 and `x86-64-v3` in RHEL 10
-- and the latter especially trips tests that expect not to have AVX.

These cases are few enough that we can just set them back explicitly.
2024-05-02 15:11:23 +02:00
bors fcc06c894b Auto merge of #123939 - WaffleLapkin:never-fallback-unsafe-lint, r=compiler-errors
Add a lint against never type fallback affecting unsafe code

~~I'm not very happy with the code quality... `VecGraph` not allowing you to get predecessors is very annoying. This should work though, so there is that.~~ (ended up updating `VecGraph` to support getting predecessors)

~~First few commits are from https://github.com/rust-lang/rust/pull/123934 https://github.com/rust-lang/rust/pull/123980~~
2024-05-02 02:41:40 +00:00
Waffle Lapkin 0df43db50c Add proper support for all kinds of unsafe ops to the lint
(never_type_fallback_flowing_into_unsafe)
2024-05-02 03:49:49 +02:00
Maybe Waffle aa0a916c81 Add a lint against never type fallback affecting unsafe code 2024-05-02 03:47:32 +02:00
bors f92d49b7fe Auto merge of #124529 - compiler-errors:select, r=lcnr
Rewrite select (in the new solver) to use a `ProofTreeVisitor`

We can use a proof tree visitor rather than collecting and recomputing all the nested goals ourselves.

Based on #124415
2024-05-02 00:36:38 +00:00
Josh Stone 393d9334d9 Use an outlandish target feature for the negative case 2024-05-01 16:55:10 -07:00
Josh Stone 1b79bb937f Add inline comments why we're forcing the target cpu 2024-05-01 16:54:20 -07:00
Josh Stone 706f06c39a Use an explicit x86-64 cpu in tests that are sensitive to it
There are a few tests that depend on some target features **not** being
enabled by default, and usually they are correct with the default x86-64
target CPU. However, in downstream builds we have modified the default
to fit our distros -- `x86-64-v2` in RHEL 9 and `x86-64-v3` in RHEL 10
-- and the latter especially trips tests that expect not to have AVX.

These cases are few enough that we can just set them back explicitly.
2024-05-01 15:25:26 -07:00
Michael Goulet 9834c8307f Rewrite select to use a ProofTreeVisitor 2024-05-01 14:19:34 -04:00
Matthias Krüger 0dbe07f201
Rollup merge of #124566 - lcnr:normalizes-to-proof-tree, r=compiler-errors
fix `NormalizesTo` proof tree issue

fixes #124422
cc #121848

r? ``@compiler-errors``
2024-05-01 20:05:26 +02:00
bors 378a43a065 Auto merge of #124539 - Urgau:non-local-defs_modulo_modules, r=lcnr
Consider inner modules to be local in the `non_local_definitions` lint

This PR implements the [proposed fix](https://github.com/rust-lang/rust/issues/124396#issuecomment-2079553642) for #124396, that is to consider inner modules to be local in the `non_local_definitions` lint.

This PR is voluntarily kept as minimal as possible so it can be backported easily.

T-lang [nomination](https://github.com/rust-lang/rust/issues/124396#issuecomment-2079692820) will need to be removed before this can be merged.

Fixes *(nearly, needs backport)* https://github.com/rust-lang/rust/issues/124396
2024-05-01 06:21:31 +00:00