From 7e104ea4a885c8fd6f348a0d7d30911fe49d91e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 22 Jun 2020 14:18:10 +0300 Subject: Bump chalk --- crates/ra_hir_ty/Cargo.toml | 4 +- crates/ra_hir_ty/src/tests/coercion.rs | 42 +++++++------ crates/ra_hir_ty/src/tests/traits.rs | 8 +-- crates/ra_hir_ty/src/traits/chalk.rs | 86 ++++++++++++++++++++++----- crates/ra_hir_ty/src/traits/chalk/interner.rs | 1 + crates/ra_hir_ty/src/traits/chalk/mapping.rs | 9 ++- 6 files changed, 109 insertions(+), 41 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml index 112fcd07e..407322dc1 100644 --- a/crates/ra_hir_ty/Cargo.toml +++ b/crates/ra_hir_ty/Cargo.toml @@ -27,8 +27,8 @@ test_utils = { path = "../test_utils" } scoped-tls = "1" -chalk-solve = "0.11" -chalk-ir = "0.11" +chalk-solve = { version = "0.15.0-dev.0", git = "https://github.com/rust-lang/chalk" } +chalk-ir = { version = "0.15.0-dev.0", git = "https://github.com/rust-lang/chalk" } [dev-dependencies] insta = "0.16.0" diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index a2601c68a..5a1c6ccc3 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs @@ -664,6 +664,8 @@ fn test() { fn coerce_unsize_trait_object() { assert_snapshot!( infer_with_mismatches(r#" +#[lang = "sized"] +pub trait Sized {} #[lang = "unsize"] pub trait Unsize {} #[lang = "coerce_unsized"] @@ -689,19 +691,19 @@ fn test() { } "#, true), @r###" - 387..572 '{ ...bj2; }': () - 397..400 'obj': &dyn Baz - 422..424 '&S': &S - 423..424 'S': S - 434..437 'obj': &dyn Bar - 459..462 'obj': &dyn Baz - 472..475 'obj': &dyn Foo - 494..497 'obj': &dyn Bar - 507..511 'obj2': &dyn Baz - 533..535 '&S': &S - 534..535 'S': S - 545..546 '_': &dyn Foo - 565..569 'obj2': &dyn Baz + 424..609 '{ ...bj2; }': () + 434..437 'obj': &dyn Baz + 459..461 '&S': &S + 460..461 'S': S + 471..474 'obj': &dyn Bar + 496..499 'obj': &dyn Baz + 509..512 'obj': &dyn Foo + 531..534 'obj': &dyn Bar + 544..548 'obj2': &dyn Baz + 570..572 '&S': &S + 571..572 'S': S + 582..583 '_': &dyn Foo + 602..606 'obj2': &dyn Baz "### ); } @@ -710,6 +712,8 @@ fn test() { fn coerce_unsize_super_trait_cycle() { assert_snapshot!( infer_with_mismatches(r#" +#[lang = "sized"] +pub trait Sized {} #[lang = "unsize"] pub trait Unsize {} #[lang = "coerce_unsized"] @@ -734,12 +738,12 @@ fn test() { } "#, true), @r###" - 291..347 '{ ...obj; }': () - 301..304 'obj': &dyn D - 315..317 '&S': &S - 316..317 'S': S - 327..330 'obj': &dyn A - 341..344 'obj': &dyn D + 328..384 '{ ...obj; }': () + 338..341 'obj': &dyn D + 352..354 '&S': &S + 353..354 'S': S + 364..367 'obj': &dyn A + 378..381 'obj': &dyn D "### ); } diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 646e1715c..71c0c2d27 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1753,11 +1753,11 @@ fn test() { 384..500 '{ ...(f); }': () 394..397 'bar': Bar u32> 423..426 'bar': Bar u32> - 423..432 'bar.foo()': {unknown} + 423..432 'bar.foo()': (u8, u32) 443..446 'opt': Opt 465..466 'f': fn(u8) -> u32 487..490 'opt': Opt - 487..497 'opt.map(f)': Opt u32, (u8,)>> + 487..497 'opt.map(f)': Opt 495..496 'f': fn(u8) -> u32 "### ); @@ -1830,9 +1830,9 @@ fn test() { 634..643 'Lazy::new': fn new Foo>(fn() -> Foo) -> Lazy Foo> 634..660 'Lazy::...n_ptr)': Lazy Foo> 644..659 'make_foo_fn_ptr': fn() -> Foo - 670..672 'r2': {unknown} + 670..672 'r2': usize 675..680 'lazy2': Lazy Foo> - 675..686 'lazy2.foo()': {unknown} + 675..686 'lazy2.foo()': usize 549..551 '{}': () "### ); diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 2f35d6d49..8ef4941c0 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -48,6 +48,9 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn adt_datum(&self, struct_id: AdtId) -> Arc { self.db.struct_datum(self.krate, struct_id) } + fn adt_repr(&self, _struct_id: AdtId) -> rust_ir::AdtRepr { + unreachable!() + } fn impl_datum(&self, impl_id: ImplId) -> Arc { self.db.impl_datum(self.krate, impl_id) } @@ -128,8 +131,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { well_known_trait: rust_ir::WellKnownTrait, ) -> Option> { let lang_attr = lang_attr_from_well_known_trait(well_known_trait); - let lang_items = self.db.crate_lang_items(self.krate); - let trait_ = match lang_items.target(lang_attr) { + let trait_ = match self.db.lang_item(self.krate, lang_attr.into()) { Some(LangItemTarget::TraitId(trait_)) => trait_, _ => return None, }; @@ -186,6 +188,39 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { // FIXME: implement actual object safety true } + + fn closure_kind( + &self, + _closure_id: chalk_ir::ClosureId, + _substs: &chalk_ir::Substitution, + ) -> rust_ir::ClosureKind { + // FIXME: implement closure support + unimplemented!() + } + fn closure_inputs_and_output( + &self, + _closure_id: chalk_ir::ClosureId, + _substs: &chalk_ir::Substitution, + ) -> chalk_ir::Binders> { + // FIXME: implement closure support + unimplemented!() + } + fn closure_upvars( + &self, + _closure_id: chalk_ir::ClosureId, + _substs: &chalk_ir::Substitution, + ) -> chalk_ir::Binders> { + // FIXME: implement closure support + unimplemented!() + } + fn closure_fn_substitution( + &self, + _closure_id: chalk_ir::ClosureId, + _substs: &chalk_ir::Substitution, + ) -> chalk_ir::Substitution { + // FIXME: implement closure support + unimplemented!() + } } pub(crate) fn program_clauses_for_chalk_env_query( @@ -250,7 +285,7 @@ pub(crate) fn trait_datum_query( upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate != krate, non_enumerable: true, coinductive: false, // only relevant for Chalk testing - // FIXME set these flags correctly + // FIXME: set these flags correctly marker: false, fundamental: false, }; @@ -272,20 +307,28 @@ pub(crate) fn trait_datum_query( fn well_known_trait_from_lang_attr(name: &str) -> Option { Some(match name { - "sized" => WellKnownTrait::SizedTrait, - "copy" => WellKnownTrait::CopyTrait, - "clone" => WellKnownTrait::CloneTrait, - "drop" => WellKnownTrait::DropTrait, + "sized" => WellKnownTrait::Sized, + "copy" => WellKnownTrait::Copy, + "clone" => WellKnownTrait::Clone, + "drop" => WellKnownTrait::Drop, + "fn_once" => WellKnownTrait::FnOnce, + "fn_mut" => WellKnownTrait::FnMut, + "fn" => WellKnownTrait::Fn, + "unsize" => WellKnownTrait::Unsize, _ => return None, }) } fn lang_attr_from_well_known_trait(attr: WellKnownTrait) -> &'static str { match attr { - WellKnownTrait::SizedTrait => "sized", - WellKnownTrait::CopyTrait => "copy", - WellKnownTrait::CloneTrait => "clone", - WellKnownTrait::DropTrait => "drop", + WellKnownTrait::Sized => "sized", + WellKnownTrait::Copy => "copy", + WellKnownTrait::Clone => "clone", + WellKnownTrait::Drop => "drop", + WellKnownTrait::FnOnce => "fn_once", + WellKnownTrait::FnMut => "fn_mut", + WellKnownTrait::Fn => "fn", + WellKnownTrait::Unsize => "unsize", } } @@ -309,8 +352,9 @@ pub(crate) fn struct_datum_query( .unwrap_or_else(Vec::new); let flags = rust_ir::AdtFlags { upstream, - // FIXME set fundamental flag correctly + // FIXME set fundamental and phantom_data flags correctly fundamental: false, + phantom_data: false, }; let struct_datum_bound = rust_ir::AdtDatumBound { fields: Vec::new(), // FIXME add fields (only relevant for auto traits) @@ -448,11 +492,23 @@ pub(crate) fn fn_def_datum_query( let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); let bound = rust_ir::FnDefDatumBound { // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway - argument_types: sig.value.params().iter().map(|ty| ty.clone().to_chalk(db)).collect(), - return_type: sig.value.ret().clone().to_chalk(db), + inputs_and_output: make_binders( + rust_ir::FnDefInputsAndOutputDatum { + argument_types: sig + .value + .params() + .iter() + .map(|ty| ty.clone().to_chalk(db)) + .collect(), + return_type: sig.value.ret().clone().to_chalk(db), + } + .shifted_in(&Interner), + 0, + ), where_clauses, }; - let datum = FnDefDatum { id: fn_def_id, binders: make_binders(bound, sig.num_binders) }; + let datum = + FnDefDatum { id: fn_def_id, binders: make_binders(bound, sig.num_binders), abi: () }; Arc::new(datum) } diff --git a/crates/ra_hir_ty/src/traits/chalk/interner.rs b/crates/ra_hir_ty/src/traits/chalk/interner.rs index 56aab640c..15426b022 100644 --- a/crates/ra_hir_ty/src/traits/chalk/interner.rs +++ b/crates/ra_hir_ty/src/traits/chalk/interner.rs @@ -42,6 +42,7 @@ impl chalk_ir::interner::Interner for Interner { type DefId = InternId; type InternedAdtId = crate::TypeCtorId; type Identifier = TypeAliasId; + type FnAbi = (); fn debug_adt_id(type_kind_id: AdtId, fmt: &mut fmt::Formatter<'_>) -> Option { tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt))) diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index 18e5c9c16..ac82ea831 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs @@ -65,7 +65,10 @@ impl ToChalk for Ty { &Interner, predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)), ); - let bounded_ty = chalk_ir::DynTy { bounds: make_binders(where_clauses, 1) }; + let bounded_ty = chalk_ir::DynTy { + bounds: make_binders(where_clauses, 1), + lifetime: LIFETIME_PLACEHOLDER.to_lifetime(&Interner), + }; chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner) } Ty::Opaque(opaque_ty) => { @@ -319,6 +322,10 @@ impl ToChalk for TypeCtor { // this should not be reached, since we don't represent TypeName::Error with TypeCtor unreachable!() } + TypeName::Closure(_) => { + // FIXME: implement closure support + unreachable!() + } } } } -- cgit v1.2.3