Commit Graph

1588 Commits

Author SHA1 Message Date
Michael Goulet
086cf34634 Don't ICE when computing ctype's repr_nullable_ptr for possibly-unsized ty 2023-09-07 06:04:37 +00:00
bors
4e5b31c2b0 Auto merge of #115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, r=est31
Lint on invalid usage of `UnsafeCell::raw_get` in reference casting

This PR proposes to take into account `UnsafeCell::raw_get` method call for non-Freeze types for the `invalid_reference_casting` lint.

The goal of this is to catch those kind of invalid reference casting:
```rust
fn as_mut<T>(x: &T) -> &mut T {
    unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) }
    //~^ ERROR casting `&T` to `&mut T` is undefined behavior
}
```

r? `@est31`
2023-09-07 00:24:45 +00:00
Matthias Krüger
93543bc8bc
Rollup merge of #115578 - ouz-a:rustc_clarify, r=oli-obk
Clarify cryptic comments

Clarifies some unclear comments that lurked in the compiler.

r? ``@oli-obk``
2023-09-06 19:31:49 +02:00
ouz-a
7928c5f830 make comments less cryptic 2023-09-06 12:09:29 +03:00
Gurinder Singh
10f4917568 Emit unused doc comment warnings for pat and expr fields 2023-09-03 08:21:18 +05:30
Matthias Krüger
888dc2e3b0
Rollup merge of #115424 - notriddle:notriddle/issue-106413, r=oli-obk
diagnostics: avoid wrong `unused_parens` on `x as (T) < y`

Fixes #106413
Fixes #80636
2023-09-01 21:41:39 +02:00
bors
1accf068d8 Auto merge of #113126 - Bryanskiy:delete_old, r=petrochenkov
Replace old private-in-public diagnostic with type privacy lints

Next part of RFC https://github.com/rust-lang/rust/issues/48054.

r? `@petrochenkov`
2023-09-01 12:40:01 +00:00
Michael Howell
ba9af10846
Use terminology more sensibly 2023-08-31 22:40:43 -07:00
Michael Howell
62835c9531 diagnostics: avoid wrong unused_parens on x as (T) < y 2023-08-31 20:14:49 -07:00
Weihang Lo
a11805ae46
feat(rustc_lint): make CheckLintName respect lint level 2023-08-30 19:24:44 +01:00
Weihang Lo
cdbad43aba
refactor(rustc_lint): inline check_lint_name_cmdline 2023-08-30 17:35:07 +01:00
Ralf Jung
d1c4fe94c3 some more is_zst that should be is_1zst 2023-08-29 14:11:27 +02:00
Weihang Lo
1d526692d4
Rollup merge of #115152 - weihanglo:lint-refactor, r=compiler-errors
refactor(lint): translate `RenamedOrRemovedLint`

I was trying to address <https://github.com/rust-lang/cargo/issues/12495> and found that maybe I should refactor relevant lints a bit.

This PR translates `RenamedOrRemovedLint` into fluent file. To make diagnostic types clearer and easier to organize, this PR splits it into two structs.

The second commit adds lifetime annotations for removing unnecessary clones. If people feel too noisy, we can revert such change.

### Possibly relevant UI tests:

* `tests/ui/lint-removed*`
* `tests/ui/lint-renamed*`
* `tests/ui/rustdoc-renamed.rs`
* `tests/rustdoc-ui/lints/unknown-renamed-lints.rs`
2023-08-24 22:53:59 +01:00
Urgau
89800a27fc Lint on invalid UnsafeCell::raw_get with invalid_reference_casting lint 2023-08-24 15:00:21 +02:00
bors
8a6b67f988 Auto merge of #115094 - Mark-Simulacrum:bootstrap-update, r=ozkanonur
Update bootstrap compiler to 1.73.0 beta
2023-08-24 11:10:52 +00:00
Weihang Lo
73152a3efb
refactor: use references to reduce unnecessary clones 2023-08-24 01:09:55 +01:00
Weihang Lo
81a24922e7
lint: translate RenamedOrRemovedLint 2023-08-24 01:09:46 +01:00
Mark Rousskov
0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
Urgau
aa7730003e Improve note for the invalid_reference_casting lint
Add link to the book interior mutability chapter,
https://doc.rust-lang.org/book/ch15-05-interior-mutability.html.
2023-08-23 11:27:33 +02:00
Dylan DPC
7257e9c2de
Rollup merge of #115100 - Urgau:invalid_ref_casting-ptr-writes, r=est31
Add support for `ptr::write`s for the `invalid_reference_casting` lint

