File: dot-notation-type-namespace-suggest-path-sep.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 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; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (123 lines) | stat: -rw-r--r-- 3,191 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// see also https://github.com/rust-lang/rust/issues/22692

type Alias = Vec<u32>;

mod foo {
    fn bar() {}
}

fn main() {
    let _ = String.new();
    //~^ ERROR expected value, found struct `String`
    //~| HELP use the path separator

    let _ = String.default;
    //~^ ERROR expected value, found struct `String`
    //~| HELP use the path separator

    let _ = Vec::<()>.with_capacity(1);
    //~^ ERROR expected value, found struct `Vec`
    //~| HELP use the path separator

    let _ = Alias.new();
    //~^ ERROR expected value, found type alias `Alias`
    //~| HELP use the path separator

    let _ = Alias.default;
    //~^ ERROR expected value, found type alias `Alias`
    //~| HELP use the path separator

    let _ = foo.bar;
    //~^ ERROR expected value, found module `foo`
    //~| HELP use the path separator
}

macro_rules! Type {
    () => {
        ::std::cell::Cell
        //~^ ERROR expected value, found struct `std::cell::Cell`
        //~| ERROR expected value, found struct `std::cell::Cell`
        //~| ERROR expected value, found struct `std::cell::Cell`
    };
    (alias) => {
        Alias
        //~^ ERROR expected value, found type alias `Alias`
        //~| ERROR expected value, found type alias `Alias`
        //~| ERROR expected value, found type alias `Alias`
    };
}

macro_rules! create {
    (type method) => {
        Vec.new()
        //~^ ERROR expected value, found struct `Vec`
        //~| HELP use the path separator
    };
    (type field) => {
        Vec.new
        //~^ ERROR expected value, found struct `Vec`
        //~| HELP use the path separator
    };
    (macro method) => {
        Type!().new(0)
        //~^ HELP use the path separator
    };
    (macro method alias) => {
        Type!(alias).new(0)
        //~^ HELP use the path separator
    };
}

macro_rules! check_ty {
    ($Ty:ident) => {
        $Ty.foo
        //~^ ERROR expected value, found type alias `Alias`
        //~| HELP use the path separator
    };
}
macro_rules! check_ident {
    ($Ident:ident) => {
        Alias.$Ident
        //~^ ERROR expected value, found type alias `Alias`
        //~| HELP use the path separator
    };
}
macro_rules! check_ty_ident {
    ($Ty:ident, $Ident:ident) => {
        $Ty.$Ident
        //~^ ERROR expected value, found type alias `Alias`
        //~| HELP use the path separator
    };
}

fn interaction_with_macros() {
    //
    // Verify that we do not only suggest to replace `.` with `::` if the receiver is a
    // macro call but that we also correctly suggest to surround it with angle brackets.
    //

    Type!().get();
    //~^ HELP use the path separator

    Type! {}.get;
    //~^ HELP use the path separator

    Type!(alias).get();
    //~^ HELP use the path separator

    Type! {alias}.get;
    //~^ HELP use the path separator

    //
    // Ensure that the suggestion is shown for expressions inside of macro definitions.
    //

    let _ = create!(type method);
    let _ = create!(type field);
    let _ = create!(macro method);
    let _ = create!(macro method alias);

    let _ = check_ty!(Alias);
    let _ = check_ident!(foo);
    let _ = check_ty_ident!(Alias, foo);
}