diff options
| author | kennytm <kennytm@gmail.com> | 2018-01-05 17:22:07 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-05 17:22:07 +0800 |
| commit | 2ac50febbdba0da1f2392fd447c1f08a14674dda (patch) | |
| tree | 4e8e9ade9d781058e2c6d7d0be95e8fbf585fe2b /src/rustllvm/RustWrapper.cpp | |
| parent | 26d129ce3900df3536f29f84b955b6fe8d6b35d0 (diff) | |
| parent | 000e907c1fc73ca249252cba3b2c9b1a20de857d (diff) | |
| download | rust-2ac50febbdba0da1f2392fd447c1f08a14674dda.tar.gz rust-2ac50febbdba0da1f2392fd447c1f08a14674dda.zip | |
Rollup merge of #47149 - dtolnay:spans, r=jseyfried
Span::resolved_at and Span::located_at to combine behavior of two spans Proc macro spans serve two mostly unrelated purposes: controlling name resolution and controlling error messages. It can be useful to mix the name resolution behavior of one span with the line/column error message locations of a different span. In particular, consider the case of a trait brought into scope within the def_site of a custom derive. I want to invoke trait methods on the fields of the user's struct. If the field type does not implement the right trait, I want the error message to underline the corresponding struct field. Generating the method call with the def_site span is not ideal -- it compiles and runs but error messages sadly always point to the derive attribute like we saw with Macros 1.1. ``` | 4 | #[derive(HeapSize)] | ^^^^^^^^ ``` Generating the method call with the same span as the struct field's ident or type is not correct -- it shows the right underlines but fails to resolve to the trait in scope at the def_site. ``` | 7 | bad: std::thread::Thread, | ^^^^^^^^^^^^^^^^^^^^^^^^ ``` The correct span for the method call is one that combines the def_site's name resolution with the struct field's line/column. ```rust field.span.resolved_at(Span::def_site()) // equivalently Span::def_site().located_at(field.span) ``` Adding both because which one is more natural will depend on context. Addresses https://github.com/rust-lang/rust/issues/38356#issuecomment-354947143. r? @jseyfried
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
