`span_to_snippet` return value is a `Result`, not an `Option`
This commit is contained in:
parent
5774db6f3a
commit
badbb2daec
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue