Skip to content

Commit

Permalink
Auto merge of rust-lang#45999 - jseyfried:def_site_span, r=nrc
Browse files Browse the repository at this point in the history
Rename `Span::default` -> `Span::def_site`

I think the explicitness here is warranted.
c.f. rust-lang#45934
r? @nrc
  • Loading branch information
bors committed Nov 18, 2017
2 parents 79a1385 + 74cc1fd commit 859c716
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ impl TokenStream {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Span(syntax_pos::Span);

#[unstable(feature = "proc_macro", issue = "38356")]
impl Default for Span {
fn default() -> Span {
impl Span {
/// A span that resolves at the macro definition site.
#[unstable(feature = "proc_macro", issue = "38356")]
pub fn def_site() -> Span {
::__internal::with_sess(|(_, mark)| {
let call_site = mark.expn_info().unwrap().call_site;
Span(call_site.with_ctxt(SyntaxContext::empty().apply_mark(mark)))
Expand Down Expand Up @@ -351,7 +352,7 @@ pub struct TokenTree {
#[unstable(feature = "proc_macro", issue = "38356")]
impl From<TokenNode> for TokenTree {
fn from(kind: TokenNode) -> TokenTree {
TokenTree { span: Span::default(), kind: kind }
TokenTree { span: Span::def_site(), kind: kind }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libproc_macro/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Quote for Term {

impl Quote for Span {
fn quote(self) -> TokenStream {
quote!(::Span::default())
quote!(::Span::def_site())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui-fulldeps/proc-macro/auxiliary/three-equals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use proc_macro::{TokenStream, TokenNode, Span, Diagnostic};

fn parse(input: TokenStream) -> Result<(), Diagnostic> {
let mut count = 0;
let mut last_span = Span::default();
let mut last_span = Span::def_site();
for tree in input {
let span = tree.span;
if count >= 3 {
Expand All @@ -37,7 +37,7 @@ fn parse(input: TokenStream) -> Result<(), Diagnostic> {
}

if count < 3 {
return Err(Span::default()
return Err(Span::def_site()
.error(format!("found {} equal signs, need exactly 3", count))
.help("input must be: `===`"))
}
Expand Down

0 comments on commit 859c716

Please sign in to comment.