forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#126497 - petrochenkov:delehyg, r=compiler-e…
…rrors delegation: Fix hygiene for `self` And fix diagnostics for `self` from a macro. The missing rib caused `self` to be treated as a generic parameter and ignore `macro_rules` hygiene. Addresses this comment rust-lang#124135 (comment).
- Loading branch information
Showing
5 changed files
with
81 additions
and
22 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
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,20 @@ | ||
#![feature(fn_delegation)] | ||
#![allow(incomplete_features)] | ||
|
||
macro_rules! emit_self { () => { self } } | ||
//~^ ERROR expected value, found module `self` | ||
//~| ERROR expected value, found module `self` | ||
|
||
struct S; | ||
impl S { | ||
fn method(self) { | ||
emit_self!(); | ||
} | ||
} | ||
|
||
fn foo(arg: u8) {} | ||
reuse foo as bar { | ||
emit_self!() | ||
} | ||
|
||
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,31 @@ | ||
error[E0424]: expected value, found module `self` | ||
--> $DIR/self-hygiene.rs:4:34 | ||
| | ||
LL | macro_rules! emit_self { () => { self } } | ||
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter | ||
... | ||
LL | / fn method(self) { | ||
LL | | emit_self!(); | ||
| | ------------ in this macro invocation | ||
LL | | } | ||
| |_____- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters | ||
| | ||
= note: this error originates in the macro `emit_self` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0424]: expected value, found module `self` | ||
--> $DIR/self-hygiene.rs:4:34 | ||
| | ||
LL | macro_rules! emit_self { () => { self } } | ||
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter | ||
... | ||
LL | / reuse foo as bar { | ||
LL | | emit_self!() | ||
| | ------------ in this macro invocation | ||
LL | | } | ||
| |_- delegation supports a `self` parameter, but a macro invocation can only access identifiers it receives from parameters | ||
| | ||
= note: this error originates in the macro `emit_self` (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 E0424`. |