Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE on beta in macro expansion: "byte index out of bounds" in resolve_imports #56411

Closed
Shadlock0133 opened this issue Dec 1, 2018 · 3 comments · Fixed by #57908
Closed

ICE on beta in macro expansion: "byte index out of bounds" in resolve_imports #56411

Shadlock0133 opened this issue Dec 1, 2018 · 3 comments · Fixed by #57908
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Shadlock0133
Copy link
Contributor

lib.rs:

macro_rules! import {
    ( $($name:ident),* ) => {
        $(
            mod $name;
            pub use self::$name;
        )*
    }
}

import!(day1);

day1.rs is empty
error

ice git:(master)  RUST_BACKTRACE=1 cargo +beta build
   Compiling ice v0.1.0 (/home/shadlock0133/projects/rust/ice)                                           
thread 'main' panicked at 'byte index 45 is out of bounds of `self::$name`', libcore/str/mod.rs:2094:9   
stack backtrace:                                                                                         
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace                                          
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49                                            
   1: std::sys_common::backtrace::print                                                                  
             at libstd/sys_common/backtrace.rs:71                                                        
             at libstd/sys_common/backtrace.rs:59                                                        
   2: std::panicking::default_hook::{{closure}}                                                          
             at libstd/panicking.rs:211                                                                  
   3: std::panicking::default_hook                                                                       
             at libstd/panicking.rs:227                                                                  
   4: rustc::util::common::panic_hook                                                                    
   5: std::panicking::rust_panic_with_hook                                                               
             at libstd/panicking.rs:480                                                                  
   6: std::panicking::continue_panic_fmt                                                                 
             at libstd/panicking.rs:390                                                                  
   7: rust_begin_unwind                                                                                  
             at libstd/panicking.rs:325                                                                  
   8: core::panicking::panic_fmt                                                                         
             at libcore/panicking.rs:77                                                                  
   9: core::str::slice_error_fail                                                                        
             at libcore/str/mod.rs:0                                                                     
  10: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::RangeTo<usize>>::index::{{closure}}
  11: rustc_resolve::Resolver::report_conflict                                                           
  12: rustc_resolve::resolve_imports::ImportResolver::resolve_imports                                    
  13: rustc_resolve::macros::<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a, 'crateloader>>::resolve_imports
  14: syntax::ext::expand::MacroExpander::expand_fragment                                                
  15: syntax::ext::expand::MacroExpander::expand_crate                                                   
  16: rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}}                              
  17: rustc::util::common::time                                                                          
  18: rustc_driver::driver::phase_2_configure_and_expand                                                 
  19: rustc_driver::driver::compile_input                                                                
  20: rustc_driver::run_compiler_with_pool                                                               
  21: rustc_driver::driver::spawn_thread_pool                                                            
  22: rustc_driver::run_compiler                                                                         
  23: <scoped_tls::ScopedKey<T>>::set                                                                    
  24: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once                    
  25: __rust_maybe_catch_panic                                                                           
             at libpanic_unwind/lib.rs:102                                                               
  26: rustc_driver::run                                                                                  
  27: rustc_driver::main                                                                                 
  28: std::rt::lang_start::{{closure}}                                                                   
  29: std::panicking::try::do_call                                                                       
             at libstd/rt.rs:59                                                                          
             at libstd/panicking.rs:310                                                                  
  30: __rust_maybe_catch_panic                                                                           
             at libpanic_unwind/lib.rs:102                                                               
  31: std::rt::lang_start_internal                                                                       
             at libstd/panicking.rs:289                                                                  
             at libstd/panic.rs:392                                                                      
             at libstd/rt.rs:58                                                                          
  32: main                                                                                               
  33: __libc_start_main                                                                                  
  34: <unknown>                                                                                          
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: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.31.0-beta.19 (42053f9f0 2018-11-26) running on x86_64-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

error: Could not compile ice.

To learn more, run the command again with --verbose.

@Centril Centril added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Dec 2, 2018
@petrochenkov
Copy link
Contributor

More or less same as #56187.
fn report_conflict should stop doing span arithmetics.
cc @estebank @mockersf

@petrochenkov petrochenkov removed their assignment Dec 2, 2018
@mockersf
Copy link
Contributor

I don't see how not to do span arithmetics here ?
In use foo::A as B, the snippet is foo::A as B, source is A and the binding is foo::A as B.
By taking the snippet that starts at the beginning of the binding span and end at the end of source span, we have foo::A

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.

@estebank
Copy link
Contributor

@mockersf we could completely avoid span arithmetics by giving ImportDirectiveSubclass::SingleImport 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).

Centril added a commit to Centril/rust that referenced this issue Jan 26, 2019
resolve: Fix span arithmetics in the import conflict error

rust-lang#56937 rebased and fixed

Fixes rust-lang#56411
Fixes rust-lang#57071
Fixes rust-lang#57787

r? @estebank
Centril added a commit to Centril/rust that referenced this issue Jan 26, 2019
resolve: Fix span arithmetics in the import conflict error

rust-lang#56937 rebased and fixed

Fixes rust-lang#56411
Fixes rust-lang#57071
Fixes rust-lang#57787

r? @estebank
Centril added a commit to Centril/rust that referenced this issue Jan 26, 2019
resolve: Fix span arithmetics in the import conflict error

rust-lang#56937 rebased and fixed

Fixes rust-lang#56411
Fixes rust-lang#57071
Fixes rust-lang#57787

r? @estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants