]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #86165 - m-ou-se:proc-macro-span-shrink, r=dtolnay
authorManish Goregaokar <manishsmail@gmail.com>
Fri, 10 Sep 2021 15:23:14 +0000 (08:23 -0700)
committerGitHub <noreply@github.com>
Fri, 10 Sep 2021 15:23:14 +0000 (08:23 -0700)
commit000dbd27f146f4fd6ee2fb5e0f3060c440a08898
tree5d4a2ffcb93d0e604ef357304d4269805ca98feb
parentacfe7c41412808094fd85ba3b9f5ceeabfeea932
parentf9be6cd8988a48a532c99a9f5b887a6d354e5b2f
Rollup merge of #86165 - m-ou-se:proc-macro-span-shrink, r=dtolnay

Add proc_macro::Span::{before, after}.

This adds `proc_macro::Span::before()` and `proc_macro::Span::after()` to get a zero width span at the start or end of the span.

These are equivalent to rustc's `Span::shrink_to_lo()` and `Span::shrink_to_hi()` but with a less cryptic name. They are useful when generating diagnostlics like "missing \<thing\> after \<thing\>".

E.g.

```rust
syn::Error::new(ident.span().after(), "missing `:` after field name").into_compile_error()
```
compiler/rustc_expand/src/proc_macro_server.rs
library/proc_macro/src/bridge/mod.rs
library/proc_macro/src/lib.rs