From 9889e44470cbc6ae3c8e2fcfb6016ed15ed8cf51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 18 Feb 2021 17:53:09 +0300 Subject: [PATCH] Fix popping singleton paths in when generating E0433 Fixes #82156 --- compiler/rustc_resolve/src/late.rs | 11 +++++------ src/test/ui/resolve/issue-82156.rs | 3 +++ src/test/ui/resolve/issue-82156.stderr | 9 +++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/resolve/issue-82156.rs create mode 100644 src/test/ui/resolve/issue-82156.stderr diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index cca40a793dd00..bf7acddde7564 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1801,7 +1801,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { crate_lint: CrateLint, ) -> PartialRes { tracing::debug!( - "smart_resolve_path_fragment(id={:?},qself={:?},path={:?}", + "smart_resolve_path_fragment(id={:?}, qself={:?}, path={:?})", id, qself, path @@ -1841,11 +1841,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { // Before we start looking for candidates, we have to get our hands // on the type user is trying to perform invocation on; basically: - // we're transforming `HashMap::new` into just `HashMap` - let path = if let Some((_, path)) = path.split_last() { - path - } else { - return Some(parent_err); + // we're transforming `HashMap::new` into just `HashMap`. + let path = match path.split_last() { + Some((_, path)) if !path.is_empty() => path, + _ => return Some(parent_err), }; let (mut err, candidates) = diff --git a/src/test/ui/resolve/issue-82156.rs b/src/test/ui/resolve/issue-82156.rs new file mode 100644 index 0000000000000..6215259e48657 --- /dev/null +++ b/src/test/ui/resolve/issue-82156.rs @@ -0,0 +1,3 @@ +fn main() { + super(); //~ ERROR failed to resolve: there are too many leading `super` keywords +} diff --git a/src/test/ui/resolve/issue-82156.stderr b/src/test/ui/resolve/issue-82156.stderr new file mode 100644 index 0000000000000..d53599dcce61b --- /dev/null +++ b/src/test/ui/resolve/issue-82156.stderr @@ -0,0 +1,9 @@ +error[E0433]: failed to resolve: there are too many leading `super` keywords + --> $DIR/issue-82156.rs:2:5 + | +LL | super(); + | ^^^^^ there are too many leading `super` keywords + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0433`.