Skip to content

Commit 085acd0

Browse files
committed
Auto merge of rust-lang#116193 - matthiaskrgr:rollup-wpt7m5t, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#115934 (Split out the stable part of smir into its own crate to prevent accidental usage of forever unstable things) - rust-lang#116149 (Anonymize binders for `refining_impl_trait` check) - rust-lang#116178 (Add test for `const async fn`) - rust-lang#116187 (Add context to `let: Ty = loop { break };`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 376f3f0 + a6f0665 commit 085acd0

File tree

28 files changed

+272
-235
lines changed

28 files changed

+272
-235
lines changed

Cargo.lock

+10-1
Original file line numberDiff line numberDiff line change
@@ -3245,6 +3245,7 @@ dependencies = [
32453245
"rustc_driver",
32463246
"rustc_driver_impl",
32473247
"rustc_smir",
3248+
"stable_mir",
32483249
]
32493250

32503251
[[package]]
@@ -4409,7 +4410,7 @@ dependencies = [
44094410
"rustc_session",
44104411
"rustc_span",
44114412
"rustc_target",
4412-
"scoped-tls",
4413+
"stable_mir",
44134414
"tracing",
44144415
]
44154416

@@ -4946,6 +4947,14 @@ version = "1.2.0"
49464947
source = "registry+https://github.com/rust-lang/crates.io-index"
49474948
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
49484949

4950+
[[package]]
4951+
name = "stable_mir"
4952+
version = "0.1.0-preview"
4953+
dependencies = [
4954+
"scoped-tls",
4955+
"tracing",
4956+
]
4957+
49494958
[[package]]
49504959
name = "stacker"
49514960
version = "0.1.15"

compiler/rustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
1313
# Make sure rustc_smir ends up in the sysroot, because this
1414
# crate is intended to be used by stable MIR consumers, which are not in-tree
1515
rustc_smir = { path = "../rustc_smir" }
16+
stable_mir = { path = "../stable_mir" }
1617

1718
[dependencies.jemalloc-sys]
1819
version = "0.5.0"

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_infer::infer::{outlives::env::OutlivesEnvironment, TyCtxtInferExt};
55
use rustc_lint_defs::builtin::REFINING_IMPL_TRAIT;
66
use rustc_middle::traits::{ObligationCause, Reveal};
77
use rustc_middle::ty::{
8-
self, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitor,
8+
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable, TypeVisitor,
99
};
1010
use rustc_span::{Span, DUMMY_SP};
1111
use rustc_trait_selection::traits::{
@@ -176,9 +176,13 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
176176
return;
177177
};
178178

179-
// For quicker lookup, use an `IndexSet`
180-
// (we don't use one earlier because it's not foldable..)
181-
let trait_bounds = FxIndexSet::from_iter(trait_bounds);
179+
// For quicker lookup, use an `IndexSet` (we don't use one earlier because
180+
// it's not foldable..).
181+
// Also, We have to anonymize binders in these types because they may contain
182+
// `BrNamed` bound vars, which contain unique `DefId`s which correspond to syntax
183+
// locations that we don't care about when checking bound equality.
184+
let trait_bounds = FxIndexSet::from_iter(trait_bounds.fold_with(&mut Anonymize { tcx }));
185+
let impl_bounds = impl_bounds.fold_with(&mut Anonymize { tcx });
182186

183187
// Find any clauses that are present in the impl's RPITITs that are not
184188
// present in the trait's RPITITs. This will trigger on trivial predicates,
@@ -309,3 +313,20 @@ fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibili
309313
_ => None,
310314
}
311315
}
316+
317+
struct Anonymize<'tcx> {
318+
tcx: TyCtxt<'tcx>,
319+
}
320+
321+
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Anonymize<'tcx> {
322+
fn interner(&self) -> TyCtxt<'tcx> {
323+
self.tcx
324+
}
325+
326+
fn fold_binder<T>(&mut self, t: ty::Binder<'tcx, T>) -> ty::Binder<'tcx, T>
327+
where
328+
T: TypeFoldable<TyCtxt<'tcx>>,
329+
{
330+
self.tcx.anonymize_bound_vars(t)
331+
}
332+
}

