Commit Graph

424 Commits

Author SHA1 Message Date
Ben Kimock
18b0a07d49 Handle a few more simple tests 2024-05-20 11:13:10 -04:00
bors
36c0a6d40f Auto merge of #125105 - nnethercote:rustc_resolve-cleanups, r=estebank
`rustc_resolve` cleanups

Some improvements I found while looking through this code.

r? `@estebank`
2024-05-18 06:36:44 +00:00
Matthias Krüger
e62688eb96
Rollup merge of #123694 - Xiretza:expand-diagnostics, r=compiler-errors
expand: fix minor diagnostics bug

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

```
error[E0658]: attributes on expressions are experimental
 --> test.rs:4:9
  |
4 |         //! wah
  |         ^^^^^^^
  |
  = note: see issue https://github.com/rust-lang/rust/issues/15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = help: `///` is for documentation comments. For a plain comment, use `//`.
```
2024-05-17 07:20:56 +02:00
David Tolnay
0ca322c774
Add test of unused_parens lint involving macro calls 2024-05-11 15:49:03 -07:00
Ben Kimock
2bb25d3f4a Handle Deref expressions in invalid_reference_casting 2024-05-10 12:33:07 -04:00
Nicholas Nethercote
5134a04eaa Remove ordinalize.
Some minor (English only) heroics are performed to print error messages
like "5th rule of macro `m` is never used". The form "rule #5 of macro
`m` is never used" is just as good and much simpler to implement.
2024-05-10 16:42:09 +10:00
Ben Kimock
0ca1a94b2b Handle field projections like slice indexing in invalid_reference_casting 2024-05-08 17:21:06 -04:00
Matthias Krüger
9fce3dc685
Rollup merge of #124761 - Urgau:ref-casting_bigger_slice_index, r=jieyouxu
Fix insufficient logic when searching for the underlying allocation

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

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

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

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

r? ghost

Original PR description:

---

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

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

Additional ABI and codegen tests were added in https://github.com/rust-lang/rust/pull/115372
2024-05-06 00:55:49 +00:00
Urgau
cd6a0c8c77 Fix insufficient logic when searching for the underlying allocation
in the `invalid_reference_casting` lint, when trying to lint on
bigger memory layout casts.
2024-05-05 19:14:20 +02:00
bors
378a43a065 Auto merge of #124539 - Urgau:non-local-defs_modulo_modules, r=lcnr
Consider inner modules to be local in the `non_local_definitions` lint

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

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

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

Fixes *(nearly, needs backport)* https://github.com/rust-lang/rust/issues/124396
2024-05-01 06:21:31 +00:00
bors
74a8df6c65 Auto merge of #124398 - klensy:trailing-ws, r=compiler-errors
tests: remove some trailing ws

Cleans one more case of trailing whitespace in tests.
2024-04-30 00:42:32 +00:00
Urgau
21c688af86 Consider inner modules to be local in the non_local_definitions lint 2024-04-29 22:54:04 +02:00
Gurinder Singh
254a9fbe86 Prohibit const prop of unions in KnownPanicsLint
as they have a potential to ICE during layout calculation
2024-04-29 08:16:26 +05:30
klensy
411607bec4 tests: remove some trailing ws 2024-04-27 10:54:31 +03:00
Gary Guo
cfee72aa24 Fix tests and bless 2024-04-24 13:12:33 +01:00
Oli Scherer
aef0f4024a Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
2024-04-24 08:05:29 +00:00
Arvind Mukund
ed532cc186 Put the RFC behind a feature gate result_ffi_guarantees 2024-04-23 21:30:59 -07:00
Arvind Mukund
b3f6511755 Add a test against Result<(), ()> 2024-04-23 21:27:45 -07:00
Arvind Mukund
014ddac9c9 Disallow single-variant enums
Couldn't find documentation supporting that single-variant
`#[repr(Rust)]` enums with RHS assigned work as expected with this
change.

```rust
enum Variants {
  A = 17,
} // Would this be zero sized optimized guaranteed?
```
2024-04-23 21:27:44 -07:00
Arvind Mukund
223d5eb64f Add tests
Tests both `T` and `E` for niche variant optimization lints
2024-04-23 21:26:04 -07:00
Matthias Krüger
57dad1d75e
Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco
Disallow ambiguous attributes on expressions

