Commit Graph

43 Commits

Author SHA1 Message Date
Urgau
018ba0528f Use wide pointers consistenly across the compiler 2024-10-04 14:06:48 +02:00
Lukas Markeffsky
53f45c4332 borrowck: use subtyping instead of equality for ptr-to-ptr casts 2024-09-27 21:04:32 +02:00
Lukas Markeffsky
8302f2e35f add even more tests for ptr-to-ptr casts on trait objects 2024-09-27 21:04:32 +02:00
Lukas Markeffsky
39f66baa68 improve errors for invalid pointer casts 2024-09-24 23:12:02 +02:00
Lukas Markeffsky
5e60d1f87e replace "cast" with "coercion" where applicable
This changes the remaining span for the cast, because the new `Cast`
category has a higher priority (lower `Ord`) than the old `Coercion`
category, so we no longer report the region error for the "unsizing"
coercion from `*const Trait` to itself.
2024-09-24 22:20:46 +02:00
Lukas Markeffsky
d1e82d438f use more accurate spans for user type ascriptions 2024-09-24 22:20:42 +02:00
Lukas Markeffsky
b52dea8230 add another test 2024-09-24 22:18:00 +02:00
Adrian Taylor
e77eb042ce Arbitrary self types v2: pointers feature gate.
The main `arbitrary_self_types` feature gate will shortly be reused for
a new version of arbitrary self types which we are amending per [this
RFC](https://github.com/rust-lang/rfcs/blob/master/text/3519-arbitrary-self-types-v2.md).
The main amendments are:

* _do_ support `self` types which can't safely implement `Deref`
* do _not_ support generic `self` types
* do _not_ support raw pointers as `self` types.

This PR relates to the last of those bullet points: this strips pointer
support from the current `arbitrary_self_types` feature.
We expect this to cause some amount of breakage for crates using this
unstable feature to allow raw pointer self types. If that's the case, we
want to know about it, and we want crate authors to know of the upcoming
changes.

For now, this can be resolved by adding the new
`arbitrary_self_types_pointers` feature to such crates. If we determine
that use of raw pointers as self types is common, then we may maintain
that as an unstable feature even if we come to stabilize the rest of the
`arbitrary_self_types` support in future. If we don't hear that this PR
is causing breakage, then perhaps we don't need it at all, even behind
an unstable feature gate.

[Tracking issue](https://github.com/rust-lang/rust/issues/44874)

This is [step 4 of the plan outlined here](https://github.com/rust-lang/rust/issues/44874#issuecomment-2122179688)
2024-08-27 17:32:35 +00:00
Matthias Krüger
85180cd365
Rollup merge of #128759 - notriddle:notriddle/spec-to-string, r=workingjubilee,compiler-errors
alloc: add ToString specialization for `&&str`

Fixes #128690
2024-08-14 05:05:51 +02:00
Michael Howell
c6fb0f344e diagnostics: use DeepRejectCtxt for check
This makes more things match, particularly applicable blankets.
2024-08-13 10:01:13 -07:00
Michael Goulet
c5205e9d56 Normalize struct tail properly in borrowck and hir typeck 2024-08-11 19:40:03 -04:00
Michael Goulet
c6f8672dd5 Normalize when equating dyn tails in MIR borrowck 2024-08-05 14:28:06 -04:00
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