Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7e11379

Browse files
committedJul 15, 2020
Auto merge of rust-lang#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 🥰 previously rust-lang#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)` ⚡ (see rust-lang#68400 (comment)) 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
2 parents d9e8d62 + 2666aed commit 7e11379

File tree

101 files changed

+1547
-622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1547
-622
lines changed
 

‎src/librustc_codegen_ssa/back/symbol_export.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ fn exported_symbols_provider_local(
248248
}
249249

250250
match *mono_item {
251-
MonoItem::Fn(Instance { def: InstanceDef::Item(def_id), substs }) => {
251+
MonoItem::Fn(Instance { def: InstanceDef::Item(def), substs }) => {
252252
if substs.non_erasable_generics().next().is_some() {
253-
let symbol = ExportedSymbol::Generic(def_id, substs);
253+
let symbol = ExportedSymbol::Generic(def.did, substs);
254254
symbols.push((symbol, SymbolExportLevel::Rust));
255255
}
256256
}

‎src/librustc_codegen_ssa/mir/constant.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2525
constant: &mir::Constant<'tcx>,
2626
) -> Result<ConstValue<'tcx>, ErrorHandled> {
2727
match self.monomorphize(&constant.literal).val {
28-
ty::ConstKind::Unevaluated(def_id, substs, promoted) => self
28+
ty::ConstKind::Unevaluated(def, substs, promoted) => self
2929
.cx
3030
.tcx()
31-
.const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None)
31+
.const_eval_resolve(ty::ParamEnv::reveal_all(), def, substs, promoted, None)
3232
.map_err(|err| {
3333
if promoted.is_none() {
3434
self.cx

0 commit comments

Comments
 (0)
Please sign in to comment.