From 27b280e1b5370640fc0f181a52eaae6dc379d353 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Tue, 27 Sep 2022 13:42:32 +0000 Subject: [PATCH 1/2] Fix ICE in const_trait check code This fixes #102156. --- compiler/rustc_passes/src/check_const.rs | 2 +- .../rfc-2632-const-trait-impl/issue-102156.rs | 15 +++++++++++++++ .../issue-102156.stderr | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 4062862ad747c..0af538454f068 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -199,7 +199,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { .. }) = item.kind { - let def_id = trait_ref.trait_def_id().unwrap(); + let Some(def_id) = trait_ref.trait_def_id() else { return; }; let source_map = tcx.sess.source_map(); if !tcx.has_attr(def_id, sym::const_trait) { tcx.sess diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs new file mode 100644 index 0000000000000..fe4e910813013 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs @@ -0,0 +1,15 @@ +#![feature(allocator_api)] +#![feature(const_trait_impl)] + +use core::convert::{From, TryFrom}; +//~^ ERROR +//~| ERROR + +use std::pin::Pin; +use std::alloc::Allocator; +impl const From> for Pin> +where + A: 'static, +{} + +pub fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr new file mode 100644 index 0000000000000..8bf00eaff1fb9 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr @@ -0,0 +1,19 @@ +error[E0433]: failed to resolve: maybe a missing crate `core`? + --> $DIR/issue-102156.rs:4:5 + | +LL | use core::convert::{From, TryFrom}; + | ^^^^ maybe a missing crate `core`? + | + = help: consider adding `extern crate core` to use the `core` crate + +error[E0433]: failed to resolve: maybe a missing crate `core`? + --> $DIR/issue-102156.rs:4:5 + | +LL | use core::convert::{From, TryFrom}; + | ^^^^ maybe a missing crate `core`? + | + = help: consider adding `extern crate core` to use the `core` crate + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0433`. From d7fe44d98814f98354dd29532e01f1836b046d9e Mon Sep 17 00:00:00 2001 From: fee1-dead Date: Fri, 30 Sep 2022 00:31:53 +0000 Subject: [PATCH 2/2] Use let chains instead of let else --- compiler/rustc_passes/src/check_const.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs index 0af538454f068..116aaf4834981 100644 --- a/compiler/rustc_passes/src/check_const.rs +++ b/compiler/rustc_passes/src/check_const.rs @@ -198,8 +198,8 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { of_trait: Some(trait_ref), .. }) = item.kind + && let Some(def_id) = trait_ref.trait_def_id() { - let Some(def_id) = trait_ref.trait_def_id() else { return; }; let source_map = tcx.sess.source_map(); if !tcx.has_attr(def_id, sym::const_trait) { tcx.sess