Skip to content

Commit 1b5fbe2

Browse files
committed
add test for treating ExprKind::ConstParam as temp
1 parent 5fcccd1 commit 1b5fbe2

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// build-pass
2+
3+
#![feature(adt_const_params)]
4+
#![allow(incomplete_features)]
5+
6+
#[derive(PartialEq, Eq)]
7+
struct Yikes;
8+
9+
impl Yikes {
10+
fn mut_self(&mut self) {}
11+
}
12+
13+
fn foo<const YIKES: Yikes>() {
14+
YIKES.mut_self()
15+
//~^ WARNING taking a mutable reference
16+
}
17+
18+
fn main() {
19+
foo::<{ Yikes }>()
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
warning: taking a mutable reference to a `const` item
2+
--> $DIR/thir-constparam-temp.rs:14:5
3+
|
4+
LL | YIKES.mut_self()
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(const_item_mutation)]` on by default
8+
= note: each usage of a `const` item creates a new temporary
9+
= note: the mutable reference will refer to this temporary, not the original `const` item
10+
note: mutable reference created due to call to this method
11+
--> $DIR/thir-constparam-temp.rs:10:5
12+
|
13+
LL | fn mut_self(&mut self) {}
14+
| ^^^^^^^^^^^^^^^^^^^^^^
15+
note: `const` item defined here
16+
--> $DIR/thir-constparam-temp.rs:13:14
17+
|
18+
LL | fn foo<const YIKES: Yikes>() {
19+
| ^^^^^
20+
21+
warning: 1 warning emitted
22+

0 commit comments

Comments
 (0)