diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-05-17 15:45:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-17 15:45:22 +0200 |
| commit | 616650b6ca98e82fd2e8c32a6f2330dcef118421 (patch) | |
| tree | 3674cb7def64b0af02a4fcef72b5d3a013e36df8 /tests | |
| parent | 57a400d7c12a0c9dae6bc0d7b26ee67ebeeadae0 (diff) | |
| parent | 9578b59eacbdf73d577b70439d580ac3522856db (diff) | |
| download | rust-616650b6ca98e82fd2e8c32a6f2330dcef118421.tar.gz rust-616650b6ca98e82fd2e8c32a6f2330dcef118421.zip | |
Rollup merge of #141121 - compiler-errors:ambig-is-not-err, r=lcnr
Only select true errors in `impossible_predicates` See description in test. Fixes #141119 r? lcnr
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/traits/object/ambiguity-vtable-segfault.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/ui/traits/object/ambiguity-vtable-segfault.rs b/tests/ui/traits/object/ambiguity-vtable-segfault.rs new file mode 100644 index 00000000000..dff7d26ae93 --- /dev/null +++ b/tests/ui/traits/object/ambiguity-vtable-segfault.rs @@ -0,0 +1,37 @@ +// In this example below, we have two overlapping candidates for `dyn Q: Q`. +// Specifically, the user written impl for `<dyn Q as Mirror>::Assoc` and the +// built-in impl for object types. Since they differ by their region responses, +// the goal is ambiguous. This affects codegen since impossible obligations +// for method dispatch will lead to a segfault, since we end up emitting dummy +// call vtable offsets due to <https://github.com/rust-lang/rust/pull/136311>. + +// Test for <https://github.com/rust-lang/rust/issues/141119>. + +//@ run-pass + +trait Mirror { + type Assoc: ?Sized; +} +impl<T: ?Sized> Mirror for T { + type Assoc = T; +} + +trait Q: 'static { + fn q(&self); +} + +impl Q for i32 { + fn q(&self) { println!("i32"); } +} + +impl Q for <dyn Q as Mirror>::Assoc where Self: 'static { + fn q(&self) { println!("dyn Q"); } +} + +fn foo<T: Q + ?Sized>(t: &T) { + t.q(); +} + +fn main() { + foo(&1 as &dyn Q); +} |
