diff options
| author | bors <bors@rust-lang.org> | 2020-07-15 12:49:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-07-15 12:49:25 +0000 |
| commit | 7e11379f3b4c376fbb9a6c4d44f3286ccc28d149 (patch) | |
| tree | beb148fb31240b97e2a01cd208e28b02151c5bfd /src/librustc_codegen_ssa | |
| parent | d9e8d6290745a65025a3e082aea72fbe372292c6 (diff) | |
| parent | 2666aed4989c3bec9cf9f94b2d15beda4e5407f7 (diff) | |
| download | rust-7e11379f3b4c376fbb9a6c4d44f3286ccc28d149.tar.gz rust-7e11379f3b4c376fbb9a6c4d44f3286ccc28d149.zip | |
Auto merge of #74113 - lcnr:type-dependent-consts-2, r=eddyb
Support const args in type dependent paths (Take 2)
once more, except it is sound this time :smiling_face_with_three_hearts: previously #71154
-----
```rust
#![feature(const_generics)]
struct A;
impl A {
fn foo<const N: usize>(&self) -> usize { N }
}
struct B;
impl B {
fn foo<const N: usize>(&self) -> usize { 42 }
}
fn main() {
let a = A;
a.foo::<7>();
}
```
When calling `type_of` for generic const arguments, we now use the `TypeckTables` of the surrounding body to get the expected type.
This alone causes cycle errors though, as we now have `typeck_tables_of(main)` -> `...` ->
`type_of(main_ANON0 := 7)` -> `typeck_tables_of(main)` :zap: (see https://github.com/rust-lang/rust/issues/68400#issuecomment-611760290)
To prevent this we must not call `type_of(const_arg)` during `typeck_tables_of`. This is achieved by
calling `type_of(param_def_id)` instead.
We have to somehow remember the `DefId` of the param through all of typeck, which is done using the
struct `ty::WithOptConstParam<DefId>`, which replaces `DefId` where needed and contains an `Option<DefId>` to
be able to store the const parameter in case it exists.
Queries which are currently cached on disk are split into two variants: `query_name`(cached) and `query_name_(of|for)_const_arg`(not cached), with `query_name_of_const_arg` taking a pair `(did, param_did): (LocalDefId, DefId)`.
For some queries a method `query_name_of_opt_const_arg` is added to `TyCtxt` which takes a `ty::WithOptConstParam` and either calls `query_name` or `query_name_of_const_arg` depending on the value of `const_param_did`.
r? @eddyb @varkor
Diffstat (limited to 'src/librustc_codegen_ssa')
| -rw-r--r-- | src/librustc_codegen_ssa/back/symbol_export.rs | 4 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/mir/constant.rs | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index e0910c693b1..3287e7b856a 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -248,9 +248,9 @@ fn exported_symbols_provider_local( } match *mono_item { - MonoItem::Fn(Instance { def: InstanceDef::Item(def_id), substs }) => { + MonoItem::Fn(Instance { def: InstanceDef::Item(def), substs }) => { if substs.non_erasable_generics().next().is_some() { - let symbol = ExportedSymbol::Generic(def_id, substs); + let symbol = ExportedSymbol::Generic(def.did, substs); symbols.push((symbol, SymbolExportLevel::Rust)); } } diff --git a/src/librustc_codegen_ssa/mir/constant.rs b/src/librustc_codegen_ssa/mir/constant.rs index 11ec62f96ed..4943e279c7e 100644 --- a/src/librustc_codegen_ssa/mir/constant.rs +++ b/src/librustc_codegen_ssa/mir/constant.rs @@ -25,10 +25,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { constant: &mir::Constant<'tcx>, ) -> Result<ConstValue<'tcx>, ErrorHandled> { match self.monomorphize(&constant.literal).val { - ty::ConstKind::Unevaluated(def_id, substs, promoted) => self + ty::ConstKind::Unevaluated(def, substs, promoted) => self .cx .tcx() - .const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None) + .const_eval_resolve(ty::ParamEnv::reveal_all(), def, substs, promoted, None) .map_err(|err| { if promoted.is_none() { self.cx |
