Skip to content

Commit 977d7ab

Browse files
committed
refactor: use path to get ident name
1 parent 5c44314 commit 977d7ab

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1966,11 +1966,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
19661966
fn let_binding_suggestion(&mut self, err: &mut Diagnostic, ident_span: Span) -> bool {
19671967
if let Some(Expr { kind: ExprKind::Assign(lhs, ..), .. }) =
19681968
self.diagnostic_metadata.in_assignment
1969-
&& let ast::ExprKind::Path(None, _) = lhs.kind
1969+
&& let ast::ExprKind::Path(None, ref path) = lhs.kind
19701970
{
19711971
if !ident_span.from_expansion() {
1972-
let (span, text) = match self.r.tcx.sess.source_map().span_to_snippet(ident_span) {
1973-
Ok(ref name) if let Some(name) = name.strip_prefix("let") => {
1972+
let (span, text) = match path.segments.first().map(|it| it.ident.as_str()) {
1973+
Some(name) if let Some(name) = name.strip_prefix("let") => {
19741974
// a special case for #117894
19751975
let name = name.strip_prefix("_").unwrap_or(name);
19761976
(ident_span, format!("let {name}"))

0 commit comments

Comments
 (0)