Skip to content

Commit 4383aad

Browse files
committed
Auto merge of #149820 - matthiaskrgr:rollup-19r3gq5, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #147602 (Deduplicate higher-ranked lifetime capture errors in impl Trait) - #147725 (Remove -Zoom=panic) - #148491 ( Correctly provide suggestions when encountering `async fn` with a `dyn Trait` return type) - #148717 (Point at span within local macros even when error happens in nested external macro) - #149458 (Run clippy on cg_gcc in CI) - #149816 (Make typo in field and name suggestions verbose) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c61a3a4 + d1087ac commit 4383aad

File tree

186 files changed

+2374
-800
lines changed

Some content is hidden

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

186 files changed

+2374
-800
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16701670
let output = match coro {
16711671
Some(coro) => {
16721672
let fn_def_id = self.local_def_id(fn_node_id);
1673-
self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind, fn_span)
1673+
self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
16741674
}
16751675
None => match &decl.output {
16761676
FnRetTy::Ty(ty) => {
@@ -1755,9 +1755,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17551755
fn_def_id: LocalDefId,
17561756
coro: CoroutineKind,
17571757
fn_kind: FnDeclKind,
1758-
fn_span: Span,
17591758
) -> hir::FnRetTy<'hir> {
1760-
let span = self.lower_span(fn_span);
1759+
let span = self.lower_span(output.span());
17611760

17621761
let (opaque_ty_node_id, allowed_features) = match coro {
17631762
CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),

compiler/rustc_codegen_cranelift/src/allocator.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_ast::expand::allocator::{
66
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
77
};
88
use rustc_codegen_ssa::base::{allocator_kind_for_codegen, allocator_shim_contents};
9-
use rustc_session::config::OomStrategy;
109
use rustc_symbol_mangling::mangle_internal_symbol;
1110

1211
use crate::prelude::*;
@@ -15,16 +14,11 @@ use crate::prelude::*;
1514
pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut dyn Module) -> bool {
1615
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
1716
let methods = allocator_shim_contents(tcx, kind);
18-
codegen_inner(tcx, module, &methods, tcx.sess.opts.unstable_opts.oom);
17+
codegen_inner(tcx, module, &methods);
1918
true
2019
}
2120

