Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e4194c7
Deduplicate higher-ranked lifetime capture errors in impl Trait
JohnTitor Oct 12, 2025
8f55c15
Remove -Zoom=panic
bjorn3 Oct 15, 2025
109b1cf
Add test for incorrect macro span replacement
estebank Nov 8, 2025
4c6544b
Run clippy both with and without default features on the GCC backend
GuillaumeGomez Dec 9, 2025
4501327
Fix clippy lint in `cg_gcc`
GuillaumeGomez Dec 9, 2025
7339e67
Point at span within local macros even when error happens in nested e…
estebank Nov 8, 2025
20fabb4
Use return type `Span` on async fns instead of whole fn def `Span`
estebank Nov 4, 2025
76f02cf
Add test for `dyn Trait` in `async fn` return type
estebank Nov 4, 2025
7868d20
Account for `async fn` with `dyn Trait` return type in `impl Trait` s…
estebank Nov 4, 2025
fabf574
Add test for `type Alias = dyn Trait` in return type
estebank Nov 4, 2025
60b227a
Recognize `type Alias = dyn Trait` in `fn` return types
estebank Nov 4, 2025
e2168b1
Point at async fn return type instead of body in E0746
estebank Nov 5, 2025
8c63852
Provide boxing suggestion for `type Alias = dyn Trait` return type
estebank Nov 5, 2025
f7eaaf7
Account for async fn in traits and impls
estebank Nov 5, 2025
06500aa
Add message when running clippy with `--no-default-features` for cg_gcc
GuillaumeGomez Dec 9, 2025
6cd44a4
Make typo in field and name suggestions verbose
estebank Dec 9, 2025
17ae3c6
Rollup merge of #147602 - JohnTitor:dedup-lifetime-capture-errors, r=…
matthiaskrgr Dec 9, 2025
3705a80
Rollup merge of #147725 - bjorn3:remove_oom_panic, r=Amanieu
matthiaskrgr Dec 9, 2025
0e5144e
Rollup merge of #148491 - estebank:issue-147894, r=jackh726
matthiaskrgr Dec 9, 2025
4fbb8cc
Rollup merge of #148717 - estebank:macro-spans-2, r=petrochenkov
matthiaskrgr Dec 9, 2025
511a53d
Rollup merge of #149458 - GuillaumeGomez:clippy-cg_gcc, r=kobzol
matthiaskrgr Dec 9, 2025
d1087ac
Rollup merge of #149816 - estebank:verbose-typo-suggestion, r=Jonatha…
matthiaskrgr Dec 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let output = match coro {
Some(coro) => {
let fn_def_id = self.local_def_id(fn_node_id);
self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind, fn_span)
self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
}
None => match &decl.output {
FnRetTy::Ty(ty) => {
Expand Down Expand Up @@ -1755,9 +1755,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn_def_id: LocalDefId,
coro: CoroutineKind,
fn_kind: FnDeclKind,
fn_span: Span,
) -> hir::FnRetTy<'hir> {
let span = self.lower_span(fn_span);
let span = self.lower_span(output.span());

let (opaque_ty_node_id, allowed_features) = match coro {
CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),
Expand Down
39 changes: 2 additions & 37 deletions compiler/rustc_codegen_cranelift/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_ast::expand::allocator::{
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
};
use rustc_codegen_ssa::base::{allocator_kind_for_codegen, allocator_shim_contents};
use rustc_session::config::OomStrategy;
use rustc_symbol_mangling::mangle_internal_symbol;

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

fn codegen_inner(
tcx: TyCtxt<'_>,
module: &mut dyn Module,
methods: &[AllocatorMethod],
oom_strategy: OomStrategy,
) {
fn codegen_inner(tcx: TyCtxt<'_>, module: &mut dyn Module, methods: &[AllocatorMethod]) {
let usize_ty = module.target_config().pointer_type();

for method in methods {
Expand Down Expand Up @@ -65,35 +59,6 @@ fn codegen_inner(
);
}

{
let sig = Signature {
call_conv: module.target_config().default_call_conv,
params: vec![],
returns: vec![AbiParam::new(types::I8)],
};
let func_id = module
.declare_function(
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
Linkage::Export,
&sig,
)
.unwrap();
let mut ctx = Context::new();
ctx.func.signature = sig;
{
let mut func_ctx = FunctionBuilderContext::new();
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);

let block = bcx.create_block();
bcx.switch_to_block(block);
let value = bcx.ins().iconst(types::I8, oom_strategy.should_panic() as i64);
bcx.ins().return_(&[value]);
bcx.seal_all_blocks();
bcx.finalize();
}
module.define_function(func_id, &mut ctx).unwrap();
}

{
let sig = Signature {
call_conv: module.target_config().default_call_conv,
Expand Down
39 changes: 1 addition & 38 deletions compiler/rustc_codegen_gcc/src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#[cfg(feature = "master")]
use gccjit::FnAttribute;
use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
use gccjit::{Context, FunctionType, ToRValue, Type};
use rustc_ast::expand::allocator::{
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
};
use rustc_middle::bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::config::OomStrategy;
use rustc_symbol_mangling::mangle_internal_symbol;

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

create_const_value_function(
tcx,
context,
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
i8,
context.new_rvalue_from_int(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as i32),
);

create_wrapper_function(
tcx,
context,
Expand All @@ -77,34 +68,6 @@ pub(crate) unsafe fn codegen(
);
}

fn create_const_value_function(
tcx: TyCtxt<'_>,
context: &Context<'_>,
name: &str,
output: Type<'_>,
value: RValue<'_>,
) {
let func = context.new_function(None, FunctionType::Exported, output, &[], name, false);

#[cfg(feature = "master")]
{
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
tcx.sess.default_visibility(),
)));

// FIXME(antoyo): cg_llvm sets AlwaysInline, but AlwaysInline is different in GCC and using
// it here will causes linking errors when using LTO.
func.add_attribute(FnAttribute::Inline);
}

if tcx.sess.must_emit_unwind_tables() {
// TODO(antoyo): emit unwind tables.
}

let block = func.new_block("entry");
block.end_with_return(None, value);
}

fn create_wrapper_function(
tcx: TyCtxt<'_>,
context: &Context<'_>,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,11 @@ impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
}

fn set_rvalue_location<'a, 'gcc, 'tcx>(
bx: &mut Builder<'a, 'gcc, 'tcx>,
_bx: &mut Builder<'a, 'gcc, 'tcx>,
rvalue: RValue<'gcc>,
) -> RValue<'gcc> {
if let Some(location) = bx.location {
#[cfg(feature = "master")]
#[cfg(feature = "master")]
if let Some(location) = _bx.location {
rvalue.set_location(location);
}
rvalue
Expand Down
44 changes: 2 additions & 42 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use rustc_codegen_ssa::traits::BaseTypeCodegenMethods as _;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{DebugInfo, OomStrategy};
use rustc_session::config::DebugInfo;
use rustc_symbol_mangling::mangle_internal_symbol;

use crate::attributes::llfn_attrs_from_instance;
use crate::builder::SBuilder;
use crate::declare::declare_simple_fn;
use crate::llvm::{self, FALSE, FromGeneric, TRUE, Type, Value};
use crate::llvm::{self, FromGeneric, TRUE, Type};
use crate::{SimpleCx, attributes, debuginfo};

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

for method in methods {
Expand Down Expand Up @@ -87,17 +86,6 @@ pub(crate) unsafe fn codegen(
);
}

// __rust_alloc_error_handler_should_panic_v2
create_const_value_function(
tcx,
&cx,
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
&i8,
unsafe {
llvm::LLVMConstInt(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as u64, FALSE)
},
);

// __rust_no_alloc_shim_is_unstable_v2
create_wrapper_function(
tcx,
Expand All @@ -117,34 +105,6 @@ pub(crate) unsafe fn codegen(
}
}

fn create_const_value_function(
tcx: TyCtxt<'_>,
cx: &SimpleCx<'_>,
name: &str,
output: &Type,
value: &Value,
) {
let ty = cx.type_func(&[], output);
let llfn = declare_simple_fn(
&cx,
name,
llvm::CallConv::CCallConv,
llvm::UnnamedAddr::Global,
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
ty,
);

attributes::apply_to_llfn(
llfn,
llvm::AttributePlace::Function,
&[llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx)],
);

let llbb = unsafe { llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, c"entry".as_ptr()) };
let mut bx = SBuilder::build(&cx, llbb);
bx.ret(value);
}

