Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE in const_trait check code #102361

Merged
merged 2 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to return here or break out of the block so that intravisit::walk_item still runs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

let source_map = tcx.sess.source_map();
if !tcx.has_attr(def_id, sym::const_trait) {
tcx.sess
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(allocator_api)]
#![feature(const_trait_impl)]

use core::convert::{From, TryFrom};
//~^ ERROR
//~| ERROR
Comment on lines +5 to +6
Copy link
Contributor

@Rageking8 Rageking8 Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the error code to make it a tad clearer, or is it mostly unnecessary for this case? Not sure on the error annotations guidelines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The errors are expected, but checking the error message is mostly unnecessary because we are only ensuring that it doesn't ICE.


use std::pin::Pin;
use std::alloc::Allocator;
impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
where
A: 'static,
{}

pub fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr
Original file line number Diff line number Diff line change
@@ -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`.