From c3dc014378e855bf41fd75e5b4ff956b67766656 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Sun, 15 Apr 2018 20:47:45 +0900 Subject: [PATCH] Check generated save-analysis, instead of `bug!()`ing Injected crates don't have extern info. Let's skip them. --- src/librustc_save_analysis/lib.rs | 3 ++- .../save-analysis-rfc2126/Makefile | 2 ++ .../save-analysis-rfc2126/validate_json.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/test/run-make-fulldeps/save-analysis-rfc2126/validate_json.py diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 34a9b57c9dc..f494e982f7f 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -115,7 +115,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { let span = match *self.tcx.extern_crate(n.as_def_id()) { Some(ExternCrate { span, .. }) => span, None => { - bug!("no data for crate {}", n); + debug!("Skipping crate {}, no data", n); + continue; } }; let lo_loc = self.span_utils.sess.codemap().lookup_char_pos(span.lo()); diff --git a/src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile b/src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile index 2f5ed6716d6..a132668ec7c 100644 --- a/src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile +++ b/src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile @@ -2,7 +2,9 @@ all: extern_absolute_paths.rs extern_in_paths.rs krate2 $(RUSTC) extern_absolute_paths.rs -Zsave-analysis + cat $(TMPDIR)/save-analysis/extern_absolute_paths.json | "$(PYTHON)" validate_json.py $(RUSTC) extern_in_paths.rs -Zsave-analysis + cat $(TMPDIR)/save-analysis/extern_in_paths.json | "$(PYTHON)" validate_json.py krate2: krate2.rs $(RUSTC) $< diff --git a/src/test/run-make-fulldeps/save-analysis-rfc2126/validate_json.py b/src/test/run-make-fulldeps/save-analysis-rfc2126/validate_json.py new file mode 100644 index 00000000000..caab8d0d626 --- /dev/null +++ b/src/test/run-make-fulldeps/save-analysis-rfc2126/validate_json.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +# Copyright 2018 The Rust Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution and at +# http://rust-lang.org/COPYRIGHT. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +import sys +import json + +crates = json.loads(sys.stdin.readline().strip())["prelude"]["external_crates"] +assert any(map(lambda c: c["id"]["name"] == "krate2", crates))