diff options
Diffstat (limited to 'src/librustc/traits/error_reporting.rs')
| -rw-r--r-- | src/librustc/traits/error_reporting.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index e649f1b49df..61456b3b003 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -551,6 +551,24 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { let OnUnimplementedNote { message, label } = self.on_unimplemented_note(trait_ref, obligation); let have_alt_message = message.is_some() || label.is_some(); + let span = match self.tcx.sess.codemap().span_to_snippet(span) { + Ok(ref s) if s.starts_with("for ") => { + // On for loops, this error is caused by the element being iterated + // on, but the span points at the entire for loop. Instead of: + // + // / for c in "asdf" { + // | ... + // | } + // |_^ `&str` is not an iterator + // + // lets point at: + // + // for c in "asdf" { + // ^^^^^^^^^^^^^^^ `&str` is not an iterator + self.tcx.sess.codemap().span_until_char(span, '{') + } + _ => span, + }; let mut err = struct_span_err!( self.tcx.sess, |
