From 3c82a6148613185e53794e0bc2f87232c0eebbf8 Mon Sep 17 00:00:00 2001 From: danieljofficial Date: Fri, 1 May 2026 14:20:12 +0100 Subject: [PATCH 1/6] move tests from issues into associated-consts --- .../assoc-const-and-type-same-name.rs} | 0 .../assoc-const-in-array-initializer.rs} | 0 .../assoc-const-in-array-size.rs} | 0 .../assoc-const-in-static-array-size.rs} | 0 .../assoc-const-through-assoc-type-path.rs} | 0 .../no-assoc-item-bytes-on-usize.rs} | 0 .../no-assoc-item-bytes-on-usize.stderr} | 0 .../trait-const-with-phantom-data-lifetime.rs} | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{issues/issue-44247.rs => associated-consts/assoc-const-and-type-same-name.rs} (100%) rename tests/ui/{issues/issue-31267-additional.rs => associated-consts/assoc-const-in-array-initializer.rs} (100%) rename tests/ui/{issues/issue-24947.rs => associated-consts/assoc-const-in-array-size.rs} (100%) rename tests/ui/{issues/issue-25145.rs => associated-consts/assoc-const-in-static-array-size.rs} (100%) rename tests/ui/{issues/issue-42956.rs => associated-consts/assoc-const-through-assoc-type-path.rs} (100%) rename tests/ui/{issues/issue-28586.rs => associated-consts/no-assoc-item-bytes-on-usize.rs} (100%) rename tests/ui/{issues/issue-28586.stderr => associated-consts/no-assoc-item-bytes-on-usize.stderr} (100%) rename tests/ui/{issues/issue-34780.rs => associated-consts/trait-const-with-phantom-data-lifetime.rs} (100%) diff --git a/tests/ui/issues/issue-44247.rs b/tests/ui/associated-consts/assoc-const-and-type-same-name.rs similarity index 100% rename from tests/ui/issues/issue-44247.rs rename to tests/ui/associated-consts/assoc-const-and-type-same-name.rs diff --git a/tests/ui/issues/issue-31267-additional.rs b/tests/ui/associated-consts/assoc-const-in-array-initializer.rs similarity index 100% rename from tests/ui/issues/issue-31267-additional.rs rename to tests/ui/associated-consts/assoc-const-in-array-initializer.rs diff --git a/tests/ui/issues/issue-24947.rs b/tests/ui/associated-consts/assoc-const-in-array-size.rs similarity index 100% rename from tests/ui/issues/issue-24947.rs rename to tests/ui/associated-consts/assoc-const-in-array-size.rs diff --git a/tests/ui/issues/issue-25145.rs b/tests/ui/associated-consts/assoc-const-in-static-array-size.rs similarity index 100% rename from tests/ui/issues/issue-25145.rs rename to tests/ui/associated-consts/assoc-const-in-static-array-size.rs diff --git a/tests/ui/issues/issue-42956.rs b/tests/ui/associated-consts/assoc-const-through-assoc-type-path.rs similarity index 100% rename from tests/ui/issues/issue-42956.rs rename to tests/ui/associated-consts/assoc-const-through-assoc-type-path.rs diff --git a/tests/ui/issues/issue-28586.rs b/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.rs similarity index 100% rename from tests/ui/issues/issue-28586.rs rename to tests/ui/associated-consts/no-assoc-item-bytes-on-usize.rs diff --git a/tests/ui/issues/issue-28586.stderr b/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.stderr similarity index 100% rename from tests/ui/issues/issue-28586.stderr rename to tests/ui/associated-consts/no-assoc-item-bytes-on-usize.stderr diff --git a/tests/ui/issues/issue-34780.rs b/tests/ui/associated-consts/trait-const-with-phantom-data-lifetime.rs similarity index 100% rename from tests/ui/issues/issue-34780.rs rename to tests/ui/associated-consts/trait-const-with-phantom-data-lifetime.rs From 30e0c8f548170621d0d4c1e23a5a3ec8eee636f4 Mon Sep 17 00:00:00 2001 From: danieljofficial Date: Fri, 1 May 2026 14:30:58 +0100 Subject: [PATCH 2/6] add issue links and bless --- tests/ui/associated-consts/assoc-const-and-type-same-name.rs | 2 ++ .../ui/associated-consts/assoc-const-in-array-initializer.rs | 2 ++ tests/ui/associated-consts/assoc-const-in-array-size.rs | 4 ++-- .../ui/associated-consts/assoc-const-in-static-array-size.rs | 2 ++ .../associated-consts/assoc-const-through-assoc-type-path.rs | 2 ++ tests/ui/associated-consts/no-assoc-item-bytes-on-usize.rs | 2 +- .../ui/associated-consts/no-assoc-item-bytes-on-usize.stderr | 2 +- .../trait-const-with-phantom-data-lifetime.rs | 2 ++ 8 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/ui/associated-consts/assoc-const-and-type-same-name.rs b/tests/ui/associated-consts/assoc-const-and-type-same-name.rs index 1ddd5a6dc0b3f..a7304562f593d 100644 --- a/tests/ui/associated-consts/assoc-const-and-type-same-name.rs +++ b/tests/ui/associated-consts/assoc-const-and-type-same-name.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/44247 + //@ check-pass #![allow(dead_code)] trait T { diff --git a/tests/ui/associated-consts/assoc-const-in-array-initializer.rs b/tests/ui/associated-consts/assoc-const-in-array-initializer.rs index ef7a5002bf162..9787d8d677621 100644 --- a/tests/ui/associated-consts/assoc-const-in-array-initializer.rs +++ b/tests/ui/associated-consts/assoc-const-in-array-initializer.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/31267 + //@ run-pass #[derive(Clone, Copy, Debug)] diff --git a/tests/ui/associated-consts/assoc-const-in-array-size.rs b/tests/ui/associated-consts/assoc-const-in-array-size.rs index c607cb7ec89d6..b6db21550a435 100644 --- a/tests/ui/associated-consts/assoc-const-in-array-size.rs +++ b/tests/ui/associated-consts/assoc-const-in-array-size.rs @@ -1,6 +1,6 @@ //@ run-pass -// #24947 ICE using a trait-associated const in an array size - +// Regression test for https://github.com/rust-lang/rust/issues/24947 +// ICE using a trait-associated const in an array size struct Foo; diff --git a/tests/ui/associated-consts/assoc-const-in-static-array-size.rs b/tests/ui/associated-consts/assoc-const-in-static-array-size.rs index 7edaa91d4a0cf..a7700f7c48610 100644 --- a/tests/ui/associated-consts/assoc-const-in-static-array-size.rs +++ b/tests/ui/associated-consts/assoc-const-in-static-array-size.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/25145 + //@ run-pass struct S; diff --git a/tests/ui/associated-consts/assoc-const-through-assoc-type-path.rs b/tests/ui/associated-consts/assoc-const-through-assoc-type-path.rs index 5d6d4249a7d88..5202bdd6d82f1 100644 --- a/tests/ui/associated-consts/assoc-const-through-assoc-type-path.rs +++ b/tests/ui/associated-consts/assoc-const-through-assoc-type-path.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/42956 + //@ check-pass #![allow(dead_code)] diff --git a/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.rs b/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.rs index 9520e0e51a15a..7b05a074c3672 100644 --- a/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.rs +++ b/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.rs @@ -1,4 +1,4 @@ -// Regression test for issue #28586 +// Regression test for issue https://github.com/rust-lang/rust/issues/28586 pub trait Foo {} impl Foo for [u8; usize::BYTES] {} diff --git a/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.stderr b/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.stderr index dda147954facd..982d58cf0ac58 100644 --- a/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.stderr +++ b/tests/ui/associated-consts/no-assoc-item-bytes-on-usize.stderr @@ -1,5 +1,5 @@ error[E0599]: no associated function or constant named `BYTES` found for type `usize` in the current scope - --> $DIR/issue-28586.rs:4:26 + --> $DIR/no-assoc-item-bytes-on-usize.rs:4:26 | LL | impl Foo for [u8; usize::BYTES] {} | ^^^^^ associated function or constant not found in `usize` diff --git a/tests/ui/associated-consts/trait-const-with-phantom-data-lifetime.rs b/tests/ui/associated-consts/trait-const-with-phantom-data-lifetime.rs index 4470e3af682b0..16be49f299690 100644 --- a/tests/ui/associated-consts/trait-const-with-phantom-data-lifetime.rs +++ b/tests/ui/associated-consts/trait-const-with-phantom-data-lifetime.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/34780 + //@ check-pass use std::marker::PhantomData; From f4c3a71a9f7733aa1f314cd8146aa0a2b2c03d05 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Fri, 1 May 2026 20:39:17 +0000 Subject: [PATCH 3/6] Do not depend on typeck to borrow-check inline consts. --- .../rustc_borrowck/src/universal_regions.rs | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index ab31ed61c123f..804d2757cf998 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -23,6 +23,7 @@ use rustc_hir::lang_items::LangItem; use rustc_index::IndexVec; use rustc_infer::infer::NllRegionVariableOrigin; use rustc_macros::extension; +use rustc_middle::mir::RETURN_PLACE; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{ self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, @@ -584,7 +585,6 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { /// see `DefiningTy` for details. fn defining_ty(&self) -> DefiningTy<'tcx> { let tcx = self.infcx.tcx; - let typeck_root_def_id = tcx.typeck_root_def_id_local(self.mir_def); match tcx.hir_body_owner_kind(self.mir_def) { BodyOwnerKind::Closure | BodyOwnerKind::Fn => { @@ -614,36 +614,40 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { } BodyOwnerKind::Const { .. } | BodyOwnerKind::Static(..) => { - let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id); - if self.mir_def == typeck_root_def_id { - let args = self.infcx.replace_free_regions_with_nll_infer_vars( - NllRegionVariableOrigin::FreeRegion, - identity_args, - ); - DefiningTy::Const(self.mir_def.to_def_id(), args) - } else { - // FIXME: this line creates a query dependency between borrowck and typeck. - // - // This is required for `AscribeUserType` canonical query, which will call - // `type_of(inline_const_def_id)`. That `type_of` would inject erased lifetimes - // into borrowck, which is ICE #78174. - // - // As a workaround, inline consts have an additional generic param (`ty` - // below), so that `type_of(inline_const_def_id).args(args)` uses the - // proper type with NLL infer vars. - let ty = tcx - .typeck(self.mir_def) - .node_type(tcx.local_def_id_to_hir_id(self.mir_def)); - let args = InlineConstArgs::new( - tcx, - InlineConstArgsParts { parent_args: identity_args, ty }, - ) - .args; - let args = self.infcx.replace_free_regions_with_nll_infer_vars( - NllRegionVariableOrigin::FreeRegion, - args, - ); - DefiningTy::InlineConst(self.mir_def.to_def_id(), args) + match tcx.def_kind(self.mir_def) { + DefKind::InlineConst => { + // This is required for `AscribeUserType` canonical query, which will call + // `type_of(inline_const_def_id)`. That `type_of` would inject erased lifetimes + // into borrowck, which is ICE #78174. + // + // As a workaround, inline consts have an additional generic param (`ty` + // below), so that `type_of(inline_const_def_id).substs(substs)` uses the + // proper type with NLL infer vars. + // + // Fetch the actual type from MIR, as `type_of` returns something useless + // like ``. + let body = tcx.mir_promoted(self.mir_def).0.borrow(); + let ty = body.local_decls[RETURN_PLACE].ty; + let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.to_def_id()); + let parent_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id); + let args = + InlineConstArgs::new(tcx, InlineConstArgsParts { parent_args, ty }) + .args; + let args = self.infcx.replace_free_regions_with_nll_infer_vars( + NllRegionVariableOrigin::FreeRegion, + args, + ); + DefiningTy::InlineConst(self.mir_def.to_def_id(), args) + } + _ => { + let identity_args = + GenericArgs::identity_for_item(tcx, self.mir_def.to_def_id()); + let args = self.infcx.replace_free_regions_with_nll_infer_vars( + NllRegionVariableOrigin::FreeRegion, + identity_args, + ); + DefiningTy::Const(self.mir_def.to_def_id(), args) + } } } From 200d4e3b8a61a5c256245f3edd1616f746648cfa Mon Sep 17 00:00:00 2001 From: danieljofficial Date: Sat, 2 May 2026 11:38:56 +0100 Subject: [PATCH 4/6] move tests from issues into attributes folder --- .../attribute-on-wrong-item-inline-repr.rs} | 0 .../attribute-on-wrong-item-inline-repr.stderr} | 0 .../cfg-attr-feature-gate-and-rustc-dummy.rs} | 0 .../issue-49632.rs => attributes/inline-attribute-on-closure.rs} | 0 .../no-mangle-on-const-error.fixed} | 0 .../issue-45562.rs => attributes/no-mangle-on-const-error.rs} | 0 .../no-mangle-on-const-error.stderr} | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{issues/issue-43988.rs => attributes/attribute-on-wrong-item-inline-repr.rs} (100%) rename tests/ui/{issues/issue-43988.stderr => attributes/attribute-on-wrong-item-inline-repr.stderr} (100%) rename tests/ui/{issues/issue-24434.rs => attributes/cfg-attr-feature-gate-and-rustc-dummy.rs} (100%) rename tests/ui/{issues/issue-49632.rs => attributes/inline-attribute-on-closure.rs} (100%) rename tests/ui/{issues/issue-45562.fixed => attributes/no-mangle-on-const-error.fixed} (100%) rename tests/ui/{issues/issue-45562.rs => attributes/no-mangle-on-const-error.rs} (100%) rename tests/ui/{issues/issue-45562.stderr => attributes/no-mangle-on-const-error.stderr} (100%) diff --git a/tests/ui/issues/issue-43988.rs b/tests/ui/attributes/attribute-on-wrong-item-inline-repr.rs similarity index 100% rename from tests/ui/issues/issue-43988.rs rename to tests/ui/attributes/attribute-on-wrong-item-inline-repr.rs diff --git a/tests/ui/issues/issue-43988.stderr b/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr similarity index 100% rename from tests/ui/issues/issue-43988.stderr rename to tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr diff --git a/tests/ui/issues/issue-24434.rs b/tests/ui/attributes/cfg-attr-feature-gate-and-rustc-dummy.rs similarity index 100% rename from tests/ui/issues/issue-24434.rs rename to tests/ui/attributes/cfg-attr-feature-gate-and-rustc-dummy.rs diff --git a/tests/ui/issues/issue-49632.rs b/tests/ui/attributes/inline-attribute-on-closure.rs similarity index 100% rename from tests/ui/issues/issue-49632.rs rename to tests/ui/attributes/inline-attribute-on-closure.rs diff --git a/tests/ui/issues/issue-45562.fixed b/tests/ui/attributes/no-mangle-on-const-error.fixed similarity index 100% rename from tests/ui/issues/issue-45562.fixed rename to tests/ui/attributes/no-mangle-on-const-error.fixed diff --git a/tests/ui/issues/issue-45562.rs b/tests/ui/attributes/no-mangle-on-const-error.rs similarity index 100% rename from tests/ui/issues/issue-45562.rs rename to tests/ui/attributes/no-mangle-on-const-error.rs diff --git a/tests/ui/issues/issue-45562.stderr b/tests/ui/attributes/no-mangle-on-const-error.stderr similarity index 100% rename from tests/ui/issues/issue-45562.stderr rename to tests/ui/attributes/no-mangle-on-const-error.stderr From 40904ddd753acb12a5343a5e398317f2a2276aae Mon Sep 17 00:00:00 2001 From: danieljofficial Date: Sat, 2 May 2026 12:02:25 +0100 Subject: [PATCH 5/6] add issue links and bless attribute tests --- .../attribute-on-wrong-item-inline-repr.rs | 2 ++ .../attribute-on-wrong-item-inline-repr.stderr | 18 +++++++++--------- .../cfg-attr-feature-gate-and-rustc-dummy.rs | 2 ++ .../attributes/inline-attribute-on-closure.rs | 2 ++ .../attributes/no-mangle-on-const-error.fixed | 2 ++ .../ui/attributes/no-mangle-on-const-error.rs | 2 ++ .../attributes/no-mangle-on-const-error.stderr | 2 +- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/ui/attributes/attribute-on-wrong-item-inline-repr.rs b/tests/ui/attributes/attribute-on-wrong-item-inline-repr.rs index bd23e0e2457df..c29edbe14f244 100644 --- a/tests/ui/attributes/attribute-on-wrong-item-inline-repr.rs +++ b/tests/ui/attributes/attribute-on-wrong-item-inline-repr.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/43988 + #![feature(stmt_expr_attributes)] fn main() { diff --git a/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr b/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr index d393255e0ee1d..49f67bf6ad044 100644 --- a/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr +++ b/tests/ui/attributes/attribute-on-wrong-item-inline-repr.stderr @@ -1,5 +1,5 @@ error: `#[inline]` attribute cannot be used on statements - --> $DIR/issue-43988.rs:5:5 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:7:5 | LL | #[inline] | ^^^^^^^^^ @@ -7,7 +7,7 @@ LL | #[inline] = help: `#[inline]` can only be applied to functions error[E0539]: malformed `inline` attribute input - --> $DIR/issue-43988.rs:10:5 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:12:5 | LL | #[inline(XYZ)] | ^^^^^^^^^---^^ @@ -28,7 +28,7 @@ LL + #[inline] | error: `#[inline]` attribute cannot be used on statements - --> $DIR/issue-43988.rs:10:5 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:12:5 | LL | #[inline(XYZ)] | ^^^^^^^^^^^^^^ @@ -36,7 +36,7 @@ LL | #[inline(XYZ)] = help: `#[inline]` can only be applied to functions error[E0552]: unrecognized representation hint - --> $DIR/issue-43988.rs:15:12 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:17:12 | LL | #[repr(nothing)] | ^^^^^^^ @@ -45,7 +45,7 @@ LL | #[repr(nothing)] = note: for more information, visit error[E0552]: unrecognized representation hint - --> $DIR/issue-43988.rs:19:12 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:21:12 | LL | #[repr(something_not_real)] | ^^^^^^^^^^^^^^^^^^ @@ -54,7 +54,7 @@ LL | #[repr(something_not_real)] = note: for more information, visit error[E0539]: malformed `repr` attribute input - --> $DIR/issue-43988.rs:25:5 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:27:5 | LL | #[repr] | ^^^^^^^ expected this to be a list @@ -62,7 +62,7 @@ LL | #[repr] = note: for more information, visit error[E0539]: malformed `inline` attribute input - --> $DIR/issue-43988.rs:31:5 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:33:5 | LL | #[inline(ABC)] | ^^^^^^^^^---^^ @@ -83,7 +83,7 @@ LL + #[inline] | error: `#[inline]` attribute cannot be used on expressions - --> $DIR/issue-43988.rs:31:5 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:33:5 | LL | #[inline(ABC)] | ^^^^^^^^^^^^^^ @@ -91,7 +91,7 @@ LL | #[inline(ABC)] = help: `#[inline]` can only be applied to functions error[E0539]: malformed `repr` attribute input - --> $DIR/issue-43988.rs:36:14 + --> $DIR/attribute-on-wrong-item-inline-repr.rs:38:14 | LL | let _z = #[repr] 1; | ^^^^^^^ expected this to be a list diff --git a/tests/ui/attributes/cfg-attr-feature-gate-and-rustc-dummy.rs b/tests/ui/attributes/cfg-attr-feature-gate-and-rustc-dummy.rs index 429bcf4a8d87d..c7f56494f8ee8 100644 --- a/tests/ui/attributes/cfg-attr-feature-gate-and-rustc-dummy.rs +++ b/tests/ui/attributes/cfg-attr-feature-gate-and-rustc-dummy.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/24434 + //@ check-pass #![cfg_attr(true, feature(rustc_attrs))] diff --git a/tests/ui/attributes/inline-attribute-on-closure.rs b/tests/ui/attributes/inline-attribute-on-closure.rs index f17891c45013f..981d58e11e466 100644 --- a/tests/ui/attributes/inline-attribute-on-closure.rs +++ b/tests/ui/attributes/inline-attribute-on-closure.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/49632 + //@ run-pass #![feature(stmt_expr_attributes)] diff --git a/tests/ui/attributes/no-mangle-on-const-error.fixed b/tests/ui/attributes/no-mangle-on-const-error.fixed index 529b5bd744e03..0612385521dde 100644 --- a/tests/ui/attributes/no-mangle-on-const-error.fixed +++ b/tests/ui/attributes/no-mangle-on-const-error.fixed @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/45562 + //@ run-rustfix #![deny(unused_attributes)] diff --git a/tests/ui/attributes/no-mangle-on-const-error.rs b/tests/ui/attributes/no-mangle-on-const-error.rs index 7c30a967c7848..0366ce2e4b231 100644 --- a/tests/ui/attributes/no-mangle-on-const-error.rs +++ b/tests/ui/attributes/no-mangle-on-const-error.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/45562 + //@ run-rustfix #![deny(unused_attributes)] diff --git a/tests/ui/attributes/no-mangle-on-const-error.stderr b/tests/ui/attributes/no-mangle-on-const-error.stderr index 3372986af9373..af46ea8a5b9e2 100644 --- a/tests/ui/attributes/no-mangle-on-const-error.stderr +++ b/tests/ui/attributes/no-mangle-on-const-error.stderr @@ -1,5 +1,5 @@ error: const items should never be `#[no_mangle]` - --> $DIR/issue-45562.rs:5:14 + --> $DIR/no-mangle-on-const-error.rs:7:14 | LL | #[no_mangle] pub const RAH: usize = 5; | ----------^^^^^^^^^^^^^^^ From 8a77369ca4aa14a4c72105f7b75631d25961d911 Mon Sep 17 00:00:00 2001 From: EvoPot Date: Sat, 2 May 2026 06:01:15 +0300 Subject: [PATCH 6/6] Add extra symbol check for `.to_owned()` Previously when adding a suggestion for using `Cow::into_owned()` instead of `ToOwned::to_owned()`, the compiler would just convert the methods `Span` into a `String` and do checks on that `String`. This PR adds an extra guard to that suggestion by checking if the method is `sym::to_owned_method`. --- .../src/diagnostics/conflict_errors.rs | 23 ++++++++++--------- compiler/rustc_span/src/symbol.rs | 1 + src/tools/clippy/clippy_utils/src/sym.rs | 1 - 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index f7d35f3ff3b4b..61a2dbc2f5fc2 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -3536,17 +3536,18 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { && let ty::Adt(adt_def, _) = return_ty.kind() && adt_def.did() == cow_did { - if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(return_span) { - if let Some(pos) = snippet.rfind(".to_owned") { - let byte_pos = BytePos(pos as u32 + 1u32); - let to_owned_span = return_span.with_hi(return_span.lo() + byte_pos); - err.span_suggestion_short( - to_owned_span.shrink_to_hi(), - "try using `.into_owned()` if you meant to convert a `Cow<'_, T>` to an owned `T`", - "in", - Applicability::MaybeIncorrect, - ); - } + let typeck = tcx.typeck(self.mir_def_id()); + if let Some(expr) = self.find_expr(return_span) + && let Some(def_id) = typeck.type_dependent_def_id(expr.hir_id) + && tcx.is_diagnostic_item(sym::to_owned_method, def_id) + && let Some(to_owned_ident) = expr.method_ident() + { + err.span_suggestion_short( + to_owned_ident.span.shrink_to_lo(), + "try using `.into_owned()` if you meant to convert a `Cow<'_, T>` to an owned `T`", + "in", + Applicability::MaybeIncorrect, + ); } } } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index caeb923c18f78..f46ea8295ae92 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2046,6 +2046,7 @@ symbols! { thumb2, thumb_mode: "thumb-mode", tmm_reg, + to_owned_method, to_string, to_vec, tool_attributes, diff --git a/src/tools/clippy/clippy_utils/src/sym.rs b/src/tools/clippy/clippy_utils/src/sym.rs index 87aac25f5bd12..367ec897dae48 100644 --- a/src/tools/clippy/clippy_utils/src/sym.rs +++ b/src/tools/clippy/clippy_utils/src/sym.rs @@ -606,7 +606,6 @@ generate! { to_ne_bytes, to_os_string, to_owned, - to_owned_method, to_path_buf, to_string_method, to_uppercase,