Commit Graph

7364 Commits

Author SHA1 Message Date
Jake Goulding
d95d6ceecb dead_code treats #[repr(transparent)] the same as #[repr(C)]
Fixes #119659
2024-01-18 13:04:31 -05:00
bors
8424f8e8cd Auto merge of #120089 - matthiaskrgr:rollup-xyfqrb5, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #119172 (Detect `NulInCStr` error earlier.)
 - #119833 (Make tcx optional from StableMIR run macro and extend it to accept closures)
 - #119967 (Add `PatKind::Err` to AST/HIR)
 - #119978 (Move async closure parameters into the resultant closure's future eagerly)
 - #120021 (don't store const var origins for known vars)
 - #120038 (Don't create a separate "basename" when naming and opening a MIR dump file)
 - #120057 (Don't ICE when deducing future output if other errors already occurred)
 - #120073 (Remove spastorino from users_on_vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-18 16:39:32 +00:00
Nadrieril
0a9bb97229 Consistently warn unreachable subpatterns 2024-01-18 17:29:54 +01:00
Nadrieril
12ebc3dd96 Add tests 2024-01-18 15:42:25 +01:00
bors
a34faab155 Auto merge of #118553 - jackh726:lint-implied-bounds, r=lcnr
error on incorrect implied bounds in wfcheck except for Bevy dependents

Rebase of #109763

Additionally, special cases Bevy `ParamSet` types to not trigger the lint. This is tracked in #119956.

Fixes #109628
2024-01-18 14:16:55 +00:00
Krasimir Georgiev
2cc81baaf4 tests/ui/asm/inline-syntax: adapt for LLVM 18 2024-01-18 12:48:38 +00:00
David Wood
46652dd254
llvm: simplify data layout check
Don't skip the inconsistent data layout check for custom LLVMs.

With #118708, all targets will have a simple test that would trigger this
check if LLVM's data layouts do change - so data layouts would be
corrected during the LLVM upgrade. Therefore, with builtin targets, this
check won't trigger with our LLVM because each target will have been
confirmed to work. With non-builtin targets, this check is probably
useful to have because you can change the data layout in your target and
if its wrong then that could lead to bugs.

When using a custom LLVM, the same justification makes sense for
non-builtin targets as with our LLVM, the user can update their target to
match their LLVM and that's probably a good thing to do. However, with
a custom LLVM, the user cannot change the builtin target data layouts if
they don't match - though given that the compiler's data layout is used
for layout computation and a bunch of other things - you could get some
bugs because of the mismatch and probably want to know about that.

`CFG_LLVM_ROOT` was also always set during local development with
`download-ci-llvm` so this bug would never trigger locally.

Signed-off-by: David Wood <david@davidtw.co>
2024-01-18 10:46:03 +00:00
Matthias Krüger
34362b826d
Rollup merge of #120057 - oli-obk:not_sure_wtf_is_going_on, r=compiler-errors
Don't ICE when deducing future output if other errors already occurred

The situation can't really happen outside of erroneous code. What was interesting is that it ICEd before emitting any other diagnostics. This was because the other errors were silenced due to cycle_delay_bug cycle errors.

r? ```@compiler-errors```

fixes #119890
2024-01-18 10:34:20 +01:00
Matthias Krüger
536fc22917
Rollup merge of #119978 - compiler-errors:async-closure-captures, r=oli-obk
Move async closure parameters into the resultant closure's future eagerly

Move async closure parameters into the closure's resultant future eagerly.

Before, we used to desugar `async |p1, p2, ..| { body }` as `|p1, p2, ..| { || async { body } }`. Now, we desugar the above like `|p1, p2, ..| { async move { let p1 = p1; let p2 = p2; ... body } }`. This mirrors the same desugaring that `async fn` does with its parameter types, and the compiler literally uses the same code via a shared helper function.

This removes the necessity for E0708, since now expressions like `async |x: i32| { x }` will not give you confusing borrow errors.

This does *not* fix the case where async closures have self-borrows. This will come with a general implementation of async closures, which is still in the works.

r? oli-obk
2024-01-18 10:34:18 +01:00
Matthias Krüger
c3e237c3ac
Rollup merge of #119833 - celinval:smir-accept-closures, r=oli-obk
Make tcx optional from StableMIR run macro and extend it to accept closures

Change `run` macro to avoid sometimes unnecessary dependency on `TyCtxt`, and introduce `run_with_tcx` to capture use cases where `tcx` is required. Additionally, extend both macros to accept closures that may capture variables.

I've also modified the `internal()` method to make it safer, by accepting the type context to force the `'tcx` lifetime to match the context lifetime.

These are non-backward compatible changes, but they only affect internal APIs which are provided today as helper functions until we have a stable API to start the compiler.
2024-01-18 10:34:17 +01:00
Matthias Krüger
ff8c7a7816
Rollup merge of #119172 - nnethercote:earlier-NulInCStr, r=petrochenkov
Detect `NulInCStr` error earlier.

By making it an `EscapeError` instead of a `LitError`. This makes it like the other errors produced when checking string literals contents, e.g. for invalid escape sequences or bare CR chars.

NOTE: this means these errors are issued earlier, before expansion, which changes behaviour. It will be possible to move the check back to the later point if desired. If that happens, it's likely that all the string literal contents checks will be delayed together.

One nice thing about this: the old approach had some code in `report_lit_error` to calculate the span of the nul char from a range. This code used a hardwired `+2` to account for the `c"` at the start of a C string literal, but this should have changed to a `+3` for raw C string literals to account for the `cr"`, which meant that the caret in `cr"` nul error messages was one short of where it should have been. The new approach doesn't need any of this and avoids the off-by-one error.

r? ```@fee1-dead```
2024-01-18 10:34:17 +01:00
Celina G. Val
6a573cbc60 Revert changes to internal method for now
- Move fix to a separate PR
2024-01-17 19:59:57 -08:00
Jack Huey
a9e30e6cdf Don't use compat versions of implied bounds in ImpliedOutlivesBounds query 2024-01-17 22:03:06 -05:00
Ali MJ Al-Nasrawy
d96003dd2a Correctly handle normalization in implied bounds
Special-case Bevy dependents to not error
2024-01-17 21:27:34 -05:00
Michael Goulet
ec263df5e4 Suggest wrapping mac args in parens rather than the whole expression 2024-01-18 00:01:13 +00:00
Michael Goulet
c1c7707238 Deny braced macro invocations in let-else 2024-01-17 23:59:11 +00:00
Zalathar
99797bbd9f coverage: Format all remaining tests
These tests can simply be reformatted as normal, because the resulting changes
are unimportant.
2024-01-18 10:42:37 +11:00
clubby789
3f7c7842e6 Move removed-syntax tests to their own directory 2024-01-17 22:17:44 +00:00
Kevin Reid
c48cdfe8ee Remove unnecessary lets and borrowing from Waker::noop() usage.
`Waker::noop()` now returns a `&'static Waker` reference, so it can be
passed directly to `Context` creation with no temporary lifetime issue.
2024-01-17 12:00:27 -08:00
Matthias Krüger
99a8b6aa67
Rollup merge of #120056 - oli-obk:arg_mismatch_ice, r=compiler-errors
Use FnOnceOutput instead of FnOnce where expected

fixes #119847
2024-01-17 20:21:24 +01:00
Matthias Krüger
cd5eb6a896
Rollup merge of #120031 - compiler-errors:construct-closure-ty-eagerly, r=oli-obk
Construct closure type eagerly

Construct the returned closure type *before* checking the body, in the same match as we were previously deducing the coroutine types based off of the closure kind.

This simplifies some changes I'm doing in the async closure PR, and imo just seems easier to read (since we only need one match on closure kind, instead of two). There's no reason I can tell that we needed to create the closure type *after* the body was checked.

