Skip to content

Commit 8c39296

Browse files
committed
Auto merge of rust-lang#137848 - matthiaskrgr:rollup-vxtrkis, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#136503 (Tweak output of const panic diagnostic) - rust-lang#137390 (tests: fix up new test for nocapture -> capture(none) change) - rust-lang#137617 (Introduce `feature(generic_const_parameter_types)`) - rust-lang#137719 (Add missing case explanation for doc inlined re-export of doc hidden item) - rust-lang#137763 (Use `mk_ty_from_kind` a bit less, clean up lifetime handling in borrowck) - rust-lang#137769 (Do not yeet `unsafe<>` from type when formatting unsafe binder) - rust-lang#137776 (Some `rustc_transmute` cleanups) - rust-lang#137800 (Remove `ParamEnv::without_caller_bounds`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0c72c0d + c03756a commit 8c39296

File tree

206 files changed

+996
-1002
lines changed

Some content is hidden

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

206 files changed

+996
-1002
lines changed

Cargo.lock

-2
Original file line numberDiff line numberDiff line change
@@ -4501,8 +4501,6 @@ dependencies = [
45014501
"rustc_abi",
45024502
"rustc_data_structures",
45034503
"rustc_hir",
4504-
"rustc_infer",
4505-
"rustc_macros",
45064504
"rustc_middle",
45074505
"rustc_span",
45084506
"tracing",

compiler/rustc_borrowck/src/type_check/mod.rs

+13-31
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rustc_mir_dataflow::move_paths::MoveData;
3838
use rustc_mir_dataflow::points::DenseLocationMap;
3939
use rustc_span::def_id::CRATE_DEF_ID;
4040
use rustc_span::source_map::Spanned;
41-
use rustc_span::{DUMMY_SP, Span, sym};
41+
use rustc_span::{Span, sym};
4242
use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
4343
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
4444
use tracing::{debug, instrument, trace};
@@ -51,7 +51,6 @@ use crate::polonius::legacy::{PoloniusFacts, PoloniusLocationTable};
5151
use crate::polonius::{PoloniusContext, PoloniusLivenessContext};
5252
use crate::region_infer::TypeTest;
5353
use crate::region_infer::values::{LivenessValues, PlaceholderIndex, PlaceholderIndices};
54-
use crate::renumber::RegionCtxt;
5554
use crate::session_diagnostics::{MoveUnsized, SimdIntrinsicArgConst};
5655
use crate::type_check::free_region_relations::{CreateResult, UniversalRegionRelations};
5756
use crate::universal_regions::{DefiningTy, UniversalRegions};
@@ -2121,35 +2120,31 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21212120
//
21222121
// Note that other checks (such as denying `dyn Send` -> `dyn
21232122
// Debug`) are in `rustc_hir_typeck`.
2124-
if let ty::Dynamic(src_tty, ..) = src_tail.kind()
2125-
&& let ty::Dynamic(dst_tty, ..) = dst_tail.kind()
2123+
if let ty::Dynamic(src_tty, _src_lt, _) = *src_tail.kind()
2124+
&& let ty::Dynamic(dst_tty, dst_lt, _) = *dst_tail.kind()
21262125
&& src_tty.principal().is_some()
21272126
&& dst_tty.principal().is_some()
21282127
{
21292128
// Remove auto traits.
21302129
// Auto trait checks are handled in `rustc_hir_typeck` as FCW.
2131-
let src_obj = tcx.mk_ty_from_kind(ty::Dynamic(
2130+
let src_obj = Ty::new_dynamic(
2131+
tcx,
21322132
tcx.mk_poly_existential_predicates(
21332133
&src_tty.without_auto_traits().collect::<Vec<_>>(),
21342134
),
2135-
tcx.lifetimes.re_static,
2135+
// FIXME: Once we disallow casting `*const dyn Trait + 'short`
2136+
// to `*const dyn Trait + 'long`, then this can just be `src_lt`.
2137+
dst_lt,
21362138
ty::Dyn,
2137-
));
2138-
let dst_obj = tcx.mk_ty_from_kind(ty::Dynamic(
2139+
);
2140+
let dst_obj = Ty::new_dynamic(
2141+
tcx,
21392142
tcx.mk_poly_existential_predicates(
21402143
&dst_tty.without_auto_traits().collect::<Vec<_>>(),
21412144
),
2142-
tcx.lifetimes.re_static,
2145+
dst_lt,
21432146
ty::Dyn,
2144-
));
2145-
2146-
// Replace trait object lifetimes with fresh vars, to allow
2147-
// casts like
2148-
// `*mut dyn FnOnce() + 'a` -> `*mut dyn FnOnce() + 'static`
2149-
let src_obj =
2150-
freshen_single_trait_object_lifetime(self.infcx, src_obj);
2151-
let dst_obj =
2152-
freshen_single_trait_object_lifetime(self.infcx, dst_obj);
2147+
);
21532148

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

@@ -2707,16 +2702,3 @@ impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {
27072702
Ok(output)
27082703
}
27092704
}
2710-
2711-
fn freshen_single_trait_object_lifetime<'tcx>(
2712-
infcx: &BorrowckInferCtxt<'tcx>,
2713-
ty: Ty<'tcx>,
2714-
) -> Ty<'tcx> {
2715-
let &ty::Dynamic(tty, _, dyn_kind @ ty::Dyn) = ty.kind() else { bug!("expected trait object") };
2716-
2717-
let fresh = infcx
2718-
.next_region_var(rustc_infer::infer::RegionVariableOrigin::MiscVariable(DUMMY_SP), || {
2719-
RegionCtxt::Unknown
2720-
});
2721-
infcx.tcx.mk_ty_from_kind(ty::Dynamic(tty, fresh, dyn_kind))
2722-
}

