File: issue-100365.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,245,420 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (50 lines) | stat: -rw-r--r-- 1,521 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
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!();
}