Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proc_macro: Stabilize Span::resolved_at and Span::located_at #69041

Merged
merged 2 commits into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,14 @@ impl Span {

/// Creates a new span with the same line/column information as `self` but
/// that resolves symbols as though it were at `other`.
#[unstable(feature = "proc_macro_span", issue = "54725")]
#[stable(feature = "proc_macro_span_resolved_at", since = "1.43.0")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe I'm being stupid but since this was merged on the 25th April shouldn't this be since = "1.44.0" what with 1.43.0 being released on the 23rd April

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With 1.43 released before this was merged, it's actually going to be stabilized in 1.45 (the GitHub milestone this PR is assigned to is also the one for 1.45). I've already opened #71574 to fix the attribute.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm not crazy? Good to know :-)

pub fn resolved_at(&self, other: Span) -> Span {
Span(self.0.resolved_at(other.0))
}

/// Creates a new span with the same name resolution behavior as `self` but
/// with the line/column information of `other`.
#[unstable(feature = "proc_macro_span", issue = "54725")]
#[stable(feature = "proc_macro_span_located_at", since = "1.43.0")]
pub fn located_at(&self, other: Span) -> Span {
other.resolved_at(*self)
}
Expand Down
32 changes: 32 additions & 0 deletions src/test/ui/proc-macro/auxiliary/resolved-located-at.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// force-host
// no-prefer-dynamic

#![feature(proc_macro_def_site)]
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_hygiene)]
#![feature(proc_macro_quote)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
use proc_macro::*;

#[proc_macro]
pub fn resolve_located_at(input: TokenStream) -> TokenStream {
match &*input.into_iter().collect::<Vec<_>>() {
[a, b, ..] => {
// The error is reported at input `a`.
let mut diag = Diagnostic::new(Level::Error, "expected error");
diag.set_spans(Span::def_site().located_at(a.span()));
diag.emit();

// Resolves to `struct S;` at def site, but the error is reported at input `b`.
let s = TokenTree::Ident(Ident::new("S", b.span().resolved_at(Span::def_site())));
quote!({
struct S;

$s
})
}
_ => panic!("unexpected input"),
}
}
12 changes: 12 additions & 0 deletions src/test/ui/proc-macro/resolved-located-at.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// aux-build:resolved-located-at.rs

#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate resolved_located_at;

fn main() {
resolve_located_at!(a b)
//~^ ERROR expected error
//~| ERROR mismatched types
}
21 changes: 21 additions & 0 deletions src/test/ui/proc-macro/resolved-located-at.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error: expected error
--> $DIR/resolved-located-at.rs:9:25
|
LL | resolve_located_at!(a b)
| ^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/resolved-located-at.rs:9:27
|
LL | fn main() {
| - expected `()` because of default return type
LL | resolve_located_at!(a b)
| ^ expected `()`, found struct `main::S`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.