Skip to content

Rollup of 8 pull requests #137848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b41c232
tests: fix up new test for nocapture -> capture(none) change
durin42 Feb 21, 2025
b3330f8
Remove `ParamEnv::without_caller_bounds`
BoxyUwU Feb 26, 2025
4747bb6
Add missing case explanation for doc inlined re-export of doc hidden …
GuillaumeGomez Feb 27, 2025
371c073
Use mk_ty_from_kind a bit less, clean up lifetime handling in borrowck
compiler-errors Feb 28, 2025
5bf2237
Do not yeet unsafe<> from type
compiler-errors Feb 28, 2025
5f58985
Remove `rustc_transmute`'s dependence on `rustc_infer`.
nnethercote Feb 28, 2025
43e017f
Remove `rustc_transmute`'s dependence on `rustc_macros`.
nnethercote Feb 28, 2025
1970311
Remove unnecessary `allow(unused)` attribute.
nnethercote Feb 28, 2025
dfb2222
Remove unused feature from `rustc_transmute`.
nnethercote Feb 28, 2025
785e21d
Remove `allow(unused_variables)` for `rustc_transmute`.
nnethercote Feb 28, 2025
b0530c9
Remove `allow(dead_code)` attributes.
nnethercote Feb 28, 2025
7d4d09e
Shorten span of panic failures in const context
estebank Feb 3, 2025
df5b279
Introduce `feature(generic_const_parameter_types)`
BoxyUwU Feb 25, 2025
f012947
Rollup merge of #136503 - estebank:const-panic, r=RalfJung
matthiaskrgr Mar 1, 2025
11ddd56
Rollup merge of #137390 - durin42:llvm-21-nocapture-rename, r=nikic
matthiaskrgr Mar 1, 2025
415b207
Rollup merge of #137617 - BoxyUwU:generic_const_parameter_types, r=lcnr
matthiaskrgr Mar 1, 2025
db12f00
Rollup merge of #137719 - GuillaumeGomez:missing-doc, r=notriddle
matthiaskrgr Mar 1, 2025
1d9992d
Rollup merge of #137763 - compiler-errors:ty-nits, r=BoxyUwU
matthiaskrgr Mar 1, 2025
b7853ef
Rollup merge of #137769 - compiler-errors:empty-unsafe-fmt, r=ytmimi
matthiaskrgr Mar 1, 2025
b6c1b63
Rollup merge of #137776 - nnethercote:rustc_transmute-cleanups, r=jsw…
matthiaskrgr Mar 1, 2025
c03756a
Rollup merge of #137800 - BoxyUwU:param_env_docs, r=compiler-errors
matthiaskrgr Mar 1, 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
2 changes: 0 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4501,8 +4501,6 @@ dependencies = [
"rustc_abi",
"rustc_data_structures",
"rustc_hir",
"rustc_infer",
"rustc_macros",
"rustc_middle",
"rustc_span",
"tracing",
Expand Down
44 changes: 13 additions & 31 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use rustc_mir_dataflow::move_paths::MoveData;
use rustc_mir_dataflow::points::DenseLocationMap;
use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::source_map::Spanned;
use rustc_span::{DUMMY_SP, Span, sym};
use rustc_span::{Span, sym};
use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
use tracing::{debug, instrument, trace};
Expand All @@ -51,7 +51,6 @@ use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable};
use crate::polonius::{PoloniusContext, PoloniusLivenessContext};
use crate::region_infer::TypeTest;
use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices};
use crate::renumber::RegionCtxt;
use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
use crate::universal_regions::{DefiningTy, UniversalRegions};
Expand Down Expand Up @@ -2121,35 +2120,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
//
// Note that other checks (such as denying `dyn Send` -> `dyn
// Debug`) are in `rustc_hir_typeck`.
if let ty::Dynamic(src_tty, ..) = src_tail.kind()
&& let ty::Dynamic(dst_tty, ..) = dst_tail.kind()
if let ty::Dynamic(src_tty, _src_lt, _) = *src_tail.kind()
&& let ty::Dynamic(dst_tty, dst_lt, _) = *dst_tail.kind()
&& src_tty.principal().is_some()
&& dst_tty.principal().is_some()
{
// Remove auto traits.
// Auto trait checks are handled in `rustc_hir_typeck` as FCW.
let src_obj = tcx.mk_ty_from_kind(ty::Dynamic(
let src_obj = Ty::new_dynamic(
tcx,
tcx.mk_poly_existential_predicates(
&src_tty.without_auto_traits().collect::<Vec<_>>(),
),
tcx.lifetimes.re_static,
// FIXME: Once we disallow casting `*const dyn Trait + 'short`
// to `*const dyn Trait + 'long`, then this can just be `src_lt`.
dst_lt,
ty::Dyn,
));
let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic(
);
let dst_obj = Ty::new_dynamic(
tcx,
tcx.mk_poly_existential_predicates(
&dst_tty.without_auto_traits().collect::<Vec<_>>(),
),
tcx.lifetimes.re_static,
dst_lt,
ty::Dyn,
));

// Replace trait object lifetimes with fresh vars, to allow
// casts like
// `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static`
let src_obj =
freshen_single_trait_object_lifetime(self.infcx, src_obj);
let dst_obj =
freshen_single_trait_object_lifetime(self.infcx, dst_obj);
);

