diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 238145a061f55..32b55a05124ac 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2046,7 +2046,8 @@ impl<'a> LoweringContext<'a> { }; // Correctly resolve `self` imports - if path.segments.last().unwrap().identifier.name == keywords::SelfValue.name() { + if path.segments.len() > 1 && + path.segments.last().unwrap().identifier.name == keywords::SelfValue.name() { let _ = path.segments.pop(); if ident.name == keywords::SelfValue.name() { *name = path.segments.last().unwrap().identifier.name; diff --git a/src/test/ui/issue-47623.rs b/src/test/ui/issue-47623.rs new file mode 100644 index 0000000000000..0c886fdb52faa --- /dev/null +++ b/src/test/ui/issue-47623.rs @@ -0,0 +1,13 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use self; //~ERROR `self` imports are only allowed within a { } list + +fn main() {} diff --git a/src/test/ui/issue-47623.stderr b/src/test/ui/issue-47623.stderr new file mode 100644 index 0000000000000..c5a42d4d846e8 --- /dev/null +++ b/src/test/ui/issue-47623.stderr @@ -0,0 +1,8 @@ +error[E0429]: `self` imports are only allowed within a { } list + --> $DIR/issue-47623.rs:11:5 + | +11 | use self; //~ERROR `self` imports are only allowed within a { } list + | ^^^^ + +error: aborting due to previous error +