Skip to content

Commit

Permalink
Gate self span hack on rustc <= 1.46.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed Feb 5, 2021
1 parent 15c4b86 commit 22d5222
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ tracing-attributes = "0.1.8"
tracing-futures = "0.2"
trybuild = { version = "1.0.19", features = ["diff"] }

[build-dependencies]
version_check = "0.9"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
if let Some(true) = version_check::is_max_version("1.46") {
println!("cargo:rustc-cfg=self_span_hack");
}
}
1 change: 1 addition & 0 deletions src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl VisitMut for ReplaceSelf<'_> {
fn visit_ident_mut(&mut self, i: &mut Ident) {
if i == "self" {
*i = quote::format_ident!("{}{}", self.0, i);
#[cfg(self_span_hack)]
i.set_span(self.1);
}

Expand Down
16 changes: 8 additions & 8 deletions tests/ui/self-span.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0308]: mismatched types
--> $DIR/self-span.rs:16:21
--> $DIR/self-span.rs:17:21
|
16 | async fn method(self) {
| ^^^^ expected `()`, found struct `S`
17 | let _: () = self;
| -- expected due to this
| -- ^^^^ expected `()`, found struct `S`
| |
| expected due to this

error: the `Self` constructor can only be used with tuple or unit structs
--> $DIR/self-span.rs:18:23
Expand All @@ -13,12 +13,12 @@ error: the `Self` constructor can only be used with tuple or unit structs
| ^^^^ help: use curly brackets: `Self { /* fields */ }`

error[E0308]: mismatched types
--> $DIR/self-span.rs:24:21
--> $DIR/self-span.rs:25:21
|
24 | async fn method(self) {
| ^^^^ expected `()`, found enum `E`
25 | let _: () = self;
| -- expected due to this
| -- ^^^^ expected `()`, found enum `E`
| |
| expected due to this

error[E0533]: expected unit struct, unit variant or constant, found struct variant `Self::V`
--> $DIR/self-span.rs:26:23
Expand Down

0 comments on commit 22d5222

Please sign in to comment.