From 7ebde241c00cd9eb816b1aa7cb212a946afb0d3e Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 9 Feb 2019 18:24:54 +0100 Subject: Fix two crashes found by running inference on all of rustc --- .../src/ty/snapshots/tests__infer_std_crash_1.snap | 13 +++++++++ .../src/ty/snapshots/tests__infer_std_crash_2.snap | 14 +++++++++ crates/ra_hir/src/ty/tests.rs | 33 ++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_1.snap create mode 100644 crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_2.snap (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_1.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_1.snap new file mode 100644 index 000000000..4b99788e4 --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_1.snap @@ -0,0 +1,13 @@ +--- +created: "2019-02-09T16:56:24.803326529Z" +creator: insta@0.6.1 +source: crates/ra_hir/src/ty/tests.rs +expression: "&result" +--- +[54; 139) '{ ... } }': () +[60; 137) 'match ... }': () +[66; 83) 'someth...nknown': Maybe<[unknown]> +[94; 124) 'Maybe:...thing)': Maybe<[unknown]> +[106; 123) 'ref mu...ething': &mut [unknown] +[128; 130) '()': () + diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_2.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_2.snap new file mode 100644 index 000000000..fd0b39b7d --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_2.snap @@ -0,0 +1,14 @@ +--- +created: "2019-02-09T17:03:11.974225590Z" +creator: insta@0.6.1 +source: crates/ra_hir/src/ty/tests.rs +expression: "&result" +--- +[23; 53) '{ ...n']; }': () +[29; 50) '&[0, b...b'\n']': &[u8] +[30; 50) '[0, b'...b'\n']': [u8] +[31; 32) '0': u8 +[34; 39) 'b'\n'': u8 +[41; 42) '1': u8 +[44; 49) 'b'\n'': u8 + diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 2621d1b55..3139eba0b 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -630,6 +630,39 @@ fn test() { ); } +#[test] +fn infer_std_crash_1() { + // caused stack overflow, taken from std + check_inference( + "infer_std_crash_1", + r#" +enum Maybe { + Real(T), + Fake, +} + +fn write() { + match something_unknown { + Maybe::Real(ref mut something) => (), + } +} +"#, + ); +} + +#[test] +fn infer_std_crash_2() { + // caused "equating two type variables, ...", taken from std + check_inference( + "infer_std_crash_2", + r#" +fn test_line_buffer() { + &[0, b'\n', 1, b'\n']; +} +"#, + ); +} + fn infer(content: &str) -> String { let (db, _, file_id) = MockDatabase::with_single_file(content); let source_file = db.parse(file_id); -- cgit v1.2.3