diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 20411fcc16fbb..001db316723b5 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -119,6 +119,11 @@ fn mir_borrowck( def: LocalDefId, ) -> Result<&FxIndexMap>, ErrorGuaranteed> { assert!(!tcx.is_typeck_child(def.to_def_id())); + if tcx.is_trivial_const(def) { + debug!("Skipping borrowck because of trivial const"); + let opaque_types = Default::default(); + return Ok(tcx.arena.alloc(opaque_types)); + } let (input_body, _) = tcx.mir_promoted(def); debug!("run query mir_borrowck: {}", tcx.def_path_str(def)); diff --git a/tests/ui/traits/const-traits/trivial-const-ice-149278.rs b/tests/ui/traits/const-traits/trivial-const-ice-149278.rs new file mode 100644 index 0000000000000..bfc49ebe02090 --- /dev/null +++ b/tests/ui/traits/const-traits/trivial-const-ice-149278.rs @@ -0,0 +1,11 @@ +trait Trait2: Sized {} + +impl Trait2 for () { + const FOO: () = { + //~^ ERROR const `FOO` is not a member of trait `Trait2` + //~^^ ERROR item does not constrain `Assoc::{opaque#0}` + type Assoc = impl Copy; //~ ERROR `impl Trait` in type aliases is unstable + }; +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/trivial-const-ice-149278.stderr b/tests/ui/traits/const-traits/trivial-const-ice-149278.stderr new file mode 100644 index 0000000000000..9b328bd59d24c --- /dev/null +++ b/tests/ui/traits/const-traits/trivial-const-ice-149278.stderr @@ -0,0 +1,37 @@ +error[E0438]: const `FOO` is not a member of trait `Trait2` + --> $DIR/trivial-const-ice-149278.rs:4:5 + | +LL | / const FOO: () = { +LL | | +LL | | +LL | | type Assoc = impl Copy; +LL | | }; + | |______^ not a member of trait `Trait2` + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/trivial-const-ice-149278.rs:7:22 + | +LL | type Assoc = impl Copy; + | ^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: item does not constrain `Assoc::{opaque#0}` + --> $DIR/trivial-const-ice-149278.rs:4:11 + | +LL | const FOO: () = { + | ^^^ + | + = note: consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]` +note: this opaque type is supposed to be constrained + --> $DIR/trivial-const-ice-149278.rs:7:22 + | +LL | type Assoc = impl Copy; + | ^^^^^^^^^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0438, E0658. +For more information about an error, try `rustc --explain E0438`.