Repository navigation
No index for a field #50493
Copy link
Copy link
Closed
Labels
P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Milestone
Description
This is a strange one to summarize. As best as I have been able to tell: the compiler ICEs with "no index for a field" if two derived functions each independently acknowledge the existence of a field that is not visible to them.
In any case, here is as far as I got minimizing this one:
#!/bin/sh
cargo new --lib repro
cargo new --lib repro_derive
echo >repro/src/lib.rs '
#[macro_use]
extern crate repro_derive;
#[derive(Derive)]
struct Restricted {
pub(in restricted) field: usize,
}
mod restricted {}
fn main() {}
'
echo >>repro/Cargo.toml '
repro_derive = { path = "../repro_derive" }
'
echo >repro_derive/src/lib.rs '
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_derive(Derive)]
pub fn derive(_: TokenStream) -> TokenStream {
let code = "
fn one(r: Restricted) {
r.field;
}
fn two(r: Restricted) {
r.field;
}
";
code.parse().unwrap()
}
'
echo >>repro_derive/Cargo.toml '
[lib]
proc-macro = true
'
cargo build --manifest-path repro/Cargo.tomlReasonable error message on stable and beta. But on nightly:
error: visibilities can only be restricted to ancestor modules
--> src/lib.rs:7:12
|
7 | pub(in restricted) field: usize,
| ^^^^^^^^^^
error[E0616]: field `field` of struct `Restricted` is private
--> src/lib.rs:5:10
|
5 | #[derive(Derive)]
| ^^^^^^
thread 'main' panicked at 'no index for a field', libcore/option.rs:914:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0616`.
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
Mentioning @petrochenkov who added the panicking function in #49718.
Metadata
Metadata
Assignees
Labels
P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Activity
emilyalbini commentedon May 7, 2018
Yep, a bisect points to #49718 as the cause. Also cc-ing the reviewer: @eddyb
nikomatsakis commentedon May 10, 2018
triage: P-high
@petrochenkov -- do you think you'll have time to investigate this?
petrochenkov commentedon May 10, 2018
Well, it's clear what happens - due to some earlier errors we do not resolve (to index) some field access so it ends up without entry in "resolution table" (
TypeckTables::field_indices).This probably needs a
self.is_tainted_by_errors()check inserted somewhere before thetcx.field_index(...)causing the ICE.(It would be nice if someone could post a backtrace,
RUST_BACKTRACE=1never worked on mingw andgdbbreakpoints on panics in rustc also stopped working some time ago.)dtolnay commentedon May 10, 2018
dlrobertson commentedon May 12, 2018
I took a quick look at this since I just worked on another ICE with
TypeckTables::field_indices(#50618). Similar to the fix for #50618 I think a better fix would be to fixtypeckby returningtcx.types.errhere instead offield_ty, but someone with more experience may want to weigh in on that.vegard commentedon May 14, 2018
I found this smaller input (which seems to be crashing in the same way) by fuzzing:
I can open a new issue if you think it's a different bug.
dlrobertson commentedon May 14, 2018
@vegard I get the expected output when I use my local build for the linked PR. Thanks for the additional test case!