compiler/rustc_hir_typeck/src/demand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
545545
// Climb the HIR tree to see if the current `Expr` is part of a `break;` statement.
546546
let Some(
547547
hir::Node::Stmt(hir::Stmt { kind: hir::StmtKind::Semi(&ref p), .. })
548+
| hir::Node::Block(hir::Block { expr: Some(&ref p), .. })
548549
| hir::Node::Expr(&ref p),
549550
) = self.tcx.hir().find(parent_id)
550551
else {

compiler/rustc_smir/Cargo.toml

+8-18
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,14 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
# Use optional dependencies for rustc_* in order to support building this crate separately.
8-
rustc_hir = { path = "../rustc_hir", optional = true }
9-
rustc_middle = { path = "../rustc_middle", optional = true }
10-
rustc_span = { path = "../rustc_span", optional = true }
11-
rustc_target = { path = "../rustc_target", optional = true }
12-
rustc_driver = { path = "../rustc_driver", optional = true }
13-
rustc_interface = { path = "../rustc_interface", optional = true}
14-
rustc_session = {path = "../rustc_session", optional = true}
7+
rustc_hir = { path = "../rustc_hir" }
8+
rustc_middle = { path = "../rustc_middle" }
9+
rustc_span = { path = "../rustc_span" }
10+
rustc_target = { path = "../rustc_target" }
11+
rustc_driver = { path = "../rustc_driver" }
12+
rustc_interface = { path = "../rustc_interface" }
13+
rustc_session = {path = "../rustc_session" }
1514
tracing = "0.1"
16-
scoped-tls = "1.0"
15+
stable_mir = {path = "../stable_mir" }
1716

1817
[features]
19-
default = [
20-
"rustc_hir",
21-
"rustc_middle",
22-
"rustc_span",
23-
"rustc_target",
24-
"rustc_driver",
25-
"rustc_interface",
26-
"rustc_session",
27-
]

compiler/rustc_smir/src/lib.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,12 @@
1010
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
1111
test(attr(allow(unused_variables), deny(warnings)))
1212
)]
13-
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
13+
#![feature(rustc_private)]
1414
#![feature(ptr_metadata)]
1515
#![feature(type_alias_impl_trait)] // Used to define opaque types.
1616
#![feature(intra_doc_pointers)]
1717

18-
// Declare extern rustc_* crates to enable building this crate separately from the compiler.
19-
#[cfg(not(feature = "default"))]
20-
extern crate rustc_hir;
21-
#[cfg(not(feature = "default"))]
22-
extern crate rustc_middle;
23-
#[cfg(not(feature = "default"))]
24-
extern crate rustc_span;
25-
#[cfg(not(feature = "default"))]
26-
extern crate rustc_target;
27-
2818
pub mod rustc_internal;
29-
pub mod stable_mir;
3019

3120
// Make this module private for now since external users should not call these directly.
3221
mod rustc_smir;
33-
34-
#[macro_use]
35-
extern crate scoped_tls;

compiler/rustc_smir/src/rustc_internal/mod.rs

+12-81
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,17 @@
33
//! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs
44
//! until stable MIR is complete.
55
6-
use std::fmt::Debug;
76
use std::ops::{ControlFlow, Index};
87

