Auto merge of #45999 - jseyfried:def_site_span, r=nrc
Rename `Span::default` -> `Span::def_site` I think the explicitness here is warranted. c.f. #45934 r? @nrc
This commit is contained in:
commit
859c716fbb
3 changed files with 8 additions and 7 deletions
|
@ -177,9 +177,10 @@ impl TokenStream {
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub struct Span(syntax_pos::Span);
|
pub struct Span(syntax_pos::Span);
|
||||||
|
|
||||||
#[unstable(feature = "proc_macro", issue = "38356")]
|
impl Span {
|
||||||
impl Default for Span {
|
/// A span that resolves at the macro definition site.
|
||||||
fn default() -> Span {
|
#[unstable(feature = "proc_macro", issue = "38356")]
|
||||||
|
pub fn def_site() -> Span {
|
||||||
::__internal::with_sess(|(_, mark)| {
|
::__internal::with_sess(|(_, mark)| {
|
||||||
let call_site = mark.expn_info().unwrap().call_site;
|
let call_site = mark.expn_info().unwrap().call_site;
|
||||||
Span(call_site.with_ctxt(SyntaxContext::empty().apply_mark(mark)))
|
Span(call_site.with_ctxt(SyntaxContext::empty().apply_mark(mark)))
|
||||||
|
@ -351,7 +352,7 @@ pub struct TokenTree {
|
||||||
#[unstable(feature = "proc_macro", issue = "38356")]
|
#[unstable(feature = "proc_macro", issue = "38356")]
|
||||||
impl From<TokenNode> for TokenTree {
|
impl From<TokenNode> for TokenTree {
|
||||||
fn from(kind: TokenNode) -> TokenTree {
|
fn from(kind: TokenNode) -> TokenTree {
|
||||||
TokenTree { span: Span::default(), kind: kind }
|
TokenTree { span: Span::def_site(), kind: kind }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ impl Quote for Term {
|
||||||
|
|
||||||
impl Quote for Span {
|
impl Quote for Span {
|
||||||
fn quote(self) -> TokenStream {
|
fn quote(self) -> TokenStream {
|
||||||
quote!(::Span::default())
|
quote!(::Span::def_site())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ use proc_macro::{TokenStream, TokenNode, Span, Diagnostic};
|
||||||
|
|
||||||
fn parse(input: TokenStream) -> Result<(), Diagnostic> {
|
fn parse(input: TokenStream) -> Result<(), Diagnostic> {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut last_span = Span::default();
|
let mut last_span = Span::def_site();
|
||||||
for tree in input {
|
for tree in input {
|
||||||
let span = tree.span;
|
let span = tree.span;
|
||||||
if count >= 3 {
|
if count >= 3 {
|
||||||
|
@ -37,7 +37,7 @@ fn parse(input: TokenStream) -> Result<(), Diagnostic> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if count < 3 {
|
if count < 3 {
|
||||||
return Err(Span::default()
|
return Err(Span::def_site()
|
||||||
.error(format!("found {} equal signs, need exactly 3", count))
|
.error(format!("found {} equal signs, need exactly 3", count))
|
||||||
.help("input must be: `===`"))
|
.help("input must be: `===`"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue