]> git.lizzy.rs Git - rust.git/commitdiff
Check generated save-analysis, instead of `bug!()`ing
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Sun, 15 Apr 2018 11:47:45 +0000 (20:47 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Sun, 15 Apr 2018 12:41:28 +0000 (21:41 +0900)
Injected crates don't have extern info. Let's skip them.

src/librustc_save_analysis/lib.rs
src/test/run-make-fulldeps/save-analysis-rfc2126/Makefile
src/test/run-make-fulldeps/save-analysis-rfc2126/validate_json.py [new file with mode: 0644]

index 34a9b57c9dc3de8a78f3e6515863925a475bf1f8..f494e982f7f20cb531b04cc83b58a331aca1874a 100644 (file)
@@ -115,7 +115,8 @@ pub fn get_external_crates(&self) -> Vec<ExternalCrateData> {
             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());
index 2f5ed6716d64567b821ab396fadfcda5a61ce371..a132668ec7c8a43a4e85426fe98f5976e492013e 100644 (file)
@@ -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 (file)
index 0000000..caab8d0
--- /dev/null
@@ -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 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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))