Skip to content

Commit 3f808f2

Browse files
committed
Auto merge of #152602 - jhpratt:rollup-uaxGseW, r=jhpratt
Rollup of 11 pull requests Successful merges: - #151998 (Set hidden visibility on naked functions in compiler-builtins) - #149460 (rustdoc: sort stable items first) - #152076 (Feed `ErrorGuaranteed` from late lifetime resolution errors through to bound variable resolution) - #152471 (improve associated-type suggestions from bounds) - #152573 (move `escape_symbol_name` to `cg_ssa`) - #152594 (c-variadic: implement `va_arg` for `wasm64`) - #151386 (rustdoc: more js cleanup) - #152567 (nix-dev-shell: fix a typo) - #152568 (Port `#[lang]` and `#[panic_handler]` to the new attribute parsers) - #152575 (layout_of unexpected rigid alias delayed bug) - #152587 (A couple of tiny polonius things)
2 parents 29fa07e + 4bcbf62 commit 3f808f2

File tree

67 files changed

+968
-333
lines changed

Some content is hidden

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

67 files changed

+968
-333
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
878878

879879
(hir::ParamName::Fresh, hir::LifetimeParamKind::Elided(kind))
880880
}
881-
LifetimeRes::Static { .. } | LifetimeRes::Error => return None,
881+
LifetimeRes::Static { .. } | LifetimeRes::Error(..) => return None,
882882
res => panic!(
883883
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
884884
res, ident, ident.span
@@ -1931,26 +1931,29 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19311931
source: LifetimeSource,
19321932
syntax: LifetimeSyntax,
19331933
) -> &'hir hir::Lifetime {
1934-
let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
1935-
let res = match res {
1936-
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
1937-
LifetimeRes::Fresh { param, .. } => {
1938-
assert_eq!(ident.name, kw::UnderscoreLifetime);
1939-
let param = self.local_def_id(param);
1940-
hir::LifetimeKind::Param(param)
1941-
}
1942-
LifetimeRes::Infer => {
1943-
assert_eq!(ident.name, kw::UnderscoreLifetime);
1944-
hir::LifetimeKind::Infer
1945-
}
1946-
LifetimeRes::Static { .. } => {
1947-
assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
1948-
hir::LifetimeKind::Static
1949-
}
1950-
LifetimeRes::Error => hir::LifetimeKind::Error,
1951-
LifetimeRes::ElidedAnchor { .. } => {
1952-
panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
1934+
let res = if let Some(res) = self.resolver.get_lifetime_res(id) {
1935+
match res {
1936+
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
1937+
LifetimeRes::Fresh { param, .. } => {
1938+
assert_eq!(ident.name, kw::UnderscoreLifetime);
1939+
let param = self.local_def_id(param);
1940+
hir::LifetimeKind::Param(param)
1941+
}
1942+
LifetimeRes::Infer => {
1943+
assert_eq!(ident.name, kw::UnderscoreLifetime);
1944+
hir::LifetimeKind::Infer
1945+
}
1946+
LifetimeRes::Static { .. } => {
1947+
assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
1948+
hir::LifetimeKind::Static
1949+
}
1950+
LifetimeRes::Error(guar) => hir::LifetimeKind::Error(guar),
1951+
LifetimeRes::ElidedAnchor { .. } => {
1952+
panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
1953+
}
19531954
}
1955+
} else {
1956+
hir::LifetimeKind::Error(self.dcx().span_delayed_bug(ident.span, "unresolved lifetime"))
19541957
};
19551958

19561959
debug!(?res);
@@ -2014,12 +2017,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20142017
// AST resolution emitted an error on those parameters, so we lower them using
20152018
// `ParamName::Error`.
20162019
let ident = self.lower_ident(param.ident);
2017-
let param_name =
2018-
if let Some(LifetimeRes::Error) = self.resolver.get_lifetime_res(param.id) {
2019-
ParamName::Error(ident)
2020-
} else {
2021-
ParamName::Plain(ident)
2022-
};
2020+
let param_name = if let Some(LifetimeRes::Error(..)) =
2021+
self.resolver.get_lifetime_res(param.id)
2022+
{
2023+
ParamName::Error(ident)
2024+
} else {
2025+
ParamName::Plain(ident)
2026+
};
20232027
let kind =
20242028
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
20252029

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::path::PathBuf;
22

33
use rustc_ast::{LitIntType, LitKind, MetaItemLit};
4+
use rustc_hir::LangItem;
45
use rustc_hir::attrs::{
56
BorrowckGraphvizFormatKind, CguFields, CguKind, DivergingBlockBehavior,
67
DivergingFallbackBehavior, RustcCleanAttribute, RustcCleanQueries, RustcLayoutType,
@@ -12,7 +13,7 @@ use rustc_span::Symbol;
1213
use super::prelude::*;
1314
use super::util::parse_single_integer;
1415
use crate::session_diagnostics::{
15-
AttributeRequiresOpt, CguFieldsMissing, RustcScalableVectorCountOutOfRange,
16+
AttributeRequiresOpt, CguFieldsMissing, RustcScalableVectorCountOutOfRange, UnknownLangItem,
1617
};
1718

1819
pub(crate) struct RustcMainParser;
@@ -626,6 +627,32 @@ impl<S: Stage> SingleAttributeParser<S> for RustcScalableVectorParser {
626627
}
627628
}
628629

630+
pub(crate) struct LangParser;
631+
632+
impl<S: Stage> SingleAttributeParser<S> for LangParser {
633+
const PATH: &[Symbol] = &[sym::lang];
634+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
635+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
636+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); // Targets are checked per lang item in `rustc_passes`
637+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
638+
639+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
640+
let Some(nv) = args.name_value() else {
641+
cx.expected_name_value(cx.attr_span, None);
642+
return None;
643+
};
644+
let Some(name) = nv.value_as_str() else {
645+
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
646+
return None;
647+
};
648+
let Some(lang_item) = LangItem::from_name(name) else {
649+
cx.emit_err(UnknownLangItem { span: cx.attr_span, name });
650+
return None;
651+
};
652+
Some(AttributeKind::Lang(lang_item, cx.attr_span))
653+
}
654+
}
655+
629656
pub(crate) struct RustcHasIncoherentInherentImplsParser;
630657

