Skip to content

Commit 805c44d

Browse files
committed
cleanup
1 parent a7fe4df commit 805c44d

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

src/librustc_middle/query/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,11 @@ rustc_queries! {
228228
///
229229
/// See the README for the `mir` module for details.
230230
query mir_const(key: ty::WithOptParam<LocalDefId>) -> &'tcx Steal<mir::Body<'tcx>> {
231-
desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
231+
desc {
232+
|tcx| "processing MIR for {}`{}`",
233+
if key.param_did.is_some() { "the const argument " } else { "" },
234+
tcx.def_path_str(key.did.to_def_id()),
235+
}
232236
no_hash
233237
}
234238

@@ -246,8 +250,9 @@ rustc_queries! {
246250
) {
247251
no_hash
248252
desc {
249-
|tcx| "processing the potential const argument `{}`",
250-
tcx.def_path_str(key.did.to_def_id())
253+
|tcx| "processing {}`{}`",
254+
if key.param_did.is_some() { "the const argument " } else { "" },
255+
tcx.def_path_str(key.did.to_def_id()),
251256
}
252257
}
253258

@@ -497,7 +502,10 @@ rustc_queries! {
497502
cache_on_disk_if { true }
498503
}
499504
query unsafety_check_result_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult {
500-
desc { |tcx| "unsafety-checking the const arg `{}`", tcx.def_path_str(key.0.to_def_id()) }
505+
desc {
506+
|tcx| "unsafety-checking the const argument `{}`",
507+
tcx.def_path_str(key.0.to_def_id())
508+
}
501509
}
502510

503511
/// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.

src/librustc_middle/ty/mod.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ignore-tidy-filelength
2-
32
pub use self::fold::{TypeFoldable, TypeVisitor};
43
pub use self::AssocItemContainer::*;
54
pub use self::BorrowKind::*;
@@ -1571,11 +1570,45 @@ pub type PlaceholderType = Placeholder<BoundVar>;
15711570

15721571
pub type PlaceholderConst = Placeholder<BoundVar>;
15731572

1573+
/// A `DefId` which is potentially bundled with its corresponding generic parameter
1574+
/// in case `did` is a const argument.
1575+
///
1576+
/// This is used to prevent cycle errors during typeck
1577+
/// as `type_of(const_arg)` depends on `typeck_tables_of(owning_body)`
1578+
/// which once again requires the type of its generic arguments.
1579+
///
1580+
/// Luckily we only need to deal with const arguments once we
1581+
/// know their corresponding parameters. We (ab)use this by
1582+
/// calling `type_of(param_did)` for these arguments.
1583+
///
1584+
/// ```rust
1585+
/// #![feature(const_generics)]
1586+
///
1587+
/// struct A;
1588+
/// impl A {
1589+
/// fn foo<const N: usize>(&self) -> usize { N }
1590+
/// }
1591+
/// struct B;
1592+
/// impl B {
1593+
/// fn foo<const N: u8>(&self) -> usize { 42 }
1594+
/// }
1595+
///
1596+
/// fn main() {
1597+
/// let a = A;
1598+
/// a.foo::<7>();
1599+
/// }
1600+
/// ```
15741601
#[derive(Copy, Clone, Debug, TypeFoldable, Lift, RustcEncodable, RustcDecodable)]
15751602
#[derive(PartialEq, Eq, PartialOrd, Ord)]
15761603
#[derive(Hash, HashStable)]
15771604
pub struct WithOptParam<T> {
15781605
pub did: T,
1606+
/// The `DefId` of the corresponding generic paramter in case `did` is
1607+
/// a const argument.
1608+
///
1609+
/// Note that even if `did` is a const argument, this may still be `None`.
1610+
/// All queries taking `WithOptParam` start by calling `tcx.opt_const_param_of(def.did)`
1611+
/// to potentially update `param_did` in case it `None`.
15791612
pub param_did: Option<DefId>,
15801613
}
15811614

@@ -2896,7 +2929,6 @@ impl<'tcx> TyCtxt<'tcx> {
28962929
match instance {
28972930
ty::InstanceDef::Item(def) => {
28982931
if let Some((did, param_did)) = def.as_const_arg() {
2899-
// The `param_did` is only `Some` for local `DefId`s.
29002932
self.optimized_mir_of_const_arg((did, param_did))
29012933
} else {
29022934
self.optimized_mir(def.did)

src/test/ui/impl-trait/auto-trait-leak.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: ...which requires borrow-checking `cycle1`...
99
|
1010
LL | fn cycle1() -> impl Clone {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...which requires processing the potential const argument `cycle1`...
12+
note: ...which requires processing `cycle1`...
1313
--> $DIR/auto-trait-leak.rs:12:1
1414
|
1515
LL | fn cycle1() -> impl Clone {
@@ -45,7 +45,7 @@ note: ...which requires borrow-checking `cycle2`...
4545
|
4646
LL | fn cycle2() -> impl Clone {
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^
48-
note: ...which requires processing the potential const argument `cycle2`...
48+
note: ...which requires processing `cycle2`...
4949
--> $DIR/auto-trait-leak.rs:20:1
5050
|
5151
LL | fn cycle2() -> impl Clone {

0 commit comments

Comments
 (0)