~~This also has the side-effect of making it so that the universe of the closure synthetic infer vars are lower than any infer vars that come from checking the body. We can also get rid of `next_root_ty_var` hack from closure checking (though in general we still need this, #119106). cc ```@lcnr``` since you may care about this hack 😆~~

r? ```@oli-obk```
2024-01-17 20:21:22 +01:00
Matthias Krüger
6ca77ff722
Rollup merge of #120020 - oli-obk:long_const_eval_err_taint, r=compiler-errors
Gracefully handle missing typeck information if typeck errored

fixes #116893

I created some logs and the typeck of `fn main` is exactly the same, no matter whether the constant's body is what it is, or if it is replaced with `panic!()`. The latter will cause the ICE not to be emitted though. The reason for that is that we abort compilation if *errors* were emitted, but not if *lint errors* were emitted. This took me way too long to debug, and is another reason why I would have liked https://github.com/rust-lang/compiler-team/issues/633
2024-01-17 20:21:21 +01:00
Matthias Krüger
22f19130df
Rollup merge of #119975 - lukas-code:inferring-return-types-and-opaque-types-do-mix-sometimes, r=compiler-errors
Don't ICE if TAIT-defining fn contains a closure with `_` in return type

The `delay_span_bug` got added in 0e82aaeb67 to reduce the amount of errors emitted for functions that have `_` in their return type, because inference doesn't apply to function items. But this logic shouldn't apply to closures, because their return types *can* be inferred.

Fixes https://github.com/rust-lang/rust/issues/119916.
2024-01-17 20:21:20 +01:00
Oli Scherer
f1ef930c9d Don't ICE when deducing future output if other errors already occurred 2024-01-17 16:27:57 +00:00
bors
6ae4cfbbb0 Auto merge of #118708 - davidtwco:target-tier-assembly-test, r=Mark-Simulacrum
tests: add sanity-check assembly test for every target

Fixes #119910.

Adds a basic assembly test checking that each target can produce assembly and update the target tier policy to require this.

cc rust-lang/compiler-team#655
r? `@wesleywiser`
2024-01-17 16:18:28 +00:00
Andrew Zhogin
8507f5105b Improved collapse_debuginfo attribute, added command-line flag (no|external|yes) 2024-01-17 23:18:14 +07:00
Oli Scherer
d6b99b9c92 Use FnOnceOutput instead of FnOnce where expected 2024-01-17 14:23:41 +00:00
bors
c58a5da7d4 Auto merge of #119930 - Urgau:check-cfg-empty-values-means-empty, r=petrochenkov
Add way to express that no values are expected with check-cfg

This PR adds way to express no-values (no values expected) with `--check-cfg` by making empty `values()` no longer mean `values(none())` (internal: `&[None]`) and now be an empty list (internal: `&[]`).

### Context

Currently `--check-cfg` has a way to express that _any value is expected_ with `values(any())`, but has no way to do the inverse and say that _no value is expected_.

This would be particularly useful for build systems that control a config name and it's values as they could always declare a config name as expected and if in the current state they have values pass them and if not pass an empty list.

To give a more concrete example, Cargo `--check-cfg` currently needs to generate:
 - `--check-cfg=cfg(feature, values(...))` for the case with declared features
 - and `--check-cfg=cfg()` for the case without any features declared

This means that when there are no features declared, users will get an `unexpected config name` but from the point of view of Cargo the config name `feature` is expected, it's just that for now there aren't any values for it.

See [Cargo `check_cfg_args` function](92395d9010/src/cargo/core/compiler/mod.rs (L1263-L1281)) for more details.

### De-specializing *empty* `values()`

To solve this issue I propose that we "de-specialize" empty `values()` to no longer mean `values(none())` but to actually mean empty set/list. This is one of the last source of confusion for my-self and others with the `--check-cfg` syntax.

> The confusing part here is that an empty `values()` currently means the same as `values(none())`, i.e. an expected list of values with the _none_ variant (as in `#[cfg(name)]` where the value is none) instead of meaning an empty set.

Before the new `cfg()` syntax, defining the _none_ variant was only possible under certain circumstances, so in https://github.com/rust-lang/rust/pull/111068 I decided to make `values()` to mean the _none_ variant, but it is no longer necessary since https://github.com/rust-lang/rust/pull/119473 which introduced the `none()` syntax.

A simplified representation of the proposed "de-specialization" would be:

| Syntax                                  | List/set of expected values |
|-----------------------------------------|-----------------------------|
| `cfg(name)`/`cfg(name, values(none()))` | `&[None]`                   |
| `cfg(name, values())`                   | `&[]`                       |

Note that I have my-self made the mistake of using an empty `values()` as meaning empty set, see https://github.com/rust-lang/cargo/pull/13011.

`@rustbot` label +F-check-cfg
r? `@petrochenkov`
cc `@epage`
2024-01-17 14:01:05 +00:00
bors
52790a98e5 Auto merge of #119670 - cjgillot:gvn-arithmetic, r=oli-obk
Fold arithmetic identities in GVN

Extracted from https://github.com/rust-lang/rust/pull/111344

This PR implements a few arithmetic folds for unary and binary operations.
This should take care of the missed optimizations introduced by https://github.com/rust-lang/rust/pull/116012.
2024-01-17 11:46:49 +00:00
Oli Scherer
b1ce8a4ecd Move check_mod_impl_wf query call out of track_errors and bubble errors up instead. 2024-01-17 10:02:19 +00:00
David Wood
a87034c297
tests: add sanity-check assembly test for every target
Adds a basic assembly test checking that each target can produce assembly
and update the target tier policy to require this.

Signed-off-by: David Wood <david@davidtw.co>
2024-01-17 09:44:11 +00:00
bors
f45fe573a5 Auto merge of #119651 - novafacing:proc_macro_c_str_literals, r=Amanieu
proc_macro: Add Literal::c_string constructor

Adds a constructor for C string literals, hopefully starts addressing #118560.

Tracking issue: #119750
2024-01-17 05:07:38 +00:00
bors
6bf600bc98 Auto merge of #120019 - lcnr:fn-wf, r=BoxyUwU
fix fn/const items implied bounds and wf check (rebase)

A rebase of #104098, see that PR for discussion. This is pretty much entirely the work of `@aliemjay.` I received his permission for this rebase.

---

These are two distinct changes (edit: actually three, see below):
1. Wf-check all fn item args. This is a soundness fix.
Fixes #104005

2. Use implied bounds from impl header in borrowck of associated functions/consts. This strictly accepts more code and helps to mitigate the impact of other breaking changes.
Fixes #98852
Fixes #102611

The first is a breaking change and will likely have a big impact without the the second one. See the first commit for how it breaks libstd.

Landing the second one without the first will allow more incorrect code to pass. For example an exploit of #104005 would be as simple as:
```rust
use core::fmt::Display;

trait ExtendLt<Witness> {
    fn extend(self) -> Box<dyn Display>;
}

impl<T: Display> ExtendLt<&'static T> for T {
    fn extend(self) -> Box<dyn Display> {
        Box::new(self)
    }
}

fn main() {
    let val = (&String::new()).extend();
    println!("{val}");
}
```

The third change is to to check WF of user type annotations before normalizing them (fixes #104764, fixes #104763). It is mutually dependent on the second change above: an attempt to land it separately in #104746 caused several crater regressions that can all be mitigated by using the implied from the impl header. It is also necessary for the soundness of associated consts that use the implied bounds of impl header. See #104763 and how the third commit fixes the soundness issue in `tests/ui/wf/wf-associated-const.rs` that was introduces by the previous commit.

r? types
2024-01-17 02:35:06 +00:00
Michael Goulet
37a5464bc8 Eagerly instantiate closure ty 2024-01-17 00:43:44 +00:00
Camille GILLOT
20a8a23cb3 Bless incremental tests. 2024-01-16 23:49:39 +00:00
Celina G. Val
2564811e7b Remove tcx function and make internal fn safer
I added `tcx` argument to `internal` to force 'tcx to be the same
lifetime as TyCtxt. The only other solution I could think is to change
this function to be `unsafe`.
2024-01-16 14:35:18 -08:00
Camille GILLOT
22ed51e136 Do not read a scalar on a non-scalar layout. 2024-01-16 22:32:48 +00:00
Camille GILLOT
3c48243b6f Simplify Len. 2024-01-16 22:20:54 +00:00
Camille GILLOT
5fc23ad8e6 Simplify unary operations. 2024-01-16 22:20:54 +00:00
Camille GILLOT
666030c51b Simplify binary ops. 2024-01-16 22:20:53 +00:00
novafacing
ee007ab187 proc_macro_c_str_literals: Implement Literal::c_string constructor 2024-01-16 13:27:58 -08:00
LegionMammal978
bc3fb5245a Rename pointer field on Pin
The internal, unstable field of `Pin` can conflict with fields from the
inner type accessed via the `Deref` impl. Rename it from `pointer` to
`__pointer`, to make it less likely to conflict with anything else.
2024-01-16 14:58:42 -05:00
bors
92f2e0aa62 Auto merge of #116520 - Enselic:large-copy-into-fn, r=oli-obk
large_assignments: Lint on specific large args passed to functions

Requires lowering function call arg spans down to MIR, which is done in the second commit.

Part of #83518

Also see
* https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/arg.20Spans.20for.20TerminatorKind.3A.3ACall.3F
* https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/move_size_limit.20lint

r? `@oli-obk` (E-mentor)
2024-01-16 19:33:14 +00:00
Celina G. Val
f91ccf9ace Remove tcx from SMIR run macro and accept closures
Simplify the `run` macro to avoid sometimes unnecessary dependency
on `TyCtxt`. Instead, users can use the new internal method `tcx()`.
Additionally, extend the macro to accept closures that may capture
variables.

These are non-backward compatible changes, but they only affect
internal APIs which are provided today as helper functions until we
have a stable API to start the compiler.
2024-01-16 11:17:51 -08:00
bors
e64f8495e7 Auto merge of #120025 - matthiaskrgr:rollup-e9ai06k, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #118361 (stabilise bound_map)
 - #119816 (Define hidden types in confirmation)
 - #119900 (Inline `check_closure`, simplify `deduce_sig_from_projection`)
 - #119969 (Simplify `closure_env_ty` and `closure_env_param`)
 - #119990 (Add private `NonZero<T>` type alias.)
 - #119998 (Update books)
 - #120002 (Lint `overlapping_ranges_endpoints` directly instead of collecting into a Vec)
 - #120018 (Don't allow `.html` files in `tests/mir-opt/`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-16 17:33:12 +00:00
Michael Goulet
f4e35c60b0 Fix async closure call suggestion 2024-01-16 17:12:10 +00:00
Michael Goulet
f1ee076f81 Async closures will move params into the future always 2024-01-16 17:12:10 +00:00
Matthias Krüger
d4b276caa4
Rollup merge of #119816 - oli-obk:tait_ice_unify_obligations, r=lcnr
Define hidden types in confirmation

fixes  #111470

r? `@lcnr` or `@compiler-errors`

explanation in the newly added test
2024-01-16 17:55:22 +01:00
Lukas Markeffsky
22833c177e add test for non-defining use of TAIT in foreign function item 2024-01-16 15:37:03 +00:00
Lukas Markeffsky
450cb5eda6 Don't ICE if TAIT-defining fn contains a closure with _ in return type 2024-01-16 15:37:03 +00:00
bors
bf2637f4e8 Auto merge of #119954 - scottmcm:option-unwrap-failed, r=WaffleLapkin
Split out `option::unwrap_failed` like we have `result::unwrap_failed`

...and like `option::expect_failed`
2024-01-16 15:32:39 +00:00
bors
533cfde67c Auto merge of #119947 - compiler-errors:old-solver-instantiate-response, r=lcnr
Make sure to instantiate placeholders correctly in old solver

When creating the query substitution guess for an input placeholder type like `!1_T` (in universe 1), we were guessing the response substitution with something like `!0_T`. This failed to unify with `!1_T`, causing an ICE.

This PR reworks the query substitution guess code to work a bit more like the new solver. I'm *pretty* sure this is correct, though I'd really appreciate some scrutiny from someone (*cough* lcnr) who knows a bit more about query instantiation :)

Fixes #119941

r? lcnr
2024-01-16 13:33:04 +00:00
bors
fa0dc208d0 Auto merge of #119672 - cjgillot:dse-sandwich, r=oli-obk
Sandwich MIR optimizations between DSE.

This PR reorders MIR optimization passes in an attempt to increase their efficiency.

- Stop running CopyProp before GVN, it's useless as GVN will do the same thing anyway. Instead, we perform CopyProp at the end of the pipeline, to ensure we do not emit copy/move chains.
- Run DSE before GVN, as it increases the probability to have single-assignment locals.
- Run DSE after the final CopyProp to turn copies into moves.

r? `@ghost`
2024-01-16 11:34:16 +00:00
Oli Scherer
3599c18874 Skip dead code checks on items that failed typeck 2024-01-16 10:52:28 +00:00
Ali MJ Al-Nasrawy
aac2f84794 wf-check type annotations before normalization 2024-01-16 09:25:28 +01:00
Ali MJ Al-Nasrawy
8d4693c0f8 borrowck: use implied bounds from impl header 2024-01-16 09:25:28 +01:00
Ali MJ Al-Nasrawy
a3fe3bbb2c borrowck: wf-check fn item args 2024-01-16 09:25:28 +01:00
bors
f9c2421a2a Auto merge of #119439 - cjgillot:gvn-faster, r=oli-obk
Avoid some redundant work in GVN

The first 2 commits are about reducing the perf effect.

Third commit avoids doing redundant work: is a local is SSA, it already has been simplified, and the resulting value is in `self.locals`. No need to call any code on it.

The last commit avoids removing some storage statements.

r? wg-mir-opt
2024-01-16 05:17:49 +00:00
Zalathar
1f9353ae2c coverage: Tweak individual tests to be unaffected by rustfmt
Some of these tests use non-standard formatting that we can simulate by
strategically adding `//` line comments.

One contains `where` clauses that would be split across multiple lines, which
we can keep on one line by moving the bounds to the generic type instead.
2024-01-16 16:14:27 +11:00
Zalathar
f1494425bb coverage: Add #[rustfmt::skip] to tests with non-standard formatting
These tests deliberately use non-standard formatting, so that the line
execution counts reported by `llvm-cov` reveal additional information about
where code regions begin and end.
2024-01-16 15:56:37 +11:00
asquared31415
a8bb418ae5 make unsafe_op_in_unsafe_fn MachineApplicable and add it to 2024 compatibility 2024-01-15 23:06:39 +00:00
bors
714b29a17f Auto merge of #119610 - Nadrieril:never_pattern_bindings, r=compiler-errors
never patterns: Check bindings wrt never patterns

Never patterns:
- Shouldn't contain bindings since they never match anything;
- Don't count when checking that or-patterns have consistent bindings.

r? `@compiler-errors`
2024-01-15 21:24:13 +00:00
Martin Nordholts
8f440f06c6 large_assignments: Lint on specific large args passed to functions 2024-01-15 19:07:12 +01:00
bors
67e7b84425 Auto merge of #119987 - matthiaskrgr:rollup-f7lkx4w, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #119818 (Silence some follow-up errors [3/x])
 - #119870 (std: Doc blocking behavior of LazyLock)
 - #119897 (`OutputTypeParameterMismatch` -> `SignatureMismatch`)
 - #119963 (Fix `allow_internal_unstable` for `(min_)specialization`)
 - #119971 (Use `zip_eq` to enforce that things being zipped have equal sizes)
 - #119974 (Minor `trimmed_def_paths` improvements)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-15 16:45:41 +00:00
bors
1ead4761e9 Auto merge of #119878 - scottmcm:inline-always-unwrap, r=workingjubilee
Tune the inlinability of `unwrap`

Fixes #115463
cc `@thomcc`

This tweaks `unwrap` on ~~`Option` &~~ `Result` to be two parts:
- `#[inline(always)]` for checking the discriminant
- `#[cold]` for actually panicking

The idea here is that checking the discriminant on a `Result` ~~or `Option`~~ should always be trivial enough to be worth inlining, even in `opt-level=z`, especially compared to passing it to a function.

As seen in the issue and codegen test, this will hopefully help particularly for things like `.try_into().unwrap()`s that are actually infallible, but in a way that's only visible with the inlining.

EDIT: I've restricted this to `Result` to avoid combining effects
2024-01-15 09:20:46 +00:00
Matthias Krüger
0891cb4d81
Rollup merge of #119963 - clubby789:spec-allow-internal-unstable, r=compiler-errors
Fix `allow_internal_unstable` for `(min_)specialization`

Fixes #119950

Blocked on #119949 (comment doesn't make sense until that merges)

I'd like to follow this up and look for more instances of not properly checking spans for features but I wanted to fix the motivating issue.
2024-01-15 08:44:49 +01:00
Matthias Krüger
73256c68b8
Rollup merge of #119818 - oli-obk:even_more_follow_up_errors3, r=compiler-errors
Silence some follow-up errors [3/x]

this is one piece of the requested cleanups from https://github.com/rust-lang/rust/pull/117449

Keep error types around, even in obligations.

These help silence follow-up errors, as we now figure out that some types (most notably inference variables) are equal to an error type.

But it also allows figuring out more types in the presence of errors, possibly causing more errors.
2024-01-15 08:44:46 +01:00
Scott McMurray
23483664a2 Split out option::unwrap_failed like we have result::unwrap_failed
...and like `option::expect_failed`
2024-01-14 12:45:01 -08:00
Guillaume Gomez
8914ca722c
Rollup merge of #119561 - notriddle:master, r=fmease
rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 5)