98
use crate::rustc_internal;
10-
use crate::stable_mir::CompilerError;
11-
use crate::{
12-
rustc_smir::Tables,
13-
stable_mir::{self, with},
14-
};
9+
use crate::rustc_smir::Tables;
1510
use rustc_driver::{Callbacks, Compilation, RunCompiler};
1611
use rustc_interface::{interface, Queries};
1712
use rustc_middle::mir::interpret::AllocId;
1813
use rustc_middle::ty::TyCtxt;
1914
pub use rustc_span::def_id::{CrateNum, DefId};
2015
use rustc_span::Span;
21-
22-
fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
23-
let mut ret = None;
24-
with(|tables| tables.rustc_tables(&mut |t| ret = Some(f(t))));
25-
ret.unwrap()
26-
}
27-
28-
pub fn item_def_id(item: &stable_mir::CrateItem) -> DefId {
29-
with_tables(|t| t[item.0])
30-
}
31-
32-
pub fn crate_item(did: DefId) -> stable_mir::CrateItem {
33-
with_tables(|t| t.crate_item(did))
34-
}
35-
36-
pub fn adt_def(did: DefId) -> stable_mir::ty::AdtDef {
37-
with_tables(|t| t.adt_def(did))
38-
}
39-
40-
pub fn foreign_def(did: DefId) -> stable_mir::ty::ForeignDef {
41-
with_tables(|t| t.foreign_def(did))
42-
}
43-
44-
pub fn fn_def(did: DefId) -> stable_mir::ty::FnDef {
45-
with_tables(|t| t.fn_def(did))
46-
}
47-
48-
pub fn closure_def(did: DefId) -> stable_mir::ty::ClosureDef {
49-
with_tables(|t| t.closure_def(did))
50-
}
51-
52-
pub fn generator_def(did: DefId) -> stable_mir::ty::GeneratorDef {
53-
with_tables(|t| t.generator_def(did))
54-
}
55-
56-
pub fn alias_def(did: DefId) -> stable_mir::ty::AliasDef {
57-
with_tables(|t| t.alias_def(did))
58-
}
59-
60-
pub fn param_def(did: DefId) -> stable_mir::ty::ParamDef {
61-
with_tables(|t| t.param_def(did))
62-
}
63-
64-
pub fn br_named_def(did: DefId) -> stable_mir::ty::BrNamedDef {
65-
with_tables(|t| t.br_named_def(did))
66-
}
67-
68-
pub fn trait_def(did: DefId) -> stable_mir::ty::TraitDef {
69-
with_tables(|t| t.trait_def(did))
70-
}
71-
72-
pub fn impl_def(did: DefId) -> stable_mir::ty::ImplDef {
73-
with_tables(|t| t.impl_def(did))
74-
}
16+
use stable_mir::CompilerError;
7517

7618
impl<'tcx> Index<stable_mir::DefId> for Tables<'tcx> {
7719
type Output = DefId;
@@ -82,6 +24,15 @@ impl<'tcx> Index<stable_mir::DefId> for Tables<'tcx> {
8224
}
8325
}
8426

27+
impl<'tcx> Index<stable_mir::ty::Span> for Tables<'tcx> {
28+
type Output = Span;
29+
30+
#[inline(always)]
31+
fn index(&self, index: stable_mir::ty::Span) -> &Self::Output {
32+
&self.spans[index.0]
33+
}
34+
}
35+
8536
impl<'tcx> Tables<'tcx> {
8637
pub fn crate_item(&mut self, did: DefId) -> stable_mir::CrateItem {
8738
stable_mir::CrateItem(self.create_def_id(did))
@@ -178,32 +129,12 @@ pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
178129
}
179130

180131
pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
181-
crate::stable_mir::run(
132+
stable_mir::run(
182133
Tables { tcx, def_ids: vec![], alloc_ids: vec![], spans: vec![], types: vec![] },
183134
f,
184135
);
185136
}
186137

187-
/// A type that provides internal information but that can still be used for debug purpose.
188-
#[derive(Clone)]
189-
pub struct Opaque(String);
190-
191-
impl std::fmt::Display for Opaque {
192-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
193-
write!(f, "{}", self.0)
194-
}
195-
}
196-
197-
impl std::fmt::Debug for Opaque {
198-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
199-
write!(f, "{:?}", self.0)
200-
}
201-
}
202-
203-
pub(crate) fn opaque<T: Debug>(value: &T) -> Opaque {
204-
Opaque(format!("{value:?}"))
205-
}
206-
207138
pub struct StableMir<B = (), C = ()>
208139
where
209140
B: Send,

compiler/rustc_smir/src/rustc_smir/alloc.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ use rustc_middle::mir::{
33
ConstValue,
44
};
55

6-
use crate::{
7-
rustc_smir::{Stable, Tables},
8-
stable_mir::mir::Mutability,
9-
stable_mir::ty::{Allocation, ProvenanceMap},
10-
};
6+
use crate::rustc_smir::{Stable, Tables};
7+
use stable_mir::mir::Mutability;
8+
use stable_mir::ty::{Allocation, ProvenanceMap};
119

1210
/// Creates new empty `Allocation` from given `Align`.
1311
fn new_empty_allocation(align: rustc_target::abi::Align) -> Allocation {

0 commit comments

Comments
 (0)