This implements the suggestion in [#15701](https://github.com/rust-lang/rust/issues/15701#issuecomment-2033124217) to disallow ambiguous outer attributes on expressions. This should resolve one of the concerns blocking the stabilization of `stmt_expr_attributes`.
2024-04-23 12:10:26 +02:00
Matthias Krüger
d5cfc5c07a
Rollup merge of #123680 - compiler-errors:gen-kw, r=Nadrieril
Deny gen keyword in `edition_2024_compat` lints

Splits the `keyword_idents` lint into two -- `keyword_idents_2018` and `keyword_idents_2024` -- since each corresponds to a future-compat warning in a different edition. Group these together into a new `keyword_idents` lint group, and add the latter to the `rust_2024_compatibility` so that `gen` is ready for the 2024 edition.

cc `@traviscross` `@ehuss`
2024-04-23 06:24:55 +02:00
Markus Reiter
33e68aadc9
Stabilize generic NonZero. 2024-04-22 18:48:47 +02:00
Xiretza
bfacfe2510 expand: fix minor diagnostics bug
The error mentions `///`, when it's actually `//!`:

error[E0658]: attributes on expressions are experimental
 --> test.rs:4:9
  |
4 |         //! wah
  |         ^^^^^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = help: `///` is for documentation comments. For a plain comment, use `//`.
2024-04-22 16:28:20 +00:00
Michael Goulet
7789874e6e Deny gen keyword in edition_2024_compat lints 2024-04-22 11:51:50 -04:00
bors
f22a0c2d9f Auto merge of #123594 - Urgau:fix-non_local_def-lint-overflow, r=lcnr
Fix trait solver overflow with `non_local_definitions` lint

This PR fixes the trait solver overflow with the `non_local_definitions` lint reported in https://github.com/rust-lang/rust/issues/123573 using the suggestion from `@lcnr:` https://github.com/rust-lang/rust/issues/123573#issuecomment-2041348320 to use the next trait solver.

~~I have not (yet) tried to create a minimized repro~~ ``@compiler-errors`` did the minimization (thanks you) but I have manually tested on the `starlark-rust` project that it fixes the issue.

Fixes #123573
r? `@lcnr`
2024-04-21 17:02:03 +00:00
Dominik Stolz
5af861cf7b Disallow ambiguous attributes on expressions 2024-04-18 20:42:19 +02:00
Ben Kimock
7457a0d441 Use the rustc_private libc less in tests 2024-04-15 08:54:11 -04:00
Michael Goulet
0db2a4010a Silence unused_imports lint for redundant imports 2024-04-11 14:38:21 -04:00
surechen
c8490a0608 skip unused_parens's suggestion for Paren in macro.
fixes #120642
2024-04-10 17:56:43 +08:00
Urgau
c2e2245fd8 Fix trait solver overflow with non_local_definitions lint 2024-04-09 18:40:04 +02:00
Guillaume Gomez
b3f40e3448
Rollup merge of #123653 - Urgau:split-test-non_local_defs, r=compiler-errors
Split `non_local_definitions` lint tests in separate test files

This PR splits the giant `non_local_definitions` lint UI test in separate test files.

This change is extracted from #123594 (where it was requested https://github.com/rust-lang/rust/pull/123594#discussion_r1555261772), to ease the review of the other PR and to reduce the size of the other PR.

r? ``@compiler-errors``
2024-04-09 13:39:22 +02:00
Urgau
ddc16e98e6 Split non_local_definitions lint tests in separate test files 2024-04-09 00:42:48 +02:00
Urgau
c4a97d9407 Unify all the always-false cfgs under the FALSE cfg 2024-04-07 01:16:45 +02:00
Urgau
2f2d5cc38d Put non_local_definitions lint back to warn-by-default 2024-04-05 19:25:58 +02:00
Urgau
8edf2558d2 Update non-local impl definition lint rule note 2024-04-05 19:25:58 +02:00
Urgau
a1d7bff7ef Eliminate false-positives in the non-local lint with the type-system 2024-04-05 19:25:43 +02:00
joboet
989660c3e6
rename expose_addr to expose_provenance 2024-04-03 16:00:38 +02:00
Jacob Pratt
e9ef8e1efa
Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=Amanieu
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance

As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066).

The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".)

The new name nicely matches `ptr::without_provenance`.
2024-04-02 20:37:39 -04:00
Urgau
16d11c539f Add support for NonNull in ambiguous_wide_ptr_comparisions 2024-03-29 22:02:07 +01:00
Urgau
d4b514f982 Add detection of [Partial]Ord methods to the ambiguous wide ptr cmp lint 2024-03-29 16:36:17 +01:00
Ralf Jung
67b9d7d184 rename ptr::from_exposed_addr -> ptr::with_exposed_provenance 2024-03-23 13:18:33 +01:00
bors
c308726599 Auto merge of #119552 - krtab:dead_code_priv_mod_pub_field, r=cjgillot,saethlin
Replace visibility test with reachability test in dead code detection

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

Also included is a fix for an error now flagged by the lint
2024-03-23 00:37:05 +00:00
bors
47dd709bed Auto merge of #121123 - compiler-errors:item-assumptions, r=oli-obk
Split an item bounds and an item's super predicates

This is the moral equivalent of #107614, but instead for predicates this applies to **item bounds**. This PR splits out the item bounds (i.e. *all* predicates that are assumed to hold for the alias) from the item *super predicates*, which are the subset of item bounds which share the same self type as the alias.

## Why?

Much like #107614, there are places in the compiler where we *only* care about super-predicates, and considering predicates that possibly don't have anything to do with the alias is problematic. This includes things like closure signature inference (which is at its core searching for `Self: Fn(..)` style bounds), but also lints like `#[must_use]`, error reporting for aliases, computing type outlives predicates.

Even in cases where considering all of the `item_bounds` doesn't lead to bugs, unnecessarily considering irrelevant bounds does lead to a regression (#121121) due to doing extra work in the solver.

## Example 1 - Trait Aliases

This is best explored via an example:

```
type TAIT<T> = impl TraitAlias<T>;

trait TraitAlias<T> = A + B where T: C;
```

The item bounds list for `Tait<T>` will include:
* `Tait<T>: A`
* `Tait<T>: B`
* `T: C`

While `item_super_predicates` query will include just the first two predicates.

Side-note: You may wonder why `T: C` is included in the item bounds for `TAIT`? This is because when we elaborate `TraitAlias<T>`, we will also elaborate all the predicates on the trait.

## Example 2 - Associated Type Bounds

```
type TAIT<T> = impl Iterator<Item: A>;
```

The `item_bounds` list for `TAIT<T>` will include:
* `Tait<T>: Iterator`
* `<Tait<T> as Iterator>::Item: A`

But the `item_super_predicates` will just include the first bound, since that's the only bound that is relevant to the *alias* itself.

## So what

This leads to some diagnostics duplication just like #107614, but none of it will be user-facing. We only see it in the UI test suite because we explicitly disable diagnostic deduplication.

Regarding naming, I went with `super_predicates` kind of arbitrarily; this can easily be changed, but I'd consider better names as long as we don't block this PR in perpetuity.
2024-03-21 06:12:24 +00:00
Michael Goulet
aa39dbb962 Split item bounds and item super predicates 2024-03-20 13:00:34 -04:00
Alex Macleod
a8452461dc Ignore paths from expansion in unused_qualifications 2024-03-20 16:30:26 +00:00
Matthias Krüger
489c2e9918
Rollup merge of #122435 - jieyouxu:unused_qualifications_global_paths, r=petrochenkov
Don't trigger `unused_qualifications` on global paths

Fixes #122374.
2024-03-19 18:03:49 +01:00
Michael Goulet
0db06bf004 Detect allocator for box in must_not_suspend lint 2024-03-18 14:12:28 -04:00
许杰友 Jieyou Xu (Joe)
60de7554de
Invoke decorate when error level is beyond warning, including error 2024-03-17 14:41:37 +00:00