Skip to content

Commit 3fda0e4

Browse files
Auto merge of rust-lang#150839 - matthiaskrgr:rollup-3a0ebXJ, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#149961 (tidy: add if-installed prefix condition to extra checks system) - rust-lang#150475 (std: sys: fs: uefi: Implement initial File) - rust-lang#150533 (std: sys: fs: uefi: Implement remove_dir_all) - rust-lang#150549 (fix missing_panics_doc in `std::os::fd::owned`) - rust-lang#150699 (MGCA: Support literals as direct const arguments) - rust-lang#150721 (Deprecated doc intra link) - rust-lang#150802 (Minor cleanups to fn_abi_new_uncached) - rust-lang#150803 (compiler-builtins subtree update) - rust-lang#150809 (Update `literal-escaper` version to `0.0.7`) - rust-lang#150811 (Store defids instead of symbol names in the aliases list) - rust-lang#150825 (Query associated_item_def_ids when needed) r? @ghost
2 parents 31cd367 + 0fbcfb9 commit 3fda0e4

50 files changed

Lines changed: 701 additions & 281 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,9 +3412,9 @@ checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
34123412

34133413
[[package]]
34143414
name = "rustc-literal-escaper"
3415-
version = "0.0.5"
3415+
version = "0.0.7"
34163416
source = "registry+https://github.com/rust-lang/crates.io-index"
3417-
checksum = "e4ee29da77c5a54f42697493cd4c9b9f31b74df666a6c04dfc4fde77abe0438b"
3417+
checksum = "8be87abb9e40db7466e0681dc8ecd9dcfd40360cb10b4c8fe24a7c4c3669b198"
34183418

34193419
[[package]]
34203420
name = "rustc-main"

compiler/rustc_ast/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2024"
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
99
memchr = "2.7.6"
10-
rustc-literal-escaper = "0.0.5"
10+
rustc-literal-escaper = "0.0.7"
1111
rustc_ast_ir = { path = "../rustc_ast_ir" }
1212
rustc_data_structures = { path = "../rustc_data_structures" }
1313
rustc_index = { path = "../rustc_index" }

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,34 @@ impl AttributeExt for Attribute {
235235
}
236236
}
237237

238+
fn deprecation_note(&self) -> Option<Symbol> {
239+
match &self.kind {
240+
AttrKind::Normal(normal) if normal.item.path == sym::deprecated => {
241+
let meta = &normal.item;
242+
243+
// #[deprecated = "..."]
244+
if let Some(s) = meta.value_str() {
245+
return Some(s);
246+
}
247+
248+
// #[deprecated(note = "...")]
249+
if let Some(list) = meta.meta_item_list() {
250+
for nested in list {
251+
if let Some(mi) = nested.meta_item()
252+
&& mi.path == sym::note
253+
&& let Some(s) = mi.value_str()
254+
{
255+
return Some(s);
256+
}
257+
}
258+
}
259+
260+
None
261+
}
262+
_ => None,
263+
}
264+
}
265+
238266
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
239267
match &self.kind {
240268
AttrKind::DocComment(..) => Some(self.style),
@@ -277,6 +305,7 @@ impl Attribute {
277305

278306
pub fn may_have_doc_links(&self) -> bool {
279307
self.doc_str().is_some_and(|s| comments::may_have_doc_links(s.as_str()))
308+
|| self.deprecation_note().is_some_and(|s| comments::may_have_doc_links(s.as_str()))
280309
}
281310

282311
/// Extracts the MetaItem from inside this Attribute.
@@ -873,6 +902,11 @@ pub trait AttributeExt: Debug {
873902
/// * `#[doc(...)]` returns `None`.
874903
fn doc_str(&self) -> Option<Symbol>;
875904

905+
/// Returns the deprecation note if this is deprecation attribute.
906+
/// * `#[deprecated = "note"]` returns `Some("note")`.
907+
/// * `#[deprecated(note = "note", ...)]` returns `Some("note")`.
908+
fn deprecation_note(&self) -> Option<Symbol>;
909+
876910
fn is_proc_macro_attr(&self) -> bool {
877911
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
878912
.iter()

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25362536

25372537
overly_complex_const(self)
25382538
}
2539+
ExprKind::Lit(literal) => {
2540+
let span = expr.span;
2541+
let literal = self.lower_lit(literal, span);
2542+
2543+
ConstArg {
2544+
hir_id: self.lower_node_id(expr.id),
2545+
kind: hir::ConstArgKind::Literal(literal.node),
2546+
span,
2547+
}
2548+
}
25392549
_ => overly_complex_const(self),
25402550
}
25412551
}

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_middle::mir::mono::Visibility;
1010
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf};
1111
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
1212
use rustc_session::config::CrateType;
13-
use rustc_span::Symbol;
1413
use rustc_target::spec::{Arch, RelocModel};
1514
use tracing::debug;
1615

@@ -92,17 +91,19 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
9291
}
9392

