Commit Graph

44 Commits

Author SHA1 Message Date
bors 8a3765582c Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwco
Add lint against ambiguous wide pointer comparisons

This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang.

## `ambiguous_wide_pointer_comparisons`

*warn-by-default*

The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands.

### Example

```rust
let ab = (A, B);
let a = &ab.0 as *const dyn T;
let b = &ab.1 as *const dyn T;

let _ = a == b;
```

### Explanation

The comparison includes metadata which may not be expected.

-------

This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one.

~~One thing: is the current naming right? `invalid` seems a bit too much.~~

Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11 14:33:16 +00:00
jyn eb53721a34 recurse into refs when comparing tys for diagnostics 2023-12-07 23:00:46 -05:00
Urgau 5e1bfb538f Adjust tests for newly added ambiguous_wide_pointer_comparisons lint 2023-12-06 09:03:48 +01:00
bors fad6bb80fa Auto merge of #118075 - tmiasko:validate-critical-call-edges, r=cjgillot
Validate there are no critical call edges in optimized MIR
2023-11-25 09:10:44 +00:00
Nilstrieb 41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Tomasz Miąsko cef892ebab Validate there are no critical call edges in optimized MIR 2023-11-22 01:56:31 +01:00
bors 6d069a0ac7 Auto merge of #117359 - tmiasko:call-def, r=cjgillot
Fix def-use check for call terminators

Fixes #117331.
2023-11-15 01:31:46 +00:00
Matthias Krüger d2cdf6c479 Rollup merge of #117686 - compiler-errors:gen-body, r=wesleywiser
Build pre-coroutine-transform coroutine body on error

I was accidentally building the post-transform coroutine body, rather than the pre-transform coroutine body. There's no pinning expected here yet, and the return type isn't yet transformed into `CoroutineState`.

Fixes #117670
2023-11-14 21:50:38 +01:00
Tomasz Miąsko 6873465600 Fix def-use check for call terminators 2023-11-14 17:07:34 +01:00
Tomasz Miąsko 78da577650 Custom MIR: Support cleanup blocks
Cleanup blocks are declared with `bb (cleanup) = { ... }`.

`Call` and `Drop` terminators take an additional argument describing the
unwind action, which is one of the following:

* `UnwindContinue()`
* `UnwindUnreachable()`
* `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup`
* `UnwindCleanup(block)`

Also support unwind resume and unwind terminate terminators:

* `UnwindResume()`
* `UnwindTerminate(reason)`
2023-11-14 08:23:58 +01:00
Michael Goulet 0ba7d19769 Build pre-coroutine-transform coroutine body 2023-11-07 21:14:43 +00:00
Ben Kimock f9bd7dabcf Check alignment of pointers only when read/written through 2023-11-04 13:01:32 -04:00
Nadrieril d5070e32ea Lint overlapping ranges as a separate pass 2023-10-27 05:16:26 +02:00
Oli Scherer e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Matthew Jasper e324a59eb6 Address review comments
- Add doc comment to new type
- Restore "only supported directly in conditions of `if` and `while` expressions" note
- Rename variant with clearer name
2023-09-13 15:00:31 +00:00
Matthew Jasper 333388fd3c Move let expression checking to parsing
There was an incomplete version of the check in parsing and a second
version in AST validation. This meant that some, but not all, invalid
uses were allowed inside macros/disabled cfgs. It also means that later
passes have a hard time knowing when the let expression is in a valid
location, sometimes causing ICEs.

- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a
  valid location.
- Suppress later errors and MIR construction for invalid let
  expressions.
2023-09-11 15:51:18 +00:00
Tomasz Miąsko fe3cd2d194 Fix inlining with -Zalways-encode-mir
Only inline functions that are considered eligible for inlining
by the reachability pass.

This constraint was previously indirectly enforced by only exporting MIR
of eligible functions, but that approach doesn't work with
-Zalways-encode-mir enabled.
2023-08-27 23:52:27 +02:00
Camille GILLOT c535326537 Add test. 2023-08-17 17:02:04 +00:00
Mara Bos 0e729404da Change default panic handler message format. 2023-07-29 11:42:50 +02:00
bors a8a29070f0 Auto merge of #100036 - DrMeepster:box_free_free_box, r=oli-obk
Remove `box_free` lang item

