diff options
| author | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-07-08 11:42:59 +0200 |
|---|---|---|
| committer | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-07-15 12:58:33 +0200 |
| commit | 805c44d5d32d23e18d962f14e34869ddcef588fd (patch) | |
| tree | 1cf859c1495553ea83995a130ba9b214b784ff11 /src | |
| parent | a7fe4df04a095bad08a4158ce0cabed632a16828 (diff) | |
| download | rust-805c44d5d32d23e18d962f14e34869ddcef588fd.tar.gz rust-805c44d5d32d23e18d962f14e34869ddcef588fd.zip | |
cleanup
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_middle/query/mod.rs | 16 | ||||
| -rw-r--r-- | src/librustc_middle/ty/mod.rs | 36 | ||||
| -rw-r--r-- | src/test/ui/impl-trait/auto-trait-leak.stderr | 4 |
3 files changed, 48 insertions, 8 deletions
diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 8c4b8cd1c8f..fbd4f4b7f54 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -228,7 +228,11 @@ rustc_queries! { /// /// See the README for the `mir` module for details. query mir_const(key: ty::WithOptParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> { - desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) } + desc { + |tcx| "processing MIR for {}`{}`", + if key.param_did.is_some() { "the const argument " } else { "" }, + tcx.def_path_str(key.did.to_def_id()), + } no_hash } @@ -246,8 +250,9 @@ rustc_queries! { ) { no_hash desc { - |tcx| "processing the potential const argument `{}`", - tcx.def_path_str(key.did.to_def_id()) + |tcx| "processing {}`{}`", + if key.param_did.is_some() { "the const argument " } else { "" }, + tcx.def_path_str(key.did.to_def_id()), } } @@ -497,7 +502,10 @@ rustc_queries! { cache_on_disk_if { true } } query unsafety_check_result_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult { - desc { |tcx| "unsafety-checking the const arg `{}`", tcx.def_path_str(key.0.to_def_id()) } + desc { + |tcx| "unsafety-checking the const argument `{}`", + tcx.def_path_str(key.0.to_def_id()) + } } /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error. diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 92ebe9b2d18..5e2cce42d93 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1,5 +1,4 @@ // ignore-tidy-filelength - pub use self::fold::{TypeFoldable, TypeVisitor}; pub use self::AssocItemContainer::*; pub use self::BorrowKind::*; @@ -1571,11 +1570,45 @@ pub type PlaceholderType = Placeholder<BoundVar>; pub type PlaceholderConst = Placeholder<BoundVar>; +/// A `DefId` which is potentially bundled with its corresponding generic parameter +/// in case `did` is a const argument. +/// +/// This is used to prevent cycle errors during typeck +/// as `type_of(const_arg)` depends on `typeck_tables_of(owning_body)` +/// which once again requires the type of its generic arguments. +/// +/// Luckily we only need to deal with const arguments once we +/// know their corresponding parameters. We (ab)use this by +/// calling `type_of(param_did)` for these arguments. +/// +/// ```rust +/// #![feature(const_generics)] +/// +/// struct A; +/// impl A { +/// fn foo<const N: usize>(&self) -> usize { N } +/// } +/// struct B; +/// impl B { +/// fn foo<const N: u8>(&self) -> usize { 42 } +/// } +/// +/// fn main() { +/// let a = A; +/// a.foo::<7>(); +/// } +/// ``` #[derive(Copy, Clone, Debug, TypeFoldable, Lift, RustcEncodable, RustcDecodable)] #[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(Hash, HashStable)] pub struct WithOptParam<T> { pub did: T, + /// The `DefId` of the corresponding generic paramter in case `did` is + /// a const argument. + /// + /// Note that even if `did` is a const argument, this may still be `None`. + /// All queries taking `WithOptParam` start by calling `tcx.opt_const_param_of(def.did)` + /// to potentially update `param_did` in case it `None`. pub param_did: Option<DefId>, } @@ -2896,7 +2929,6 @@ impl<'tcx> TyCtxt<'tcx> { match instance { ty::InstanceDef::Item(def) => { if let Some((did, param_did)) = def.as_const_arg() { - // The `param_did` is only `Some` for local `DefId`s. self.optimized_mir_of_const_arg((did, param_did)) } else { self.optimized_mir(def.did) diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index cba894bec9d..679b26efe59 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -9,7 +9,7 @@ note: ...which requires borrow-checking `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires processing the potential const argument `cycle1`... +note: ...which requires processing `cycle1`... --> $DIR/auto-trait-leak.rs:12:1 | LL | fn cycle1() -> impl Clone { @@ -45,7 +45,7 @@ note: ...which requires borrow-checking `cycle2`... | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires processing the potential const argument `cycle2`... +note: ...which requires processing `cycle2`... --> $DIR/auto-trait-leak.rs:20:1 | LL | fn cycle2() -> impl Clone { |
