]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/proc-macro/amputate-span.rs
1 // aux-build:amputate-span.rs
4 // compile-flags: --extern amputate_span
6 // This test has been crafted to ensure the following things:
8 // 1. There's a resolution error that prompts the compiler to suggest
9 // adding a `use` item.
11 // 2. There are no `use` or `extern crate` items in the source
12 // code. In fact, there is only one item, the `fn main`
15 // 3. The single `fn main` declaration has an attribute attached to it
16 // that just deletes the first token from the given item.
18 // You need all of these conditions to hold in order to replicate the
19 // scenario that yielded issue 87613, where the compiler's suggestion
23 // help: consider importing this struct
25 // 47 | hey */ async use std::process::Command;
26 // | ++++++++++++++++++++++++++
29 // The first condition is necessary to force the compiler issue a
30 // suggestion. The second condition is necessary to force the
31 // suggestion to be issued at a span associated with the sole
32 // `fn`-item of this crate. The third condition is necessary in order
33 // to yield the weird state where the associated span of the `fn`-item
34 // does not actually cover all of the original source code of the
35 // `fn`-item (which is why we are calling it an "amputated" span
38 // Note that satisfying conditions 2 and 3 requires the use of the
39 // `--extern` compile flag.
41 // You might ask yourself: What code would do such a thing? The
42 // answer is: the #[tokio::main] attribute does *exactly* this (as
43 // well as injecting some other code into the `fn main` that it
46 #[amputate_span::drop_first_token]
48 hey */ async
fn main() {
49 Command
::new("git"); //~ ERROR [E0433]
52 // (The /* ... */ comment in the above is not part of the original
53 // bug. It is just meant to illustrate one particular facet of the
54 // original non-ideal behavior, where we were transcribing the
55 // trailing comment as part of the emitted suggestion, for better or
60 #[amputate_span::drop_first_token]
61 /* another interesting
62 case */ async
fn foo() {
63 Command
::new("git"); //~ ERROR [E0433]