debug!(?src_tty, ?dst_tty, ?src_obj, ?dst_obj);

Expand Down Expand Up @@ -2707,16 +2702,3 @@ impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
Ok(output)
}
}

fn freshen_single_trait_object_lifetime<'tcx>(
infcx: &BorrowckInferCtxt<'tcx>,
ty: Ty<'tcx>,
) -> Ty<'tcx> {
let &ty::Dynamic(tty, _, dyn_kind @ ty::Dyn) = ty.kind() else { bug!("expected trait object") };

let fresh = infcx
.next_region_var(rustc_infer::infer::RegionVariableOrigin::MiscVariable(DUMMY_SP), || {
RegionCtxt::Unknown
});
infcx.tcx.mk_ty_from_kind(ty::Dynamic(tty, fresh, dyn_kind))
}
5 changes: 3 additions & 2 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const_eval_frame_note_inner = inside {$where_ ->
*[other] {""}
}

const_eval_frame_note_last = the failure occurred here

const_eval_in_bounds_test = out-of-bounds pointer use
const_eval_incompatible_calling_conventions =
calling a function with calling convention {$callee_conv} using calling convention {$caller_conv}
Expand Down Expand Up @@ -300,8 +302,7 @@ const_eval_overflow_arith =
const_eval_overflow_shift =
overflowing shift by {$shift_amount} in `{$intrinsic}`

const_eval_panic =
the evaluated program panicked at '{$msg}', {$file}:{$line}:{$col}
const_eval_panic = evaluation panicked: {$msg}

const_eval_panic_non_str = argument to `panic!()` in a const context must have type `&str`

Expand Down
21 changes: 16 additions & 5 deletions compiler/rustc_const_eval/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ impl MachineStopType for ConstEvalErrKind {
| ModifiedGlobal
| WriteThroughImmutablePointer => {}
AssertFailure(kind) => kind.add_args(adder),
Panic { msg, line, col, file } => {
Panic { msg, .. } => {
adder("msg".into(), msg.into_diag_arg(&mut None));
adder("file".into(), file.into_diag_arg(&mut None));
adder("line".into(), line.into_diag_arg(&mut None));
adder("col".into(), col.into_diag_arg(&mut None));
}
}
}
Expand All @@ -72,7 +69,7 @@ pub fn get_span_and_frames<'tcx>(
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack);
// Filter out `requires_caller_location` frames.
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
let span = stacktrace.first().map(|f| f.span).unwrap_or(tcx.span);
let span = stacktrace.last().map(|f| f.span).unwrap_or(tcx.span);

let mut frames = Vec::new();

Expand Down Expand Up @@ -115,6 +112,20 @@ pub fn get_span_and_frames<'tcx>(
}
}

// In `rustc`, we present const-eval errors from the outer-most place first to the inner-most.
// So we reverse the frames here. The first frame will be the same as the span from the current
// `TyCtxtAt<'_>`, so we remove it as it would be redundant.
frames.reverse();
if frames.len() > 0 {
frames.remove(0);
}
if let Some(last) = frames.last_mut()
// If the span is not going to be printed, we don't want the span label for `is_last`.
&& tcx.sess.source_map().span_to_snippet(last.span.source_callsite()).is_ok()
{
last.has_label = true;
}

(span, frames)
}

