about summary refs log tree commit diff
path: root/tests/ui/object-safety
AgeCommit message (Collapse)AuthorLines
2024-10-10UI tests: Rename "object safe" to "dyn compatible"León Orell Valerian Liehr-2913/+0
2024-10-10Rename feature object_safe_for_dispatch to dyn_compatible_for_dispatchLeón Orell Valerian Liehr-14/+14
2024-09-27Rollup merge of #130826 - fmease:compiler-mv-obj-safe-dyn-compat, ↵Matthias Krüger-60/+60
r=compiler-errors Compiler: Rename "object safe" to "dyn compatible" Completed T-lang FCP: https://github.com/rust-lang/lang-team/issues/286#issuecomment-2338905118. Tracking issue: https://github.com/rust-lang/rust/issues/130852 Excludes `compiler/rustc_codegen_cranelift` (to be filed separately). Includes Stable MIR. Regarding https://github.com/rust-lang/rust/labels/relnotes, I guess I will manually open a https://github.com/rust-lang/rust/labels/relnotes-tracking-issue since this change affects everything (compiler, library, tools, docs, books, everyday language). r? ghost
2024-09-27On implicit `Sized` bound on fn argument, point at type instead of patternEsteban Küber-4/+4
Instead of ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:20 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^ doesn't have a size known at compile-time ``` output ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:29 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time ```
2024-09-25Compiler: Rename "object safe" to "dyn compatible"León Orell Valerian Liehr-60/+60
2024-09-03Rollup merge of #127692 - veera-sivarajan:bugfix-125139, r=estebankMatthias Krüger-0/+815
Suggest `impl Trait` for References to Bare Trait in Function Header Fixes #125139 This PR suggests `impl Trait` when `&Trait` is found as a function parameter type or return type. This makes use of existing diagnostics by adding `peel_refs()` when checking for type equality. Additionaly, it makes a few other improvements: 1. Checks if functions inside impl blocks have bare trait in their headers. 2. Introduces a trait `NextLifetimeParamName` similar to the existing `NextTypeParamName` for suggesting a lifetime name. Also, abstracts out the common logic between the two trait impls. ### Related Issues I ran into a bunch of related diagnostic issues but couldn't fix them within the scope of this PR. So, I have created the following issues: 1. [Misleading Suggestion when Returning a Reference to a Bare Trait from a Function](https://github.com/rust-lang/rust/issues/127689) 2. [Verbose Error When a Function Takes a Bare Trait as Parameter](https://github.com/rust-lang/rust/issues/127690) 3. [Incorrect Suggestion when Returning a Bare Trait from a Function](https://github.com/rust-lang/rust/issues/127691) r​? ```@estebank``` since you implemented #119148
2024-08-19Suggest `impl Trait` for References to Bare Trait in Function HeaderVeera-25/+25
2024-07-26Rollup merge of #126090 - compiler-errors:supertrait-assoc-ty-unsoundness, ↵Matthias Krüger-0/+126
r=lcnr Fix supertrait associated type unsoundness ### What? Object safety allows us to name `Self::Assoc` associated types in certain positions if they come from our trait or one of our supertraits. When this check was implemented, I think it failed to consider that supertraits can have different args, and it was only checking def-id equality. This is problematic, since we can sneak different implementations in by implementing `Supertrait<NotActuallyTheSupertraitSubsts>` for a `dyn` type. This can be used to implement an unsound transmute function. See the committed test. ### How do we fix it? We consider the whole trait ref when checking for supertraits. Right now, this is implemented using equality *without* normalization. We erase regions since those don't affect trait selection. This is a limitation that could theoretically affect code that should be accepted, but doesn't matter in practice -- there are 0 crater regression. We could make this check stronger, but I would be worried about cycle issues. I assume that most people are writing `Self::Assoc` so they don't really care about the trait ref being normalized. --- ### What is up w the stacked commit This is built on top of https://github.com/rust-lang/rust/pull/122804 though that's really not related, it's just easier to make this modification with the changes to the object safety code that I did in that PR. The only thing is that PR may make this unsoundness slightly easier to abuse, since there are more positions that allow self-associated-types -- I am happy to stall that change until this PR merges. --- Fixes #126079 r? lcnr
2024-07-15Fix unsoundness when associated types dont actually come from supertraitsMichael Goulet-0/+115
2024-07-15Item bounds can reference self projections and still be object safeMichael Goulet-0/+11
2024-07-13Update TestsVeera-0/+815
2024-07-12Make parse error suggestions verbose and fix spansEsteban Küber-2/+12
Go over all structured parser suggestions and make them verbose style. When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-06-21Fix remaining casesMichael Goulet-1/+1
2024-06-03Make WHERE_CLAUSES_OBJECT_SAFETY a regular object safety violationMichael Goulet-2/+0
2024-04-07tests/ui: remove workaround for broken revisioned run-rustfix test许杰友 Jieyou Xu (Joe)-8/+4
2024-03-10Ignore tests w/ current/next revisions from compare-mode=next-solverMichael Goulet-0/+1
2024-03-07Merge collect_mod_item_types query into check_well_formedOli Scherer-18/+18
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-37/+37
2024-02-14Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errorsbors-33/+336
Continue compilation after check_mod_type_wf errors The ICEs fixed here were probably reachable through const eval gymnastics before, but now they are easily reachable without that, too. The new errors are often bugfixes, where useful errors were missing, because they were reported after the early abort. In other cases sometimes they are just duplication of already emitted errors, which won't be user-visible due to deduplication. fixes https://github.com/rust-lang/rust/issues/120860
2024-02-14Continue compilation after check_mod_type_wf errorsOli Scherer-33/+336
2024-02-09Be less confident when `dyn` suggestion is not checked for object safetytrevyn-10/+10
2024-02-07Stop using `hir_ty_to_ty` in rustc_privacyOli Scherer-21/+1
2024-02-07Update testsr0cky-2/+4
2024-02-01review comment: change wordingEsteban Küber-1/+1
2024-02-01On E0277 be clearer about implicit `Sized` bounds on type params and assoc typesEsteban Küber-2/+2
``` error[E0277]: the size for values of type `[i32]` cannot be known at compilation time --> f100.rs:2:33 | 2 | let _ = std::mem::size_of::<[i32]>(); | ^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[i32]` note: required by an implicit `Sized` bound in `std::mem::size_of` --> /home/gh-estebank/rust/library/core/src/mem/mod.rs:312:22 | 312 | pub const fn size_of<T>() -> usize { | ^ required by the implicit `Sized` requirement on this bound in `size_of` ``` Fix #120178.
2024-01-29Avoid ICE in trait without `dyn` lintEsteban Küber-109/+215
Do not attempt to provide an accurate suggestion for `impl Trait` in bare trait types when linting. Instead, only do the object safety check when an E0782 is already going to be emitted in the 2021 edition. Fix #120241.
2024-01-19Update tests after rebaseEsteban Küber-0/+165
Fix #119652.
2024-01-19Avoid ICE: Check diagnostic is error before downgradingEsteban Küber-0/+94
Fix #119633.
2024-01-17Don't ICE when deducing future output if other errors already occurredOli Scherer-0/+32
2024-01-09Avoid silencing relevant follow-up errorsOli Scherer-3/+25
2024-01-04Silence redundant warning when E0038 will be emittedEsteban Küber-25/+11
2024-01-03Account for object unsafe traitsEsteban Küber-0/+57
Fix #119525.
2023-12-14update use of feature flagslcnr-1/+1
2023-11-24Show number in error message even for one errorNilstrieb-14/+14
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-10-30Auto merge of #116405 - estebank:issue-103155, r=davidtwcobors-12/+12
Detect object safety errors when assoc type is missing When an associated type with GATs isn't specified in a `dyn Trait`, emit an object safety error instead of only complaining about the missing associated type, as it will lead the user down a path of three different errors before letting them know that what they were trying to do is impossible to begin with. Fix #103155.
2023-10-30Detect object safety errors when assoc type is missingEsteban Küber-12/+12
When an associated type with GATs isn't specified in a `dyn Trait`, emit an object safety error instead of only complaining about the missing associated type, as it will lead the user down a path of three different errors before letting them know that what they were trying to do is impossible to begin with. Fix #103155.
2023-10-29On object safety error, mention new enum as alternativeEsteban Küber-0/+5
When we encounter a `dyn Trait` that isn't object safe, look for its implementors. If there's one, mention using it directly If there are less than 9, mention the possibility of creating a new enum and using that instead. Account for object unsafe `impl Trait on dyn Trait {}`. Make a distinction between public and sealed traits. Fix #80194.
2023-10-19Suggest relaxing implicit `type Assoc: Sized;` boundEsteban Küber-0/+44
Fix #85378.
2023-10-08always show and explain sub regionAli MJ Al-Nasrawy-7/+1
2023-10-05Add a note to duplicate diagnosticsAlex Macleod-0/+2
2023-09-02Do not require associated types with Self: Sized to uphold bounds when ↵Michael Goulet-21/+31
confirming object candidate
2023-08-26Remove unnecessary `select_obligations_where_possible` and redundant errorsEsteban Küber-27/+4
2023-08-26On let binding type point to type parameter that introduced unmet boundEsteban Küber-2/+25
On the following example, point at `String` instead of the whole type: ``` error[E0277]: the trait bound `String: Copy` is not satisfied --> $DIR/own-bound-span.rs:14:24 | LL | let _: <S as D>::P<String>; | ^^^^^^ the trait `Copy` is not implemented for `String` | note: required by a bound in `D::P` --> $DIR/own-bound-span.rs:4:15 | LL | type P<T: Copy>; | ^^^^ required by this bound in `D::P` ```
2023-07-28Update existing UI testsLeón Orell Valerian Liehr-34/+14
2023-07-10Do not set up wrong span for adjustmentsMichael Goulet-1/+1
2023-07-05Test that you can't circumvent the `Sized` bound checkOli Scherer-0/+73
2023-07-05Make `unused_associated_type_bounds`'s lint level changeableOli Scherer-0/+3
2023-07-05Add more testsOli Scherer-0/+59
2023-07-05Lint now-unnecessary associated type boundsOli Scherer-0/+41
2023-07-05Don't require associated types with `Self: Sized` bounds in `dyn Trait` objectsOli Scherer-13/+3