Skip to content

Commit 7878a91

Browse files
committed
Auto merge of rust-lang#148420 - Zalathar:rollup-1rrbzk7, r=Zalathar
Rollup of 5 pull requests Successful merges: - rust-lang#144194 (Provide additional context to errors involving const traits) - rust-lang#148232 (ci: add runners for vanilla LLVM 21) - rust-lang#148240 (rustc_codegen: fix musttail returns for cast/indirect ABIs) - rust-lang#148247 (Remove a special case and move another one out of reachable_non_generics) - rust-lang#148370 (Point at inner item when it uses generic type param from outer item or `Self`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c5dabe8 + c10e1e4 commit 7878a91

File tree

94 files changed

+972
-136
lines changed

Some content is hidden

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

94 files changed

+972
-136
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ fn prepare_lto(
7777
// should have default visibility.
7878
symbols_below_threshold.push(c"__llvm_profile_counter_bias".to_owned());
7979

80+
// LTO seems to discard this otherwise under certain circumstances.
81+
symbols_below_threshold.push(c"rust_eh_personality".to_owned());
82+
8083
// If we're performing LTO for the entire crate graph, then for each of our
8184
// upstream dependencies, find the corresponding rlib and load the bitcode
8285
// from the archive.

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_codegen_ssa::mir::place::PlaceRef;
1616
use rustc_codegen_ssa::traits::*;
1717
use rustc_data_structures::small_c_str::SmallCStr;
1818
use rustc_hir::def_id::DefId;
19-
use rustc_middle::bug;
2019
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2120
use rustc_middle::ty::layout::{
2221
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers,
@@ -1458,10 +1457,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14581457

14591458
match &fn_abi.ret.mode {
14601459
PassMode::Ignore | PassMode::Indirect { .. } => self.ret_void(),
1461-
PassMode::Direct(_) | PassMode::Pair { .. } => self.ret(call),
1462-
mode @ PassMode::Cast { .. } => {
1463-
bug!("Encountered `PassMode::{mode:?}` during codegen")
1464-
}
1460+
PassMode::Direct(_) | PassMode::Pair { .. } | PassMode::Cast { .. } => self.ret(call),
14651461
}
14661462
}
14671463

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
5151
return Default::default();
5252
}
5353

54-
// Check to see if this crate is a "special runtime crate". These
55-
// crates, implementation details of the standard library, typically
56-
// have a bunch of `pub extern` and `#[no_mangle]` functions as the
57-
// ABI between them. We don't want their symbols to have a `C`
58-
// export level, however, as they're just implementation details.
59-
// Down below we'll hardwire all of the symbols to the `Rust` export
60-
// level instead.
61-
let special_runtime_crate =
62-
tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
54+
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
6355

6456
let mut reachable_non_generics: DefIdMap<_> = tcx
6557
.reachable_set(())
@@ -104,11 +96,12 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
10496
if tcx.cross_crate_inlinable(def_id) { None } else { Some(def_id) }
10597
})
10698
.map(|def_id| {
107-
// We won't link right if this symbol is stripped during LTO.
108-
let name = tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())).name;
109-
let used = name == "rust_eh_personality";
110-
111-
let export_level = if special_runtime_crate {
99+
let export_level = if is_compiler_builtins {
100+
// We don't want to export compiler-builtins symbols from any
101+
// dylibs, even rust dylibs. Unlike all other crates it gets
102+
// duplicated in every linker invocation and it may otherwise
103+
// unintentionally override definitions of these symbols by
104+
// libgcc or compiler-rt for C code.
112105
SymbolExportLevel::Rust
113106
} else {
114107
symbol_export_level(tcx, def_id.to_def_id())
@@ -131,8 +124,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
131124
SymbolExportKind::Text
132125
},
133126
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
134-
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
135-
|| used,
127+
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER),
136128
rustc_std_internal_symbol: codegen_attrs
137129
.flags
138130
.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL),

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10631063
let return_dest = self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs);
10641064
target.map(|target| (return_dest, target))
10651065
}
1066-
CallKind::Tail => None,
1066+
CallKind::Tail => {
1067+
if fn_abi.ret.is_indirect() {
1068+
match self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs) {
1069+
ReturnDest::Nothing => {}
1070+
_ => bug!(
1071+
"tail calls to functions with indirect returns cannot store into a destination"
1072+
),
1073+
}
1074+
}
1075+
None
1076+
}
10671077
};
10681078