9493
impl CodegenCx<'_, '_> {
95-
fn add_aliases(&self, aliasee: &llvm::Value, aliases: &[(Symbol, Linkage, Visibility)]) {
94+
fn add_aliases(&self, aliasee: &llvm::Value, aliases: &[(DefId, Linkage, Visibility)]) {
9695
let ty = self.get_type_of_global(aliasee);
9796

9897
for (alias, linkage, visibility) in aliases {
98+
let symbol_name = self.tcx.symbol_name(Instance::mono(self.tcx, *alias));
99+
99100
tracing::debug!("ALIAS: {alias:?} {linkage:?} {visibility:?}");
100101
let lldecl = llvm::add_alias(
101102
self.llmod,
102103
ty,
103104
AddressSpace::ZERO,
104105
aliasee,
105-
&CString::new(alias.as_str()).unwrap(),
106+
&CString::new(symbol_name.name).unwrap(),
106107
);
107108

108109
llvm::set_visibility(lldecl, base::visibility_to_llvm(*visibility));

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use rustc_middle::middle::codegen_fn_attrs::{
1313
use rustc_middle::mir::mono::Visibility;
1414
use rustc_middle::query::Providers;
1515
use rustc_middle::span_bug;
16-
use rustc_middle::ty::{self as ty, Instance, TyCtxt};
16+
use rustc_middle::ty::{self as ty, TyCtxt};
1717
use rustc_session::lint;
1818
use rustc_session::parse::feature_err;
19-
use rustc_span::{Span, Symbol, sym};
19+
use rustc_span::{Span, sym};
2020
use rustc_target::spec::Os;
2121

2222
use crate::errors;
@@ -291,8 +291,6 @@ fn process_builtin_attrs(
291291
)
292292
.expect("eii should have declaration macro with extern target attribute");
293293

294-
let symbol_name = tcx.symbol_name(Instance::mono(tcx, extern_item));
295-
296294
// this is to prevent a bug where a single crate defines both the default and explicit implementation
297295
// for an EII. In that case, both of them may be part of the same final object file. I'm not 100% sure
298296
// what happens, either rustc deduplicates the symbol or llvm, or it's random/order-dependent.
@@ -310,7 +308,7 @@ fn process_builtin_attrs(
310308
}
311309

312310
codegen_fn_attrs.foreign_item_symbol_aliases.push((
313-
Symbol::intern(symbol_name.name),
311+
extern_item,
314312
if i.is_default { Linkage::LinkOnceAny } else { Linkage::External },
315313
Visibility::Default,
316314
));

compiler/rustc_hir/src/hir.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ pub enum ConstArgKind<'hir, Unambig = ()> {
518518
/// This variant is not always used to represent inference consts, sometimes
519519
/// [`GenericArg::Infer`] is used instead.
520520
Infer(Unambig),
521+
Literal(LitKind),
521522
}
522523

523524
#[derive(Clone, Copy, Debug, HashStable_Generic)]
@@ -1400,6 +1401,14 @@ impl AttributeExt for Attribute {
14001401
}
14011402
}
14021403

1404+
#[inline]
1405+
fn deprecation_note(&self) -> Option<Symbol> {
1406+
match &self {
1407+
Attribute::Parsed(AttributeKind::Deprecation { deprecation, .. }) => deprecation.note,
1408+
_ => None,
1409+
}
1410+
}
1411+
14031412
fn is_automatically_derived_attr(&self) -> bool {
14041413
matches!(self, Attribute::Parsed(AttributeKind::AutomaticallyDerived(..)))
14051414
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ pub fn walk_const_arg<'v, V: Visitor<'v>>(
11041104
ConstArgKind::Path(qpath) => visitor.visit_qpath(qpath, *hir_id, qpath.span()),
11051105
ConstArgKind::Anon(anon) => visitor.visit_anon_const(*anon),
11061106
ConstArgKind::Error(_) => V::Result::output(), // errors and spans are not important
1107+
ConstArgKind::Literal(..) => V::Result::output(), // FIXME(mcga)
11071108
}
11081109
}
11091110

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@ impl<'tcx> InherentCollect<'tcx> {
7979
}
8080

8181
if self.tcx.features().rustc_attrs() {
82-
let items = self.tcx.associated_item_def_ids(impl_def_id);
83-
8482
if !self.tcx.has_attr(ty_def_id, sym::rustc_has_incoherent_inherent_impls) {
8583
let impl_span = self.tcx.def_span(impl_def_id);
8684
return Err(self.tcx.dcx().emit_err(errors::InherentTyOutside { span: impl_span }));
8785
}
8886

87+
let items = self.tcx.associated_item_def_ids(impl_def_id);
8988
for &impl_item in items {
9089
if !find_attr!(
9190
self.tcx.get_all_attrs(impl_item),

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub mod generics;
2222
use std::assert_matches::assert_matches;
2323
use std::slice;
2424

25+
use rustc_ast::LitKind;
2526
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
2627
use rustc_errors::codes::*;
2728
use rustc_errors::{
@@ -2391,6 +2392,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23912392
hir::ConstArgKind::Anon(anon) => self.lower_const_arg_anon(anon),
23922393
hir::ConstArgKind::Infer(()) => self.ct_infer(None, const_arg.span),
23932394
hir::ConstArgKind::Error(e) => ty::Const::new_error(tcx, e),
2395+
hir::ConstArgKind::Literal(kind) if let FeedConstTy::WithTy(anon_const_type) = feed => {
2396+
self.lower_const_arg_literal(&kind, anon_const_type, const_arg.span)
2397+
}
2398+
hir::ConstArgKind::Literal(..) => {
2399+
let e = self.dcx().span_err(const_arg.span, "literal of unknown type");
2400+
ty::Const::new_error(tcx, e)
2401+
}
23942402
}
23952403
}
23962404

@@ -2773,6 +2781,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27732781
}
27742782
}
27752783

2784+
#[instrument(skip(self), level = "debug")]
2785+
fn lower_const_arg_literal(&self, kind: &LitKind, ty: Ty<'tcx>, span: Span) -> Const<'tcx> {
2786+
let tcx = self.tcx();
2787+
let input = LitToConstInput { lit: *kind, ty, neg: false };
2788+
tcx.at(span).lit_to_const(input)
2789+
}
2790+
27762791
#[instrument(skip(self), level = "debug")]
27772792
fn try_lower_anon_const_lit(
27782793
&self,

0 commit comments

Comments
 (0)