This PR adds support for `ptr::write` and others for the `invalid_reference_casting` lint.

Detecting instances where instead of using the deref (`*`) operator to assign someone uses `ptr::write`, `ptr::write_unaligned` or `ptr::write_volatile`.

```rust
let data_len = 5u64;

std::ptr::write(
    std::mem::transmute::<*const u64, *mut u64>(&data_len),
    new_data_len,
);
```

r? ``@est31``
2023-08-23 05:35:17 +00:00
Michael Goulet
e9897c3a71
Rollup merge of #115011 - compiler-errors:warn-on-elided-assoc-ct-lt, r=cjgillot
Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`)

Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since #97313. This is not correct behavior (see #38831).

I originally opened #114716 to fix this, but given the time that has passed, the crater results seem pretty bad: https://github.com/rust-lang/rust/pull/114716#issuecomment-1682091952

This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
2023-08-22 09:00:49 -07:00
Urgau
7ee77b5d1b Add support for ptr::write for the invalid_reference_casting lint 2023-08-22 15:47:29 +02:00
mojave2
d2744175ac
unknown unstable lint command line
fix ##113702

fix #113702

unknown unstable lint command lint

improve impelementation
2023-08-22 18:58:39 +08:00
Michael Goulet
fad7d220fd Warn on elided lifetimes in associated constants 2023-08-20 00:21:47 +00:00
Matthias Krüger
2667d853a6
Rollup merge of #114784 - Urgau:many-improve-invalid_reference_casting-lint, r=est31
Improve `invalid_reference_casting` lint

This PR improves the `invalid_reference_casting` lint:
 - by considering an unlimited number of casts instead only const to mut ptr
 - by also considering ptr-to-integer and integer-to-ptr casts
 - by also taking into account [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast), [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast-1) and [`ptr::cast_const`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_const)

Most of this improvements comes from skimming Github Code Search result for [`&mut \*.*as \*const`](https://github.com/search?q=lang%3Arust+%2F%26mut+%5C*.*as+%5C*const%2F&type=code)

r? ``@est31`` (maybe)
2023-08-16 20:10:37 +02:00
Guillaume Gomez
f0987ab45b
Rollup merge of #114772 - fee1-dead-contrib:typed-did, r=b-naber
Add `{Local}ModDefId` to more strongly type DefIds`

Based on #110862 by `@Nilstrieb`
2023-08-15 14:29:45 +02:00
Urgau
91b05f8e09 Improve invalid_reference_casting lint 2023-08-15 10:14:45 +02:00
yukang
c44b35e1c3 match scrutinee need necessary parentheses for structs 2023-08-14 18:05:13 +08:00
Nilstrieb
c75fc573aa Use {Local}ModDefId in many queries 2023-08-14 07:22:48 +00:00
bors
570601f0aa Auto merge of #114757 - Urgau:transmute-with-invalid_reference_casting, r=est31
Also consider `mem::transmute` with the `invalid_reference_casting` lint

This PR extend the `invalid_reference_casting` lint with regard to the `std::mem::transmute` function.