631658
impl<S: Stage> NoArgsAttributeParser<S> for RustcHasIncoherentInherentImplsParser {
@@ -641,6 +668,15 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcHasIncoherentInherentImplsParse
641668
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcHasIncoherentInherentImpls;
642669
}
643670

671+
pub(crate) struct PanicHandlerParser;
672+
673+
impl<S: Stage> NoArgsAttributeParser<S> for PanicHandlerParser {
674+
const PATH: &[Symbol] = &[sym::panic_handler];
675+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
676+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); // Targets are checked per lang item in `rustc_passes`
677+
const CREATE: fn(Span) -> AttributeKind = |span| AttributeKind::Lang(LangItem::PanicImpl, span);
678+
}
679+
644680
pub(crate) struct RustcHiddenTypeOfOpaquesParser;
645681

646682
impl<S: Stage> NoArgsAttributeParser<S> for RustcHiddenTypeOfOpaquesParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ attribute_parsers!(
181181
Single<IgnoreParser>,
182182
Single<InlineParser>,
183183
Single<InstructionSetParser>,
184+
Single<LangParser>,
184185
Single<LinkNameParser>,
185186
Single<LinkOrdinalParser>,
186187
Single<LinkSectionParser>,
@@ -254,6 +255,7 @@ attribute_parsers!(
254255
Single<WithoutArgs<NoMangleParser>>,
255256
Single<WithoutArgs<NoStdParser>>,
256257
Single<WithoutArgs<NonExhaustiveParser>>,
258+
Single<WithoutArgs<PanicHandlerParser>>,
257259
Single<WithoutArgs<PanicRuntimeParser>>,
258260
Single<WithoutArgs<ParenSugarParser>>,
259261
Single<WithoutArgs<PassByValueParser>>,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,15 @@ pub(crate) struct DocAliasMalformed {
10131013
pub span: Span,
10141014
}
10151015

1016+
#[derive(Diagnostic)]
1017+
#[diag("definition of an unknown lang item: `{$name}`", code = E0522)]
1018+
pub(crate) struct UnknownLangItem {
1019+
#[primary_span]
1020+
#[label("definition of unknown lang item `{$name}`")]
1021+
pub span: Span,
1022+
pub name: Symbol,
1023+
}
1024+
10161025
#[derive(Diagnostic)]
10171026
#[diag("target `{$current_target}` does not support `#[instruction_set({$instruction_set}::*)]`")]
10181027
pub(crate) struct UnsupportedInstructionSet<'a> {

compiler/rustc_borrowck/src/polonius/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ impl LocalizedConstraintGraphVisitor for LoanLivenessVisitor<'_> {
182182
//
183183
// FIXME: analyze potential unsoundness, possibly in concert with a borrowck
184184
// implementation in a-mir-formality, fuzzing, or manually crafting counter-examples.
185-
let location = self.liveness.location_from_point(node.point);
186-
if self.liveness.is_live_at(node.region, location) {
185+
if self.liveness.is_live_at_point(node.region, node.point) {
187186
self.live_loans.insert(node.point, loan);
188187
}
189188
}

compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,17 @@ impl LivenessValues {
131131
}
132132
}
133133

134-
/// Returns whether `region` is marked live at the given `location`.
134+
/// Returns whether `region` is marked live at the given
135+
/// [`location`][rustc_middle::mir::Location].
135136
pub(crate) fn is_live_at(&self, region: RegionVid, location: Location) -> bool {
136137
let point = self.location_map.point_from_location(location);
138+
self.is_live_at_point(region, point)
139+
}
140+
141+
/// Returns whether `region` is marked live at the given
142+
/// [`point`][rustc_mir_dataflow::points::PointIndex].
143+
#[inline]
144+
pub(crate) fn is_live_at_point(&self, region: RegionVid, point: PointIndex) -> bool {
137145
if let Some(points) = &self.points {
138146
points.row(region).is_some_and(|r| r.contains(point))
139147
} else {

compiler/rustc_codegen_cranelift/src/global_asm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ fn codegen_global_asm_inner<'tcx>(
106106
match *piece {
107107
InlineAsmTemplatePiece::String(ref s) => global_asm.push_str(s),
108108
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier: _, span } => {
109+
use rustc_codegen_ssa::back::symbol_export::escape_symbol_name;
109110
match operands[operand_idx] {
110111
GlobalAsmOperandRef::Const { ref string } => {
111112
global_asm.push_str(string);
@@ -121,7 +122,7 @@ fn codegen_global_asm_inner<'tcx>(
121122
let symbol = tcx.symbol_name(instance);
122123
// FIXME handle the case where the function was made private to the
123124
// current codegen unit
124-
global_asm.push_str(symbol.name);
125+
global_asm.push_str(&escape_symbol_name(tcx, symbol.name, span));
125126
}
126127
GlobalAsmOperandRef::SymStatic { def_id } => {
127128
if cfg!(not(feature = "inline_asm_sym")) {
@@ -133,7 +134,7 @@ fn codegen_global_asm_inner<'tcx>(
133134

134135
let instance = Instance::mono(tcx, def_id);
135136
let symbol = tcx.symbol_name(instance);
136-
global_asm.push_str(symbol.name);
137+
global_asm.push_str(&escape_symbol_name(tcx, symbol.name, span));
137138
}
138139
}
139140
}

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
400400
match *piece {
401401
InlineAsmTemplatePiece::String(ref s) => template_str.push_str(s),
402402
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier: _, span } => {
403+
use rustc_codegen_ssa::back::symbol_export::escape_symbol_name;
403404
match operands[operand_idx] {
404405
GlobalAsmOperandRef::Const { ref string } => {
405406
// Const operands get injected directly into the
@@ -414,7 +415,7 @@ impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
414415
llvm::LLVMRustGetMangledName(llval, s);
415416
})
416417
.expect("symbol is not valid UTF-8");
417-
template_str.push_str(&escape_symbol_name(self, symbol, span));
418+
template_str.push_str(&escape_symbol_name(self.tcx, &symbol, span));
418419
}
419420
GlobalAsmOperandRef::SymStatic { def_id } => {
420421
let llval = self
@@ -428,7 +429,7 @@ impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
428429
llvm::LLVMRustGetMangledName(llval, s);
429430
})
430431
.expect("symbol is not valid UTF-8");
431-
template_str.push_str(&escape_symbol_name(self, symbol, span));
432+
template_str.push_str(&escape_symbol_name(self.tcx, &symbol, span));
432433
}
433434
}
434435
}
@@ -1390,42 +1391,3 @@ fn llvm_fixup_output_type<'ll, 'tcx>(
13901391
_ => layout.llvm_type(cx),
13911392
}
13921393
}
1393-
1394-
fn escape_symbol_name<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, symbol: String, span: Span) -> String {
1395-
use rustc_target::spec::{Arch, BinaryFormat};
1396-
if !symbol.is_empty()
1397-
&& symbol.chars().all(|c| matches!(c, '0'..='9' | 'A'..='Z' | 'a'..='z' | '_' | '$' | '.'))
1398-
{
1399-
return symbol;
1400-
}
1401-
if cx.tcx.sess.target.binary_format == BinaryFormat::Xcoff {
1402-
cx.tcx.sess.dcx().span_fatal(
1403-
span,
1404-
format!(
1405-
"symbol escaping is not supported for the binary format {}",
1406-
cx.tcx.sess.target.binary_format
1407-
),
1408-
);
1409-
}
1410-
if cx.tcx.sess.target.arch == Arch::Nvptx64 {
1411-
cx.tcx.sess.dcx().span_fatal(
1412-
span,
1413-
format!(
1414-
"symbol escaping is not supported for the architecture {}",
1415-
cx.tcx.sess.target.arch
1416-
),
1417-
);
1418-
}
1419-
let mut escaped_symbol = String::new();
1420-
escaped_symbol.push('\"');
1421-
for c in symbol.chars() {
1422-
match c {
1423-
'\n' => escaped_symbol.push_str("\\\n"),
1424-
'"' => escaped_symbol.push_str("\\\""),
1425-
'\\' => escaped_symbol.push_str("\\\\"),
1426-
c => escaped_symbol.push(c),
1427-
}
1428-
}
1429-
escaped_symbol.push('\"');
1430-
escaped_symbol
1431-
}

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
4141
});
4242

4343
llvm::set_linkage(g, base::linkage_to_llvm(linkage));
44-
llvm::set_visibility(g, base::visibility_to_llvm(visibility));
44+
self.set_visibility(g, linkage, visibility);
45+
4546
self.assume_dso_local(g, false);
4647

4748
let attrs = self.tcx.codegen_instance_attrs(instance.def);
@@ -69,16 +70,7 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
6970
{
7071
llvm::SetUniqueComdat(self.llmod, lldecl);
7172
}
72-
73-
// If we're compiling the compiler-builtins crate, e.g., the equivalent of
74-
// compiler-rt, then we want to implicitly compile everything with hidden
75-
// visibility as we're going to link this object all over the place but
76-
// don't want the symbols to get exported.
77-
if linkage != Linkage::Internal && self.tcx.is_compiler_builtins(LOCAL_CRATE) {
78-
llvm::set_visibility(lldecl, llvm::Visibility::Hidden);
79-
} else {
80-
llvm::set_visibility(lldecl, base::visibility_to_llvm(visibility));
81-
}
73+
self.set_visibility(lldecl, linkage, visibility);
8274

8375
debug!("predefine_fn: instance = {:?}", instance);
8476

@@ -122,6 +114,18 @@ impl CodegenCx<'_, '_> {
122114
assume
123115
}
124116

