From 18cac495ac471d6d4baaf93d0d86a23643673d83 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 20 Mar 2023 13:40:20 -0700 Subject: [PATCH] Improve error message when parsing Ident encounters keyword --- src/ident.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ident.rs b/src/ident.rs index a24697f095..bd6f3f9f26 100644 --- a/src/ident.rs +++ b/src/ident.rs @@ -76,10 +76,16 @@ mod parsing { input.step(|cursor| { if let Some((ident, rest)) = cursor.ident() { if accept_as_ident(&ident) { - return Ok((ident, rest)); + Ok((ident, rest)) + } else { + Err(cursor.error(format_args!( + "expected identifier, found keyword `{}`", + ident, + ))) } + } else { + Err(cursor.error("expected identifier")) } - Err(cursor.error("expected identifier")) }) } }