```
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
  --> $DIR/reference_casting.rs:27:16
   |
LL |     let _num = &mut *std::mem::transmute::<_, *mut i32>(&num);
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

*I encourage anyone reviewing this PR to do so [without whitespaces](https://github.blog/2011-10-21-github-secrets/#whitespace).*
2023-08-13 12:46:00 +00:00
bors
5f3abbc52f Auto merge of #114723 - petrochenkov:noplugin2, r=davidtwco
rustc: Move `features` from `Session` to `GlobalCtxt`

Removes one more piece of mutable state.
Follow up to #114622.

The rule I used for passing feature in function signatures:
- if a crate already depends on `rustc_middle`, then `Session` is replaced with `TyCtxt`
- otherwise session and features are passed as a pair `sess: &Session, features: &Features`

The code in `rustc_lint` is ultimately used for implementing a trait from `rustc_expand`, so it also doesn't use tcx despite the dependency on `rustc_middle`.
2023-08-13 10:59:36 +00:00
Urgau
b517dd5bc9 Also consider transmute with the invalid_reference_casting lint 2023-08-12 13:05:44 +02:00
Vadim Petrochenkov
7353c96be8 rustc: Move features from Session to GlobalCtxt
Removes two pieces of mutable state.
Follow up to #114622.
2023-08-11 16:51:50 +08:00
lcnr
68884665ba downgrade internal_features to warn 2023-08-10 11:51:51 +02:00
est31
4b1bc27010 Improve diagnostics and add tests for function calls 2023-08-06 19:08:14 +02:00
Matthias Krüger
1305a43d0a
Rollup merge of #114486 - Urgau:const-context-nan-suggestion-114471, r=compiler-errors
Avoid invalid NaN lint machine-applicable suggestion in const context

This PR removes the machine-applicable suggestion in const context for the `invalid_nan_comparision` lint ~~and replace it with a simple help~~.

Fixes https://github.com/rust-lang/rust/issues/114471
2023-08-06 03:56:09 +02:00
Michael Goulet
3b3e466e36
Add FIXME as reminder to restore suggestion later 2023-08-05 17:04:30 -07:00
Urgau
b71f2becb2 Avoid invalid NaN lint machine-applicable suggestion in const context 2023-08-05 23:54:59 +02:00
Matthias Krüger
e722f6f3ac
Rollup merge of #114248 - fmease:neg-copy-rules-out-missing-copy-impl, r=b-naber
Make lint missing-copy-implementations honor negative `Copy` impls

Fixes #101980.

``@rustbot`` label A-lint F-negative_impls
2023-08-05 14:00:17 +02:00
bors
67626b8e89 Auto merge of #113734 - cjgillot:no-crate-lint, r=petrochenkov
Convert builtin "global" late lints to run per module

The compiler currently has 4 non-incremental lints:
1. `clashing_extern_declarations`;
2. `missing_debug_implementations`;
3. ~`unnameable_test_items`;~ changed by https://github.com/rust-lang/rust/pull/114414
4. `missing_docs`.

Non-incremental lints get reexecuted for each compilation, which is slow. Moreover, those lints are allow-by-default, so run for nothing most of the time. This PR attempts to make them more incremental-friendly.

`clashing_extern_declarations` is moved to a standalone query.

`missing_debug_implementation` can use `non_blanket_impls_for_ty` instead of recomputing it.

`missing_docs` is harder as it needs to track if there is a `doc(hidden)` module surrounding. I hack around this using the lint level engine. That's easy to implement and allows to re-enable the lint for a re-exported module, while a more proper solution would reuse the same device as `unnameable_test_items`.
2023-08-05 07:20:16 +00:00
est31
8cfa4fe6b2 Add #[rustc_never_returns_null_ptr]
And look for it in the useless_ptr_null_checks lint
2023-08-05 05:16:44 +02:00
bors
e173a8e663 Auto merge of #112117 - bryangarza:track-caller-feature-gate, r=compiler-errors
Add separate feature gate for async fn track caller

This patch adds a feature gate `async_fn_track_caller` that is separate from `closure_track_caller`. This is to allow enabling `async_fn_track_caller` separately.

Fixes #110009
2023-08-04 22:17:59 +00:00
Matthias Krüger
cd5317a000
Rollup merge of #114472 - estebank:issue-76140, r=compiler-errors
Reword `confusable_idents` lint

Fix #76140.
2023-08-04 21:31:59 +02:00
Matthias Krüger
99e4127d85
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.

r? compiler-errors
2023-08-04 21:31:57 +02:00
Esteban Küber
553508c22e Reword confusable idents lint
Fix #76140.
2023-08-04 16:46:08 +00:00
Camille GILLOT
905b63d64f Fetch diagnostic item later. 2023-08-04 16:09:14 +00:00
Camille GILLOT
c0a683ab14 Make rustc internal lints per module. 2023-08-04 16:09:14 +00:00
Camille GILLOT
7c34f1a8d8 Make MissingDoc a module lint. 2023-08-04 16:09:14 +00:00
Camille GILLOT
53e5fd6a61 Make MissingDebugImplementation a module lint. 2023-08-04 16:09:14 +00:00
Camille GILLOT
56063ff2fb Simplify clashing_extern_declarations. 2023-08-04 16:09:13 +00:00
Camille GILLOT
817f45f7bf Querify clashing_extern_declarations lint. 2023-08-04 16:09:13 +00:00
bors
ec5b882c2f Auto merge of #114414 - cjgillot:early-unnameable-test, r=petrochenkov
Make test harness lint about unnnameable tests.

Implementation of https://github.com/rust-lang/rust/pull/113734#discussion_r1283073418

About the options suggested in https://github.com/rust-lang/rust/issues/36629#issuecomment-404753945: adding this case to unused_attribute was just more complicated. I'll try to understand a bit more what you had in mind in https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397241123

This was just simpler to do in a standalone PR. I'll remove the corresponding changes from https://github.com/rust-lang/rust/pull/113734 later.

r? `@petrochenkov`
2023-08-04 14:13:11 +00:00
Nilstrieb
5706be1854 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
bors
1fe384649a Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk
Add `internal_features` lint

Implements https://github.com/rust-lang/compiler-team/issues/596

Also requires some more test blessing for codegen tests etc

`@jyn514` had the idea of just `allow`ing the lint by default in the test suite. I'm not sure whether this is a good idea, but it's definitely one worth considering. Additional input encouraged.
2023-08-03 22:58:02 +00:00
Matthias Krüger
7518ae566e
Rollup merge of #113657 - Urgau:expand-incorrect_fn_null_check-lint, r=cjgillot
Expand, rename and improve `incorrect_fn_null_checks` lint

This PR,

 - firstly, expand the lint by now linting on references
 - secondly, it renames the lint `incorrect_fn_null_checks` -> `useless_ptr_null_checks`
 - and thirdly it improves the lint by catching `ptr::from_mut`, `ptr::from_ref`, as well as `<*mut _>::cast` and `<*const _>::cast_mut`

Fixes https://github.com/rust-lang/rust/issues/113601
cc ```@est31```
2023-08-03 17:29:06 +02:00
Camille GILLOT
2a0a1f918d Make test harness lint about unnnameable tests. 2023-08-03 13:07:30 +00:00
Nilstrieb
5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
Urgau
ee519532f6 Also add label with original type for function pointers 2023-08-03 10:57:11 +02:00
Urgau
4b3dadbe5a Also lint on cast/cast_mut and ptr::from_mut/ptr::from_ref 2023-08-03 10:52:15 +02:00
León Orell Valerian Liehr
2b8a3b44bf
Make lint missing-copy-implementations honor negative Copy impls 2023-08-03 01:37:42 +02:00
Bryan Garza
673ab17c7f Add separate feature gate for async fn track caller
This patch adds a feature gate `async_fn_track_caller` that is separate from `closure_track_caller`. This is to allow enabling `async_fn_track_caller` separately.

Fixes #110009
2023-08-02 14:18:21 -07:00
bors
d170833431 Auto merge of #112431 - Urgau:cast_ref_to_mut_improvments, r=Nilstrieb
Improve `invalid_reference_casting` lint

This PR is a follow-up to https://github.com/rust-lang/rust/pull/111567 and https://github.com/rust-lang/rust/pull/113422.

This PR does multiple things:
 - First it adds support for deferred de-reference, the goal is to support code like this, where the casting and de-reference are not done on the same expression
    ```rust
    let myself = self as *const Self as *mut Self;
    *myself = Self::Ready(value);
    ```
 - Second it does not lint anymore on SB/TB UB code by only checking assignments (`=`, `+=`, ...) and creation of mutable references `&mut *`
 - Thirdly it greatly improves the diagnostics in particular for cast from `&mut` to `&mut` or assignments
 - ~~And lastly it renames the lint from `cast_ref_to_mut` to `invalid_reference_casting` which is more consistent with the ["rules"](https://github.com/rust-lang/rust-clippy/issues/2845) and also more consistent with what the lint checks~~ *https://github.com/rust-lang/rust/pull/113422*

This PR is best reviewed commit by commit.

r? compiler
2023-08-02 11:25:13 +00:00
Bryanskiy
e26614e6a7 Replace old private-in-public diagnostic with type privacy lints 2023-08-02 13:40:28 +03:00
Urgau
d2b7c8028f Rename incorrect_fn_null_checks to useless_ptr_null_checks 2023-08-01 19:35:31 +02:00
Urgau
743ae5a2eb Expand incorrect_fn_null_check lint with reference null checking 2023-08-01 19:35:31 +02:00
Matthias Krüger
f59a5604f9
Rollup merge of #114286 - nbdd0121:upcast, r=compiler-errors
Add missing feature gate in multiple_supertrait_upcastable doc

Fix #112424
2023-07-31 16:57:56 +02:00
Gary Guo
e617faabe7 Add missing feature gate in multiple_supertrait_upcastable doc 2023-07-31 12:28:53 +01:00
León Orell Valerian Liehr
0ca432844c
Check lazy type aliases for well-formedness 2023-07-30 11:24:15 +02:00
Urgau
20a6b57106 Improve diagnostics of the invalid_reference_casting lint 2023-07-29 12:20:59 +02:00
Urgau
50a46710a9 Avoid linting on expression that are only UB with SB/TB 2023-07-29 12:20:59 +02:00
Urgau
f3dafe91ff Add support for deferred casting for the invalid_reference_casting lint 2023-07-29 12:20:59 +02:00
Urgau
345d6b816b Revert "Temporarily switch invalid_reference_casting lint to allow-by-default"
This reverts commit f25ad54a4d.
2023-07-29 12:20:59 +02:00
bors
04411507be Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstrieb
Rename and allow `cast_ref_to_mut` lint

This PR is a small subset of https://github.com/rust-lang/rust/pull/112431, that is the renaming of the lint (`cast_ref_to_mut` -> `invalid_reference_casting`).

BUT also temporarily change the default level of the lint from deny-by-default to allow-by-default until https://github.com/rust-lang/rust/pull/112431 is merged.

r? `@Nilstrieb`
2023-07-29 07:48:44 +00:00
bors
2dc661037d Auto merge of #113099 - bvanjoi:fix-112713-2, r=petrochenkov
fix(resolve): update the ambiguity glob binding as warning recursively

Fixes #47525
Fixes #56593, but `issue-56593-2.rs` is not fixed to ensure backward compatibility.
Fixes #98467
Fixes #105235
Fixes #112713

This PR had added a field called `warn_ambiguous` in `NameBinding` which is only for back compatibly reason and used for lint.

More details: https://github.com/rust-lang/rust/pull/112743

r? `@petrochenkov`
2023-07-29 06:04:41 +00:00
bors
4734ac0943 Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, r=compiler-errors
make `noop_method_call` warn by default

r? `@compiler-errors`
2023-07-29 01:40:50 +00:00
León Orell Valerian Liehr
9213aec762
Lower generic const items to HIR 2023-07-28 22:21:40 +02:00
bohan
cac0bd0bef fix(resolve): update the ambiguity glob binding as warning recursively 2023-07-29 00:19:50 +08:00
Matthias Krüger
fa21a8c6f8
Rollup merge of #114075 - matthiaskrgr:fmt_args_rustc_3, r=wesleywiser
inline format!() args from rustc_codegen_llvm to the end (4)

r? `@WaffleLapkin`
2023-07-27 06:04:13 +02:00
bors
601a34de8c Auto merge of #113457 - davidtwco:lint-ctypes-issue-113436, r=oli-obk
lint/ctypes: fix `()` return type checks

Fixes #113436.

`()` is normally FFI-unsafe, but is FFI-safe when used as a return type. It is also desirable that a transparent newtype for `()` is FFI-safe when used as a return type.

In order to support this, when a type was deemed FFI-unsafe, because of a `()` type, and was used in return type - then the type was considered  FFI-safe. However, this was the wrong approach - it didn't check that the `()` was part of a transparent newtype! The consequence of this is that the presence of a `()` type in a more complex return type would make it the entire type be considered safe (as long as the `()` type was the first that the lint found) - which is obviously incorrect.

Instead, this logic is removed, and after [consultation with t-lang](https://github.com/rust-lang/rust/issues/113436#issuecomment-1640756721), I've fixed the bugs and inconsistencies and  made `()` FFI-safe within types.

I also refactor a function, but that's not too exciting.
2023-07-26 15:27:36 +00:00
Matthias Krüger
c64ef5e070 inline format!() args from rustc_codegen_llvm to the end (4)
r? @WaffleLapkin
2023-07-25 23:20:28 +02:00
Deadbeef
2a76c570d6 add suggestion 2023-07-23 09:58:31 +00:00
Deadbeef
626efab67f fix 2023-07-23 09:58:31 +00:00
Deadbeef
33ec4e4bb0 make noop_method_call warn by default 2023-07-23 07:09:14 +00:00
David Wood
09434a2575
lint/ctypes: only try normalize
Now that this lint runs on any external-ABI fn-ptr, normalization won't
always succeed, so use `try_normalize_erasing_regions` instead.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-21 15:42:25 +01:00
David Wood
24f90fdd26
lint/ctypes: allow () within types
Consider `()` within types to be FFI-safe, and `()` to be FFI-safe as a
return type (incl. when in a transparent newtype).

Signed-off-by: David Wood <david@davidtw.co>
2023-07-19 09:59:04 +01:00
David Wood
99b1897cf6
lint: refactor check_variant_for_ffi
Simplify this function a bit, it was quite hard to reason about.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-19 09:55:10 +01:00
David Wood
f53cef31f5
lint/ctypes: stricter () return type checks
`()` is normally FFI-unsafe, but is FFI-safe when used as a return type.
It is also desirable that a transparent newtype for `()` is FFI-safe when
used as a return type.

In order to support this, when an type was deemed FFI-unsafe, because of
a `()` type, and was used in return type - then the type was considered
FFI-safe. However, this was the wrong approach - it didn't check that the
`()` was part of a transparent newtype! The consequence of this is that
the presence of a `()` type in a more complex return type would make it
the entire type be considered safe (as long as the `()` type was the
first that the lint found) - which is obviously incorrect.

Instead, this logic is removed, and a unit return type or a transparent
wrapper around a unit is checked for directly for functions and fn-ptrs.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-19 09:44:51 +01:00
Matthias Krüger
4bbd7818b5
Rollup merge of #113832 - WaffleLapkin:track_lint_caller, r=compiler-errors
Add `#[track_caller]` to lint related diagnostic functions