compiler/rustc_const_eval/messages.ftl

+3-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ const_eval_frame_note_inner = inside {$where_ ->
109109
*[other] {""}
110110
}
111111
112+
const_eval_frame_note_last = the failure occurred here
113+
112114
const_eval_in_bounds_test = out-of-bounds pointer use
113115
const_eval_incompatible_calling_conventions =
114116
calling a function with calling convention {$callee_conv} using calling convention {$caller_conv}
@@ -300,8 +302,7 @@ const_eval_overflow_arith =
300302
const_eval_overflow_shift =
301303
overflowing shift by {$shift_amount} in `{$intrinsic}`
302304
303-
const_eval_panic =
304-
the evaluated program panicked at '{$msg}', {$file}:{$line}:{$col}
305+
const_eval_panic = evaluation panicked: {$msg}
305306
306307
const_eval_panic_non_str = argument to `panic!()` in a const context must have type `&str`
307308

compiler/rustc_const_eval/src/const_eval/error.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ impl MachineStopType for ConstEvalErrKind {
4848
| ModifiedGlobal
4949
| WriteThroughImmutablePointer => {}
5050
AssertFailure(kind) => kind.add_args(adder),
51-
Panic { msg, line, col, file } => {
51+
Panic { msg, .. } => {
5252
adder("msg".into(), msg.into_diag_arg(&mut None));
53-
adder("file".into(), file.into_diag_arg(&mut None));
54-
adder("line".into(), line.into_diag_arg(&mut None));
55-
adder("col".into(), col.into_diag_arg(&mut None));
5653
}
5754
}
5855
}
@@ -72,7 +69,7 @@ pub fn get_span_and_frames<'tcx>(
7269
let mut stacktrace = Frame::generate_stacktrace_from_stack(stack);
7370
// Filter out `requires_caller_location` frames.
7471
stacktrace.retain(|frame| !frame.instance.def.requires_caller_location(*tcx));
75-
let span = stacktrace.first().map(|f| f.span).unwrap_or(tcx.span);
72+
let span = stacktrace.last().map(|f| f.span).unwrap_or(tcx.span);
7673

7774
let mut frames = Vec::new();
7875

@@ -115,6 +112,20 @@ pub fn get_span_and_frames<'tcx>(
115112
}
116113
}
117114

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

compiler/rustc_const_eval/src/errors.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_abi::WrappingRange;
66
use rustc_errors::codes::*;
77
use rustc_errors::{
88
Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, Diagnostic, EmissionGuarantee, Level,
9+
MultiSpan, SubdiagMessageOp, Subdiagnostic,
910
};
1011
use rustc_hir::ConstContext;
1112
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
@@ -17,6 +18,7 @@ use rustc_middle::mir::interpret::{
1718
use rustc_middle::ty::{self, Mutability, Ty};
1819
use rustc_span::{Span, Symbol};
1920

21+
use crate::fluent_generated as fluent;
2022
use crate::interpret::InternKind;
2123

2224
#[derive(Diagnostic)]
@@ -278,14 +280,31 @@ pub(crate) struct NonConstImplNote {
278280
pub span: Span,
279281
}
280282

281-
#[derive(Subdiagnostic, Clone)]
282-
#[note(const_eval_frame_note)]
283+
#[derive(Clone)]
283284
pub struct FrameNote {
284-
#[primary_span]
285285
pub span: Span,
286286
pub times: i32,
287287
pub where_: &'static str,
288288
pub instance: String,
289+
pub has_label: bool,
290+
}
291+
292+
impl Subdiagnostic for FrameNote {
293+
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
294+
self,
295+
diag: &mut Diag<'_, G>,
296+
f: &F,
297+
) {
298+
diag.arg("times", self.times);
299+
diag.arg("where_", self.where_);
300+
diag.arg("instance", self.instance);
301+
let mut span: MultiSpan = self.span.into();
302+
if self.has_label && !self.span.is_dummy() {
303+
span.push_span_label(self.span, fluent::const_eval_frame_note_last);
304+
}
305+
let msg = f(diag, fluent::const_eval_frame_note.into());
306+
diag.span_note(span, msg);
307+
}
289308
}
290309

