Skip to content

Commit 33c5874

Browse files
authored
Rollup merge of rust-lang#57560 - petrochenkov:selfinmac, r=alexreg
hygiene: Do not treat `Self` ctor as a local variable Fixes rust-lang#57523
2 parents c04d6fa + 805099c commit 33c5874

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/librustc_resolve/lib.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -2017,16 +2017,14 @@ impl<'a> Resolver<'a> {
20172017
if ident.name == keywords::Invalid.name() {
20182018
return Some(LexicalScopeBinding::Def(Def::Err));
20192019
}
2020-
if ns == TypeNS {
2021-
ident.span = if ident.name == keywords::SelfUpper.name() {
2022-
// FIXME(jseyfried) improve `Self` hygiene
2023-
ident.span.with_ctxt(SyntaxContext::empty())
2024-
} else {
2025-
ident.span.modern()
2026-
}
2020+
ident.span = if ident.name == keywords::SelfUpper.name() {
2021+
// FIXME(jseyfried) improve `Self` hygiene
2022+
ident.span.with_ctxt(SyntaxContext::empty())
2023+
} else if ns == TypeNS {
2024+
ident.span.modern()
20272025
} else {
2028-
ident = ident.modern_and_legacy();
2029-
}
2026+
ident.span.modern_and_legacy()
2027+
};
20302028

20312029
// Walk backwards up the ribs in scope.
20322030
let record_used = record_used_id.is_some();

src/test/ui/resolve/issue-57523.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// compile-pass
2+
3+
struct S(u8);
4+
5+
impl S {
6+
fn method1() -> Self {
7+
Self(0)
8+
}
9+
}
10+
11+
macro_rules! define_method { () => {
12+
impl S {
13+
fn method2() -> Self {
14+
Self(0) // OK
15+
}
16+
}
17+
}}
18+
19+
define_method!();
20+
21+
fn main() {}

0 commit comments

Comments
 (0)