diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-02-05 16:02:22 +0100 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-02-05 23:47:17 +0100 |
| commit | fa9d2230a65689289f64c897ad30c83251762320 (patch) | |
| tree | 74fbc5bce88cb1a095021dfd45940b11ee0592ac /src/libsyntax/parse | |
| parent | 189930fcae287565dcef856ae8d60a83190a4b92 (diff) | |
| download | rust-fa9d2230a65689289f64c897ad30c83251762320.tar.gz rust-fa9d2230a65689289f64c897ad30c83251762320.zip | |
make codemap more robust in face of ill-formed spans.
This can be considered partial work on #8256. The main observable change: macro expansion sometimes results in spans where `lo > hi`; so for now, when we have such a span, do not attempt to return a snippet result. (Longer term, we might think about whether we could still present a snippet for the cases where this arises, e.g. perhaps by showing the whole macro as the snippet, assuming that is the sole cause of such spans; or by somehow looking up the closest AST node that holds both `lo` and `hi`, and showing that.) As a drive-by, revised the API to return a `Result` rather than an `Option`, with better information-packed error value that should help us (and maybe also our users) identify the causes of such problems in the future. Ideally the call-sites that really want an actual snippet would be updated to catch the newly added `Err` case and print something meaningful about it, but that is not part of this PR.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 6ff5c77f507..9e9ec08da03 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -1233,8 +1233,8 @@ mod test { let span = tts.iter().rev().next().unwrap().get_span(); match sess.span_diagnostic.cm.span_to_snippet(span) { - Some(s) => assert_eq!(&s[], "{ body }"), - None => panic!("could not get snippet"), + Ok(s) => assert_eq!(&s[], "{ body }"), + Err(_) => panic!("could not get snippet"), } } } |
