Change:
); // See https://github.com/rust-lang/rust/issues/32354 <del> if old_binding.is_import() || new_binding.is_import() { let binding = if new_binding.is_import() && !new_binding.span.is_dummy() { new_binding </del> <ins> let directive = match (&new_binding.kind, &old_binding.kind) { (NameBindingKind::Import { directive, .. }, _) if !new_binding.span.is_dummy() => Some((directive, new_binding.span)), (_, NameBindingKind::Import { directive, .. }) if !old_binding.span.is_dummy() => Some((directive, old_binding.span)), _ => None, }; if let Some((directive, binding_span)) = directive { let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { format!("Other{}", name) </ins> } else { <del> old_binding </del> <ins> format!("other_{}", name) </ins> }; <del> let cm = self.session.source_map(); let rename_msg = "you can use `as` to change the binding name of the import"; if let ( Ok(snippet), NameBindingKind::Import { directive, ..}, _dummy @ false, ) = ( cm.span_to_snippet(binding.span), binding.kind.clone(), binding.span.is_dummy(), ) { let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { format!("Other{}", name) } else { format!("other_{}", name) }; </del> <ins> let mut suggestion = None; match directive.subclass { ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } => suggestion = Some(format!("self as {}", suggested_name)), ImportDirectiveSubclass::SingleImport { source, .. } => { if let Some(pos) = source.span.hi().0.checked_sub(binding_span.lo().0) .map(|pos| pos as usize) { if let Ok(snippet) = self.session.source_map() .span_to_snippet(binding_span) { if pos <= snippet.len() { suggestion = Some(format!( "{} as {}{}", &snippet[..pos], suggested_name, if snippet.ends_with(";") { ";" } else { "" } )) } } } } ImportDirectiveSubclass::ExternCrate { source, target, .. } => suggestion = Some(format!( "extern crate {} as {};", source.unwrap_or(target.name), suggested_name, )), _ => unreachable!(), } let rename_msg = "you can use `as` to change the binding name of the import"; if let Some(suggestion) = suggestion { </ins> err.span_suggestion_with_applicability( <del> binding.span, &rename_msg, match directive.subclass { ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } => format!("self as {}", suggested_name), ImportDirectiveSubclass::SingleImport { source, .. } => format!( "{} as {}{}", &snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)], suggested_name, if snippet.ends_with(";") { ";" } else { "" } ), ImportDirectiveSubclass::ExternCrate { source, target, .. } => format!( "extern crate {} as {};", source.unwrap_or(target.name), suggested_name, ), _ => unreachable!(), }, </del> <ins> binding_span, rename_msg, suggestion, </ins> Applicability::MaybeIncorrect, ); } else { <del> err.span_label(binding.span, rename_msg); </del> <ins> err.span_label(binding_span, rename_msg); </ins> } }

Discussion:
As of rustc 1.33.0-nightly ( 2018-12-22) the following macro invocation fails with an ICE. Mentioning and because this may have to do with slicing introduced in . Same repro in script form:
is working on a solution in

<details </summary<p</p is empty <details<summaryerror </summary<p<pre<font color="#AB4642"<b </b</font<font color="C1B9"<bice</b</font<font color="CAFC2"<bgit:(</b</font<font color="#AB4642"<bmaster</b</font<font color="CAFC2"<b) </b</font<font color="#F7CA88"<b</b</fontRUSTBACKTRACE=1 cargo +beta build <font color="#A1B56C"<bCompiling</b</fontice v0.1.0 (/home/shadlock0133/projects/rust/ice) thread &apos;main&apos; panicked at &apos;byte index 45 is out of bounds of &apos; stack backtrace: 0: std::sys::unix::backtrace::tracing::imp::unwindbacktrace at 1: std::syscommon::backtrace::print at at 2: std::panicking::defaulthook::{{closure}} at 3: std::panicking::defaulthook at 4: rustc::util::common::panichook 5: std::panicking::rustpanicwithhook at 6: std::panicking::continuepanicfmt at 7: rustbeginunwind at 8: core::panicking::panicfmt at 9: core::str::sliceerrorfail at 10: core::str::traits::&lt;impl core::slice::SliceIndex&lt;str&gt; for core::ops::range::RangeTo&lt;usize&gt;&gt;::index::{{closure}} 11: rustcresolve::Resolver::reportconflict 12: rustcresolve::resolveimports::ImportResolver::resolveimports 13: rustcresolve::macros::&lt;impl syntax::ext::base::Resolver for rustcresolve::Resolver&lt;&apos;a, &apos;crateloader&gt;&gt;

::resolveimports 14: syntax::ext::expand::MacroExpander::expandfragment 15: syntax::ext::expand::MacroExpander::expandcrate 16: rustcdriver::driver::phase2configureandexpandinner::{{closure}} 17: rustc::util::common::time 18: rustcdriver::driver::phase2configureandexpand 19: rustcdriver::driver::compileinput 20: rustcdriver::runcompilerwithpool 21: rustcdriver::driver::spawnthreadpool 22: rustcdriver::runcompiler 23: &lt;scopedtls::ScopedKey&lt;T&gt;&gt;::set 24: &lt;std::panic::AssertUnwindSafe&lt;F&gt; as core::ops::function::FnOnce&lt;()&gt;&gt;::callonce 25: rustmaybecatchpanic at 26: rustcdriver::run 27: rustcdriver::main 28: std::rt::langstart::{{closure}} 29: std::panicking::try::docall at at 30: rustmaybecatchpanic at 31: std::rt::langstartinternal at at at 32: main 33: libcstartmain 34: &lt;unknown&gt; query stack during panic: end of query stack error: internal compiler error: unexpected panic note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: note: rustc 1.31.0-beta.19 ( 2018-11-26) running on x8664-unknown-linux-gnu note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib note: some of the compiler flags provided by cargo are hidden <font color="#AB4642"<berror:</b</fontCould not compile . To learn more, run the command again with --verbose. </pre</p</details
More or less same as should stop doing span arithmetics. cc
I don't see how not to do span arithmetics here ? In , the snippet is , source is and the binding is .

By taking the snippet that starts at the beginning of the binding span and end at the end of source span, we have In this case, I think it would be better to remove the suggestion when the issue happens in a macro because the suggestion will be wrong anyway.
we could completely avoid span arithmetics by giving more useful spans, instead of having to come up with them on the spot. The counterarguments to that would be that it would increase memory usage in every import and that this suggestion is already useless in macro context (especially in this case).