From e5f9d54661a46c3e37130716264f8c5ea7540af9 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 11 Feb 2019 23:01:52 +0100 Subject: Fix another crash --- crates/ra_hir/src/ty.rs | 4 ++-- .../snapshots/tests__infer_nested_generics_crash.snap | 12 ++++++++++++ crates/ra_hir/src/ty/tests.rs | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 crates/ra_hir/src/ty/snapshots/tests__infer_nested_generics_crash.snap (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 2dc1de41a..f28a7e731 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -450,7 +450,6 @@ impl Ty { } pub fn walk(&self, f: &mut impl FnMut(&Ty)) { - f(self); match self { Ty::Slice(t) | Ty::Array(t) => t.walk(f), Ty::RawPtr(t, _) => t.walk(f), @@ -490,10 +489,10 @@ impl Ty { | Ty::Infer(_) | Ty::Unknown => {} } + f(self); } fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { - f(self); match self { Ty::Slice(t) | Ty::Array(t) => Arc::make_mut(t).walk_mut(f), Ty::RawPtr(t, _) => Arc::make_mut(t).walk_mut(f), @@ -544,6 +543,7 @@ impl Ty { | Ty::Infer(_) | Ty::Unknown => {} } + f(self); } fn fold(mut self, f: &mut impl FnMut(Ty) -> Ty) -> Ty { diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_nested_generics_crash.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_nested_generics_crash.snap new file mode 100644 index 000000000..209454a91 --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_nested_generics_crash.snap @@ -0,0 +1,12 @@ +--- +created: "2019-02-11T21:59:04.302375838Z" +creator: insta@0.6.1 +source: crates/ra_hir/src/ty/tests.rs +expression: "&result" +--- +[92; 106) 'query_response': Canonical> +[137; 167) '{ ...lue; }': () +[143; 164) '&query....value': &QueryResponse +[144; 158) 'query_response': Canonical> +[144; 164) 'query_....value': QueryResponse + diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index e64fd2749..203f1fe4d 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -719,6 +719,25 @@ fn extra_compiler_flags() { ); } +#[test] +fn infer_nested_generics_crash() { + // another crash found typechecking rustc + check_inference( + "infer_nested_generics_crash", + r#" +struct Canonical { + value: V, +} +struct QueryResponse { + value: V, +} +fn test(query_response: Canonical>) { + &query_response.value; +} +"#, + ); +} + 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