This fixes locations reported by `-Ztrack-diagnostics`.
2023-07-18 19:06:04 +02:00
Matthias Krüger
931d9f099a
Rollup merge of #113811 - jieyouxu:fix-unused-qualifications-suggestion, r=oli-obk
Fix removal span calculation of `unused_qualifications` suggestion

Given a path such as `std::ops::Index<str>`, calculate the unnecessary qualification removal span by computing the beginning of the entire span until the ident span of the last path segment, which handles generic arguments and lifetime arguments in the last path segment. Previous logic only kept the ident span of the last path segment which is incorrect.

Closes #113808.
2023-07-18 19:06:02 +02:00
Maybe Waffle
3dd5413bfd Add #[track_caller] to lint related diagnostic functions 2023-07-18 15:48:07 +00:00
许杰友 Jieyou Xu (Joe)
33bd453f35
Fix removal span calculation of unused_qualifications suggestion 2023-07-18 09:52:08 +08:00
Michael Goulet
05f6890b3e Rename arg_iter to iter_instantiated 2023-07-17 21:04:12 +00:00
Mahdi Dibaiee
e55583c4b8 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Matthias Krüger
2cc04536b4
Rollup merge of #112729 - jieyouxu:unused-qualifications-suggestion, r=b-naber
Add machine-applicable suggestion for `unused_qualifications` lint

