diff --git a/Cargo.lock b/Cargo.lock index f8f2a9c6d73..a30a644e371 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -435,15 +435,15 @@ dependencies = [ [[package]] name = "chalk-base" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" +source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" dependencies = [ - "lazy_static 1.4.0", + "lazy_static", ] [[package]] name = "chalk-derive" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" +source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" dependencies = [ "proc-macro2 1.0.3", "quote 1.0.2", @@ -454,7 +454,7 @@ dependencies = [ [[package]] name = "chalk-engine" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" +source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" dependencies = [ "chalk-base", "chalk-derive", @@ -465,7 +465,7 @@ dependencies = [ [[package]] name = "chalk-ir" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" +source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" dependencies = [ "chalk-base", "chalk-derive", @@ -474,13 +474,13 @@ dependencies = [ [[package]] name = "chalk-solve" version = "0.10.1-dev" -source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" +source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" dependencies = [ "chalk-base", "chalk-derive", "chalk-engine", "chalk-ir", - "ena 0.14.0", + "ena", "itertools 0.9.0", "petgraph", "rustc-hash", @@ -1044,15 +1044,6 @@ dependencies = [ "strum_macros", ] -[[package]] -name = "ena" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8944dc8fa28ce4a38f778bd46bf7d923fe73eed5a439398507246c8e017e6f36" -dependencies = [ - "log", -] - [[package]] name = "ena" version = "0.14.0" @@ -3273,7 +3264,7 @@ dependencies = [ "bitflags", "cfg-if", "crossbeam-utils 0.7.2", - "ena 0.14.0", + "ena", "indexmap", "jobserver", "lazy_static", @@ -3729,7 +3720,7 @@ dependencies = [ "bitflags", "cfg-if", "crossbeam-utils 0.7.2", - "ena 0.14.0", + "ena", "indexmap", "jobserver", "lazy_static", diff --git a/src/librustc_middle/Cargo.toml b/src/librustc_middle/Cargo.toml index 8e809e338ea..34dece1a2ad 100644 --- a/src/librustc_middle/Cargo.toml +++ b/src/librustc_middle/Cargo.toml @@ -30,7 +30,7 @@ rustc_serialize = { path = "../librustc_serialize" } rustc_ast = { path = "../librustc_ast" } rustc_span = { path = "../librustc_span" } byteorder = { version = "1.3" } -chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" } +chalk-ir = { git = "https://github.com/jackh726/chalk.git", rev = "58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" } #chalk-ir = "0.10.0" smallvec = { version = "1.0", features = ["union", "may_dangle"] } measureme = "0.7.1" diff --git a/src/librustc_traits/Cargo.toml b/src/librustc_traits/Cargo.toml index c85cd1765ab..cb056dba9ea 100644 --- a/src/librustc_traits/Cargo.toml +++ b/src/librustc_traits/Cargo.toml @@ -19,8 +19,8 @@ rustc_span = { path = "../librustc_span" } #chalk-ir = "0.10.0" #chalk-rust-ir = "0.10.0" #chalk-solve = "0.10.0" -chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" } -chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" } +chalk-solve = { git = "https://github.com/jackh726/chalk.git", rev = "58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" } +chalk-ir = { git = "https://github.com/jackh726/chalk.git", rev = "58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_infer = { path = "../librustc_infer" } rustc_trait_selection = { path = "../librustc_trait_selection" } diff --git a/src/librustc_traits/chalk/db.rs b/src/librustc_traits/chalk/db.rs index 367c5980279..95a6f45f92f 100644 --- a/src/librustc_traits/chalk/db.rs +++ b/src/librustc_traits/chalk/db.rs @@ -175,9 +175,39 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t fn fn_def_datum( &self, - _fn_def_id: chalk_ir::FnDefId>, + fn_def_id: chalk_ir::FnDefId>, ) -> Arc>> { - unimplemented!() + let def_id = match fn_def_id.0 { + RustDefId::FnDef(def_id) => def_id, + _ => bug!("Did not use `FnDef` variant when expecting FnDef."), + }; + let bound_vars = bound_vars_for_item(self.tcx, def_id); + let binders = binders_for(&self.interner, bound_vars); + + let predicates = self.tcx.predicates_defined_on(def_id).predicates; + let where_clauses: Vec<_> = predicates + .into_iter() + .map(|(wc, _)| wc.subst(self.tcx, &bound_vars)) + .filter_map(|wc| LowerInto::>>>::lower_into(wc, &self.interner)).collect(); + + let sig = self.tcx.fn_sig(def_id); + // FIXME(chalk): Why does this have a Binder + let argument_types = sig + .inputs() + .skip_binder() + .iter() + .map(|t| t.subst(self.tcx, &bound_vars).lower_into(&self.interner)) + .collect(); + + let return_type = + sig.output().skip_binder().subst(self.tcx, &bound_vars).lower_into(&self.interner); + + let bound = + chalk_solve::rust_ir::FnDefDatumBound { argument_types, where_clauses, return_type }; + Arc::new(chalk_solve::rust_ir::FnDefDatum { + id: fn_def_id, + binders: chalk_ir::Binders::new(binders, bound), + }) } fn impl_datum( diff --git a/src/librustc_traits/chalk/lowering.rs b/src/librustc_traits/chalk/lowering.rs index e4483843dd0..247dcb76c13 100644 --- a/src/librustc_traits/chalk/lowering.rs +++ b/src/librustc_traits/chalk/lowering.rs @@ -167,20 +167,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi ty::PredicateKind::Projection(predicate) => predicate.lower_into(interner), ty::PredicateKind::WellFormed(arg) => match arg.unpack() { GenericArgKind::Type(ty) => match ty.kind { - // These types are always WF. - ty::Str | ty::Placeholder(..) | ty::Error(_) | ty::Never => { - chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)) - } + // FIXME(chalk): In Chalk, a placeholder is WellFormed if it + // `FromEnv`. However, when we "lower" Params, we don't update + // the environment. + ty::Placeholder(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)), - // FIXME(chalk): Well-formed only if ref lifetime outlives type - ty::Ref(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)), - - ty::Param(..) => panic!("No Params expected."), - - // FIXME(chalk) -- ultimately I think this is what we - // want to do, and we just have rules for how to prove - // `WellFormed` for everything above, instead of - // inlining a bit the rules of the proof here. _ => chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::WellFormed( chalk_ir::WellFormed::Ty(ty.lower_into(interner)), )), @@ -360,9 +351,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { ), ) } - FnDef(def_id, _) => apply( + FnDef(def_id, substs) => apply( chalk_ir::TypeName::FnDef(chalk_ir::FnDefId(RustDefId::FnDef(def_id))), - empty(), + substs.lower_into(interner), ), FnPtr(sig) => { let (inputs_and_outputs, binders, _named_regions) = diff --git a/src/test/ui/chalkify/impl_wf.rs b/src/test/ui/chalkify/impl_wf.rs index 8aa87642292..fdc94f69bf2 100644 --- a/src/test/ui/chalkify/impl_wf.rs +++ b/src/test/ui/chalkify/impl_wf.rs @@ -8,12 +8,9 @@ trait Bar { impl Foo for i32 { } -// FIXME(chalk): blocked on better handling of builtin traits for non-struct -// application types (or a workaround) -/* impl Foo for str { } -//^ ERROR the size for values of type `str` cannot be known at compilation time -*/ +//~^ ERROR the size for values of type `str` cannot be known at compilation time + // Implicit `T: Sized` bound. impl Foo for Option { } diff --git a/src/test/ui/chalkify/impl_wf.stderr b/src/test/ui/chalkify/impl_wf.stderr index befd688741c..5293bbaecd3 100644 --- a/src/test/ui/chalkify/impl_wf.stderr +++ b/src/test/ui/chalkify/impl_wf.stderr @@ -1,5 +1,17 @@ +error[E0277]: the size for values of type `str` cannot be known at compilation time + --> $DIR/impl_wf.rs:11:6 + | +LL | trait Foo: Sized { } + | ----- required by this bound in `Foo` +... +LL | impl Foo for str { } + | ^^^ doesn't have a size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `str` + = note: to learn more, visit + error[E0277]: the trait bound `f32: Foo` is not satisfied - --> $DIR/impl_wf.rs:43:6 + --> $DIR/impl_wf.rs:40:6 | LL | trait Baz where U: Foo { } | --- required by this bound in `Baz` @@ -7,6 +19,6 @@ LL | trait Baz where U: Foo { } LL | impl Baz for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/chalkify/type_inference.rs b/src/test/ui/chalkify/type_inference.rs index 5175c5d062a..171969afc7f 100644 --- a/src/test/ui/chalkify/type_inference.rs +++ b/src/test/ui/chalkify/type_inference.rs @@ -18,11 +18,9 @@ fn main() { // is expecting a variable of type `i32`. This behavior differs from the // old-style trait solver. I guess this will change, that's why I'm // adding that test. - // FIXME(chalk): partially blocked on float/int special casing only_foo(x); //~ ERROR the trait bound `f64: Foo` is not satisfied // Here we have two solutions so we get back the behavior of the old-style // trait solver. - // FIXME(chalk): blocked on float/int special casing - //only_bar(x); // ERROR the trait bound `{float}: Bar` is not satisfied + only_bar(x); //~ ERROR the trait bound `f64: Bar` is not satisfied } diff --git a/src/test/ui/chalkify/type_inference.stderr b/src/test/ui/chalkify/type_inference.stderr index ee9e67c6c78..47675929264 100644 --- a/src/test/ui/chalkify/type_inference.stderr +++ b/src/test/ui/chalkify/type_inference.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `f64: Foo` is not satisfied - --> $DIR/type_inference.rs:22:5 + --> $DIR/type_inference.rs:21:5 | LL | fn only_foo(_x: T) { } | --- required by this bound in `only_foo` @@ -7,6 +7,15 @@ LL | fn only_foo(_x: T) { } LL | only_foo(x); | ^^^^^^^^ the trait `Foo` is not implemented for `f64` -error: aborting due to previous error +error[E0277]: the trait bound `f64: Bar` is not satisfied + --> $DIR/type_inference.rs:25:5 + | +LL | fn only_bar(_x: T) { } + | --- required by this bound in `only_bar` +... +LL | only_bar(x); + | ^^^^^^^^ the trait `Bar` is not implemented for `f64` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/chalkify/type_wf.rs b/src/test/ui/chalkify/type_wf.rs index 396baf814a0..7c469d99c57 100644 --- a/src/test/ui/chalkify/type_wf.rs +++ b/src/test/ui/chalkify/type_wf.rs @@ -1,5 +1,4 @@ -// FIXME(chalk): should have an error, see below -// check-pass +// check-fail // compile-flags: -Z chalk trait Foo { } @@ -16,17 +15,11 @@ fn main() { x: 5, }; - // FIXME(chalk): blocked on float/int special handling. Needs to know that {float}: !i32 - /* - let s = S { // ERROR the trait bound `{float}: Foo` is not satisfied + let s = S { //~ ERROR the trait bound `f64: Foo` is not satisfied x: 5.0, }; - */ - // FIXME(chalk): blocked on float/int special handling. Needs to know that {float}: Sized - /* let s = S { x: Some(5.0), }; - */ } diff --git a/src/test/ui/chalkify/type_wf.stderr b/src/test/ui/chalkify/type_wf.stderr new file mode 100644 index 00000000000..ab585a6ed21 --- /dev/null +++ b/src/test/ui/chalkify/type_wf.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `f64: Foo` is not satisfied + --> $DIR/type_wf.rs:18:13 + | +LL | struct S { + | ---------------- required by `S` +... +LL | let s = S { + | ^ the trait `Foo` is not implemented for `f64` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index c08f02b972e..aec6b5d2523 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -79,10 +79,9 @@ const WHITELIST: &[&str] = &[ "byteorder", "cc", "cfg-if", + "chalk-base", "chalk-derive", - "chalk-engine", "chalk-ir", - "chalk-macros", "cloudabi", "cmake", "compiler_builtins",