Follow up

* https://github.com/rust-lang/rust/pull/116214
* https://github.com/rust-lang/rust/pull/116432
* https://github.com/rust-lang/rust/pull/116824
* https://github.com/rust-lang/rust/pull/118105
2024-01-14 20:17:23 +01:00
clubby789
0529ccf341 Fix allow_internal_unstable for (min_)specialization 2024-01-14 13:50:02 +00:00
Guillaume Gomez
5ad0ed52e9
Rollup merge of #119944 - compiler-errors:no-match-due-to-gat-bounds, r=fmease
Don't ICE when noting GAT bounds in `report_no_match_method_error`

We can encounter `BindingObligation`s from GATs that we should handle in `report_no_match_method_error`. I assume we can encounter them from methods, though I didn't really feel like wasting my time creating a repro.

Fixes #119942
2024-01-14 14:02:28 +01:00
Young-Flash
c0a5a859b9 test: add test case for impl trait arg suggestion 2024-01-14 18:54:07 +08:00
bors
8847bda592 Auto merge of #119361 - sjwang05:issue-119352, r=WaffleLapkin
Fix ICE when suggesting dereferencing binop operands

Fixes #119352
2024-01-14 09:39:03 +00:00
bors
0dab65b8a1 Auto merge of #119934 - compiler-errors:could-impl, r=jackh726
Make `InferCtxtExt::could_impl_trait` more precise, less ICEy