22-
fn codegen_inner(
23-
tcx: TyCtxt<'_>,
24-
module: &mut dyn Module,
25-
methods: &[AllocatorMethod],
26-
oom_strategy: OomStrategy,
27-
) {
21+
fn codegen_inner(tcx: TyCtxt<'_>, module: &mut dyn Module, methods: &[AllocatorMethod]) {
2822
let usize_ty = module.target_config().pointer_type();
2923

3024
for method in methods {
@@ -65,35 +59,6 @@ fn codegen_inner(
6559
);
6660
}
6761

68-
{
69-
let sig = Signature {
70-
call_conv: module.target_config().default_call_conv,
71-
params: vec![],
72-
returns: vec![AbiParam::new(types::I8)],
73-
};
74-
let func_id = module
75-
.declare_function(
76-
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
77-
Linkage::Export,
78-
&sig,
79-
)
80-
.unwrap();
81-
let mut ctx = Context::new();
82-
ctx.func.signature = sig;
83-
{
84-
let mut func_ctx = FunctionBuilderContext::new();
85-
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
86-
87-
let block = bcx.create_block();
88-
bcx.switch_to_block(block);
89-
let value = bcx.ins().iconst(types::I8, oom_strategy.should_panic() as i64);
90-
bcx.ins().return_(&[value]);
91-
bcx.seal_all_blocks();
92-
bcx.finalize();
93-
}
94-
module.define_function(func_id, &mut ctx).unwrap();
95-
}
96-
9762
{
9863
let sig = Signature {
9964
call_conv: module.target_config().default_call_conv,

compiler/rustc_codegen_gcc/src/allocator.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#[cfg(feature = "master")]
22
use gccjit::FnAttribute;
3-
use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
3+
use gccjit::{Context, FunctionType, ToRValue, Type};
44
use rustc_ast::expand::allocator::{
55
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
66
};
77
use rustc_middle::bug;
88
use rustc_middle::ty::TyCtxt;
9-
use rustc_session::config::OomStrategy;
109
use rustc_symbol_mangling::mangle_internal_symbol;
1110

1211
use crate::GccContext;
@@ -59,14 +58,6 @@ pub(crate) unsafe fn codegen(
5958
create_wrapper_function(tcx, context, &from_name, Some(&to_name), &types, output);
6059
}
6160

62-
create_const_value_function(
63-
tcx,
64-
context,
65-
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
66-
i8,
67-
context.new_rvalue_from_int(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as i32),
68-
);
69-
7061
create_wrapper_function(
7162
tcx,
7263
context,
@@ -77,34 +68,6 @@ pub(crate) unsafe fn codegen(
7768
);
7869
}
7970

80-
fn create_const_value_function(
81-
tcx: TyCtxt<'_>,
82-
context: &Context<'_>,
83-
name: &str,
84-
output: Type<'_>,
85-
value: RValue<'_>,
86-
) {
87-
let func = context.new_function(None, FunctionType::Exported, output, &[], name, false);
88-
89-
#[cfg(feature = "master")]
90-
{
91-
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
92-
tcx.sess.default_visibility(),
93-
)));
94-
95-
// FIXME(antoyo): cg_llvm sets AlwaysInline, but AlwaysInline is different in GCC and using
96-
// it here will causes linking errors when using LTO.
97-
func.add_attribute(FnAttribute::Inline);
98-
}
99-
100-
if tcx.sess.must_emit_unwind_tables() {
101-
// TODO(antoyo): emit unwind tables.
102-
}
103-
104-
let block = func.new_block("entry");
105-
block.end_with_return(None, value);
106-
}
107-
10871
fn create_wrapper_function(
10972
tcx: TyCtxt<'_>,
11073
context: &Context<'_>,

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,11 @@ impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
500500
}
501501

502502
fn set_rvalue_location<'a, 'gcc, 'tcx>(
503-
bx: &mut Builder<'a, 'gcc, 'tcx>,
503+
_bx: &mut Builder<'a, 'gcc, 'tcx>,
504504
rvalue: RValue<'gcc>,
505505
) -> RValue<'gcc> {
506-
if let Some(location) = bx.location {
507-
#[cfg(feature = "master")]
506+
#[cfg(feature = "master")]
507+
if let Some(location) = _bx.location {
508508
rvalue.set_location(location);
509509
}
510510
rvalue

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use rustc_codegen_ssa::traits::BaseTypeCodegenMethods as _;
77
use rustc_middle::bug;
88
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
99
use rustc_middle::ty::TyCtxt;
10-
use rustc_session::config::{DebugInfo, OomStrategy};
10+
use rustc_session::config::DebugInfo;
1111
use rustc_symbol_mangling::mangle_internal_symbol;
1212

1313
use crate::attributes::llfn_attrs_from_instance;
1414
use crate::builder::SBuilder;
1515
use crate::declare::declare_simple_fn;
16-
use crate::llvm::{self, FALSE, FromGeneric, TRUE, Type, Value};
16+
use crate::llvm::{self, FromGeneric, TRUE, Type};
1717
use crate::{SimpleCx, attributes, debuginfo};
1818

1919
pub(crate) unsafe fn codegen(
@@ -28,7 +28,6 @@ pub(crate) unsafe fn codegen(
2828
64 => cx.type_i64(),
2929
tws => bug!("Unsupported target word size for int: {}", tws),
3030
};
31-
let i8 = cx.type_i8();
3231
let i8p = cx.type_ptr();
3332

3433
for method in methods {
@@ -87,17 +86,6 @@ pub(crate) unsafe fn codegen(
8786
);
8887
}
8988

90-
// __rust_alloc_error_handler_should_panic_v2
91-
create_const_value_function(
92-
tcx,
93-
&cx,
94-
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
95-
&i8,
96-
unsafe {
97-
llvm::LLVMConstInt(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as u64, FALSE)
98-
},
99-
);
100-
10189
// __rust_no_alloc_shim_is_unstable_v2
10290
create_wrapper_function(
10391
tcx,
@@ -117,34 +105,6 @@ pub(crate) unsafe fn codegen(
117105
}
118106
}
119107

120-
fn create_const_value_function(
121-
tcx: TyCtxt<'_>,
122-
cx: &SimpleCx<'_>,
123-
name: &str,
124-
output: &Type,
125-
value: &Value,
126-
) {
127-
let ty = cx.type_func(&[], output);
128-
let llfn = declare_simple_fn(
129-
&cx,
130-
name,
131-
llvm::CallConv::CCallConv,
132-
llvm::UnnamedAddr::Global,
133-
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
134-
ty,
135-
);
136-
137-
attributes::apply_to_llfn(
138-
llfn,
139-
llvm::AttributePlace::Function,
140-
&[llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx)],
141-
);
142-
143-
let llbb = unsafe { llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, c"entry".as_ptr()) };
144-
let mut bx = SBuilder::build(&cx, llbb);
145-
bx.ret(value);
146-
}
147-
148108
fn create_wrapper_function(
149109
tcx: TyCtxt<'_>,
150110
cx: &SimpleCx<'_>,

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::middle::exported_symbols::{
1515
use rustc_middle::query::LocalCrate;
1616
use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolName, Ty, TyCtxt};
1717
use rustc_middle::util::Providers;
18-
use rustc_session::config::{CrateType, OomStrategy};
18+
use rustc_session::config::CrateType;
1919
use rustc_symbol_mangling::mangle_internal_symbol;
2020
use rustc_target::spec::{Arch, Os, TlsModel};
2121
use tracing::debug;
@@ -493,7 +493,6 @@ pub(crate) fn allocator_shim_symbols(
493493
.map(move |method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
494494
.chain([
495495
mangle_internal_symbol(tcx, global_fn_name(ALLOC_ERROR_HANDLER).as_str()),
496-
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
497496
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
498497
])
499498
.map(move |symbol_name| {

compiler/rustc_errors/src/emitter.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,12 @@ pub trait Emitter {
474474
.chain(span.span_labels().iter().map(|sp_label| sp_label.span))
475475
.filter_map(|sp| {
476476
if !sp.is_dummy() && source_map.is_imported(sp) {
477-
let maybe_callsite = sp.source_callsite();
478-
if sp != maybe_callsite {
479-
return Some((sp, maybe_callsite));
477+
let mut span = sp;
478+
while let Some(callsite) = span.parent_callsite() {
479+
span = callsite;
480+
if !source_map.is_imported(span) {
481+
return Some((sp, span));
482+
}
480483
}
481484
}
482485
None

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ struct BoundVarContext<'a, 'tcx> {
6666
rbv: &'a mut ResolveBoundVars,
6767
disambiguator: &'a mut DisambiguatorState,
6868
scope: ScopeRef<'a>,
69+
opaque_capture_errors: RefCell<Option<OpaqueHigherRankedLifetimeCaptureErrors>>,
70+
}
71+
72+
struct OpaqueHigherRankedLifetimeCaptureErrors {
73+
bad_place: &'static str,
74+
capture_spans: Vec<Span>,
75+
decl_spans: Vec<Span>,
6976
}
7077

7178
#[derive(Debug)]
@@ -253,6 +260,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
253260
rbv: &mut rbv,
254261
scope: &Scope::Root { opt_parent_item: None },
255262
disambiguator: &mut DisambiguatorState::new(),
263+
opaque_capture_errors: RefCell::new(None),
256264
};
257265
match tcx.hir_owner_node(local_def_id) {
258266
hir::OwnerNode::Item(item) => visitor.visit_item(item),
@@ -597,6 +605,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
597605
})
598606
});
599607

608+
self.emit_opaque_capture_errors();
609+
600610
let captures = captures.into_inner().into_iter().collect();
601611
debug!(?captures);
602612
self.rbv.opaque_captured_lifetimes.insert(opaque.def_id, captures);
@@ -1089,12 +1099,20 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
10891099
F: for<'b> FnOnce(&mut BoundVarContext<'b, 'tcx>),
10901100
{
10911101
let BoundVarContext { tcx, rbv, disambiguator, .. } = self;
1092-
let mut this = BoundVarContext { tcx: *tcx, rbv, disambiguator, scope: &wrap_scope };
1102+
let nested_errors = RefCell::new(self.opaque_capture_errors.borrow_mut().take());
1103+
let mut this = BoundVarContext {
1104+
tcx: *tcx,
1105+
rbv,
1106+
disambiguator,
1107+
scope: &wrap_scope,
1108+
opaque_capture_errors: nested_errors,
1109+
};
10931110
let span = debug_span!("scope", scope = ?this.scope.debug_truncated());
10941111
{
10951112
let _enter = span.enter();
10961113
f(&mut this);
10971114
}
1115+
*self.opaque_capture_errors.borrow_mut() = this.opaque_capture_errors.into_inner();
10981116
}
10991117

11001118
fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind>) {
@@ -1424,21 +1442,52 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
14241442
};
14251443

14261444
let decl_span = self.tcx.def_span(lifetime_def_id);
1427-
let (span, label) = if capture_span != decl_span {
1428-
(capture_span, None)
1429-
} else {
1430-
let opaque_span = self.tcx.def_span(opaque_def_id);
1431-
(opaque_span, Some(opaque_span))
1432-
};
1445+
let opaque_span = self.tcx.def_span(opaque_def_id);
1446+
1447+
let mut errors = self.opaque_capture_errors.borrow_mut();
1448+
let error_info = errors.get_or_insert_with(|| OpaqueHigherRankedLifetimeCaptureErrors {
1449+
bad_place,
1450+
capture_spans: Vec::new(),
1451+
decl_spans: Vec::new(),
1452+
});
1453+
1454+
if error_info.capture_spans.is_empty() {
1455+
error_info.capture_spans.push(opaque_span);
1456+
}
1457+
1458+
if capture_span != decl_span && capture_span != opaque_span {
1459+
error_info.capture_spans.push(capture_span);
1460+
}
1461+
1462+
if !error_info.decl_spans.contains(&decl_span) {
1463+
error_info.decl_spans.push(decl_span);
1464+
}
1465+
1466+
// Errors should be emitted by `emit_opaque_capture_errors`.
1467+
Err(self.tcx.dcx().span_delayed_bug(capture_span, "opaque capture error not emitted"))
1468+
}
1469+
1470+
fn emit_opaque_capture_errors(&self) -> Option<ErrorGuaranteed> {
1471+
let errors = self.opaque_capture_errors.borrow_mut().take()?;
1472+
if errors.capture_spans.is_empty() {
1473+
return None;
1474+
}
1475+
1476+
let mut span = rustc_errors::MultiSpan::from_span(errors.capture_spans[0]);
1477+
for &capture_span in &errors.capture_spans[1..] {
1478+
span.push_span_label(capture_span, "");
1479+
}
1480+
let decl_span = rustc_errors::MultiSpan::from_spans(errors.decl_spans);
14331481

14341482
// Ensure that the parent of the def is an item, not HRTB
14351483
let guar = self.tcx.dcx().emit_err(errors::OpaqueCapturesHigherRankedLifetime {
14361484
span,
1437-
label,
1485+
label: Some(errors.capture_spans[0]),
14381486
decl_span,
1439-
bad_place,
1487+
bad_place: errors.bad_place,
14401488
});
1441-
Err(guar)
1489+
1490+
Some(guar)
14421491
}
14431492

14441493
#[instrument(level = "trace", skip(self, opaque_capture_scopes), ret)]

0 commit comments

Comments
 (0)