Skip to content

Commit 4df80b1

Browse files
Rollup merge of #151288 - fix/151250, r=BoxyUwU
Use `find_attr` instead of `attr::contains_name` in `lower_const_item_rhs` Fixes #151250 `attr::contains_name` uses `AttributeExt::name()` to filter, but for `hir::Attribute::Parsed`, this method will return `None`, and then `attr::contains_name` will return `false` here. So that the previous logic cannot work as expected. r? @BoxyUwU
2 parents 9f49af8 + db9f9e6 commit 4df80b1

5 files changed

Lines changed: 59 additions & 1 deletion

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23842384
Some(ConstItemRhs::TypeConst(anon)) => {
23852385
hir::ConstItemRhs::TypeConst(self.lower_anon_const_to_const_arg_and_alloc(anon))
23862386
}
2387-
None if attr::contains_name(attrs, sym::type_const) => {
2387+
None if find_attr!(attrs, AttributeKind::TypeConst(_)) => {
23882388
let const_arg = ConstArg {
23892389
hir_id: self.next_id(),
23902390
kind: hir::ConstArgKind::Error(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ needs-rustc-debug-assertions
2+
3+
#![feature(min_generic_const_args)]
4+
#![expect(incomplete_features)]
5+
6+
trait Tr {
7+
#[type_const]
8+
const SIZE: usize;
9+
}
10+
11+
struct T;
12+
13+
impl Tr for T {
14+
#[type_const]
15+
const SIZE: usize;
16+
//~^ ERROR associated constant in `impl` without body
17+
}
18+
19+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: associated constant in `impl` without body
2+
--> $DIR/type-const-assoc-const-without-body.rs:15:5
3+
|
4+
LL | const SIZE: usize;
5+
| ^^^^^^^^^^^^^^^^^-
6+
| |
7+
| help: provide a definition for the constant: `= <expr>;`
8+
9+
error: aborting due to 1 previous error
10+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ needs-rustc-debug-assertions
2+
3+
#![feature(min_generic_const_args)]
4+
#![expect(incomplete_features)]
5+
6+
impl S { //~ ERROR cannot find type `S` in this scope
7+
#[type_const]
8+
const SIZE: usize;
9+
//~^ ERROR associated constant in `impl` without body
10+
}
11+
12+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: associated constant in `impl` without body
2+
--> $DIR/type-const-inherent-assoc-const-without-body.rs:8:5
3+
|
4+
LL | const SIZE: usize;
5+
| ^^^^^^^^^^^^^^^^^-
6+
| |
7+
| help: provide a definition for the constant: `= <expr>;`
8+
9+
error[E0425]: cannot find type `S` in this scope
10+
--> $DIR/type-const-inherent-assoc-const-without-body.rs:6:6
11+
|
12+
LL | impl S {
13+
| ^ not found in this scope
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)