-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #31089 - fhahn:macro-ice, r=pnkfelix
This is a work in progress PR that potentially should fix #29084, #28308, #25385, #28288, #31011. I think this may also adresse parts of #2887. The problem in this issues seems to be that when transcribing macro arguments, we just clone the argument Nonterminal, which still has to original spans. This leads to the unprintable spans. One solution would be to update the spans of the inserted argument to match the argument in the macro definition. So for [this testcase](https://github.com/rust-lang/rust/compare/master...fhahn:macro-ice?expand=1#diff-f7def7420c51621640707b6337726876R2) the error message would be displayed in the macro definition: src/test/compile-fail/issue-31011.rs:4:12: 4:22 error: attempted access of field `trace` on type `&T`, but no field with that name was found src/test/compile-fail/issue-31011.rs:4 if $ctx.trace { Currently I've added a very simple `update_span` function, which updates the span of the outer-most expression of a `NtExpr`, but this `update_span` function should be updated to handle all Nonterminals. But I'm pretty new to the macro system and would like to check if this approach makes sense, before doing that.
- Loading branch information
Showing
12 changed files
with
354 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
|
||
macro_rules! foo { | ||
($e:expr) => { $e.foo() } | ||
//~^ ERROR no method named `foo` found for type `i32` in the current scope | ||
} | ||
|
||
fn main() { | ||
let a = 1i32; | ||
foo!(a); | ||
//~^ NOTE in this expansion of foo! | ||
|
||
foo!(1i32.foo()); | ||
//~^ ERROR no method named `foo` found for type `i32` in the current scope | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
mod stuff { | ||
pub struct Item { | ||
c_object: Box<CObj>, | ||
} | ||
pub struct CObj { | ||
name: Option<String>, | ||
} | ||
impl Item { | ||
pub fn new() -> Item { | ||
Item { | ||
c_object: Box::new(CObj { name: None }), | ||
} | ||
} | ||
} | ||
} | ||
|
||
macro_rules! check_ptr_exist { | ||
($var:expr, $member:ident) => ( | ||
(*$var.c_object).$member.is_some() | ||
//~^ ERROR field `name` of struct `stuff::CObj` is private | ||
//~^^ ERROR field `c_object` of struct `stuff::Item` is private | ||
); | ||
} | ||
|
||
fn main() { | ||
let item = stuff::Item::new(); | ||
println!("{}", check_ptr_exist!(item, name)); | ||
//~^ NOTE in this expansion of check_ptr_exist! | ||
//~^^ NOTE in this expansion of check_ptr_exist! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
macro_rules! width( | ||
($this:expr) => { | ||
$this.width.unwrap() | ||
//~^ ERROR cannot use `self.width` because it was mutably borrowed | ||
} | ||
); | ||
|
||
struct HasInfo { | ||
width: Option<usize> | ||
} | ||
|
||
impl HasInfo { | ||
fn get_size(&mut self, n: usize) -> usize { | ||
n | ||
} | ||
|
||
fn get_other(&mut self) -> usize { | ||
self.get_size(width!(self)) | ||
//~^ NOTE in this expansion of width! | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
macro_rules! not_an_lvalue { | ||
($thing:expr) => { | ||
$thing = 42; | ||
//~^ ERROR invalid left-hand side expression | ||
} | ||
} | ||
|
||
fn main() { | ||
not_an_lvalue!(99); | ||
//~^ NOTE in this expansion of not_an_lvalue! | ||
} |
Oops, something went wrong.