The implementation for `InferCtxtExt::could_impl_trait` was very wrong. Along with being pretty poorly named, way too specific to ADTs, it was also doing impl substitution wrong -- this caused an ICE (#119915).

This PR generalizes that code, gives it a clearer name, makes it stop using the new trait solver (lol), and fixes some fallout bad suggestions that are made worse with the code fix.

Fixes #119915
2024-01-14 06:37:15 +00:00
bors
aa5f781bd4 Auto merge of #119341 - sjwang05:issue-58462, r=WaffleLapkin
Suggest quoting unquoted idents in attrs

Closes #58462
2024-01-14 04:37:45 +00:00
Michael Goulet
985e1e031b Add a simpler test 2024-01-13 23:09:37 +00:00
Michael Goulet
24c1f4aa80 Make sure to instantiate placeholders correctly in old solver 2024-01-13 22:57:44 +00:00
bors
3deb9bbf84 Auto merge of #119945 - matthiaskrgr:rollup-oy3e1j2, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #119189 (Move section "Installing from Source" to seperate file)
 - #119925 (store the segment name when resolution fails)
 - #119935 (Move personality implementation out of PAL)
 - #119937 (Improve UEFI target docs)
 - #119938 (Allow unauthorized users to user the has-merge-commits label)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-13 22:05:46 +00:00
Michael Goulet
04a6fd241b Make InferCtxtExt::could_impl_trait less messed up 2024-01-13 22:00:34 +00:00
Matthias Krüger
70bc26d0e7
Rollup merge of #119925 - bvanjoi:fix-112672, r=Nilstrieb
store the segment name when resolution fails

Fixes #112672

The `find_cfg_stripped` does indeed get executed within `smart_resolve_report_errors`. However, this error is not reported as it is subsequently overridden by `parent_err`. (See: https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/late.rs#L3760)

This PR changes `last_segment` to `segment`, which stores the name of the failed resolution, and ensures that the result of `find_cfg_stripped` is also included in `parent_err`.

r? ```@Nilstrieb```
2024-01-13 22:35:08 +01:00
Michael Goulet
0b45ff5dac Don't ICE when noting GAT bounds in report_no_match_method_error 2024-01-13 20:55:54 +00:00
bors
d78329b92e Auto merge of #119088 - George-lewis:glewis/suggest-upgrading-compiler, r=Nilstrieb
Suggest Upgrading Compiler for Gated Features

This PR addresses #117318

I have a few questions:

1. Do we want to specify the current version and release date of the compiler? I have added this in via environment variables, which I found in the code for the rustc cli where it handles the `--version` flag
  a. How can I handle the changing message in the tests?
3. Do we want to only show this message when the compiler is old?
  a. How can we determine when the compiler is old?

I'll wait until we figure out the message to bless the tests
2024-01-13 20:06:03 +00:00
George-lewis
d56cdd48cb Bless tests
Update tests
2024-01-13 12:46:58 -05:00
Urgau
41b69aae91 Add way to express no-values with check-cfg 2024-01-13 17:19:46 +01:00
bors
c6c4abf584 Auto merge of #119927 - matthiaskrgr:rollup-885ws57, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #119587 (Varargs support for system ABI)
 - #119891 (rename `reported_signature_mismatch` to reflect its use)
 - #119894 (Allow `~const` on associated type bounds again)
 - #119896 (Taint `_` placeholder types in trait impl method signatures)
 - #119898 (Remove unused `ErrorReporting` variant from overflow handling)
 - #119902 (fix typo in `fn()` docs)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-13 16:09:45 +00:00
bors
1d8d7b16cb Auto merge of #117285 - joboet:move_platforms_to_pal, r=ChrisDenton
Move platform modules into `sys::pal`

This is the initial step of #117276. `sys` just re-exports everything from the current `sys` for now, I'll move the implementations for the individual features one-by-one after this PR merges.
2024-01-13 14:10:56 +00:00
Matthias Krüger
9696ef7c12
Rollup merge of #119896 - oli-obk:variance_ice, r=compiler-errors
Taint `_` placeholder types in trait impl method signatures

We report an error right below for them, but that kind of broken type can cause subsequent ICEs.

fixes #119867
2024-01-13 15:10:29 +01:00
Matthias Krüger
2c7ce1c453
Rollup merge of #119894 - fmease:tilde-const-assoc-ty-bounds, r=compiler-errors
Allow `~const` on associated type bounds again

This follows from [this Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/419616-t-compiler.2Fproject-const-traits/topic/projections.20on.20.28~.29const.20Trait.20.26.20.28~.29const.20assoc.20ty.20bounds).

Basically in my opinion, it makes sense to allow `~const` on associated type bounds again since they're quite useful even though we haven't implemented the proposed syntax `<Ty as ~const Trait>::Proj`/`<Ty as const Trait>::Proj` yet; that can happen as a follow-up.

This already allows more code to compile since `T::Assoc` where `T` is a type parameter and where the predicate `<T as ~const Trait>` is in the environment gets elaborated to (pseudo) `<T as ~const Trait>::Assoc`.

```rs
#[const_trait]
trait Trait {
    type Assoc: ~const Trait;
    fn func() -> i32;
}

const fn function<T: ~const Trait>() -> i32 {
    T::Assoc::func()
}
```

`~const` associated type bounds also work together with `const` bounds:

```rs
struct Type<const N: i32>;

fn procedure<T: const Trait>() -> Type<{ T::Assoc::func() }> { // `Trait` comes from above
    Type
}
```

NB: This PR also starts allowing `~const` bounds in the generics and the where-clause of trait associated types since it's trivial to support them. However, I don't know if those bounds are actually useful. Maybe we should continue to reject them?
For reference, it wouldn't make any sense to allow `~const Trait` in GACs (generic associated constants, `generic_const_items`) because they'd be absolutely useless (contrary to `const Trait`).

~~[``@]rustbot`` ping project-const-traits~~
r? project-const-traits
2024-01-13 15:10:29 +01:00
Matthias Krüger
7b507db24b
Rollup merge of #119587 - beepster4096:system_varargs, r=petrochenkov
Varargs support for system ABI

This PR allows functions with the `system` ABI to be variadic (under the `extended_varargs_abi_support` feature tracked in #100189). On x86 windows, the `system` ABI is equivalent to `C` for variadic functions. On other platforms, `system` is already equivalent to `C`.

Fixes #110505
2024-01-13 15:10:28 +01:00
bohan
c288cb1f74 store the segment name when resolution fails 2024-01-13 21:06:38 +08:00
bors
284cb714d2 Auto merge of #119871 - nnethercote:overhaul-treat-err-as-bug, r=compiler-errors
Overhaul `-Ztreat-err-as-bug`

It's current behaviour is surprising, in a bad way. This also makes the implementation more complex than it needs to be.

r? `@oli-obk`
2024-01-13 08:15:52 +00:00
beepster4096
41e224b1bc allow system abi to be variadic 2024-01-12 23:19:54 -08:00
bors
7585c62658 Auto merge of #119473 - Urgau:check-cfg-explicit-none, r=petrochenkov
Add explicit `none()` value variant in check-cfg

This PR adds an explicit none value variant in check-cfg values: `values(none())`.

Currently the only way to define the none variant is with an empty `values()` which means that if someone has a cfg that takes none and strings they need to use two invocations: `--check-cfg=cfg(foo) --check-cfg=cfg(foo, values("bar"))`.
Which would now be `--check-cfg=cfg(foo, values(none(),"bar"))`, this is simpler and easier to understand.

`--check-cfg=cfg(foo)`, `--check-cfg=cfg(foo, values())` and `--check-cfg=cfg(foo, values(none()))` would be equivalent.

*Another motivation for doing this is to make empty `values()` actually means no-values, but this is orthogonal to this PR and adding `none()` is sufficient in it-self.*

`@rustbot` label +F-check-cfg
r? `@petrochenkov`
2024-01-13 06:17:46 +00:00
bors
89110dafe7 Auto merge of #118947 - Bryanskiy:delegStep1, r=petrochenkov,lcnr
Delegation implementation: step 1

See https://github.com/rust-lang/rust/issues/118212 for more details.

r? `@petrochenkov`
2024-01-13 04:19:17 +00:00
bors
f1f8687b06 Auto merge of #118924 - Urgau:check-cfg-exclude-well-known-from-diag, r=petrochenkov
Exclude well known names from showing a suggestion in check-cfg

This PR adds an exclusion for well known names from showing in suggestions of check-cfg/`unexpected_cfgs`.

Follow-up to https://github.com/rust-lang/rust/pull/118213 and fixes https://github.com/rust-lang/rust/pull/118213#issuecomment-1854189934.

r? `@petrochenkov`
2024-01-13 02:13:20 +00:00
sjwang05
c36b5d5353
Fix ICE when suggesting dereferencing binop operands 2024-01-12 17:49:37 -08:00
Nicholas Nethercote
f1ac54123f Don't consider delayed bugs for -Ztreat-err-as-bug.
`-Ztreat-err-as-bug` treats normal errors and delayed bugs equally,
which can lead to some really surprising results.

This commit changes `-Ztreat-err-as-bug` so it ignores delayed bugs,
unless they get promoted to proper bugs and are printed.

This feels to me much simpler and more logical. And it simplifies the
implementation:
- The `-Ztreat-err-as-bug` check is removed from in
  `DiagCtxt::{delayed_bug,span_delayed_bug}`.
- `treat_err_as_bug` doesn't need to count delayed bugs.
- The `-Ztreat-err-as-bug` panic message is simpler, because it doesn't
  have to mention delayed bugs.

Output of delayed bugs is now more consistent. They're always printed
the same way. Previously when they triggered `-Ztreat-err-as-bug` they
would be printed slightly differently, via `span_bug` in
`span_delayed_bug` or `delayed_bug`.

A minor behaviour change: the "no errors encountered even though
`span_delayed_bug` issued" printed before delayed bugs is now a note
rather than a bug. This is done so it doesn't get counted as an error
that might trigger `-Ztreat-err-as-bug`, which would be silly.
This means that if you use `-Ztreat-err-as-bug=1` and there are no
normal errors but there are delayed bugs, the first delayed bug will be
shown (and the panic will happen after it's printed).

Also, I have added a second note saying "those delayed bugs will now be
shown as internal compiler errors". I think this makes it clearer what
is happening, because the whole concept of delayed bugs is non-obvious.

There are some test changes.
- equality-in-canonical-query.rs: Minor output changes, and the error
  count reduces by one because the "no errors encountered even though
  `span_delayed_bug` issued" message is no longer counted as an error.
- rpit_tait_equality_in_canonical_query.rs: Ditto.
- storage-live.rs: The query stack disappears because these delayed bugs
  are now printed at the end, rather than when they are created.
- storage-return.rs, span_delayed_bug.rs: now need
  `-Zeagerly-emit-delayed-bugs` because they need the delayed bugs
  emitted immediately to preserve behaviour.
2024-01-13 09:59:56 +11:00
Nilstrieb
a04ac4952c Improve let_underscore_lock
- lint if the lock was in a nested pattern
- lint if the lock is inside a `Result<Lock, _>`
2024-01-12 23:18:58 +01:00
bors
3071aefdb2 Auto merge of #117321 - chenyukang:yukang-fix-117142, r=petrochenkov
Fix unused_parens issue when cast is followed LT

Fixes #117142

The original check only checks `a as (i32) < 0`, this fix extends it to handle `b + a as (i32) < 0`.

A better way is maybe we suggest `(a as i32) < 0` instead of suppressing the warning, maybe following PR could improve it.
2024-01-12 22:15:55 +00:00
sjwang05
aa8ecd0652
Suggest quoting unquoted idents in attrs 2024-01-12 13:59:47 -08:00
bors
2319be8e26 Auto merge of #119452 - AngelicosPhosphoros:make_nonzeroint_get_assume_nonzero, r=scottmcm
Add assume into `NonZeroIntX::get`

LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments.

Related to https://github.com/rust-lang/rust/issues/119422
Related to https://github.com/llvm/llvm-project/issues/76628
Related to https://github.com/rust-lang/rust/issues/49572
2024-01-12 20:18:04 +00:00
Scott McMurray
b858c591dd Tune the inlinability of Result::unwrap 2024-01-12 10:57:58 -08:00
Urgau
29afbbd5a9 Exclude well known names from showing a suggestion in check-cfg 2024-01-12 18:47:05 +01:00
Oli Scherer
4586fdce47 Taint _ placeholder types 2024-01-12 16:33:29 +00:00
León Orell Valerian Liehr
f28373978e
Allow ~const on assoc ty bounds again 2024-01-12 17:22:18 +01:00
Guillaume Gomez
dafbe17a02
Rollup merge of #119885 - DianQK:revert-pr-113923, r=petrochenkov
Revert #113923

Per [#t-compiler/meetings > [weekly] 2024-01-11](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11) discussion, revert #113923. Also revert associated #118568.

The PR #113923 causes the regression issue #118609. We need more time to find a proper solution.

Discussions start at [412365838](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11/near/412365838) and continue to [412369643](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11/near/412369643).

Fixes #118609.

r? compiler
2024-01-12 15:16:58 +01:00
Guillaume Gomez
c997b29a3a
Rollup merge of #119884 - GuillaumeGomez:rename-env-opt, r=davidtwco
Rename `--env` option flag to `--env-set`

As discussed [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Stabilizing.20.60--env.60.20option.20flag.3F). We rename `--env` to not conflicting names with the [RFC](https://github.com/rust-lang/rfcs/pull/2794).

r? `@davidtwco`
2024-01-12 15:16:58 +01:00
Guillaume Gomez
504794b908
Rollup merge of #119872 - compiler-errors:eagerly-emit-delayed-bugs, r=oli-obk,nnethercote
Give me a way to emit all the delayed bugs as errors (add `-Zeagerly-emit-delayed-bugs`)

This is probably a *better* way to inspect all the delayed bugs in a program that what exists currently (and therefore makes it very easy to choose the right number `N` with `-Zemit-err-as-bug=N`, though I guess the naming is a bit ironic when you pair both of the flags together, but that feels like naming bikeshed more than anything).

This pacifies my only concern with https://github.com/rust-lang/rust/pull/119871#issuecomment-1888170259, because (afaict?) that PR doesn't allow you to intercept a delayed bug's stack trace anymore, which as someone who debugs the compiler a lot, is something that I can *promise* that I do.

r? `@nnethercote` or `@oli-obk`
2024-01-12 15:16:57 +01:00
Guillaume Gomez
46c3c014eb
Rollup merge of #119817 - compiler-errors:normalize-opaques, r=lcnr
Remove special-casing around `AliasKind::Opaque` when structurally resolving in new solver

This fixes a few inconsistencies around where we don't eagerly resolve opaques to their (locally-defined) hidden types in the new solver. It essentially allows this code to work:
```rust
fn main() {
    type Tait = impl Sized;
    struct S {
        i: i32,
    }
    let x: Tait = S { i: 0 };
    println!("{}", x.i);
}
```

Since `Tait` is defined in `main`, we are able to poke through the type of `x` with deref.

r? lcnr
2024-01-12 15:16:56 +01:00
bors
174e73a3f6 Auto merge of #119396 - Nadrieril:intersection-tracking, r=WaffleLapkin
Exhaustiveness: track overlapping ranges precisely

The `overlapping_range_endpoints` lint has false positives, e.g. https://github.com/rust-lang/rust/issues/117648. I expected that removing these false positives would have too much of a perf impact but never measured it. This PR is an experiment to see if the perf loss is manageable.

r? `@ghost`
2024-01-12 11:29:06 +00:00
Bryanskiy
d69cd6473c Delegation implementation: step 1 2024-01-12 14:11:16 +03:00
DianQK
aa874c5513
Revert "Auto merge of #113923 - DianQK:restore-no-builtins-lto, r=pnkfelix"
This reverts commit 8c2b577217, reversing
changes made to 9cf18e98f8.
2024-01-12 18:23:04 +08:00
DianQK
6d29eac04b
Revert "Auto merge of #118568 - DianQK:no-builtins-symbols, r=pnkfelix"
This reverts commit 503e129328, reversing
changes made to 0e7f91b75e.
2024-01-12 18:22:39 +08:00
Guillaume Gomez
462bcac629 Rename --env option flag to --env-set 2024-01-12 11:02:57 +01:00
bors
bfd799f1a5 Auto merge of #119879 - matthiaskrgr:rollup-y710der, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #119781 (fix typo)
 - #119865 (Set `c_str_literals` stabilization version back to `CURRENT_RUSTC_VERSION`)
 - #119866 (Convert `effects` description to doc comment)
 - #119868 (Register even erroneous impls)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-12 09:11:57 +00:00
joboet
df3cb23e01
update debuginfo tests on Windows 2024-01-12 08:50:14 +01:00
Matthias Krüger
d7a720a863
Rollup merge of #119868 - oli-obk:unknown_lifetime_ice, r=compiler-errors
Register even erroneous impls

Otherwise the specialization graph fails to pick it up, even though other code assumes that all impl blocks have an entry in the specialization graph.

also includes an unrelated cleanup of the specialization graph query

fixes  #119827
2024-01-12 08:23:59 +01:00
bors
2b1365b34f Auto merge of #119735 - lcnr:provisional-cache-readd, r=compiler-errors
next solver: provisional cache

this adds the cache removed in #115843. However, it should now correctly track whether a provisional result depends on an inductive or coinductive stack.

While working on this, I was using the following doc: https://hackmd.io/VsQPjW3wSTGUSlmgwrDKOA. I don't think it's too helpful to understanding this, but am somewhat hopeful that the inline comments are more useful.

There are quite a few future perf improvements here. Given that this is already very involved I don't believe it is worth it (for now). While working on this PR one of my few attempts to significantly improve perf ended up being unsound again because I was not careful enough 

r? `@compiler-errors`
2024-01-12 07:04:42 +00:00
Nicholas Nethercote
9018d2c455 Detect NulInCStr error earlier.
By making it an `EscapeError` instead of a `LitError`. This makes it
like the other errors produced when checking string literals contents,
e.g. for invalid escape sequences or bare CR chars.

NOTE: this means these errors are issued earlier, before expansion,
which changes behaviour. It will be possible to move the check back to
the later point if desired. If that happens, it's likely that all the
string literal contents checks will be delayed together.

One nice thing about this: the old approach had some code in
`report_lit_error` to calculate the span of the nul char from a range.
This code used a hardwired `+2` to account for the `c"` at the start of
a C string literal, but this should have changed to a `+3` for raw C
string literals to account for the `cr"`, which meant that the caret in
`cr"` nul error messages was one short of where it should have been. The
new approach doesn't need any of this and avoids the off-by-one error.
2024-01-12 16:19:37 +11:00
bors
5431404b87 Auto merge of #118548 - Enselic:bench-padding, r=thomcc,ChrisDenton
libtest: Fix padding of benchmarks run as tests

### Summary

The first commit adds regression tests for libtest padding.

The second commit fixes padding for benches run as tests and updates the blessed output of the regression tests to make it clear what effect the fix has on padding.

Closes #104092 which is **E-help-wanted** and **regression-from-stable-to-stable**

### More details

Before this fix we applied padding _before_ manually doing what `convert_benchmarks_to_tests()` does which affects padding calculations. Instead use `convert_benchmarks_to_tests()` first if applicable and then apply padding afterwards so it becomes correct.

Benches should only be padded when run as benches to make it easy to compare the benchmark numbers. Not when run as tests.

r? `@ghost` until CI passes.
2024-01-12 05:06:03 +00:00
Michael Goulet
7df43d3c81 Give me a way to emit all the delayed bugs 2024-01-12 03:30:17 +00:00
Oli Scherer
6679e2c2f2 Register even erroneous impls
Otherwise the specialization graph fails to pick it up, even though other code assumes that all impl blocks have an entry in the specialization graph.
2024-01-11 20:34:59 +00:00
Matthias Krüger
ca17ce4558
Rollup merge of #119852 - RalfJung:const-err4, r=compiler-errors
give const-err4 a more descriptive name

Also, doesn't look like this still needs to be per-bitwidth

r? ``@oli-obk``
2024-01-11 19:42:52 +01:00
Matthias Krüger
8294356a5d
Rollup merge of #119842 - Zalathar:kind, r=oli-obk
coverage: Add enums to accommodate other kinds of coverage mappings

Extracted from  #118305.

LLVM supports several different kinds of coverage mapping regions, but currently we only ever emit ordinary “code” regions.  This PR performs the plumbing required to add other kinds of regions as enum variants, but does not add any specific variants other than `Code`.

The main motivation for this change is branch coverage, but it will also allow separate experimentation with gap regions and skipped regions, which might help in producing more accurate and useful coverage reports.

---

``@rustbot`` label +A-code-coverage
2024-01-11 19:42:51 +01:00
Matthias Krüger
f5387a1c38
Rollup merge of #119841 - nnethercote:rm-DiagnosticBuilder-buffer, r=oli-obk
Remove `DiagnosticBuilder::buffer`

`DiagnosticBuilder::buffer` doesn't do much, and part of what it does (for `-Ztreat-err-as-bug`) it shouldn't.

This PR strips it back, replaces its uses, and finally removes it, making a few cleanups in the vicinity along the way.

r? ``@oli-obk``
2024-01-11 19:42:51 +01:00
Matthias Krüger
6beb676990
Rollup merge of #119836 - hi-rustin:rustin-patch-docs-blank-line, r=ChrisDenton
chore: remove unnecessary blank line

It seems no need to add an unnecessary line here.
2024-01-11 19:42:50 +01:00
Matthias Krüger
bd61caf58b
Rollup merge of #119813 - oli-obk:even_more_follow_up_errors2, r=estebank
Silence some follow-up errors [2/x]

this is one piece of the requested cleanups from https://github.com/rust-lang/rust/pull/117449

the `type_of` query frequently uses astconv to convert a `hir::Ty` to a `ty::Ty`. This process is infallible, but may produce errors as it goes. All the error reporting sites that had access to the `ItemCtxt` are now tainting it, causing `type_of` to return a `ty::Error` instead of anything else.
2024-01-11 19:42:49 +01:00
Michael Goulet
68c2f11240 Remove special-casing around aliaskind in new solver 2024-01-11 16:54:11 +00:00
Ralf Jung
db860566bc give const-err4 a more descriptive name 2024-01-11 14:57:12 +01:00
hi-rustin
90cc8ba4bc fix: update broken stderr
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-11 21:39:44 +08:00
Nadrieril
a24f4db41b Only lint ranges that really overlap 2024-01-11 14:04:11 +01:00
Camille GILLOT
bc35ee41fa Do not run simplify_locals inside DSE.
The full pass is run short after.
2024-01-11 09:58:22 +00:00
Camille GILLOT
974b727874 Bless ui-fulldeps. 2024-01-11 09:58:22 +00:00
Camille GILLOT
0aedd6e86f Sandwich MIR optimizations between DSE. 2024-01-11 09:58:19 +00:00
Oli Scherer
fb44c848c3 Keep error types around, even in obligations.
These help silence follow up errors
2024-01-11 09:52:25 +00:00
Oli Scherer
55cab535e7 Taint more aggressively in astconv 2024-01-11 09:03:26 +00:00
Oli Scherer
af7f8f9811 Silence follow up errors if astconv already errored 2024-01-11 09:03:26 +00:00
Takayuki Maeda
6794dc9a5f
Rollup merge of #116343 - Nilstrieb:maybe-dont-mention-all-the-weird-lang-items-just-saying, r=bjorn3
Stop mentioning internal lang items in no_std binary errors

When writing a no_std binary, you'll be greeted with nonsensical errors mentioning lang items like eh_personality and start. That's pretty bad because it makes you think that you need to define them somewhere! But oh no, now you're getting the `internal_features` lint telling you that you shouldn't use them! But you need a no_std binary! What now?

No problem! Writing a no_std binary is super easy. Just use panic=abort and supply your own platform specific entrypoint symbol (like `main`) and you're good to go. Would be nice if the compiler told you that, right?

This makes it so that it does do that.

I don't _love_ the new messages yet, but they're decent I think. They can probably be improved, please suggest improvements.
2024-01-11 15:41:46 +09:00
Nicholas Nethercote
2aac288c18 Use the right level with -Ztreat-err-as-bug.
Errors in `DiagCtxtInner::emit_diagnostic` are never set to
`Level::Bug`, because the condition never succeeds, because
`self.treat_err_as_bug()` is called *before* the error counts are
incremented.

This commit switches to `self.treat_next_err_as_bug()`, fixing the
problem. This changes the error message output to actually say "internal
compiler error".
2024-01-11 16:55:10 +11:00
Zalathar
124fff0777 coverage: Add enums to accommodate other kinds of coverage mappings 2024-01-11 16:43:12 +11:00
bors
3a6bf351a3 Auto merge of #119677 - cjgillot:early-cfg-opt, r=oli-obk
Reorder early post-inlining passes.

`RemoveZsts`, `RemoveUnneededDrops` and `UninhabitedEnumBranching` only depend on types, so they should be executed together early after MIR inlining introduces those types.

This does not change the end-result, but this makes the pipeline a bit more consistent.
2024-01-11 04:09:07 +00:00
Matthias Krüger
d37de53425
Rollup merge of #119803 - oli-obk:even_more_follow_up_errors, r=compiler-errors
Silence some follow-up errors [1/x]

this is one piece of the requested cleanups from https://github.com/rust-lang/rust/pull/117449

When we use `-> impl SomeTrait<_>` as a return type, we are both using the "infer return type suggestion" code path, and the infer opaque type code path within the same function. That can lead to confusing diagnostics, so silence all opaque type diagnostics in that case.
2024-01-11 03:02:43 +01:00
Matthias Krüger
d93df41c1d
Rollup merge of #119790 - celinval:smir-all-traits, r=oli-obk
Fix all_trait* methods to return all traits available in StableMIR

Also provide a mechanism to retrieve traits and implementations for a given crate.

This fixes https://github.com/rust-lang/project-stable-mir/issues/37
2024-01-11 03:02:42 +01:00
Matthias Krüger
4dcc5a05ea
Rollup merge of #119715 - Nadrieril:graceful-type-error, r=compiler-errors
Exhaustiveness: abort on type error

This adds an error path to exhaustiveness checking so that we abort instead of ICEing when encountering a stray `ty::Error`.

Fixes https://github.com/rust-lang/rust/issues/119493
Fixes https://github.com/rust-lang/rust/issues/119778

r? `@compiler-errors`
2024-01-11 03:02:41 +01:00
Nadrieril
5ccd29d6f0 Add more tests 2024-01-10 23:25:27 +01:00
Nilstrieb
da26317a8a Stop mentioning internal lang items in no_std binary errors
When writing a no_std binary, you'll be greeted with nonsensical errors
mentioning lang items like eh_personality and start. That's pretty bad
because it makes you think that you need to define them somewhere! But
oh no, now you're getting the `internal_features` lint telling you that
you shouldn't use them! But you need a no_std binary! What now?

No problem! Writing a no_std binary is super easy. Just use panic=abort
and supply your own platform specific entrypoint symbol (like `main`)
and you're good to go. Would be nice if the compiler told you that,
right?

This makes it so that it does do that.
2024-01-10 21:18:54 +01:00
Oli Scherer
0ae00444dc Make sure the new solver agrees 2024-01-10 16:05:24 +00:00
Oli Scherer
08fc5e8acd Define hidden types in confirmation 2024-01-10 16:03:05 +00:00
Nadrieril
dee657f9f9 Add test case for #119778 2024-01-10 14:50:48 +01:00
Oli Scherer
0e82aaeb67 Avoid follow up errors 2024-01-10 08:52:44 +00:00
Matthias Krüger
4571ef9152
Rollup merge of #119772 - oli-obk:whackamole, r=compiler-errors
Fix an ICE that occurs after an error has already been reported

fixes #117491

cc `@jswrenn`
2024-01-10 06:28:45 +01:00
Matthias Krüger
7c378d0058
Rollup merge of #119769 - fmease:rustdoc-off-by-one-dyn-trait-def-gen-args, r=GuillaumeGomez
rustdoc: offset generic args of cross-crate trait object types when cleaning

Fixes #119529.

This PR contains several refactorings apart from the bug fix.
Best reviewed commit by commit.
r? GuillaumeGomez
2024-01-10 06:28:44 +01:00
Matthias Krüger
33f27d32a9
Rollup merge of #106893 - clubby789:struct-update-help, r=compiler-errors
Explain base expression for struct update syntax

Fixes #106890

`@rustbot` label +A-diagnostics
2024-01-10 06:28:44 +01:00
Celina G. Val
af3c2c9f6d Fix all_trait* methods to return all trait available
Also provide a mechanism to retrieve traits and implementations for a
given crate.
2024-01-09 15:45:03 -08:00
bors
94807670a6 Auto merge of #117449 - oli-obk:query_merge_immobile_game, r=matthewjasper
Avoid silencing relevant follow-up errors

r? `@matthewjasper`

This PR only adds new errors to tests that are already failing and fixes one ICE.

Several tests were changed to not emit new errors. I believe all of them were faulty tests, and not explicitly testing for the code that had new errors.
2024-01-09 22:50:49 +00:00
Oli Scherer
0978f6e010 Avoid silencing relevant follow-up errors 2024-01-09 21:08:16 +00:00
clubby789
f1b8b7d7ae Add error code for missing base expression in struct update syntax 2024-01-09 19:25:54 +00:00
Urgau
15078c25d6 Add explicit none() value variant in check-cfg 2024-01-09 19:03:06 +01:00
Guillaume Gomez
f4d06256d8
Rollup merge of #119721 - compiler-errors:constness-implication, r=fee1-dead
`~const` trait and projection bounds do not imply their non-const counterparts

This PR removes the hack where we install a non-const trait and projection bound for every `const_trait` and `~const` projection bound we have in the AST. It ends up messing up more things than it fixes, see words below.

Fixes #119718

cc `@fmease` `@fee1-dead` `@oli-obk`
r? fee1-dead or one of y'all i don't care

---

My understanding is that this hack was added to support the following code:

```rust
pub trait Owo<X = <Self as Uwu>::T> {}

#[const_trait]
pub trait Uwu: Owo {}
```

Which is concretely lifted from in the `FromResidual` and `Try` traits. Since within the param-env of `trait Uwu`, we only know that `Self: ~const Uwu` and not `Self: Uwu`, the projection `<Self as Uwu>::T` is not satsifyable.

This causes problems such as #119718, since instantiations of `FnDef` types coming from `const fn` really do **only** implement one of `FnOnce` or `const FnOnce`!

---

In the long-term, I believe that such code should really look something more like:

```rust
#[const_trait]
pub trait Owo<X = <Self as ~const Uwu>::T> {}

#[const_trait]
pub trait Uwu: Owo {}
```

... and that we should introduce some sort of `<T as ~const Foo>::Bar` bound syntax, since due to the fact that `~const` bounds can be present in item bounds, e.g.

```rust
#[const_trait] trait Foo { type Bar: ~const Destruct; }
```

It's easy to see that `<T as Foo>::Bar` and `<T as ~const Foo>::Bar` (or `<T as const Foo>::Bar`) can be distinct types with distinct item bounds!

**Admission**: I know I've said before that I don't like `~const` projection syntax, I do at this point believe they're necessary to fully express bounds and types in a maybe-const world.
2024-01-09 17:52:21 +01:00
Guillaume Gomez
3da96aed94
Rollup merge of #118680 - djkoloski:shell_argfiles, r=compiler-errors
Add support for shell argfiles

Closes https://github.com/rust-lang/compiler-team/issues/684
2024-01-09 17:52:21 +01:00
Oli Scherer
4f0869ea89 Fix an ICE that occurs after an error has already been reported 2024-01-09 16:09:30 +00:00
León Orell Valerian Liehr
17ec134fa4
Update tests 2024-01-09 17:07:38 +01:00
Nadrieril
560beb1ad4 Check bindings around never patterns 2024-01-09 17:00:24 +01:00
Nadrieril
342ea15490 Add tests 2024-01-09 16:49:12 +01:00
Guillaume Gomez
9b905417f5
Rollup merge of #119699 - cjgillot:simplify-unreachable, r=oli-obk
Merge dead bb pruning and unreachable bb deduplication.

Both routines share the same basic structure: iterate on all bbs to identify work, and then renumber bbs.

We can do both at once.
2024-01-09 13:23:18 +01:00
Guillaume Gomez
4a24b5bc05
Rollup merge of #117556 - obeis:static-mut-ref-lint, r=davidtwco
Disallow reference to `static mut` and adding `static_mut_ref` lint

Closes #114447

r? `@scottmcm`
2024-01-09 13:23:15 +01:00
lcnr
242633fe52 add comments and tests 2024-01-09 11:53:50 +01:00
bors
be00c5a9b8 Auto merge of #118968 - aliemjay:canon-static, r=lcnr
unify query canonicalization mode

Exclude from canonicalization only the static lifetimes that appear in the param env because of #118965 . Any other occurrence can be canonicalized safely AFAICT.

r? `@lcnr`
2024-01-09 09:20:33 +00:00
bors
dc641039d2 Auto merge of #117703 - compiler-errors:recursive-async, r=lcnr
Support async recursive calls (as long as they have indirection)

Before #101692, we stored coroutine witness types directly inside of the coroutine. That means that a coroutine could not contain itself (as a witness field) without creating a cycle in the type representation of the coroutine, which we detected with the `OpaqueTypeExpander`, which is used to detect cycles when expanding opaque types after that are inferred to contain themselves.

After `-Zdrop-tracking-mir` was stabilized, we no longer store these generator witness fields directly, but instead behind a def-id based query. That means there is no technical obstacle in the compiler preventing coroutines from containing themselves per se, other than the fact that for a coroutine to have a non-infinite layout, it must contain itself wrapped in a layer of allocation indirection (like a `Box`).

This means that it should be valid for this code to work:

```
async fn async_fibonacci(i: u32) -> u32 {
    if i == 0 || i == 1 {
        i
    } else {
        Box::pin(async_fibonacci(i - 1)).await
          + Box::pin(async_fibonacci(i - 2)).await
    }
}
```

Whereas previously, you'd need to coerce the future to `Pin<Box<dyn Future<Output = ...>>` before `await`ing it, to prevent the async's desugared coroutine from containing itself across as await point.

This PR does two things:
1. Only report an error if an opaque expansion cycle is detected *not* through coroutine witness fields.
    * Instead, if we find an opaque cycle through coroutine witness fields, we compute the layout of the coroutine. If that results in a cycle error, we report it as a recursive async fn.
4. Reworks the way we report layout errors having to do with coroutines, to make up for the diagnostic regressions introduced by (1.). We actually do even better now, pointing out the call sites of the recursion!
2024-01-09 07:20:50 +00:00
Matthias Krüger
deb504b777
Rollup merge of #119712 - madsravn:parsing-errors, r=estebank
Adding alignment to the cases to test for specific error messages.

Adding alignment to the list of cases to test for specific error message. Covers `>`, `^` and `<`.

Pinging people who chimed in last time ( https://github.com/rust-lang/rust/pull/106805 ): ``@estebank`` , ``@compiler-errors`` and ``@Nilstrieb``
2024-01-09 05:33:22 +01:00
Matthias Krüger
1974f5cba9
Rollup merge of #118649 - compiler-errors:coherence-ambig, r=lcnr
Make inductive cycles in coherence ambiguous always

Logical conclusion of https://github.com/rust-lang/rust/issues/114040
One step after #116493

cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/20

r? lcnr to kick off the FCP after review... maybe we should wait until 1.75 is landed? In that case, I'd still like to get the FCP boxes checked sooner since that'll be near the holidays which means everyone's away.
2024-01-09 05:33:21 +01:00
vuittont60
1b08e25c9d
fix typo 2024-01-09 10:47:04 +08:00
sjwang05
6dd0772707
Emit suggestion when trying to write exclusive ranges as ..< 2024-01-08 16:06:37 -08:00
Matthias Krüger
5efa69d979
Rollup merge of #119704 - chenyukang:yukang-fix-let_underscore, r=Nilstrieb
Fix two variable binding issues in lint let_underscore

Fixes #119696
Fixes #119697
2024-01-09 00:19:35 +01:00
Matthias Krüger
e6bc9f0637
Rollup merge of #119663 - petrochenkov:rmakefix, r=Mark-Simulacrum
tests: Normalize `\r\n` to `\n` in some run-make tests

The output is produced by printf from C code in these cases, and printf prints in text mode, which means `\n` will be printed as `\r\n` on Windows.

In --bless mode the new output with `\r\n` will replace expected output in `tests/run-make/raw-dylib-*\output.txt` files, which use \n, always resulting in dirty files in the repo.
2024-01-09 00:19:34 +01:00
Matthias Krüger
34771e2f9a
Rollup merge of #119660 - RalfJung:const-ub-enum, r=oli-obk
remove an unnecessary stderr-per-bitwidth

also update some regexp, `a(lloc)?` would no longer match now that we have compiletest itself do alloc ID normalization.

r? ````@oli-obk````
2024-01-09 00:19:34 +01:00
Matthias Krüger
70e3f8d240
Rollup merge of #119033 - Zalathar:unicode, r=davidtwco
coverage: `llvm-cov` expects column numbers to be bytes, not code points

Normally the compiler emits column numbers as a 1-based number of Unicode code points.

But when we embed coverage mappings for `-Cinstrument-coverage`, those mappings will ultimately be read by the `llvm-cov` tool. That tool assumes that column numbers are 1-based numbers of *bytes*, and relies on that assumption when slicing up source code to apply highlighting (in HTML reports, and in text-based reports with colour).

For the very common case of all-ASCII source code, bytes and code points are the same, so the difference isn't noticeable. But for code that contains non-ASCII characters, emitting column numbers as code points will result in `llvm-cov` slicing strings in the wrong places, producing mangled output or fatal errors.

(See https://github.com/taiki-e/cargo-llvm-cov/issues/275 as an example of what can go wrong.)
2024-01-09 00:19:33 +01:00
Matthias Krüger
ee7d4c1561
Rollup merge of #118903 - azhogin:azhogin/skip_second_stmt_debuginfo.rs, r=petrochenkov
Improved support of collapse_debuginfo attribute for macros.

Added walk_chain_collapsed function to consider collapse_debuginfo attribute in parent macros in call chain.
Fixed collapse_debuginfo attribute processing for cranelift (there was if/else branches error swap).

cc https://github.com/rust-lang/rust/issues/100758
2024-01-09 00:19:32 +01:00
Michael Goulet
841184bcae Make cycle error more resilient to where it starts
Also don't recomment recursive_async crate anymore

Co-authored-by: lcnr <rust@lcnr.de>
2024-01-08 20:30:24 +00:00
Michael Goulet
fa2ff51ace Only compute layout of opaque if coroutine is the cause of an opaque cycle 2024-01-08 20:30:24 +00:00
Michael Goulet
199af7cef0 Point out source of recursion 2024-01-08 20:30:24 +00:00
Michael Goulet
82a2215481 Don't check for recursion in generator witness fields 2024-01-08 20:30:21 +00:00
David Koloski
684aa2c9d1 Add support for shell argfiles 2024-01-08 15:25:55 -05:00
Mads Ravn
506c06636b Removing redudant note from parse error 2024-01-08 19:41:01 +01:00
Michael Howell
8b52275ee3 rustdoc: hide modals when resizing the sidebar
Follow-up for
https://github.com/rust-lang/rust/pull/119477#discussion_r1439085011
2024-01-08 09:54:05 -07:00
Michael Goulet
760673e97d Remove logic in one_bound in astconv that prefers non-const bounds 2024-01-08 15:31:53 +00:00
Michael Goulet
8abf133c4b Make inductive cycles in coherence ambiguous always 2024-01-08 15:03:59 +00:00
Michael Goulet
e44b11f695 ~const trait or projection bounds do not imply non-const bounds 2024-01-08 15:01:14 +00:00
Zalathar
6971e9332d coverage: llvm-cov expects column numbers to be bytes, not code points 2024-01-08 21:58:46 +11:00
Andrew Zhogin
f2dbebafad Improved support of collapse_debuginfo attribute for macros. 2024-01-08 17:47:18 +07:00
Zalathar
585a285619 coverage: Test for column numbers involving non-ASCII characters 2024-01-08 21:43:22 +11:00
yukang
75df38e816 Fix 2 variable binding issues in let_underscore 2024-01-08 16:50:14 +08:00
Matthias Krüger
bf20ade5bf
Rollup merge of #119711 - Nilstrieb:makewtf, r=WaffleLapkin
Delete unused makefile in tests/ui

??????????
2024-01-08 00:38:36 +01:00
Matthias Krüger
26768609fb
Rollup merge of #119708 - compiler-errors:pointer-like, r=Nilstrieb
Unions are not `PointerLike`

I introduced the `PointerLike` trait to enforce `dyn*` coercions only from types that share the same ABI as a pointer. On top of needing to be scalar, they also should not be unions, since CTFE chokes on scalar reads for union types.

Fixes #119695
2024-01-08 00:38:35 +01:00
Matthias Krüger
39b3ef17a1
Rollup merge of #119705 - fmease:tilde-const-assoc-fns-trait-impls, r=compiler-errors
Support `~const` in associated functions in trait impls

Fixes #119700.
2024-01-08 00:38:35 +01:00
Matthias Krüger
0207e24406
Rollup merge of #119703 - compiler-errors:impl-trait-tweaks, r=fmease
Impl trait diagnostic tweaks

1. Tweak some names for `impl Trait` being used in the wrong position
2. Remove two helper functions that are no longer needed since RPITIT is stable, and which causes matches to be a bit obtuse.
3. Split and fix the part where the error notes that it's "only allowed in XX"

Fixes #119629
2024-01-08 00:38:34 +01:00
Matthias Krüger
a9b6908e7f
Rollup merge of #116129 - fu5ha:better-pin-docs-2, r=Amanieu
Rewrite `pin` module documentation to clarify usage and invariants

The documentation of `pin` today does not give a complete treatment of pinning from first principles, nor does it adequately help build intuition and understanding for how the different elements of the pinning story fit together.

This rewrite attempts to address these in a way that makes the concept more approachable while also making the documentation more normative.

This PR picks up where `@mcy` left off in #88500 (thanks to him for the original work and `@Manishearth` for mentioning it such that I originally found it). I've directly incorporated much of the feedback left on the original PR and have rewritten and changed some of the main conceits of the prose to better adhere to the feedback from the reviewers on that PR or just explain something in (hopefully) a better way.
2024-01-08 00:38:33 +01:00
Nadrieril
4b2e8bc841 Abort analysis on type error 2024-01-07 22:13:08 +01:00
Nilstrieb
5be2a85351 Delete unused makefile in tests/ui
??????????
2024-01-07 20:48:31 +01:00
Mads Ravn
5b30586ba8 Adding alignment to the list of cases to test for specific error message. Covers >, ^ and <. 2024-01-07 20:39:46 +01:00
Michael Goulet
68bb76634d Unions are not PointerLike 2024-01-07 19:28:00 +00:00
Michael Goulet
7e38b70cc0 Split note, fix const/static impl trait error 2024-01-07 18:00:03 +00:00
León Orell Valerian Liehr
3acc5a0da3
effects: support ~const in assoc fns in trait impls 2024-01-07 18:22:47 +01:00
Gray Olson
d7a886a807 update ui tests 2024-01-07 08:56:20 -08:00
Michael Goulet
8af1a6a1e5 Make ImplTraitPosition display more descriptive 2024-01-07 16:40:53 +00:00
bors
75c68cfd2b Auto merge of #119675 - cjgillot:set-no-discriminant, r=tmiasko
Skip threading over no-op SetDiscriminant.

Fixes https://github.com/rust-lang/rust/issues/119674
2024-01-07 15:34:05 +00:00
Camille GILLOT
4071572cb4 Merge dead bb pruning and unreachable bb deduplication. 2024-01-07 15:12:10 +00:00
Obei Sideg
a8aa6878f6 Update test for E0796 and static_mut_ref lint 2024-01-07 17:29:25 +03:00
Camille GILLOT
7e39100586 Avoid recording no-op replacements. 2024-01-07 13:54:05 +00:00
Camille GILLOT
4ee01faaf0 Do not re-simplify SSA locals. 2024-01-07 13:54:05 +00:00
The 8472
93b34a5ffa mark vec::IntoIter pointers as !nonnull 2024-01-07 03:44:04 +01:00
Camille GILLOT
a8c4d43cb1 Reorder early post-inlining passes. 2024-01-07 01:42:57 +00:00
bors
78c988fe3e Auto merge of #119035 - saethlin:remove-linker-requirement, r=onur-ozkan
Run Miri and mir-opt tests without a target linker

Normally, we need a linker for the target to build the standard library. That's only because `std` declares crate-type lib and dylib; building the dylib is what creates a need for the linker.

But for mir-opt tests (and for Miri) we do not need to build a `libstd.so`. So with this PR, when we build the standard library for mir-opt tests, instead of `cargo build` we run `cargo rustc --crate-type=lib` which overrides the configured crate types in `std`'s manifest.

I've also swapped in what seems to me a better hack than `BOOTSTRAP_SKIP_TARGET_SANITY` to prevent cross-interpreting with Miri from checking for a target linker and expanded it to mir-opt tests too. Whether it's actually better is up to a reviewer.
2024-01-07 00:32:24 +00:00
Camille GILLOT
41eb9a49af Skip threading over no-op SetDiscriminant. 2024-01-07 00:28:20 +00:00
Ben Kimock
735a6a4212 Run Miri and mir-opt tests without a target linker 2024-01-06 14:17:33 -05:00
Vadim Petrochenkov
c51828ae8b tests: Normalize \r\n to \n in some run-make tests
The output is produced by printf from C code in these cases, and printf prints in text mode, which means `\n` will be printed as `\r\n` on Windows.
In --bless mode the new output with `\r\n` will replace expected output in `tests/run-make/raw-dylib-*\output.txt` files, which use \n, always resulting in dirty files in the repo.
2024-01-06 18:46:35 +03:00
Matthias Krüger
6ab546e034
Rollup merge of #119655 - Nilstrieb:cleanup-the-error-count-monster-mess, r=WaffleLapkin
Remove ignore-stage1 that was added when changing error count msg

The bootstrap bump has happened, so the bootstrap compiler now contains the new diagnostic.

this was added in #118138
2024-01-06 16:07:49 +01:00
Matthias Krüger
1d6ab69ab1
Rollup merge of #119624 - petrochenkov:dialoc4, r=compiler-errors
rustc_span: More consistent span combination operations

Also add more tests for using `tt` in addition to `ident`, and some other minor tweaks, see individual commits.

This is a part of https://github.com/rust-lang/rust/pull/119412 that doesn't yet add side tables for metavariable spans.
2024-01-06 16:07:48 +01:00
Matthias Krüger
909f2b63a3
Rollup merge of #119591 - Enselic:DestinationPropagation-stable, r=cjgillot
rustc_mir_transform: Make DestinationPropagation stable for queries

By using `FxIndexMap` instead of `FxHashMap`, so that the order of visiting of locals is deterministic.

We also need to bless
`copy_propagation_arg.foo.DestinationPropagation.panic*.diff`. Do not review the diff of the diff. Instead look at the diff files before and after this commit. Both before and after this commit, 3 statements are replaced with nop. It's just that due to change in ordering, different statements are replaced. But the net result is the same. In other words, compare this diff (before fix):
* 090d5eac72/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

With this diff (after fix):
* f603babd63/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

and you can see that both before and after the fix, we replace 3 statements with `nop`s.

I find it _slightly_ surprising that the test this PR affects did not previously fail spuriously due to the indeterminism of `FxHashMap`, but I guess in can be explained with the predictability of small `FxHashMap`s with `usize` (`Local`) keys, or something along those lines.

This should fix [this](https://github.com/rust-lang/rust/pull/119252#discussion_r1436101791) comment, but I wanted to make a separate PR for this fix for a simpler development and review process.

Part of https://github.com/rust-lang/rust/issues/84447 which is E-help-wanted.

r? `@cjgillot` who is reviewer for the highly related PR https://github.com/rust-lang/rust/pull/119252.
2024-01-06 16:07:47 +01:00
Matthias Krüger
923578e6f9
Rollup merge of #118781 - RalfJung:core-panic-feature, r=the8472
merge core_panic feature into panic_internals

I don't know why those are two separate features, but it does not seem intentional. This merge is useful because with https://github.com/rust-lang/rust/pull/118123, panic_internals is recognized as an internal feature, but core_panic is not -- but core_panic definitely should be internal.
2024-01-06 16:07:46 +01:00
Matthias Krüger
d5fd88cb85
Rollup merge of #118194 - notriddle:notriddle/tuple-unit, r=GuillaumeGomez
rustdoc: search for tuples and unit by type with `()`

This feature extends rustdoc to support the syntax that most users will naturally attempt to use to search for tuples. Part of https://github.com/rust-lang/rust/issues/60485

Function signature searches already support tuples and unit. The explicit name `primitive:tuple` and `primitive:unit` can be used to match a tuple or unit, while `()` will match either one. It also follows the direction set by the actual language for parens as a group, so `(u8,)` will only match a tuple, while `(u8)` will match a plain, unwrapped byte—thanks to loose search semantics, it will also match the tuple.

## Preview

* [`option<t>, option<u> -> (t, u)`](<https://notriddle.com/rustdoc-html-demo-5/tuple-unit/std/index.html?search=option%3Ct%3E%2C option%3Cu%3E -%3E (t%2C u)>)
* [`[t] -> (t,)`](<https://notriddle.com/rustdoc-html-demo-5/tuple-unit/std/index.html?search=[t] -%3E (t%2C)>)
* [`(ipaddr,) -> socketaddr`](<https://notriddle.com/rustdoc-html-demo-5/tuple-unit/std/index.html?search=(ipaddr%2C) -%3E socketaddr>)

## Motivation

When type-based search was first landed, it was directly [described as incomplete][a comment].

[a comment]: https://github.com/rust-lang/rust/pull/23289#issuecomment-79437386

Filling out the missing functionality is going to mean adding support for more of Rust's [type expression] syntax, such as tuples (in this PR), references, raw pointers, function pointers, and closures.

[type expression]: https://doc.rust-lang.org/reference/types.html#type-expressions

There does seem to be demand for this sort of thing, such as [this Discord message](https://discord.com/channels/442252698964721669/443150878111694848/1042145740065099796) expressing regret at rustdoc not supporting tuples in search queries.

## Reference description (from the Rustdoc book)

<table>
<thead>
  <tr>
    <th>Shorthand</th>
    <th>Explicit names</th>
  </tr>
</thead>
<tbody>
  <tr><td colspan="2">Before this PR</td></tr>
  <tr>
    <td><code>[]</code></td>
    <td><code>primitive:slice</code> and/or <code>primitive:array</code></td>
  </tr>
  <tr>
    <td><code>[T]</code></td>
    <td><code>primitive:slice&lt;T&gt;</code> and/or <code>primitive:array&lt;T&gt;</code></td>
  </tr>
  <tr>
    <td><code>!</code></td>
    <td><code>primitive:never</code></td>
  </tr>
  <tr><td colspan="2">After this PR</td></tr>
  <tr>
    <td><code>()</code></td>
    <td><code>primitive:unit</code> and/or <code>primitive:tuple</code></td>
  </tr>
  <tr>
    <td><code>(T)</code></td>
    <td><code>T</code></td>
  </tr>
  <tr>
    <td><code>(T,)</code></td>
    <td><code>primitive:tuple&lt;T&gt;</code></td>
  </tr>
</tbody>
</table>

A single type expression wrapped in parens is the same as that type expression, since parens act as the grouping operator. If they're empty, though, they will match both `unit` and `tuple`, and if there's more than one type (or a trailing or leading comma) it is the same as `primitive:tuple<...>`.

However, since items can be left out of the query, `(T)` will still return results for types that match tuples, even though it also matches the type on its own. That is, `(u32)` matches `(u32,)` for the exact same reason that it also matches `Result<u32, Error>`.

## Future direction

The [type expression grammar](https://doc.rust-lang.org/reference/types.html#type-expressions) from the Reference is given below:

<pre><code>Syntax
    Type :
        TypeNoBounds
        | <a href="https://doc.rust-lang.org/reference/types/impl-trait.html">ImplTraitType</a>
        | <a href="https://doc.rust-lang.org/reference/types/trait-object.html">TraitObjectType</a>
<br>
    TypeNoBounds :
        <a href="https://doc.rust-lang.org/reference/types.html#parenthesized-types">ParenthesizedType</a>
        | <a href="https://doc.rust-lang.org/reference/types/impl-trait.html">ImplTraitTypeOneBound</a>
        | <a href="https://doc.rust-lang.org/reference/types/trait-object.html">TraitObjectTypeOneBound</a>
        | <a href="https://doc.rust-lang.org/reference/paths.html#paths-in-types">TypePath</a>
        | <a href="https://doc.rust-lang.org/reference/types/tuple.html#tuple-types">TupleType</a>
        | <a href="https://doc.rust-lang.org/reference/types/never.html">NeverType</a>
        | <a href="https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut">RawPointerType</a>
        | <a href="https://doc.rust-lang.org/reference/types/pointer.html#shared-references-">ReferenceType</a>
        | <a href="https://doc.rust-lang.org/reference/types/array.html">ArrayType</a>
        | <a href="https://doc.rust-lang.org/reference/types/slice.html">SliceType</a>
        | <a href="https://doc.rust-lang.org/reference/types/inferred.html">InferredType</a>
        | <a href="https://doc.rust-lang.org/reference/paths.html#qualified-paths">QualifiedPathInType</a>
        | <a href="https://doc.rust-lang.org/reference/types/function-pointer.html">BareFunctionType</a>
        | <a href="https://doc.rust-lang.org/reference/macros.html#macro-invocation">MacroInvocation</a>
</code></pre>

ImplTraitType and TraitObjectType (and ImplTraitTypeOneBound and TraitObjectTypeOneBound) are not yet implemented. They would mostly desugar to `trait:`, similarly to how `!` desugars to `primitive:never`.

ParenthesizedType and TuplePath are added in this PR.

TypePath is already implemented (except const generics, which is not planned, and function-like trait syntax, which is planned as part of closure support).

NeverType is already implemented.

RawPointerType and ReferenceType require parsing and fixes to the search index to store this information, but otherwise their behavior seems simple enough. Just like tuples and slices, `&T` would be equivalent to `primitive:reference<T>`, `&mut T` would be equivalent to `primitive:reference<keyword:mut, T>`, `*T` would be equivalent to `primitive:pointer<T>`, `*mut T` would be equivalent to `primitive:pointer<keyword:mut, T>`, and `*const T` would be equivalent to `primitive:pointer<keyword:const, T>`. Lifetime generics support is not planned, because lifetime subtyping seems too complicated.

ArrayType is subsumed by SliceType right now. Implementing const generics is not planned, because it seems like it would require a lot of implementation complexity for not much gain.

InferredType isn't really covered right now. Its semantics in a search context are not obvious.

QualifiedPathInType is not implemented, and it is not planned. I would need a use case to justify it, and act as a guide for what the exact semantics should be.

BareFunctionType is not implemented. Along with function-like trait syntax, which is formally considered a TypePath, it's the biggest missing feature to be able to do structured searches over generic APIs like `Option`.

MacroInvocation is not parsed (macro names are, but they don't mean the same thing here at all). Those are gone by the time Rustdoc sees the source code.
2024-01-06 16:07:46 +01:00
Ralf Jung
42921900a3 remove an unnecessary stderr-per-bitwidth 2024-01-06 14:54:08 +01:00
AngelicosPhosphoros
8f432d4ae6 Add assume into NonZeroIntX::get
LLVM currently don't support range metadata for function arguments so it fails to optimize non zero integers using their invariant if they are provided using by-value function arguments.

Related to https://github.com/rust-lang/rust/issues/119422
Related to https://github.com/llvm/llvm-project/issues/76628
Related to https://github.com/rust-lang/rust/issues/49572
2024-01-06 14:26:37 +01:00
Nilstrieb
5c74329887 Remove ignore-stage1 that was added when changing error count msg
The bootstrap bump has happened, so the bootstrap compiler now contains
the new diagnotic.
2024-01-06 12:53:06 +01:00
bors
e21f4cd98f Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiser
Avoid specialization in the metadata serialization code

With the exception of a perf-only specialization for byte slices and byte vectors.

This uses the same trick of introducing a new trait and having the Encodable and Decodable derives add a bound to it as used for TyEncoder/TyDecoder. The new code is clearer about which encoder/decoder uses which impl and it reduces the dependency of rustc on specialization, making it easier to remove support for specialization entirely or turn it into a construct that is only allowed for perf optimizations if we decide to do this.
2024-01-06 09:56:00 +00:00
Michael Goulet
61c776ae0a
Rollup merge of #119638 - lukas-code:suggest-constructor-cycle-error, r=cjgillot
fix cyle error when suggesting to use associated function instead of constructor

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

The first commit fixes the infinite recursion and makes the cycle error actually show up. We do this by making the `Display` for `ty::Instance` impl  respect `with_no_queries` so that it can be used in query descriptions.

The second commit fixes the cycle error `resolver_for_lowering` -> `normalize` -> `resolve_instance` (for evaluating const) -> `lang_items` (for `drop_in_place`) -> `resolver_for_lowering` (for collecting lang items). We do this by simply skipping the suggestion when encountering an unnormalized type.
2024-01-05 23:41:43 -05:00
Michael Goulet
a95a363dba
Rollup merge of #119628 - RalfJung:duplicate-test, r=compiler-errors
remove duplicate test

This was added in ace6fc3646 where overflowing-rsh-6 differed from overflowing-rsh-5 in a feature gate, but the feature has since been stabilized, making the tests 100% identical.

Most of these tests in numbers-arithmetic could be put into one file rather than having so many files that all test the same lint... but it doesn't seem worth the effort. After https://github.com/rust-lang/rust/pull/119432 we might be able to remove most of them entirely as they will be covered by the new tests added there.
2024-01-05 23:41:43 -05:00
Michael Goulet
9585ebc269
Rollup merge of #119420 - cjgillot:issue-119295, r=compiler-errors
Handle ForeignItem as TAIT scope.

Fixes #119295
2024-01-05 23:41:42 -05:00
Michael Goulet
d90c702566
Rollup merge of #119216 - weiznich:use_diagnostic_namespace_in_stdlib, r=compiler-errors
Use diagnostic namespace in stdlib

This required a minor fix to have the diagnostics shown in third party crates when the `diagnostic_namespace` feature is not enabled. See 5d63f5d8d1 for details. I've opted for having a single PR for both changes as it's really not that much code. If it is required it should be easy to split up the change into several PR's.

r? `@compiler-errors`
2024-01-05 23:41:41 -05:00
Michael Goulet
bacddd3e5d
Rollup merge of #119208 - Zalathar:hoist, r=WaffleLapkin,Swatinem
coverage: Hoist some complex code out of the main span refinement loop

The span refinement loop in `spans.rs` takes the spans that have been extracted from MIR, and modifies them to produce more helpful output in coverage reports.

It is also one of the most complicated pieces of code in the coverage instrumentor. It has an abundance of moving pieces that make it difficult to understand, and most attempts to modify it end up accidentally changing its behaviour in unacceptable ways.

This PR nevertheless tries to make a dent in it by hoisting two pieces of special-case logic out of the main loop, and into separate preprocessing passes. Coverage tests show that the resulting mappings are *almost* identical, with all known differences being unimportant.

This should hopefully unlock further simplifications to the refinement loop, since it now has fewer edge cases to worry about.
2024-01-05 23:41:41 -05:00
Obei Sideg
18edf9a64e Add test for E0796 and static_mut_ref lint 2024-01-06 06:31:36 +03:00
Camille GILLOT
eeaea57600 Rebase fallout. 2024-01-05 21:54:41 +00:00
Camille GILLOT
7366bdaea2 Handle ForeignItem as TAIT scope. 2024-01-05 21:49:37 +00:00
Lukas Markeffsky
339fa311ad fix cycle error for "use constructor" suggestion 2024-01-05 21:56:32 +01:00
Lukas Markeffsky
274674819c fix OOM when ty::Instance is used in query description 2024-01-05 21:55:29 +01:00
Martin Nordholts
95eb5bcb67 rustc_mir_transform: Make DestinationPropagation stable for queries
By using FxIndexMap instead of FxHashMap, so that the order of visiting
of locals is deterministic.

We also need to bless
copy_propagation_arg.foo.DestinationPropagation.panic*.diff. Do not
review the diff of the diff. Instead look at the diff file before and
after this commit. Both before and after this commit, 3 statements are
replaced with nop. It's just that due to change in ordering, different
statements are replaced. But the net result is the same.
2024-01-05 20:55:32 +01:00
Matthias Krüger
a060ed2c06
Rollup merge of #119622 - Nadrieril:never_patterns_macros, r=compiler-errors
never patterns: Document behavior of never patterns with macros-by-example

`never_patterns` makes `!` parse as a pattern so I was worried about breaking macros-by-example matching. Turns out we're fine because the cases that now match `$p:pat` used to error in the past. The only tricky case is `!` by itself, which backwards-compatibly doesn't match `$p:pat`. I have no idea why tho, I didn't think of that when I was implementing parsing 😅.

This adds tests so we don't regress the current behavior.

r? `@compiler-errors`
2024-01-05 20:39:54 +01:00
Matthias Krüger
ad7aabd965
Rollup merge of #119563 - compiler-errors:coroutine-resume, r=oli-obk
Check yield terminator's resume type in borrowck

In borrowck, we didn't check that the lifetimes of the `TerminatorKind::Yield`'s `resume_place` were actually compatible with the coroutine's signature. That means that the lifetimes were totally going unchecked. Whoops!

This PR implements this checking.

Fixes #119564

r? types
2024-01-05 20:39:53 +01:00
Matthias Krüger
958417fba1
Rollup merge of #119554 - matthewjasper:remove-guard-distinction, r=compiler-errors
Fix scoping for let chains in match guards

If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards.

- Remove `hir::Guard` and `thir::Guard`.
- Make the scoping different between normal guards and if let guards also check for let chains.

closes #118593
2024-01-05 20:39:52 +01:00
Matthias Krüger
8309063e0a
Rollup merge of #119506 - compiler-errors:visibilities-for-object-safety-error, r=Nilstrieb
Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`

Inside of `report_object_error`, using the `effective_visibilities` query causes cycles since it calls `type_of`, which itself may call `typeck`, which may end up reporting its own object-safety errors.

Fixes #119346
Fixes #119502
2024-01-05 20:39:52 +01:00
Matthias Krüger
ea6129084e
Rollup merge of #119354 - fmease:negative_bounds-fixes, r=compiler-errors
Make `negative_bounds` internal & fix some of its issues

r? compiler-errors
2024-01-05 20:39:51 +01:00
Matthias Krüger
fc591dbc94
Rollup merge of #119350 - fmease:lazy-ty-aliases-implied-bounds, r=compiler-errors
Imply outlives-bounds on lazy type aliases

Fixes #118479.

r? types
2024-01-05 20:39:51 +01:00
Matthias Krüger
3a0536ab51
Rollup merge of #119151 - Jules-Bertholet:no-foreign-doc-hidden-suggest, r=davidtwco
Hide foreign `#[doc(hidden)]` paths in import suggestions

Stops the compiler from suggesting to import foreign `#[doc(hidden)]` paths.

```@rustbot``` label A-suggestion-diagnostics
2024-01-05 20:39:50 +01:00
León Orell Valerian Liehr
54967d7a68
Ignore a rustdoc test 2024-01-05 20:33:16 +01:00
Nadrieril
718a4337ac Document behavior of ! with MbE 2024-01-05 19:24:44 +01:00
Ralf Jung
97c8238511 remove duplicate test 2024-01-05 18:49:25 +01:00
bors
11035f9f52 Auto merge of #119621 - compiler-errors:rollup-5mxtvuk, r=compiler-errors
Rollup of 10 pull requests

Successful merges:

 - #119034 (Allow coverage tests to ignore test modes, and to enable color in coverage reports)
 - #119148 (Tweak suggestions for bare trait used as a type)
 - #119538 (Cleanup error handlers: round 5)
 - #119566 (Remove `-Zdump-mir-spanview`)
 - #119567 (Remove `-Zreport-delayed-bugs`.)
 - #119577 (Migrate memory overlap check from validator to lint)
 - #119583 (Make `intrinsics::assume` const stable)
 - #119586 ([rustdoc] Fix invalid handling for static method calls in jump to definition feature)
 - #119588 (Move `i586-unknown-netbsd` from tier 2 to tier 3 platform support table)
 - #119601 (`Emitter` cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-05 16:31:05 +00:00
Vadim Petrochenkov
c586fe40f1 macro_rules: Add more tests for using tt in addition to ident
Generally, `tt` and `ident` should behave identically, modulo the latter accepting only a subset of token trees.
2024-01-05 19:13:52 +03:00
Michael Goulet
da700b39df
Rollup merge of #119601 - nnethercote:Emitter-cleanups, r=oli-obk
`Emitter` cleanups

Some improvements I found while looking at this code.

r? `@oli-obk`
2024-01-05 10:57:24 -05:00
Michael Goulet
3f19de6352
Rollup merge of #119586 - GuillaumeGomez:jump-to-def-static-methods, r=notriddle
[rustdoc] Fix invalid handling for static method calls in jump to definition feature

I realized when working on a clippy lint that static method calls on `Self` could not give me the method `Res`. For that, we need to use `typeck` and so that's what I did in here.

It fixes the linking to static method calls.

r? ````@notriddle````
2024-01-05 10:57:23 -05:00