File: issue-100365.rs

package info (click to toggle)
rustc 1.86.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 913,560 kB
  • sloc: xml: 158,127; python: 35,921; javascript: 19,689; sh: 19,600; cpp: 18,906; ansic: 13,124; asm: 4,376; makefile: 708; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (50 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download | duplicates (10)
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
fn main() {
    let addr = Into::<std::net::IpAddr>.into([127, 0, 0, 1]);
    //~^ ERROR expected value, found trait `Into`
    //~| HELP use the path separator

    let _ = Into.into(());
    //~^ ERROR expected value, found trait `Into`
    //~| HELP use the path separator

    let _ = Into::<()>.into;
    //~^ ERROR expected value, found trait `Into`
    //~| HELP use the path separator
}

macro_rules! Trait {
    () => {
        ::std::iter::Iterator
        //~^ ERROR expected value, found trait `std::iter::Iterator`
        //~| ERROR expected value, found trait `std::iter::Iterator`
    };
}

macro_rules! create {
    () => {
        Into::<String>.into("")
        //~^ ERROR expected value, found trait `Into`
        //~| HELP use the path separator
    };
}

fn interaction_with_macros() {
    //
    // Note that if the receiver is a macro call, we do not want to suggest to replace
    // `.` with `::` as that would be a syntax error.
    // Since the receiver is a trait and not a type, we cannot suggest to surround
    // it with angle brackets. It would be interpreted as a trait object type void of
    // `dyn` which is most likely not what the user intended to write.
    // `<_ as Trait!()>::` is also not an option as it's equally syntactically invalid.
    //

    Trait!().map(std::convert::identity); // no `help` here!

    Trait!().map; // no `help` here!

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

    let _ = create!();
}