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

add case for checking const refs in check_const_value_eq #89147

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,15 @@ fn check_const_value_eq<R: TypeRelation<'tcx>>(
get_slice_bytes(&tcx, a_val) == get_slice_bytes(&tcx, b_val)
}

(ConstValue::ByRef { alloc: alloc_a, .. }, ConstValue::ByRef { alloc: alloc_b, .. })
if a.ty.is_ref() || b.ty.is_ref() =>
{
if a.ty.is_ref() && b.ty.is_ref() {
alloc_a == alloc_b
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to have weird effects, but not worse than the Scalar::Ptr arm above. We should be using deref_const in both cases. But there's no need to try to fix this, we can just wait until I finally get my valtree PR over the finish line.

} else {
false
}
}
(ConstValue::ByRef { .. }, ConstValue::ByRef { .. }) => {
let a_destructured = tcx.destructure_const(relation.param_env().and(a));
let b_destructured = tcx.destructure_const(relation.param_env().and(b));
Expand Down
25 changes: 25 additions & 0 deletions src/test/ui/consts/refs_check_const_eq-issue-88384.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// check-pass

#![feature(fn_traits)]
#![feature(adt_const_params)]
//~^ WARNING the feature `adt_const_params` is incomplete

#[derive(PartialEq, Eq)]
struct CompileTimeSettings{
hooks: &'static[fn()],
}

struct Foo<const T: CompileTimeSettings>;

impl<const T: CompileTimeSettings> Foo<T> {
fn call_hooks(){
}
}

fn main(){
const SETTINGS: CompileTimeSettings = CompileTimeSettings{
hooks: &[],
};

Foo::<SETTINGS>::call_hooks();
}
11 changes: 11 additions & 0 deletions src/test/ui/consts/refs_check_const_eq-issue-88384.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `adt_const_params` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/refs_check_const_eq-issue-88384.rs:4:12
|
LL | #![feature(adt_const_params)]
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

warning: 1 warning emitted

12 changes: 12 additions & 0 deletions src/test/ui/consts/refs_check_const_value_eq-issue-88876.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// check-pass

#![allow(incomplete_features)]
#![feature(adt_const_params)]

struct FooConst<const ARRAY: &'static [&'static str]> {}

const FOO_ARR: &[&'static str; 2] = &["Hello", "Friend"];

fn main() {
let _ = FooConst::<FOO_ARR> {};
}