File: pr-review-132289-3.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid
  • size: 934,168 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (50 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// This is a regression test for issues that came up during review of the (closed)
// PR #132289; this 3-ish-crate (including std) test case is adapted from
// the third example from @steffahn during review.
// https://github.com/rust-lang/rust/pull/132289#issuecomment-2564599221

//@ run-pass
//@ check-run-results
//@ aux-build: pr_review_132289_3_lib.rs

extern crate pr_review_132289_3_lib;

use std::ops::Index;

use pr_review_132289_3_lib::{call, Trait};

trait SubIndex<I>: Index<I> {}

struct Param;

trait Project {
    type Ty: ?Sized;
}
impl Project for () {
    type Ty = dyn SubIndex<Param, Output = ()>;
}

impl Index<Param> for <() as Project>::Ty {
    type Output = ();

    fn index(&self, _: Param) -> &() {
        &()
    }
}

struct Struct;

impl Trait for Struct {
    fn f(&self)
    where
        // higher-ranked to allow potentially-false bounds
        for<'a> dyn Index<(), Output = ()>: Index<()>,
        // after #132289 rustc used to believe this bound false
    {
        println!("hello!");
    }
}

fn main() {
    call(&Struct); // <- would segfault if the method `f` wasn't part of the vtable
}