291310
#[derive(Subdiagnostic)]

compiler/rustc_const_eval/src/interpret/stack.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,19 @@ impl<'tcx> FrameInfo<'tcx> {
231231
pub fn as_note(&self, tcx: TyCtxt<'tcx>) -> errors::FrameNote {
232232
let span = self.span;
233233
if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
234-
errors::FrameNote { where_: "closure", span, instance: String::new(), times: 0 }
234+
errors::FrameNote {
235+
where_: "closure",
236+
span,
237+
instance: String::new(),
238+
times: 0,
239+
has_label: false,
240+
}
235241
} else {
236242
let instance = format!("{}", self.instance);
237243
// Note: this triggers a `must_produce_diag` state, which means that if we ever get
238244
// here we must emit a diagnostic. We should never display a `FrameInfo` unless we
239245
// actually want to emit a warning or error to the user.
240-
errors::FrameNote { where_: "instance", span, instance, times: 0 }
246+
errors::FrameNote { where_: "instance", span, instance, times: 0, has_label: false }
241247
}
242248
}
243249
}

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ declare_features! (
508508
(incomplete, generic_const_exprs, "1.56.0", Some(76560)),
509509
/// Allows generic parameters and where-clauses on free & associated const items.
510510
(incomplete, generic_const_items, "1.73.0", Some(113521)),
511+
/// Allows the type of const generics to depend on generic parameters
512+
(incomplete, generic_const_parameter_types, "CURRENT_RUSTC_VERSION", Some(137626)),
511513
/// Allows any generic constants being used as pattern type range ends
512514
(incomplete, generic_pattern_types, "1.86.0", Some(136574)),
513515
/// Allows registering static items globally, possibly across crates, to iterate over at runtime.

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
966966
let ty = tcx.type_of(param.def_id).instantiate_identity();
967967

968968
if tcx.features().unsized_const_params() {
969-
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
969+
enter_wf_checking_ctxt(tcx, hir_ty.span, tcx.local_parent(param.def_id), |wfcx| {
970970
wfcx.register_bound(
971971
ObligationCause::new(
972972
hir_ty.span,
@@ -980,7 +980,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
980980
Ok(())
981981
})
982982
} else if tcx.features().adt_const_params() {
983-
enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
983+
enter_wf_checking_ctxt(tcx, hir_ty.span, tcx.local_parent(param.def_id), |wfcx| {
984984
wfcx.register_bound(
985985
ObligationCause::new(
986986
hir_ty.span,

compiler/rustc_hir_analysis/src/collect.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,9 @@ fn const_param_default<'tcx>(
18221822
),
18231823
};
18241824
let icx = ItemCtxt::new(tcx, def_id);
1825-
let ct = icx.lowerer().lower_const_arg(default_ct, FeedConstTy::Param(def_id.to_def_id()));
1825+
let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
1826+
let ct = icx
1827+
.lowerer()
1828+
.lower_const_arg(default_ct, FeedConstTy::Param(def_id.to_def_id(), identity_args));
18261829
ty::EarlyBinder::bind(ct)
18271830
}

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
223223
}
224224
hir::GenericParamKind::Const { .. } => {
225225
let param_def_id = param.def_id.to_def_id();
226-
let ct_ty = tcx
227-
.type_of(param_def_id)
228-
.no_bound_vars()
229-
.expect("const parameters cannot be generic");
226+
let ct_ty = tcx.type_of(param_def_id).instantiate_identity();
230227
let ct = icx.lowerer().lower_const_param(param_def_id, param.hir_id);
231228
predicates
232229
.insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));

compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
273273

274274
// We lower to an infer even when the feature gate is not enabled
275275
// as it is useful for diagnostics to be able to see a `ConstKind::Infer`
276-
args.push(ctx.provided_kind(param, arg));
276+
args.push(ctx.provided_kind(&args, param, arg));
277277
args_iter.next();
278278
params.next();
279279
}

0 commit comments

Comments
 (0)