Skip to content

Commit c318364

Browse files
committed
Add more tests + visit_ty in some places
1 parent 8e7299d commit c318364

File tree

6 files changed

+62
-21
lines changed

6 files changed

+62
-21
lines changed

compiler/rustc_privacy/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ where
156156
let leaf = leaf.subst(tcx, ct.substs);
157157
self.visit_const(leaf)
158158
}
159-
ACNode::Binop(..)
160-
| ACNode::UnaryOp(..)
161-
| ACNode::FunctionCall(_, _)
162-
| ACNode::Cast(_, _, _) => ControlFlow::CONTINUE,
159+
ACNode::Cast(_, _, ty) => self.visit_ty(ty),
160+
ACNode::Binop(..) | ACNode::UnaryOp(..) | ACNode::FunctionCall(_, _) => {
161+
ControlFlow::CONTINUE
162+
}
163163
})
164164
}
165165

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,19 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
9797

9898
ControlFlow::CONTINUE
9999
}
100-
Node::Binop(_, _, _)
101-
| Node::UnaryOp(_, _)
102-
| Node::FunctionCall(_, _)
103-
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
100+
Node::Cast(_, _, ty) => {
101+
let ty = ty.subst(tcx, ct.substs);
102+
if ty.has_infer_types_or_consts() {
103+
failure_kind = FailureKind::MentionsInfer;
104+
} else if ty.has_param_types_or_consts() {
105+
failure_kind = cmp::min(failure_kind, FailureKind::MentionsParam);
106+
}
107+
108+
ControlFlow::CONTINUE
109+
}
110+
Node::Binop(_, _, _) | Node::UnaryOp(_, _) | Node::FunctionCall(_, _) => {
111+
ControlFlow::CONTINUE
112+
}
104113
});
105114

106115
match failure_kind {

compiler/rustc_trait_selection/src/traits/object_safety.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,10 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
838838
let leaf = leaf.subst(self.tcx, ct.substs);
839839
self.visit_const(leaf)
840840
}
841-
Node::Binop(..)
842-
| Node::UnaryOp(..)
843-
| Node::FunctionCall(_, _)
844-
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
841+
Node::Cast(_, _, ty) => self.visit_ty(ty),
842+
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
843+
ControlFlow::CONTINUE
844+
}
845845
})
846846
} else {
847847
ControlFlow::CONTINUE
@@ -860,10 +860,10 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
860860
let leaf = leaf.subst(self.tcx, ct.substs);
861861
self.visit_const(leaf)
862862
}
863-
Node::Binop(..)
864-
| Node::UnaryOp(..)
865-
| Node::FunctionCall(_, _)
866-
| Node::Cast(_, _, _) => ControlFlow::CONTINUE,
863+
Node::Cast(_, _, ty) => self.visit_ty(ty),
864+
Node::Binop(..) | Node::UnaryOp(..) | Node::FunctionCall(_, _) => {
865+
ControlFlow::CONTINUE
866+
}
867867
})
868868
} else {
869869
ControlFlow::CONTINUE
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
#![feature(const_evaluatable_checked, const_generics)]
22
#![allow(incomplete_features)]
33

4-
trait Evaluatable<const N: u128> {}
5-
impl<const N: u128> Evaluatable<N> for () {}
4+
struct Evaluatable<const N: u128> {}
65

76
struct Foo<const N: u8>([u8; N as usize])
87
//~^ Error: unconstrained generic constant
98
//~| help: try adding a `where` bound using this expression: `where [(); N as usize]:`
109
where
11-
(): Evaluatable<{N as u128}>;
10+
Evaluatable<{N as u128}>:;
11+
12+
struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:;
13+
//~^ Error: unconstrained generic constant
14+
//~| help: try adding a `where` bound using this expression: `where [(); {N as u128}]:`
15+
16+
struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:;
17+
//~^ unconstrained generic constant
18+
//~| help: try adding a `where` bound using this expression: `where [(); (N + 2) as usize]:`
1219

1320
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
error: unconstrained generic constant
2-
--> $DIR/abstract-const-as-cast-2.rs:7:25
2+
--> $DIR/abstract-const-as-cast-2.rs:6:25
33
|
44
LL | struct Foo<const N: u8>([u8; N as usize])
55
| ^^^^^^^^^^^^^^^^
66
|
77
= help: try adding a `where` bound using this expression: `where [(); N as usize]:`
88

9-
error: aborting due to previous error
9+
error: unconstrained generic constant
10+
--> $DIR/abstract-const-as-cast-2.rs:12:26
11+
|
12+
LL | struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:;
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= help: try adding a `where` bound using this expression: `where [(); {N as u128}]:`
16+
17+
error: unconstrained generic constant
18+
--> $DIR/abstract-const-as-cast-2.rs:16:25
19+
|
20+
LL | struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:;
21+
| ^^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= help: try adding a `where` bound using this expression: `where [(); (N + 2) as usize]:`
24+
25+
error: aborting due to 3 previous errors
1026

src/test/ui/const-generics/const_evaluatable_checked/abstract-const-as-cast.rs

+9
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ struct Foo<const N: u8>([u8; N as usize])
66
where
77
[(); N as usize]:;
88

9+
10+
// unifying with subtrees
11+
struct Evaluatable<const N: u16>;
12+
fn foo<const N: u8>() where Evaluatable<{N as usize as u16 }>: {
13+
let _ = Foo::<N>([1; N as usize]);
14+
}
15+
16+
struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 2) as usize]:;
17+
918
fn main() {}

0 commit comments

Comments
 (0)