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 enumerations referred to by submodules (submodule is declared before enum) #5900

Closed
mstewartgallus opened this issue Apr 16, 2013 · 6 comments · Fixed by #11832
Closed
Labels
A-resolve Area: Name resolution I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@mstewartgallus
Copy link
Contributor

WIth rust 0.6 master, and incoming, I get an internal compile error:

error: internal compiler error: node_id_to_type: no type for node `expr 0 as int  id=13)`

This is a simple test case that reproduces the error:

pub mod buffer_binding {
   use super::BufferType;

   pub struct Context { handle : BufferType }
}

pub enum BufferType {
   ArrayBuffer = 0 as int
}

Strangely, the error only happens when the enumeration is defined after the submodule.

@Aatch
Copy link
Contributor

Aatch commented Jun 7, 2013

Still valid.

Nominating for a milestone.

@huonw
Copy link
Member

huonw commented Jul 23, 2013

This appears to be an interaction between the as int and the submodule specifically, i.e. removing either of them makes it compile without issue.

@graydon
Copy link
Contributor

graydon commented Aug 22, 2013

accepted for production-ready milestone

@ghost
Copy link

ghost commented Oct 21, 2013

this still happens with 69e46f3 from master.

But thx for the workaround Aatch

@jld
Copy link
Contributor

jld commented Oct 21, 2013

#9942 looks like it might be a duplicate of this issue.

@jfager
Copy link
Contributor

jfager commented Nov 21, 2013

I've been digging into this a little bit. The direct problem on the non-compiling case given is that a cast expression needs more information than is currently available when check_item is called for the Context struct.

The lookup that's failing is

let ety = tcx.expr_ty(e);

in the ExprCast arm of middle::const_eval::eval_const_expr_partial, which is getting called via check_struct -> check_instantiable -> is_instantiable -> subtypes_require (ty_enum case) -> enum_variants.

I can make the sample code compile if I add

match variant.node.disr_expr {
    Some(e) => write_ty_to_tcx(tcx, e.id, result_ty),
    _ => {}
}

to the end of middle::typeck::collect::get_enum_variant_types and then pad out the inner case list on the ExprCast arm of middle::const_eval::eval_const_expr_partial to:

ty::ty_int(_) | ty::ty_bool | ty::ty_enum(_,_) => {

I'm pretty doubtful this is the right solution, it's just a hack to highlight the issue.

As far as why slight variations work:

  • If the cast is removed, the code compiles because we hit the ExprLit arm of eval_const_expr_partial instead of ExprCast.
  • If the enum is placed before the mod block, the code compiles because check_item gets called on the enum before it gets called on the struct, which has the side effect of putting all the right ids into the type context.

It seems like the "right" answer would be ensuring that enums are checked before things that use them, but figuring out how to do that is still a bit out of my depth.

@bors bors closed this as completed in 5a61812 Jan 31, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 28, 2020
…phansch

Fix: keep parenthesis for suggestion in `useless_conversion` lint

Note: this lint was previously named `identity_conversion`.

fixes: rust-lang#4750

changelog: fix parenthesis for `useless_conversion` lint suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name resolution 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.

6 participants