10691079
// Split the rust-call tupled arguments off.

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Concrete error types for all operations which may be invalid in a certain const context.
22
33
use hir::{ConstContext, LangItem};
4-
use rustc_errors::Diag;
54
use rustc_errors::codes::*;
5+
use rustc_errors::{Applicability, Diag, MultiSpan};
66
use rustc_hir as hir;
77
use rustc_hir::def_id::DefId;
88
use rustc_infer::infer::TyCtxtInferExt;
@@ -11,8 +11,8 @@ use rustc_middle::mir::CallSource;
1111
use rustc_middle::span_bug;
1212
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
1313
use rustc_middle::ty::{
14-
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty,
15-
suggest_constraining_type_param,
14+
self, AssocContainer, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef,
15+
Ty, suggest_constraining_type_param,
1616
};
1717
use rustc_session::parse::add_feature_diagnostics;
1818
use rustc_span::{BytePos, Pos, Span, Symbol, sym};
@@ -352,18 +352,71 @@ fn build_error_for_const_call<'tcx>(
352352
non_or_conditionally,
353353
})
354354
}
355-
_ => ccx.dcx().create_err(errors::NonConstFnCall {
356-
span,
357-
def_descr: ccx.tcx.def_descr(callee),
358-
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
359-
kind: ccx.const_kind(),
360-
non_or_conditionally,
361-
}),
355+
_ => {
356+
let def_descr = ccx.tcx.def_descr(callee);
357+
let mut err = ccx.dcx().create_err(errors::NonConstFnCall {
358+
span,
359+
def_descr,
360+
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
361+
kind: ccx.const_kind(),
362+
non_or_conditionally,
363+
});
364+
if let Some(item) = ccx.tcx.opt_associated_item(callee) {
365+
if let AssocContainer::Trait = item.container
366+
&& let parent = item.container_id(ccx.tcx)
367+
&& !ccx.tcx.is_const_trait(parent)
368+
{
369+
let assoc_span = ccx.tcx.def_span(callee);
370+
let assoc_name = ccx.tcx.item_name(callee);
371+
let mut span: MultiSpan = ccx.tcx.def_span(parent).into();
372+
span.push_span_label(assoc_span, format!("this {def_descr} is not const"));
373+
let trait_descr = ccx.tcx.def_descr(parent);
374+
let trait_span = ccx.tcx.def_span(parent);
375+
let trait_name = ccx.tcx.item_name(parent);
376+
span.push_span_label(trait_span, format!("this {trait_descr} is not const"));
377+
err.span_note(
378+
span,
379+
format!(
380+
"{def_descr} `{assoc_name}` is not const because {trait_descr} \
381+
`{trait_name}` is not const",
382+
),
383+
);
384+
if parent.is_local() && ccx.tcx.sess.is_nightly_build() {
385+
if !ccx.tcx.features().const_trait_impl() {
386+
err.help(
387+
"add `#![feature(const_trait_impl)]` to the crate attributes to \
388+
enable `#[const_trait]`",
389+
);
390+
}
391+
let indentation = ccx
392+
.tcx
393+
.sess
394+
.source_map()
395+
.indentation_before(trait_span)
396+
.unwrap_or_default();
397+
err.span_suggestion_verbose(
398+
trait_span.shrink_to_lo(),
399+
format!("consider making trait `{trait_name}` const"),
400+
format!("#[const_trait]\n{indentation}"),
401+
Applicability::MaybeIncorrect,
402+
);
403+
} else if !ccx.tcx.sess.is_nightly_build() {
404+
err.help("const traits are not yet supported on stable Rust");
405+
}
406+
}
407+
} else if ccx.tcx.constness(callee) != hir::Constness::Const {
408+
let name = ccx.tcx.item_name(callee);
409+
err.span_note(
410+
ccx.tcx.def_span(callee),
411+
format!("{def_descr} `{name}` is not const"),
412+
);
413+
}
414+
err
415+
}
362416
};
363417

364418
err.note(format!(
365-
"calls in {}s are limited to constant functions, \
366-
tuple structs and tuple variants",
419+
"calls in {}s are limited to constant functions, tuple structs and tuple variants",
367420
ccx.const_kind(),
368421
));
369422

compiler/rustc_hir_typeck/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ hir_typeck_self_ctor_from_outer_item = can't reference `Self` constructor from o
266266
.label = the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference
267267
.suggestion = replace `Self` with the actual type
268268
269+
hir_typeck_self_ctor_from_outer_item_inner_item = `Self` used in this inner item
270+
269271
hir_typeck_slicing_suggestion = consider slicing here
270272
271273
hir_typeck_struct_expr_non_exhaustive =

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,15 @@ pub(crate) struct SelfCtorFromOuterItem {
978978
pub impl_span: Span,
979979
#[subdiagnostic]
980980
pub sugg: Option<ReplaceWithName>,
981+
#[subdiagnostic]
982+
pub item: Option<InnerItem>,
983+
}
984+
985+
#[derive(Subdiagnostic)]
986+
#[label(hir_typeck_self_ctor_from_outer_item_inner_item)]
987+
pub(crate) struct InnerItem {
988+
#[primary_span]
989+
pub span: Span,
981990
}
982991

983992
#[derive(LintDiagnostic)]
@@ -987,6 +996,8 @@ pub(crate) struct SelfCtorFromOuterItemLint {
987996
pub impl_span: Span,
988997
#[subdiagnostic]
989998
pub sugg: Option<ReplaceWithName>,
999+
#[subdiagnostic]
1000+
pub item: Option<InnerItem>,
9901001
}
9911002

9921003
#[derive(Subdiagnostic)]

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,11 +1094,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10941094
span: path_span,
10951095
name: self.tcx.item_name(def.did()).to_ident_string(),
10961096
});
1097+
let item = match self
1098+
.tcx
1099+
.hir_node_by_def_id(self.tcx.hir_get_parent_item(hir_id).def_id)
1100+
{
1101+
hir::Node::Item(item) => Some(errors::InnerItem {
1102+
span: item.kind.ident().map(|i| i.span).unwrap_or(item.span),
1103+
}),
1104+
_ => None,
1105+
};
10971106
if ty.raw.has_param() {
10981107
let guar = self.dcx().emit_err(errors::SelfCtorFromOuterItem {
10991108
span: path_span,
11001109
impl_span: tcx.def_span(impl_def_id),
11011110
sugg,
1111+
item,
11021112
});
11031113
return (Ty::new_error(self.tcx, guar), res);
11041114
} else {
@@ -1109,6 +1119,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11091119
errors::SelfCtorFromOuterItemLint {
11101120
impl_span: tcx.def_span(impl_def_id),
11111121
sugg,
1122+
item,
11121123
},
11131124
);
11141125
}

compiler/rustc_resolve/messages.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ resolve_generic_params_from_outer_item_const = a `const` is a separate item from
180180
181181
resolve_generic_params_from_outer_item_const_param = const parameter from outer item
182182
183+
resolve_generic_params_from_outer_item_inner_item = {$is_self ->
184+
[true] `Self`
185+
*[false] generic parameter
186+
} used in this inner {$descr}
187+
183188
resolve_generic_params_from_outer_item_self_ty_alias = `Self` type implicitly declared here, by this `impl`
184189
185190
resolve_generic_params_from_outer_item_self_ty_param = can't use `Self` here

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::errors::{
4040
MaybeMissingMacroRulesName,
4141
};
4242
use crate::imports::{Import, ImportKind};
43-
use crate::late::{PatternSource, Rib};
43+
use crate::late::{DiagMetadata, PatternSource, Rib};
4444
use crate::{
4545
AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingError, BindingKey, Finalize,
4646
ForwardGenericParamBanReason, HasGenericParams, LexicalScopeBinding, MacroRulesScope, Module,
@@ -553,11 +553,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
553553
resolution_error: ResolutionError<'ra>,
554554
) -> Diag<'_> {
555555
match resolution_error {
556-
ResolutionError::GenericParamsFromOuterItem(
556+
ResolutionError::GenericParamsFromOuterItem {
557557
outer_res,
558558
has_generic_params,
559559
def_kind,
560-
) => {
560+
inner_item,
561+
} => {
561562
use errs::GenericParamsFromOuterItemLabel as Label;
562563
let static_or_const = match def_kind {
563564
DefKind::Static { .. } => {
@@ -575,6 +576,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
575576
sugg: None,
576577
static_or_const,
577578
is_self,
579+
item: inner_item.as_ref().map(|(span, kind)| {
580+
errs::GenericParamsFromOuterItemInnerItem {
581+
span: *span,
582+
descr: kind.descr().to_string(),
583+
}
584+
}),
578585
};
579586

580587
let sm = self.tcx.sess.source_map();
@@ -608,7 +615,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
608615
}
609616
};
610617

611-
if let HasGenericParams::Yes(span) = has_generic_params {
618+
if let HasGenericParams::Yes(span) = has_generic_params
619+
&& !matches!(inner_item, Some((_, ItemKind::Delegation(..))))
620+
{
612621
let name = self.tcx.item_name(def_id);
613622
let (span, snippet) = if span.is_empty() {
614623
let snippet = format!("<{name}>");
@@ -2401,6 +2410,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24012410
module: Option<ModuleOrUniformRoot<'ra>>,
24022411
failed_segment_idx: usize,
24032412
ident: Ident,
2413+
diag_metadata: Option<&DiagMetadata<'_>>,
24042414
) -> (String, Option<Suggestion>) {
24052415
let is_last = failed_segment_idx == path.len() - 1;
24062416
let ns = if is_last { opt_ns.unwrap_or(TypeNS) } else { TypeNS };
@@ -2506,6 +2516,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
25062516
None,
25072517
&ribs[ns_to_try],
25082518
ignore_binding,
2519+
diag_metadata,
25092520
) {
25102521
// we found a locally-imported or available item/module
25112522
Some(LexicalScopeBinding::Item(binding)) => Some(binding),
@@ -2556,6 +2567,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
25562567
None,
25572568
&ribs[ValueNS],
25582569
ignore_binding,
2570+
diag_metadata,
25592571
)
25602572
} else {
25612573
None

0 commit comments

Comments
 (0)