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 invalid syntax in proc macro attr #67567

Closed
guzt opened this issue Dec 23, 2019 · 1 comment · Fixed by #68256
Closed

ICE on invalid syntax in proc macro attr #67567

guzt opened this issue Dec 23, 2019 · 1 comment · Fixed by #68256
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@guzt
Copy link

guzt commented Dec 23, 2019

main.rs:

mod ice;
fn main() {
}

ice.rs:

use async_trait::async_trait;

#[async_trait]
pub trait T1 {
    async fn f1(&self) -> Result<m1::S1, ()>;
}

mod m1 {
    pub struct S1 {
        pub v1: String,
    }
}
pub enum E1 {}

#[async_trait]
impl T1 for () {
    async fn f1(&self) -> Result<m1::S1, ()> {
        if false {
            return m1::S1 {
                v1: format!(""),
            }
        } else {
            return Err(m1::E1::
        }
    }
}

(reduced sample courtesy of @ComputerDruid)

Output:

error: expected identifier, found `)`
  --> src/ice.rs:24:9
   |
24 |         }
   |         ^ expected identifier

error: incorrect close delimiter: `}`
  --> src/ice.rs:24:9
   |
22 |         } else {
   |                - close delimiter possibly meant for this
23 |             return Err(m1::E1::
   |                       - un-closed delimiter
24 |         }
   |         ^ incorrect close delimiter

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: DistinctSources(DistinctSources { begin: (Real("src/main.rs"), BytePos(0)), end: (Real("src/ice.rs"), BytePos(25)) })', src/libcore/result.rs:1188:5
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /b/s/w/ir/k/rust/src/liballoc/boxed.rs:1036
   7: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}
             at /b/s/w/ir/k/rust/src/libproc_macro/bridge/client.rs:305
   8: std::panicking::rust_panic_with_hook
   9: rust_begin_unwind
  10: core::panicking::panic_fmt
  11: core::result::unwrap_failed
  12: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  13: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  14: <rustc_errors::emitter::EmitterWriter as rustc_errors::emitter::Emitter>::emit_diagnostic
  15: <rustc_errors::json::JsonEmitter as rustc_errors::emitter::Emitter>::emit_diagnostic
  16: rustc_errors::HandlerInner::emit_diagnostic
  17: rustc_errors::diagnostic_builder::DiagnosticBuilder::emit_unless
  18: rustc_typeck::check::coercion::CoerceMany<E>::coerce_inner
  19: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  20: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  21: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  22: rustc_typeck::check::FnCtxt::check_block_with_expected
  23: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  24: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  25: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match
  26: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  27: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  28: rustc_typeck::check::FnCtxt::check_block_with_expected
  29: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  30: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  31: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  32: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  33: rustc_typeck::check::FnCtxt::check_block_with_expected
  34: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  35: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  36: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  37: rustc_typeck::check::check_fn
  38: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::check_expr_closure
  39: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  40: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  41: rustc_typeck::check::FnCtxt::check_argument_types
  42: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  43: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  44: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  45: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  46: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  47: rustc_typeck::check::check_fn
  48: rustc::ty::context::tls::with_context::{{closure}}
  49: rustc_typeck::check::typeck_tables_of
  50: rustc::ty::query::__query_compute::typeck_tables_of
  51: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  52: rustc::dep_graph::graph::DepGraph::with_task_impl
  53: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  54: rustc::ty::query::__query_compute::typeck_tables_of
  55: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  56: rustc::dep_graph::graph::DepGraph::with_task_impl
  57: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  58: rustc_typeck::collect::type_of
  59: rustc::ty::query::__query_compute::type_of
  60: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::type_of>::compute
  61: rustc::dep_graph::graph::DepGraph::with_task_impl
  62: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  63: rustc::hir::intravisit::walk_expr
  64: rustc::hir::intravisit::Visitor::visit_fn
  65: rustc::hir::intravisit::walk_item
  66: <rustc_typeck::collect::CollectItemTypesVisitor as rustc::hir::intravisit::Visitor>::visit_item
  67: rustc::hir::map::Map::visit_item_likes_in_module
  68: rustc_typeck::collect::collect_mod_item_types
  69: rustc::ty::query::__query_compute::collect_mod_item_types
  70: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_mod_item_types>::compute
  71: rustc::dep_graph::graph::DepGraph::with_task_impl
  72: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  73: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  74: rustc_typeck::check_crate::{{closure}}::{{closure}}
  75: rustc::util::common::time
  76: rustc_typeck::check_crate
  77: rustc_interface::passes::analysis
  78: rustc::ty::query::__query_compute::analysis
  79: rustc::dep_graph::graph::DepGraph::with_task_impl
  80: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  81: rustc::ty::context::tls::enter_global
  82: rustc_interface::interface::run_compiler_in_existing_thread_pool
  83: std::thread::local::LocalKey<T>::with
  84: scoped_tls::ScopedKey<T>::set
  85: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.42.0-nightly (c605199e8 2019-12-18) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck_tables_of] processing `<() as ice::T1>::f1::__f1`
#1 [typeck_tables_of] processing `<() as ice::T1>::f1::__f1::{{closure}}#0`
#2 [type_of] processing `<() as ice::T1>::f1::__f1::{{closure}}#0`
#3 [collect_mod_item_types] collecting item types in module `ice`
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors
@estebank estebank added 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) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 23, 2019
@Centril Centril added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example A-typesystem Area: The type system and removed A-typesystem Area: The type system labels Dec 23, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jan 2, 2020

triage: diagnostics produced prior to ICE seem like they probably help user fix problem (maybe)? So calling this P-medium. Removing nomination label.

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated labels Jan 2, 2020
@estebank estebank self-assigned this Jan 2, 2020
@JohnTitor JohnTitor added the C-bug Category: This is a bug. label Jan 12, 2020
tmandry added a commit to tmandry/rust that referenced this issue Jan 18, 2020
Do not ICE on malformed suggestion spans

Under the assumption that suggestions are by their very nature always "best effort", it is ok if we don't display them instead of having an ICE. The underlying issue of the malformed span being _created_ is left unaddressed.

Fix rust-lang#67567.

r? @petrochenkov
@bors bors closed this as completed in 7f6fdef Jan 18, 2020
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, ..) C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants