Merge #4982
4982: Bump chalk r=matklad a=lnicola
This passes the tests, but fails in a weird way on `analysis-stats`:
```
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/me/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-solve-0.14.0/src/clauses/builtin_traits/fn_family.rs:96:20
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:78
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:59
4: core::fmt::write
at src/libcore/fmt/mod.rs:1076
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1537
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:198
9: std::panicking::default_hook
at src/libstd/panicking.rs:218
10: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:477
11: rust_begin_unwind
at src/libstd/panicking.rs:385
12: core::panicking::panic_fmt
at src/libcore/panicking.rs:86
13: core::panicking::panic
at src/libcore/panicking.rs:51
14: chalk_solve::clauses::builtin_traits::fn_family::add_fn_trait_program_clauses
15: chalk_solve::clauses::builder::ClauseBuilder<I>::push_binders
16: chalk_solve::clauses::program_clauses_that_could_match
17: chalk_solve::clauses::program_clauses_for_goal
18: chalk_solve::recursive::Solver<I>::solve_new_subgoal
19: <chalk_solve::recursive::Solver<I> as chalk_solve::recursive::solve::SolveDatabase<I>>::solve_goal
20: chalk_solve::recursive::Solver<I>::solve_root_goal
21: chalk_solve::solve::Solver<I>::solve_limited
22: ra_hir_ty::traits::trait_solve_query
23: salsa::runtime::Runtime<DB>::execute_query_implementation
24: salsa::derived::slot::Slot<DB,Q,MP>::read_upgrade
25: salsa::derived::slot::Slot<DB,Q,MP>::read
26: <salsa::derived::DerivedStorage<DB,Q,MP> as salsa::plumbing::QueryStorageOps<DB,Q>>::try_fetch
27: salsa::QueryTable<DB,Q>::get
28: <T as ra_hir_ty::db::HirDatabase>::trait_solve
29: ra_hir_ty::infer::InferenceContext::resolve_ty_as_possible
30: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
31: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_coerce
32: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::check_call_arguments
33: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_method_call
34: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
35: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr
36: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_method_call
37: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
38: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_coerce
39: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
40: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
41: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_coerce
42: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_inner
43: ra_hir_ty::infer::expr::<impl ra_hir_ty::infer::InferenceContext>::infer_expr_coerce
44: ra_hir_ty::infer::infer_query
45: salsa::runtime::Runtime<DB>::execute_query_implementation
46: salsa::derived::slot::Slot<DB,Q,MP>::read_upgrade
47: salsa::derived::slot::Slot<DB,Q,MP>::read
48: <salsa::derived::DerivedStorage<DB,Q,MP> as salsa::plumbing::QueryStorageOps<DB,Q>>::try_fetch
49: ra_hir_ty::db::infer_wait
50: rust_analyzer::cli::analysis_stats::analysis_stats
51: rust_analyzer::main
52: std::rt::lang_start::{{closure}}
53: std::rt::lang_start_internal::{{closure}}
at src/libstd/rt.rs:52
54: std::panicking::try::do_call
at src/libstd/panicking.rs:297
55: std::panicking::try
at src/libstd/panicking.rs:274
56: std::panic::catch_unwind
at src/libstd/panic.rs:394
57: std::rt::lang_start_internal
at src/libstd/rt.rs:51
58: main
59: __libc_start_main
60: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
It's as if we're returning `None` for a well-known trait that `chalk` asks about. That seems to happen for `Deref`, `CoerceUnsized` and `Try`.
r? @flodiebold
Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
18a6dd4635
7 changed files with 281 additions and 59 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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<T> {}
|
||||
#[lang = "coerce_unsized"]
|
||||
|
|
@ -689,19 +691,19 @@ fn test() {
|
|||
}
|
||||
"#, true),
|
||||
@r###"
|
||||
387..572 '{ ...bj2; }': ()
|
||||
397..400 'obj': &dyn Baz<i8, i16>
|
||||
422..424 '&S': &S<i8, i16>
|
||||
423..424 'S': S<i8, i16>
|
||||
434..437 'obj': &dyn Bar<usize, i8, i16>
|
||||
459..462 'obj': &dyn Baz<i8, i16>
|
||||
472..475 'obj': &dyn Foo<i8, usize>
|
||||
494..497 'obj': &dyn Bar<usize, i8, i16>
|
||||
507..511 'obj2': &dyn Baz<i8, i16>
|
||||
533..535 '&S': &S<i8, i16>
|
||||
534..535 'S': S<i8, i16>
|
||||
545..546 '_': &dyn Foo<i8, usize>
|
||||
565..569 'obj2': &dyn Baz<i8, i16>
|
||||
424..609 '{ ...bj2; }': ()
|
||||
434..437 'obj': &dyn Baz<i8, i16>
|
||||
459..461 '&S': &S<i8, i16>
|
||||
460..461 'S': S<i8, i16>
|
||||
471..474 'obj': &dyn Bar<usize, i8, i16>
|
||||
496..499 'obj': &dyn Baz<i8, i16>
|
||||
509..512 'obj': &dyn Foo<i8, usize>
|
||||
531..534 'obj': &dyn Bar<usize, i8, i16>
|
||||
544..548 'obj2': &dyn Baz<i8, i16>
|
||||
570..572 '&S': &S<i8, i16>
|
||||
571..572 'S': S<i8, i16>
|
||||
582..583 '_': &dyn Foo<i8, usize>
|
||||
602..606 'obj2': &dyn Baz<i8, i16>
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
@ -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<T> {}
|
||||
#[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
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1753,11 +1753,11 @@ fn test() {
|
|||
384..500 '{ ...(f); }': ()
|
||||
394..397 'bar': Bar<fn(u8) -> u32>
|
||||
423..426 'bar': Bar<fn(u8) -> u32>
|
||||
423..432 'bar.foo()': {unknown}
|
||||
423..432 'bar.foo()': (u8, u32)
|
||||
443..446 'opt': Opt<u8>
|
||||
465..466 'f': fn(u8) -> u32
|
||||
487..490 'opt': Opt<u8>
|
||||
487..497 'opt.map(f)': Opt<FnOnce::Output<fn(u8) -> u32, (u8,)>>
|
||||
487..497 'opt.map(f)': Opt<u32>
|
||||
495..496 'f': fn(u8) -> u32
|
||||
"###
|
||||
);
|
||||
|
|
@ -1830,9 +1830,9 @@ fn test() {
|
|||
634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
|
||||
634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
|
||||
644..659 'make_foo_fn_ptr': fn() -> Foo
|
||||
670..672 'r2': {unknown}
|
||||
670..672 'r2': usize
|
||||
675..680 'lazy2': Lazy<Foo, fn() -> Foo>
|
||||
675..686 'lazy2.foo()': {unknown}
|
||||
675..686 'lazy2.foo()': usize
|
||||
549..551 '{}': ()
|
||||
"###
|
||||
);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
|||
fn adt_datum(&self, struct_id: AdtId) -> Arc<StructDatum> {
|
||||
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<ImplDatum> {
|
||||
self.db.impl_datum(self.krate, impl_id)
|
||||
}
|
||||
|
|
@ -128,8 +131,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
|||
well_known_trait: rust_ir::WellKnownTrait,
|
||||
) -> Option<chalk_ir::TraitId<Interner>> {
|
||||
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<Interner> for ChalkContext<'a> {
|
|||
// FIXME: implement actual object safety
|
||||
true
|
||||
}
|
||||
|
||||
fn closure_kind(
|
||||
&self,
|
||||
_closure_id: chalk_ir::ClosureId<Interner>,
|
||||
_substs: &chalk_ir::Substitution<Interner>,
|
||||
) -> rust_ir::ClosureKind {
|
||||
// FIXME: implement closure support
|
||||
unimplemented!()
|
||||
}
|
||||
fn closure_inputs_and_output(
|
||||
&self,
|
||||
_closure_id: chalk_ir::ClosureId<Interner>,
|
||||
_substs: &chalk_ir::Substitution<Interner>,
|
||||
) -> chalk_ir::Binders<rust_ir::FnDefInputsAndOutputDatum<Interner>> {
|
||||
// FIXME: implement closure support
|
||||
unimplemented!()
|
||||
}
|
||||
fn closure_upvars(
|
||||
&self,
|
||||
_closure_id: chalk_ir::ClosureId<Interner>,
|
||||
_substs: &chalk_ir::Substitution<Interner>,
|
||||
) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> {
|
||||
// FIXME: implement closure support
|
||||
unimplemented!()
|
||||
}
|
||||
fn closure_fn_substitution(
|
||||
&self,
|
||||
_closure_id: chalk_ir::ClosureId<Interner>,
|
||||
_substs: &chalk_ir::Substitution<Interner>,
|
||||
) -> chalk_ir::Substitution<Interner> {
|
||||
// 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<WellKnownTrait> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<fmt::Result> {
|
||||
tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt)))
|
||||
|
|
|
|||
|
|
@ -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!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue