Repository: rust
Issue: Import suggestion at incorrect line when first line is a struct attribute
Labels: A-diagnostics,T-compiler,C-bug,A-suggestion-diagnostics,D-invalid-suggestion

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

(From https://github.com/rust-analyzer/rust-analyzer/issues/3237#issuecomment-591366102)
```rust
#[derive(Copy, Clone)]
pub struct Symbol(&'static str);

pub const CRATE: Symbol = Symbol("crate");
pub const PROVIDES: Symbol = Symbol("provides");
pub const WITH: Symbol = Symbol("with");

impl PartialEq<Symbol> for Ident {}
```

in foo.rs,

```rust
extern crate proc_macro;

mod foo;
```

in lib.rs

and

```toml
[package]
name = "proc-macro-test"
version = "0.1.0"

[lib]
proc-macro = true
```

in Cargo.toml

And ran `cargo check --message-format=json`

I expected to see this happen:

A suggestion to place the imports on line 1, e.g. `"line_start": 1, "line_end": 1, "suggested_replacement": "use proc_macro::Ident;"`

Instead, this happened:
```json
{"reason":"compiler-message","package_id":"proc-macro-test 0.1.0 (path+file:///home/pfaria/projects/rustc-suggestion-bug)","target":{"kind":["proc-macro"],"crate_types":["proc-macro"],"name":"proc-macro-test","src_path":"/home/pfaria/projects/rustc-suggestion-bug/src/lib.rs","edition":"2015","doctest":true},"message":{"rendered":"error[E0412]: cannot find type `Ident` in this scope\n --> src/foo.rs:8:28\n  |\n8 | impl PartialEq<Symbol> for Ident {}\n  |                            ^^^^^ not found in this scope\n  |\nhelp: possible candidates are found in other modules, you can import them into scope\n  |\n2 | use proc_macro::Ident;\n  |\n2 | use proc_macro::bridge::server::Ident;\n  |\n\n","children":[{"children":[],"code":null,"level":"help","message":"possible candidates are found in other modules, you can import them into scope","rendered":null,"spans":[{"byte_end":23,"byte_start":23,"column_end":1,"column_start":1,"expansion":null,"file_name":"src/foo.rs","is_primary":true,"label":null,"line_end":2,"line_start":2,"suggested_replacement":"use proc_macro::Ident;\n\n","suggestion_applicability":"Unspecified","text":[{"highlight_end":1,"highlight_start":1,"text":"pub struct Symbol(&'static str);"}]},{"byte_end":23,"byte_start":23,"column_end":1,"column_start":1,"expansion":null,"file_name":"src/foo.rs","is_primary":true,"label":null,"line_end":2,"line_start":2,"suggested_replacement":"use proc_macro::bridge::server::Ident;\n\n","suggestion_applicability":"Unspecified","text":[{"highlight_end":1,"highlight_start":1,"text":"pub struct Symbol(&'static str);"}]}]}],"code":{"code":"E0412","explanation":"The type name used is not in scope.\n\nErroneous code examples:\n\n```compile_fail,E0412\nimpl Something {} // error: type name `Something` is not in scope\n\n// or:\n\ntrait Foo {\n    fn bar(N); // error: type name `N` is not in scope\n}\n\n// or:\n\nfn foo(x: T) {} // type name `T` is not in scope\n```\n\nTo fix this error, please verify you didn't misspell the type name, you did\ndeclare it or imported it into the scope. Examples:\n\n```\nstruct Something;\n\nimpl Something {} // ok!\n\n// or:\n\ntrait Foo {\n    type N;\n\n    fn bar(_: Self::N); // ok!\n}\n\n// or:\n\nfn foo<T>(x: T) {} // ok!\n```\n\nAnother case that causes this error is when a type is imported into a parent\nmodule. To fix this, you can follow the suggestion and use File directly or\n`use super::File;` which will import the types from the parent namespace. An\nexample that causes this error is below:\n\n```compile_fail,E0412\nuse std::fs::File;\n\nmod foo {\n    fn some_function(f: File) {}\n}\n```\n\n```\nuse std::fs::File;\n\nmod foo {\n    // either\n    use super::File;\n    // or\n    // use std::fs::File;\n    fn foo(f: File) {}\n}\n# fn main() {} // don't insert it for us; that'll break imports\n```\n"},"level":"error","message":"cannot find type `Ident` in this scope","spans":[{"byte_end":223,"byte_start":218,"column_end":33,"column_start":28,"expansion":null,"file_name":"src/foo.rs","is_primary":true,"label":"not found in this scope","line_end":8,"line_start":8,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":33,"highlight_start":28,"text":"impl PartialEq<Symbol> for Ident {}"}]}]}}
{"reason":"compiler-message","package_id":"proc-macro-test 0.1.0 (path+file:///home/pfaria/projects/rustc-suggestion-bug)","target":{"kind":["proc-macro"],"crate_types":["proc-macro"],"name":"proc-macro-test","src_path":"/home/pfaria/projects/rustc-suggestion-bug/src/lib.rs","edition":"2015","doctest":true},"message":{"rendered":"error: aborting due to previous error\n\n","children":[],"code":null,"level":"error","message":"aborting due to previous error","spans":[]}}
{"reason":"compiler-message","package_id":"proc-macro-test 0.1.0 (path+file:///home/pfaria/projects/rustc-suggestion-bug)","target":{"kind":["proc-macro"],"crate_types":["proc-macro"],"name":"proc-macro-test","src_path":"/home/pfaria/projects/rustc-suggestion-bug/src/lib.rs","edition":"2015","doctest":true},"message":{"rendered":"For more information about this error, try `rustc --explain E0412`.\n","children":[],"code":null,"level":"failure-note","message":"For more information about this error, try `rustc --explain E0412`.","spans":[]}}
```

One of the above in a more readable format:
```json
{
    "byte_end": 23,
    "byte_start": 23,
    "column_end": 1,
    "column_start": 1,
    "expansion": null,
    "file_name": "src/foo.rs",
    "is_primary": true,
    "label": null,
    "line_end": 2,
    "line_start": 2,
    "suggested_replacement": "use proc_macro::Ident;\n\n",
    "suggestion_applicability": "Unspecified",
    "text": [
        {
            "highlight_end": 1,
            "highlight_start": 1,
            "text": "pub struct Symbol(&'static str);"
        }
    ]
}
```

Note that `line_start` and `line_end` are 2, so the use statement is inserted in between the `derive` attribute and the struct `Symbol`, which causes a compilation error.

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.41.1 (f3e1a954d 2020-02-24)
binary: rustc
commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196
commit-date: 2020-02-24
host: x86_64-unknown-linux-gnu
release: 1.41.1
LLVM version: 9.0
```