Expand Down
25 changes: 22 additions & 3 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_abi::WrappingRange;
use rustc_errors::codes::*;
use rustc_errors::{
Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, Diagnostic, EmissionGuarantee, Level,
MultiSpan, SubdiagMessageOp, Subdiagnostic,
};
use rustc_hir::ConstContext;
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
Expand All @@ -17,6 +18,7 @@ use rustc_middle::mir::interpret::{
use rustc_middle::ty::{self, Mutability, Ty};
use rustc_span::{Span, Symbol};

use crate::fluent_generated as fluent;
use crate::interpret::InternKind;

#[derive(Diagnostic)]
Expand Down Expand Up @@ -278,14 +280,31 @@ pub(crate) struct NonConstImplNote {
pub span: Span,
}

#[derive(Subdiagnostic, Clone)]
#[note(const_eval_frame_note)]
#[derive(Clone)]
pub struct FrameNote {
#[primary_span]
pub span: Span,
pub times: i32,
pub where_: &'static str,
pub instance: String,
pub has_label: bool,
}

impl Subdiagnostic for FrameNote {
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self,
diag: &mut Diag<'_, G>,
f: &F,
) {
diag.arg("times", self.times);
diag.arg("where_", self.where_);
diag.arg("instance", self.instance);
let mut span: MultiSpan = self.span.into();
if self.has_label && !self.span.is_dummy() {
span.push_span_label(self.span, fluent::const_eval_frame_note_last);
}
let msg = f(diag, fluent::const_eval_frame_note.into());
diag.span_note(span, msg);
}
}

#[derive(Subdiagnostic)]
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_const_eval/src/interpret/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,19 @@ impl<'tcx> FrameInfo<'tcx> {
pub fn as_note(&self, tcx: TyCtxt<'tcx>) -> errors::FrameNote {
let span = self.span;
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
errors::FrameNote { where_: "closure", span, instance: String::new(), times: 0 }
errors::FrameNote {
where_: "closure",
span,
instance: String::new(),
times: 0,
has_label: false,
}
} else {
let instance = format!("{}", self.instance);
// Note: this triggers a `must_produce_diag` state, which means that if we ever get
// here we must emit a diagnostic. We should never display a `FrameInfo` unless we
// actually want to emit a warning or error to the user.
errors::FrameNote { where_: "instance", span, instance, times: 0 }
errors::FrameNote { where_: "instance", span, instance, times: 0, has_label: false }
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ declare_features! (
(incomplete, generic_const_exprs, "1.56.0", Some(76560)),
/// Allows generic parameters and where-clauses on free & associated const items.
(incomplete, generic_const_items, "1.73.0", Some(113521)),
/// Allows the type of const generics to depend on generic parameters
(incomplete, generic_const_parameter_types, "CURRENT_RUSTC_VERSION", Some(137626)),
/// Allows any generic constants being used as pattern type range ends
(incomplete, generic_pattern_types, "1.86.0", Some(136574)),
/// Allows registering static items globally, possibly across crates, to iterate over at runtime.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
let ty = tcx.type_of(param.def_id).instantiate_identity();

if tcx.features().unsized_const_params() {
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
enter_wf_checking_ctxt(tcx, hir_ty.span, tcx.local_parent(param.def_id), |wfcx| {
wfcx.register_bound(
ObligationCause::new(
hir_ty.span,
Expand All @@ -980,7 +980,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
Ok(())
})
} else if tcx.features().adt_const_params() {
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
enter_wf_checking_ctxt(tcx, hir_ty.span, tcx.local_parent(param.def_id), |wfcx| {
wfcx.register_bound(
ObligationCause::new(
hir_ty.span,
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,9 @@ fn const_param_default<'tcx>(
),
};
let icx = ItemCtxt::new(tcx, def_id);
let ct = icx.lowerer().lower_const_arg(default_ct, FeedConstTy::Param(def_id.to_def_id()));
let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
let ct = icx
.lowerer()
.lower_const_arg(default_ct, FeedConstTy::Param(def_id.to_def_id(), identity_args));
ty::EarlyBinder::bind(ct)
}
5 changes: 1 addition & 4 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
}
hir::GenericParamKind::Const { .. } => {
let param_def_id = param.def_id.to_def_id();
let ct_ty = tcx
.type_of(param_def_id)
.no_bound_vars()
.expect("const parameters cannot be generic");
let ct_ty = tcx.type_of(param_def_id).instantiate_identity();
let ct = icx.lowerer().lower_const_param(param_def_id, param.hir_id);
predicates
.insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(

// We lower to an infer even when the feature gate is not enabled
// as it is useful for diagnostics to be able to see a `ConstKind::Infer`
args.push(ctx.provided_kind(param, arg));
args.push(ctx.provided_kind(&args, param, arg));
args_iter.next();
params.next();
}
Expand Down
Loading
Loading