Commit Graph

31 Commits

Author SHA1 Message Date
long-long-float
332b41dbce Use ordinal number in argument error
Fix error message

Fix tests

Format
2024-07-14 13:50:09 +09:00
Maybe Lapkin
f3c13bf280 Allow casting *mut dyn T->*mut (dyn T + Send) if T has Send super trait 2024-07-07 20:07:01 +02:00
Maybe Lapkin
073f3a263b Equate types instead of using Unsize 2024-07-05 22:35:14 +02:00
Maybe Lapkin
56de9da1f8 Sort trait names before printing 2024-07-04 18:38:18 +02:00
Maybe Lapkin
a1f20f17c8 Properly normalize types in bck when checking pointer casts 2024-07-04 17:57:31 +02:00
Maybe Lapkin
9ef533e8de Fill in tracking issue 2024-07-04 17:57:31 +02:00
Maybe Lapkin
dc420a282b Use DiagSymbolList for a lint diagnostic 2024-07-04 17:57:31 +02:00
Maybe Lapkin
340d69be12 Align the changes to the lang decision 2024-07-04 17:57:29 +02:00
Waffle Lapkin
c7435571ad Actually check that the traits are the same for casting pointers to dyn _ 2024-07-04 17:56:09 +02:00
Waffle Lapkin
e85295c321 test blessing 2024-07-04 17:56:09 +02:00
Maybe Waffle
bb651d358d blessings 2024-07-04 17:56:09 +02:00
Maybe Waffle
5645e8e285 Add more checks for pointers with vtable meta
The rules for casting `*mut X<dyn A>` -> `*mut Y<dyn B>` are as follows:
- If `B` has a principal
  - `A` must have exactly the same principal (including generics)
  - Auto traits of `B` must be a subset of autotraits in `A`

Note that `X<_>` and `Y<_>` can be identity, or arbitrary structs with last field being the dyn type.
The lifetime of the trait object itself (`dyn ... + 'a`) is not checked.

This prevents a few soundness issues with `#![feature(arbitrary_self_types)]` and trait upcasting.
Namely, these checks make sure that vtable is always valid for the pointee.
2024-07-04 17:56:09 +02:00
Maybe Waffle
9e8ef92da0 Add tests for *const Trait<'a> -> *const Trait<'b> and similar casts 2024-07-04 17:56:08 +02:00
Maybe Waffle
d06cf5b399 Forbid casts of raw pointers to trait objects with the same trait, but different args 2024-07-04 17:56:08 +02:00
Maybe Waffle
36b1f4411d Add a test for *const Tr<A> to *const Tr<B> casts 2024-07-04 17:56:08 +02:00
Gurinder Singh
fb619ec208 FIx ICE while casting a type with error 2024-05-11 08:24:26 +05:30
Ralf Jung
875f0c2da0 Miri: detect wrong vtables in wide pointers 2024-04-21 13:04:51 +02:00
Lukas Markeffsky
7b21c1a457 add test for casting pointer to union with unsized tail 2024-03-19 13:57:31 +01:00
许杰友 Jieyou Xu (Joe)
ec2cc761bc
[AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
Urgau
915200fbe0 Lint on reference casting to bigger underlying allocation 2024-02-12 19:40:17 +01:00
Gurinder Singh
6e37f955e5 Emit more specific diagnostics when enums fail to cast with as 2024-02-09 09:19:44 +05:30
r0cky
c7519d42c2 Update tests 2024-02-07 10:42:01 +08:00
Veera
286f2d819e Update existing tests 2023-12-20 22:53:56 -05:00
Veera
e6e195e27e fix: diagnostic for casting reference to slice
fixes: #118790
2023-12-20 20:50:32 -05: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
Nilstrieb
b6657a8ad4 Never consider raw pointer casts to be trival
HIR typeck tries to figure out which casts are trivial by doing them as
coercions and seeing whether this works. Since HIR typeck is oblivious
of lifetimes, this doesn't work for pointer casts that only change the
lifetime of the pointee, which are, as borrowck will tell you, not
trivial.

This change makes it so that raw pointer casts are never considered
trivial.

This also incidentally fixes the "trivial cast" lint false positive on
the same code. Unfortunately, "trivial cast" lints are now never emitted
on raw pointer casts, even if they truly are trivial. This could be
fixed by also doing the lint in borrowck for raw pointers specifically.
2023-10-25 23:15:18 +02:00
ouz-a
861448b426 make unsized cast illegal 2023-09-22 18:57:27 +03:00
clubby789
c2841e2a1e Migrate 'cast to bool' diagnostic 2023-09-18 14:03:57 +00:00
asquared31415
e36adff4c2 add source type for invalid bool casts 2023-09-11 18:10:07 +00:00
Ezra Shaw
92ced4a12e
suggest is_empty for collections when casting to bool 2023-01-15 22:17:54 +13:00
Albert Larsan
cf2dff2b1e
Move /src/test to /tests 2023-01-11 09:32:08 +00:00