```
error: unnecessary qualification
  --> $DIR/unused-qualifications-suggestion.rs:17:5
   |
LL |     foo::bar();
   |     ^^^^^^^^
   |
note: the lint level is defined here
  --> $DIR/unused-qualifications-suggestion.rs:3:9
   |
LL | #![deny(unused_qualifications)]
   |         ^^^^^^^^^^^^^^^^^^^^^
help: replace it with the unqualified path
   |
LL |     bar();
   |     ~~~
```

Closes #92198.
2023-07-14 01:03:07 +02:00
Urgau
f25ad54a4d Temporarily switch invalid_reference_casting lint to allow-by-default 2023-07-13 23:01:24 +02:00
Urgau
3dbbf23e29 Rename cast_ref_to_mut lint to invalid_reference_casting 2023-07-13 23:01:24 +02:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
许杰友 Jieyou Xu (Joe)
0b5c683b06
Add machine-applicable suggestion for unused_qualifications lint 2023-07-13 08:26:02 +08:00
bors
63ef74b6aa Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obk
Uplift `clippy::fn_null_check` lint

This PR aims at uplifting the `clippy::fn_null_check` lint into rustc.

## `incorrect_fn_null_checks`

(warn-by-default)

The `incorrect_fn_null_checks` lint checks for expression that checks if a function pointer is null.

### Example

```rust
let fn_ptr: fn() = /* somehow obtained nullable function pointer */

if (fn_ptr as *const ()).is_null() { /* ... */ }
```

### Explanation

Function pointers are assumed to be non-null, checking for their nullity is incorrect.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler
2023-07-11 09:34:48 +00:00
Urgau
f6d2bf63d3 Uplift clippy::fn_null_check to rustc 2023-07-10 18:12:41 +02:00