fn create_wrapper_function(
tcx: TyCtxt<'_>,
cx: &SimpleCx<'_>,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::middle::exported_symbols::{
use rustc_middle::query::LocalCrate;
use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, Instance, SymbolName, Ty, TyCtxt};
use rustc_middle::util::Providers;
use rustc_session::config::{CrateType, OomStrategy};
use rustc_session::config::CrateType;
use rustc_symbol_mangling::mangle_internal_symbol;
use rustc_target::spec::{Arch, Os, TlsModel};
use tracing::debug;
Expand Down Expand Up @@ -493,7 +493,6 @@ pub(crate) fn allocator_shim_symbols(
.map(move |method| mangle_internal_symbol(tcx, global_fn_name(method.name).as_str()))
.chain([
mangle_internal_symbol(tcx, global_fn_name(ALLOC_ERROR_HANDLER).as_str()),
mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
mangle_internal_symbol(tcx, NO_ALLOC_SHIM_IS_UNSTABLE),
])
.map(move |symbol_name| {
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,12 @@ pub trait Emitter {
.chain(span.span_labels().iter().map(|sp_label| sp_label.span))
.filter_map(|sp| {
if !sp.is_dummy() && source_map.is_imported(sp) {
let maybe_callsite = sp.source_callsite();
if sp != maybe_callsite {
return Some((sp, maybe_callsite));
let mut span = sp;
while let Some(callsite) = span.parent_callsite() {
span = callsite;
if !source_map.is_imported(span) {
return Some((sp, span));
}
}
}
None
Expand Down
69 changes: 59 additions & 10 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ struct BoundVarContext<'a, 'tcx> {
rbv: &'a mut ResolveBoundVars,
disambiguator: &'a mut DisambiguatorState,
scope: ScopeRef<'a>,
opaque_capture_errors: RefCell<Option<OpaqueHigherRankedLifetimeCaptureErrors>>,
}

struct OpaqueHigherRankedLifetimeCaptureErrors {
bad_place: &'static str,
capture_spans: Vec<Span>,
decl_spans: Vec<Span>,
}

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

self.emit_opaque_capture_errors();

let captures = captures.into_inner().into_iter().collect();
debug!(?captures);
self.rbv.opaque_captured_lifetimes.insert(opaque.def_id, captures);
Expand Down Expand Up @@ -1089,12 +1099,20 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
F: for<'b> FnOnce(&mut BoundVarContext<'b, 'tcx>),
{
let BoundVarContext { tcx, rbv, disambiguator, .. } = self;
let mut this = BoundVarContext { tcx: *tcx, rbv, disambiguator, scope: &wrap_scope };
let nested_errors = RefCell::new(self.opaque_capture_errors.borrow_mut().take());
let mut this = BoundVarContext {
tcx: *tcx,
rbv,
disambiguator,
scope: &wrap_scope,
opaque_capture_errors: nested_errors,
};
let span = debug_span!("scope", scope = ?this.scope.debug_truncated());
{
let _enter = span.enter();
f(&mut this);
}
*self.opaque_capture_errors.borrow_mut() = this.opaque_capture_errors.into_inner();
}

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

let decl_span = self.tcx.def_span(lifetime_def_id);
let (span, label) = if capture_span != decl_span {
(capture_span, None)
} else {
let opaque_span = self.tcx.def_span(opaque_def_id);
(opaque_span, Some(opaque_span))
};
let opaque_span = self.tcx.def_span(opaque_def_id);

let mut errors = self.opaque_capture_errors.borrow_mut();
let error_info = errors.get_or_insert_with(|| OpaqueHigherRankedLifetimeCaptureErrors {
bad_place,
capture_spans: Vec::new(),
decl_spans: Vec::new(),
});

if error_info.capture_spans.is_empty() {
error_info.capture_spans.push(opaque_span);
}

if capture_span != decl_span && capture_span != opaque_span {
error_info.capture_spans.push(capture_span);
}

if !error_info.decl_spans.contains(&decl_span) {
error_info.decl_spans.push(decl_span);
}

// Errors should be emitted by `emit_opaque_capture_errors`.
Err(self.tcx.dcx().span_delayed_bug(capture_span, "opaque capture error not emitted"))
}

fn emit_opaque_capture_errors(&self) -> Option<ErrorGuaranteed> {
let errors = self.opaque_capture_errors.borrow_mut().take()?;
if errors.capture_spans.is_empty() {
return None;
}

let mut span = rustc_errors::MultiSpan::from_span(errors.capture_spans[0]);
for &capture_span in &errors.capture_spans[1..] {
span.push_span_label(capture_span, "");
}
let decl_span = rustc_errors::MultiSpan::from_spans(errors.decl_spans);

// Ensure that the parent of the def is an item, not HRTB
let guar = self.tcx.dcx().emit_err(errors::OpaqueCapturesHigherRankedLifetime {
span,
label,
label: Some(errors.capture_spans[0]),
decl_span,
bad_place,
bad_place: errors.bad_place,
});
Err(guar)

Some(guar)
}

#[instrument(level = "trace", skip(self, opaque_capture_scopes), ret)]
Expand Down
Loading
Loading