Skip to content

Commit

Permalink
Rollup merge of rust-lang#57560 - petrochenkov:selfinmac, r=alexreg
Browse files Browse the repository at this point in the history
hygiene: Do not treat `Self` ctor as a local variable

Fixes rust-lang#57523
  • Loading branch information
Centril committed Jan 13, 2019
2 parents c04d6fa + 805099c commit 33c5874
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,16 +2017,14 @@ impl<'a> Resolver<'a> {
if ident.name == keywords::Invalid.name() {
return Some(LexicalScopeBinding::Def(Def::Err));
}
if ns == TypeNS {
ident.span = if ident.name == keywords::SelfUpper.name() {
// FIXME(jseyfried) improve `Self` hygiene
ident.span.with_ctxt(SyntaxContext::empty())
} else {
ident.span.modern()
}
ident.span = if ident.name == keywords::SelfUpper.name() {
// FIXME(jseyfried) improve `Self` hygiene
ident.span.with_ctxt(SyntaxContext::empty())
} else if ns == TypeNS {
ident.span.modern()
} else {
ident = ident.modern_and_legacy();
}
ident.span.modern_and_legacy()
};

// Walk backwards up the ribs in scope.
let record_used = record_used_id.is_some();
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/resolve/issue-57523.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 33c5874

Please sign in to comment.