From badbb2daece340f2e69b54ee8a1e9071bd428222 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sat, 30 Jun 2018 08:37:15 -0700 Subject: [PATCH] `span_to_snippet` return value is a `Result`, not an `Option` --- src/diag.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diag.md b/src/diag.md index 389ba2bb..5984e862 100644 --- a/src/diag.md +++ b/src/diag.md @@ -56,7 +56,7 @@ let mut err = sess.struct_span_err(sp, "oh no! this is an error!"); // In some cases, you might need to check if `sp` is generated by a macro to // avoid printing weird errors about macro-generated code. -if let Some(snippet) = sess.codemap().span_to_snippet(sp) { +if let Ok(snippet) = sess.codemap().span_to_snippet(sp) { // Use the snippet to generate a suggested fix err.span_suggestion(suggestion_sp, "try using a qux here", format!("qux {}", snip)); } else { @@ -90,7 +90,7 @@ For example, to make our `qux` suggestion machine-applicable, we would do: ```rust,ignore let mut err = sess.struct_span_err(sp, "oh no! this is an error!"); -if let Some(snippet) = sess.codemap().span_to_snippet(sp) { +if let Ok(snippet) = sess.codemap().span_to_snippet(sp) { // Add applicability info! err.span_suggestion_with_applicability( suggestion_sp,