Skip to content

Commit f964de4

Browse files
committed
Auto merge of #149468 - chenyukang:yukang-fix-ice-149278, r=lcnr
Skipping borrowck because of trivial const r? @saethlin the [assertion](https://github.com/chenyukang/rust/blob/31c38576a4cf1a0864af536f62d11f829db1c7c8/compiler/rustc_mir_transform/src/lib.rs#L424) is added in PR: #148040 I think we also need to skip trvial const in `mir_borrowck`.
2 parents ffccab6 + 8e1f263 commit f964de4

5 files changed

Lines changed: 72 additions & 0 deletions

File tree

compiler/rustc_borrowck/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ fn mir_borrowck(
115115
def: LocalDefId,
116116
) -> Result<&FxIndexMap<LocalDefId, ty::DefinitionSiteHiddenType<'_>>, ErrorGuaranteed> {
117117
assert!(!tcx.is_typeck_child(def.to_def_id()));
118+
if tcx.is_trivial_const(def) {
119+
debug!("Skipping borrowck because of trivial const");
120+
let opaque_types = Default::default();
121+
return Ok(tcx.arena.alloc(opaque_types));
122+
}
118123
let (input_body, _) = tcx.mir_promoted(def);
119124
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
120125

compiler/rustc_mir_transform/src/trivial_const.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ where
5959
return None;
6060
}
6161

62+
if !tcx.opaque_types_defined_by(def).is_empty() {
63+
return None;
64+
}
65+
6266
let body = body_provider();
6367

6468
if body.has_opaque_types() {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait Trait2: Sized {}
2+
3+
impl Trait2 for () {
4+
const FOO: () = {
5+
//~^ ERROR const `FOO` is not a member of trait `Trait2`
6+
//~^^ ERROR item does not constrain `Assoc::{opaque#0}`
7+
type Assoc = impl Copy; //~ ERROR `impl Trait` in type aliases is unstable
8+
};
9+
}
10+
11+
fn main() {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0438]: const `FOO` is not a member of trait `Trait2`
2+
--> $DIR/trivial-const-ice-149278.rs:4:5
3+
|
4+
LL | / const FOO: () = {
5+
LL | |
6+
LL | |
7+
LL | | type Assoc = impl Copy;
8+
LL | | };
9+
| |______^ not a member of trait `Trait2`
10+
11+
error[E0658]: `impl Trait` in type aliases is unstable
12+
--> $DIR/trivial-const-ice-149278.rs:7:22
13+
|
14+
LL | type Assoc = impl Copy;
15+
| ^^^^^^^^^
16+
|
17+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
18+
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error: item does not constrain `Assoc::{opaque#0}`
22+
--> $DIR/trivial-const-ice-149278.rs:4:11
23+
|
24+
LL | const FOO: () = {
25+
| ^^^
26+
|
27+
= note: consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]`
28+
note: this opaque type is supposed to be constrained
29+
--> $DIR/trivial-const-ice-149278.rs:7:22
30+
|
31+
LL | type Assoc = impl Copy;
32+
| ^^^^^^^^^
33+
34+
error: aborting due to 3 previous errors
35+
36+
Some errors have detailed explanations: E0438, E0658.
37+
For more information about an error, try `rustc --explain E0438`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
//@ check-pass
5+
6+
#![feature(type_alias_impl_trait)]
7+
8+
type Tait = impl Sized;
9+
10+
#[define_opaque(Tait)]
11+
const FOO: Tait = 1;
12+
13+
fn main() {
14+
let _: Tait = FOO;
15+
}

0 commit comments

Comments
 (0)