Repository: rust-analyzer/rust-analyzer
Pull request #4378 (2020-05-08 16:54:22)

Add stderr to error message


bors r+
🤖


Patch:
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 614c352a0c..83f946eeea 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -501,8 +501,8 @@ impl<'a> InferenceContext<'a> {
                 }
                 Literal::ByteString(..) => {
                     let byte_type = Ty::simple(TypeCtor::Int(Uncertain::Known(IntTy::u8())));
-                    let array_type = Ty::apply_one(TypeCtor::Array, byte_type);
-                    Ty::apply_one(TypeCtor::Ref(Mutability::Shared), array_type)
+                    let slice_type = Ty::apply_one(TypeCtor::Slice, byte_type);
+                    Ty::apply_one(TypeCtor::Ref(Mutability::Shared), slice_type)
                 }
                 Literal::Char(..) => Ty::simple(TypeCtor::Char),
                 Literal::Int(_v, ty) => Ty::simple(TypeCtor::Int((*ty).into())),
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 5a0a87ed7d..3adb8baf6a 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -600,7 +600,12 @@ pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions {
 fn output(mut cmd: Command) -> Result<Output> {
     let output = cmd.output().with_context(|| format!("{:?} failed", cmd))?;
     if !output.status.success() {
-        bail!("{:?} failed, {}", cmd, output.status)
+        match String::from_utf8(output.stderr) {
+            Ok(stderr) if !stderr.is_empty() => {
+                bail!("{:?} failed, {}\nstderr:\n{}", cmd, output.status, stderr)
+            }
+            _ => bail!("{:?} failed, {}", cmd, output.status),
+        }
     }
     Ok(output)
 }


Test patch:
diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs
index 67f964ab5d..ab87f598a6 100644
--- a/crates/ra_hir_ty/src/tests/method_resolution.rs
+++ b/crates/ra_hir_ty/src/tests/method_resolution.rs
@@ -17,8 +17,8 @@ impl<T> [T] {
 #[lang = "slice_alloc"]
 impl<T> [T] {}
 
-fn test(x: &[u8]) {
-    <[_]>::foo(x);
+fn test() {
+    <[_]>::foo(b"foo");
 }
 "#),
         @r###"
@@ -26,11 +26,10 @@ fn test(x: &[u8]) {
     56..79 '{     ...     }': T
     66..73 'loop {}': !
     71..73 '{}': ()
-    131..132 'x': &[u8]
-    141..163 '{     ...(x); }': ()
-    147..157 '<[_]>::foo': fn foo<u8>(&[u8]) -> u8
-    147..160 '<[_]>::foo(x)': u8
-    158..159 'x': &[u8]
+    133..160 '{     ...o"); }': ()
+    139..149 '<[_]>::foo': fn foo<u8>(&[u8]) -> u8
+    139..157 '<[_]>:..."foo")': u8
+    150..156 'b"foo"': &[u8]
     "###
     );
 }
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs
index e17a179004..3d3088965d 100644
--- a/crates/ra_hir_ty/src/tests/simple.rs
+++ b/crates/ra_hir_ty/src/tests/simple.rs
@@ -414,7 +414,7 @@ fn test() {
     27..31 '5f32': f32
     37..41 '5f64': f64
     47..54 '"hello"': &str
-    60..68 'b"bytes"': &[u8; _]
+    60..68 'b"bytes"': &[u8]
     74..77 ''c'': char
     83..87 'b'b'': u8
     93..97 '3.14': f64
@@ -422,7 +422,7 @@ fn test() {
     113..118 'false': bool
     124..128 'true': bool
     134..202 'r#"   ...    "#': &str
-    208..218 'br#"yolo"#': &[u8; _]
+    208..218 'br#"yolo"#': &[u8]
     "###
     );
 }