File: no-method-suggested-traits.rs

package info (click to toggle)
rustc-web 1.70.0%2Bdfsg1-7~deb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,517,048 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,006; asm: 2,856
file content (77 lines) | stat: -rw-r--r-- 2,362 bytes parent folder | download | duplicates (9)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// aux-build:no_method_suggested_traits.rs
extern crate no_method_suggested_traits;

struct Foo;
enum Bar { X }

mod foo {
    pub trait Bar {
        fn method(&self) {}

        fn method2(&self) {}
    }

    impl Bar for u32 {}

    impl Bar for char {}
}

fn main() {
    // test the values themselves, and autoderef.


    1u32.method();
    //~^ ERROR no method named
    //~|items from traits can only be used if the trait is in scope
    std::rc::Rc::new(&mut Box::new(&1u32)).method();
    //~^items from traits can only be used if the trait is in scope
    //~| ERROR no method named `method` found for struct

    'a'.method();
    //~^ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&'a')).method();
    //~^ ERROR no method named

    1i32.method();
    //~^ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&1i32)).method();
    //~^ ERROR no method named

    Foo.method();
    //~^ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&Foo)).method();
    //~^ ERROR no method named

    1u64.method2();
    //~^ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&1u64)).method2();
    //~^ ERROR no method named

    no_method_suggested_traits::Foo.method2();
    //~^ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
    //~^ ERROR no method named
    no_method_suggested_traits::Bar::X.method2();
    //~^ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
    //~^ ERROR no method named

    Foo.method3();
    //~^ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&Foo)).method3();
    //~^ ERROR no method named
    Bar::X.method3();
    //~^ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&Bar::X)).method3();
    //~^ ERROR no method named

    // should have no help:
    1_usize.method3(); //~ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR no method named
    no_method_suggested_traits::Foo.method3();  //~ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3();
    //~^ ERROR no method named
    no_method_suggested_traits::Bar::X.method3();  //~ ERROR no method named
    std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3();
    //~^ ERROR no method named
}