This PR removes the `box_free` lang item, replacing it with `Box`'s `Drop` impl. Box dropping is still slightly magic because the contained value is still dropped by the compiler.
2023-06-17 16:10:57 +00:00
DrMeepster a5c6cb888e remove box_free and replace with drop impl 2023-06-16 13:41:06 -07:00
Ben Kimock c54672e25f Disable alignment checks on i686-pc-windows-msvc 2023-06-16 09:06:12 -04:00
许杰友 Jieyou Xu (Joe) edafbaffb2 Adjust UI tests for unit_bindings
- Either explicitly annotate `let x: () = expr;` where `x` has unit
  type, or remove the unit binding to leave only `expr;` instead.
- Fix disjoint-capture-in-same-closure test
2023-06-12 20:24:48 +08:00
许杰友 Jieyou Xu (Joe) 55b4549602 Show note for type ascription interpreted as a constant pattern, not a new variable
Given the code

```rust
pub fn main() {
    const y: i32 = 4;
    let y: i32 = 3;
}
```

`y` in the let binding is actually interpreted as a constant pattern
and is not a new variable, causing confusing diagnostics about
refutable patterns in local binding.

This commit extends the note for type ascription as a constant pattern
to `AscribeUserType` patterns as well.
2023-06-04 20:49:30 +08:00
Michael Goulet 847d50453c Implement custom diagnostic for ConstParamTy 2023-06-01 18:21:42 +00:00
Ben Kimock de4dddf155 Add a test for misaligned pointer derefs inside addr_of! 2023-05-27 14:52:14 -04:00
Camille GILLOT a395d2a5de Give more descriptive names to queries. 2023-04-20 18:01:07 +00:00
Camille GILLOT b275d2c30b Remove WithOptconstParam. 2023-04-20 17:48:32 +00:00
Matthias Krüger c140e25ec8 Rollup merge of #110283 - saethlin:check-panics-before-alignment, r=bjorn3
Only emit alignment checks if we have a panic_impl

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

r? `@bjorn3` because you commented that this situation could impact you as well
2023-04-13 21:58:39 +02:00
Ben Kimock 4061eb5897 Only emit alignment checks if we have a panic_impl 2023-04-13 10:58:00 -04:00
Jakob Degen d8ed2fb0bb Fix transmute intrinsic mir validation ICE 2023-04-09 18:16:05 -07:00
Oli Scherer b5d96d5ec5 Move a const-prop-lint specific hack from mir interpret to const-prop-lint and make it fallible 2023-04-04 10:39:26 +00:00
bors a5a690cf4b Auto merge of #109008 - clubby789:drop-elaborate-array, r=davidtwco
Drop array patterns using subslices

Fixes #109004
Drops contiguous subslices of an array when moving elements out with a pattern, which improves perf for large arrays
r? `@compiler-errors`
2023-04-02 12:17:52 +00:00
Ben Kimock 750707801b Disable the ui panic test on wasm32-bare 2023-03-30 23:46:44 -04:00
Ben Kimock 8ccf53332e A MIR transform that checks pointers are aligned 2023-03-23 18:23:06 -04:00
clubby789 ce2d52841b Drop subslices of arrays 2023-03-17 12:26:04 +00:00
clubby789 dd7df04e16 Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
Camille GILLOT 5d7234abb6 Add test. 2023-03-05 20:55:29 +00:00
Camille GILLOT 9aa4f6acb2 MIR-Validate StorageLive. 2023-02-25 16:27:10 +00:00
b-naber 6e1d228285 only require sub type relation on field projection types 2023-02-12 23:18:15 +01:00
Lukas Markeffsky e2a1a2ab79 yet another ui test 2023-02-05 22:51:37 +01:00
Lukas Markeffsky 9d110847ab ReErased regions are local 2023-02-05 15:29:07 +01:00
Tomasz Miąsko e489971902 Fix def-use dominance check
A definition does not dominate a use in the same statement. For example
in MIR generated for compound assignment x += a (when overflow checks
are disabled).
2023-01-27 00:54:31 +01:00
Albert Larsan cf2dff2b1e Move /src/test to /tests 2023-01-11 09:32:08 +00:00