Rollup merge of #57560 - petrochenkov:selfinmac, r=alexreg
hygiene: Do not treat `Self` ctor as a local variable Fixes https://github.com/rust-lang/rust/issues/57523
This commit is contained in:
commit
33c5874966
2 changed files with 28 additions and 9 deletions
|
@ -2017,16 +2017,14 @@ impl<'a> Resolver<'a> {
|
||||||
if ident.name == keywords::Invalid.name() {
|
if ident.name == keywords::Invalid.name() {
|
||||||
return Some(LexicalScopeBinding::Def(Def::Err));
|
return Some(LexicalScopeBinding::Def(Def::Err));
|
||||||
}
|
}
|
||||||
if ns == TypeNS {
|
ident.span = if ident.name == keywords::SelfUpper.name() {
|
||||||
ident.span = if ident.name == keywords::SelfUpper.name() {
|
// FIXME(jseyfried) improve `Self` hygiene
|
||||||
// FIXME(jseyfried) improve `Self` hygiene
|
ident.span.with_ctxt(SyntaxContext::empty())
|
||||||
ident.span.with_ctxt(SyntaxContext::empty())
|
} else if ns == TypeNS {
|
||||||
} else {
|
ident.span.modern()
|
||||||
ident.span.modern()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ident = ident.modern_and_legacy();
|
ident.span.modern_and_legacy()
|
||||||
}
|
};
|
||||||
|
|
||||||
// Walk backwards up the ribs in scope.
|
// Walk backwards up the ribs in scope.
|
||||||
let record_used = record_used_id.is_some();
|
let record_used = record_used_id.is_some();
|
||||||
|
|
21
src/test/ui/resolve/issue-57523.rs
Normal file
21
src/test/ui/resolve/issue-57523.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
// compile-pass
|
||||||
|
|
||||||
|
struct S(u8);
|
||||||
|
|
||||||
|
impl S {
|
||||||
|
fn method1() -> Self {
|
||||||
|
Self(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! define_method { () => {
|
||||||
|
impl S {
|
||||||
|
fn method2() -> Self {
|
||||||
|
Self(0) // OK
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
define_method!();
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue