Rollup merge of #151288 - fix/151250, r=BoxyUwU

Use `find_attr` instead of `attr::contains_name` in `lower_const_item_rhs`

Fixes rust-lang/rust#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
This commit is contained in:
Jonathan Brouwer
2026-01-18 18:26:06 +01:00
committed by GitHub
5 changed files with 59 additions and 1 deletions
+1 -1
View File
@@ -2384,7 +2384,7 @@ fn lower_const_item_rhs(
Some(ConstItemRhs::TypeConst(anon)) => {
hir::ConstItemRhs::TypeConst(self.lower_anon_const_to_const_arg_and_alloc(anon))
}
None if attr::contains_name(attrs, sym::type_const) => {
None if find_attr!(attrs, AttributeKind::TypeConst(_)) => {
let const_arg = ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Error(
@@ -0,0 +1,19 @@
//@ needs-rustc-debug-assertions
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
trait Tr {
#[type_const]
const SIZE: usize;
}
struct T;
impl Tr for T {
#[type_const]
const SIZE: usize;
//~^ ERROR associated constant in `impl` without body
}
fn main() {}
@@ -0,0 +1,10 @@
error: associated constant in `impl` without body
--> $DIR/type-const-assoc-const-without-body.rs:15:5
|
LL | const SIZE: usize;
| ^^^^^^^^^^^^^^^^^-
| |
| help: provide a definition for the constant: `= <expr>;`
error: aborting due to 1 previous error
@@ -0,0 +1,12 @@
//@ needs-rustc-debug-assertions
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
impl S { //~ ERROR cannot find type `S` in this scope
#[type_const]
const SIZE: usize;
//~^ ERROR associated constant in `impl` without body
}
fn main() {}
@@ -0,0 +1,17 @@
error: associated constant in `impl` without body
--> $DIR/type-const-inherent-assoc-const-without-body.rs:8:5
|
LL | const SIZE: usize;
| ^^^^^^^^^^^^^^^^^-
| |
| help: provide a definition for the constant: `= <expr>;`
error[E0425]: cannot find type `S` in this scope
--> $DIR/type-const-inherent-assoc-const-without-body.rs:6:6
|
LL | impl S {
| ^ not found in this scope
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0425`.