mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
delegation: Give declaration of self syntax context of the delegation body
Instead of the last segment of the delegation path. `self` is something that introduced by the whole delegation item, not some specific part of it, and the last segment may need to have a different context for path resolution purposes.
This commit is contained in:
@@ -3872,8 +3872,7 @@ fn resolve_delegation(
|
||||
|
||||
let Some(body) = &delegation.body else { return };
|
||||
self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| {
|
||||
let span = delegation.path.segments.last().unwrap().ident.span;
|
||||
let ident = Ident::new(kw::SelfLower, span.normalize_to_macro_rules());
|
||||
let ident = Ident::new(kw::SelfLower, body.span.normalize_to_macro_rules());
|
||||
let res = Res::Local(delegation.id);
|
||||
this.innermost_rib_bindings(ValueNS).insert(ident, res);
|
||||
|
||||
|
||||
@@ -173,19 +173,6 @@ macro_rules! self_0_ref { ($self:ident) => { &$self.0 } }
|
||||
macro_rules! m { () => { M } }
|
||||
reuse impl Trait for m!() { self_0_ref!(self) }
|
||||
|
||||
struct S1(u8);
|
||||
macro_rules! one_line_reuse { ($self:ident) => { reuse impl Trait for S1 { $self.0 } } }
|
||||
one_line_reuse!(self);
|
||||
|
||||
struct S2(u8);
|
||||
macro_rules! one_line_reuse_expr { ($x:expr) => { reuse impl Trait for S2 { $x } } }
|
||||
one_line_reuse_expr!(self.0);
|
||||
|
||||
struct S3(u8);
|
||||
macro_rules! s3 { () => { S3 } }
|
||||
macro_rules! one_line_reuse_expr2 { ($x:expr) => { reuse impl Trait for s3!() { $x } } }
|
||||
one_line_reuse_expr2!(self.0);
|
||||
|
||||
fn f() {
|
||||
let s = S(1);
|
||||
s.foo();
|
||||
@@ -194,18 +181,6 @@ fn f() {
|
||||
let m = M(41);
|
||||
m.foo();
|
||||
m.bar();
|
||||
|
||||
let s1 = S1(2);
|
||||
s1.foo();
|
||||
s1.bar();
|
||||
|
||||
let s2 = S2(4);
|
||||
s2.foo();
|
||||
s2.bar();
|
||||
|
||||
let s3 = S3(5);
|
||||
s3.foo();
|
||||
s3.bar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(fn_delegation)]
|
||||
|
||||
trait Trait {
|
||||
fn foo(&self) -> u8 { 0 }
|
||||
fn bar(&self) -> u8 { 1 }
|
||||
}
|
||||
|
||||
struct S1(u8);
|
||||
macro_rules! one_line_reuse { ($self:ident) => { reuse impl Trait for S1 { $self.0 } } }
|
||||
//~^ ERROR expected value, found module `self`
|
||||
//~| ERROR expected value, found module `self`
|
||||
one_line_reuse!(self);
|
||||
|
||||
struct S2(u8);
|
||||
macro_rules! one_line_reuse_expr { ($x:expr) => { reuse impl Trait for S2 { $x } } }
|
||||
one_line_reuse_expr!(self.0);
|
||||
//~^ ERROR expected value, found module `self`
|
||||
//~| ERROR expected value, found module `self`
|
||||
|
||||
struct S3(u8);
|
||||
macro_rules! s3 { () => { S3 } }
|
||||
macro_rules! one_line_reuse_expr2 { ($x:expr) => { reuse impl Trait for s3!() { $x } } }
|
||||
one_line_reuse_expr2!(self.0);
|
||||
//~^ ERROR expected value, found module `self`
|
||||
//~| ERROR expected value, found module `self`
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,68 @@
|
||||
error[E0424]: expected value, found module `self`
|
||||
--> $DIR/impl-reuse-self-hygiene.rs:10:76
|
||||
|
|
||||
LL | macro_rules! one_line_reuse { ($self:ident) => { reuse impl Trait for S1 { $self.0 } } }
|
||||
| --------------------------^^^^^----
|
||||
| | |
|
||||
| | `self` value is a keyword only available in methods with a `self` parameter
|
||||
| `self` not allowed in an implementation
|
||||
...
|
||||
LL | one_line_reuse!(self);
|
||||
| --------------------- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `one_line_reuse` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0424]: expected value, found module `self`
|
||||
--> $DIR/impl-reuse-self-hygiene.rs:10:76
|
||||
|
|
||||
LL | macro_rules! one_line_reuse { ($self:ident) => { reuse impl Trait for S1 { $self.0 } } }
|
||||
| --------------------------^^^^^----
|
||||
| | |
|
||||
| | `self` value is a keyword only available in methods with a `self` parameter
|
||||
| `self` not allowed in an implementation
|
||||
...
|
||||
LL | one_line_reuse!(self);
|
||||
| --------------------- in this macro invocation
|
||||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
= note: this error originates in the macro `one_line_reuse` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0424]: expected value, found module `self`
|
||||
--> $DIR/impl-reuse-self-hygiene.rs:17:22
|
||||
|
|
||||
LL | macro_rules! one_line_reuse_expr { ($x:expr) => { reuse impl Trait for S2 { $x } } }
|
||||
| ------------------------------ `self` not allowed in an implementation
|
||||
LL | one_line_reuse_expr!(self.0);
|
||||
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
|
||||
|
||||
error[E0424]: expected value, found module `self`
|
||||
--> $DIR/impl-reuse-self-hygiene.rs:17:22
|
||||
|
|
||||
LL | macro_rules! one_line_reuse_expr { ($x:expr) => { reuse impl Trait for S2 { $x } } }
|
||||
| ------------------------------ `self` not allowed in an implementation
|
||||
LL | one_line_reuse_expr!(self.0);
|
||||
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
|
||||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0424]: expected value, found module `self`
|
||||
--> $DIR/impl-reuse-self-hygiene.rs:24:23
|
||||
|
|
||||
LL | macro_rules! one_line_reuse_expr2 { ($x:expr) => { reuse impl Trait for s3!() { $x } } }
|
||||
| --------------------------------- `self` not allowed in an implementation
|
||||
LL | one_line_reuse_expr2!(self.0);
|
||||
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
|
||||
|
||||
error[E0424]: expected value, found module `self`
|
||||
--> $DIR/impl-reuse-self-hygiene.rs:24:23
|
||||
|
|
||||
LL | macro_rules! one_line_reuse_expr2 { ($x:expr) => { reuse impl Trait for s3!() { $x } } }
|
||||
| --------------------------------- `self` not allowed in an implementation
|
||||
LL | one_line_reuse_expr2!(self.0);
|
||||
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
|
||||
|
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0424`.
|
||||
Reference in New Issue
Block a user