117+
fn set_visibility(&self, lldecl: &llvm::Value, linkage: Linkage, visibility: Visibility) {
118+
// If we're compiling the compiler-builtins crate, i.e., the equivalent of
119+
// compiler-rt, then we want to implicitly compile everything with hidden
120+
// visibility as we're going to link this object all over the place but
121+
// don't want the symbols to get exported.
122+
if linkage != Linkage::Internal && self.tcx.is_compiler_builtins(LOCAL_CRATE) {
123+
llvm::set_visibility(lldecl, llvm::Visibility::Hidden);
124+
} else {
125+
llvm::set_visibility(lldecl, base::visibility_to_llvm(visibility));
126+
}
127+
}
128+
125129
fn should_assume_dso_local(&self, llval: &llvm::Value, is_declaration: bool) -> bool {
126130
let linkage = llvm::get_linkage(llval);
127131
let visibility = llvm::get_visibility(llval);

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
11221122
AllowHigherAlign::Yes,
11231123
ForceRightAdjust::No,
11241124
),
1125-
Arch::Wasm32 => emit_ptr_va_arg(
1125+
Arch::Wasm32 | Arch::Wasm64 => emit_ptr_va_arg(
11261126
bx,
11271127
addr,
11281128
target_ty,
@@ -1135,7 +1135,6 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
11351135
AllowHigherAlign::Yes,
11361136
ForceRightAdjust::No,
11371137
),
1138-
Arch::Wasm64 => bug!("c-variadic functions are not fully implemented for wasm64"),
11391138
Arch::CSky => emit_ptr_va_arg(
11401139
bx,
11411140
addr,

0 commit comments

Comments
 (0)