Skip to content

Commit 8e4c370

Browse files
committed
Auto merge of #161494 - JonathanBrouwer:rollup-67F9vC9, r=JonathanBrouwer
Rollup of 18 pull requests Successful merges: - #151061 (Build rustc and codegen backends with -Zembed-metadata=no) - #157949 (Allow self in const generics) - #158588 (trait_selection: fix assumptions-on-binders diagnostics) - #159954 (core: implement float conversion methods) - #160136 (Add `Default` implementation for `std::sync::Once`) - #160835 (resolver diagnostics: don't swallow labels and point out similar items as a note, not a label) - #161048 (Improve the ABI between the panic runtime and libstd) - #161292 (Add safety comments in alloc::Wtf8) - #161444 (Add some `rustc_type_ir` comments) - #161465 (Remove leftover immediate creation) - #152433 (Use `symlink_dir` to create junctions on Windows instead of trying to use symbolic links in `copy_link_internal`) - #159098 (Add Arc/Rc::strong_count_from_raw) - #159282 (Update documentation for `-Zdump-dep-graph`) - #161401 (Remove fields from TypeKind: Bool, Char, Float and Int) - #161431 (bootstrap: (offload) be stricter about selected compiler and paths) - #161451 (Avoid arming the Windows TLS destructor guard in fibers) - #161463 (Add myself to mailmap) - #161476 (Use bitset for locals_with_use_data) Failed merges: - #161443 (add internal DSL for testing binders)
2 parents 8536f4d + 37e357b commit 8e4c370

195 files changed

Lines changed: 2659 additions & 1225 deletions

File tree

Some content is hidden

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

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,3 +743,4 @@ Zack Corr <zack@z0w0.me> <zackcorr95@gmail.com>
743743
Zack Slayton <zack.slayton@gmail.com>
744744
Zbigniew Siciarz <zbigniew@siciarz.net> Zbigniew Siciarz <antyqjon@gmail.com>
745745
y21 <30553356+y21@users.noreply.github.com>
746+
朝倉水希 <mizuk1@mzk1.dev> <asakuramizu111@gmail.com>

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,9 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> {
478478
let errci = ErrorConstraintInfo { fr, outlived_fr, category, span };
479479

480480
let mut diag = match (category, fr_is_local, outlived_fr_is_local) {
481-
(ConstraintCategory::SolverRegionConstraint(span), _, _) => {
482-
let mut d = self.dcx().struct_span_err(
483-
span,
484-
"unsatisfied lifetime constraint from -Zassumptions-on-binders :3",
485-
);
486-
d.note("meoow :c");
487-
d
488-
}
481+
(ConstraintCategory::SolverRegionConstraint(span), _, _) => self
482+
.dcx()
483+
.struct_span_err(span, "higher-ranked lifetime bound could not be satisfied"),
489484
(ConstraintCategory::Return(kind), true, false)
490485
if self.regioncx.is_closure_fn_mut(fr) =>
491486
{

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
153153
GenericArgKind::Lifetime(r1) => {
154154
let r1_vid = self.to_region_vid(r1);
155155
let r2_vid = self.to_region_vid(r2);
156-
self.add_outlives(r1_vid, r2_vid, constraint_category);
156+
self.add_outlives(r1_vid, r2_vid, constraint_category, self.span);
157157
}
158158

159159
GenericArgKind::Type(mut t1) => {
@@ -221,6 +221,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
221221
sup: ty::RegionVid,
222222
sub: ty::RegionVid,
223223
category: ConstraintCategory<'tcx>,
224+
span: Span,
224225
) {
225226
let category = match self.category {
226227
ConstraintCategory::Boring | ConstraintCategory::BoringNoLocation => category,
@@ -229,7 +230,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
229230
self.constraints.outlives_constraints.push(OutlivesConstraint {
230231
locations: self.locations,
231232
category,
232-
span: self.span,
233+
span,
233234
sub,
234235
sup,
235236
variance_info: ty::VarianceDiagInfo::default(),
@@ -246,14 +247,14 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
246247
impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'b, 'tcx> {
247248
fn push_sub_region_constraint(
248249
&mut self,
249-
_origin: SubregionOrigin<'tcx>,
250+
origin: SubregionOrigin<'tcx>,
250251
a: ty::Region<'tcx>,
251252
b: ty::Region<'tcx>,
252253
constraint_category: ConstraintCategory<'tcx>,
253254
) {
254255
let b = self.to_region_vid(b);
255256
let a = self.to_region_vid(a);
256-
self.add_outlives(b, a, constraint_category);
257+
self.add_outlives(b, a, constraint_category, origin.span());
257258
}
258259

259260
fn push_verify(

compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_index::IndexVec;
2+
use rustc_index::bit_set::DenseBitSet;
23
use rustc_middle::mir::visit::{PlaceContext, Visitor};
34
use rustc_middle::mir::{Body, Local, Location};
45
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
@@ -97,9 +98,11 @@ impl LocalUseMap {
9798
return local_use_map;
9899
}
99100

100-
let mut locals_with_use_data: IndexVec<Local, bool> =
101-
IndexVec::from_elem(false, &body.local_decls);
102-
live_locals.iter().for_each(|&local| locals_with_use_data[local] = true);
101+
let mut locals_with_use_data: DenseBitSet<Local> =
102+
DenseBitSet::new_empty(body.local_decls.len());
103+
live_locals.iter().for_each(|&local| {
104+
locals_with_use_data.insert(local);
105+
});
103106

104107
LocalUseMapBuild { local_use_map: &mut local_use_map, location_map, locals_with_use_data }
105108
.visit_body(body);
@@ -134,12 +137,12 @@ struct LocalUseMapBuild<'me> {
134137
// obtained the same information from `live_locals` but we want to
135138
// avoid repeatedly calling `Vec::contains()` (see `LocalUseMap` for
136139
// the rationale on the time-memory trade-off we're favoring here).
137-
locals_with_use_data: IndexVec<Local, bool>,
140+
locals_with_use_data: DenseBitSet<Local>,
138141
}
139142

140143
impl Visitor<'_> for LocalUseMapBuild<'_> {
141144
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
142-
if self.locals_with_use_data[local]
145+
if self.locals_with_use_data.contains(local)
143146
&& let Some(def_use) = def_use::categorize(context)
144147
{
145148
let first_appearance = match def_use {

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ pub(crate) fn type_check<'tcx>(
188188
&mut converter,
189189
typeck.known_type_outlives_obligations,
190190
universal_region_relations.outlives.clone(),
191-
infcx.tcx.def_span(infcx.root_def_id),
192191
);
193192
}
194193

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
434434
parse_atomic_ordering(fail_ordering),
435435
weak,
436436
);
437-
let val = bx.from_immediate(val);
438-
let success = bx.from_immediate(success);
439437

440438
let mut builder = OperandRefBuilder::new(result_layout);
441439
builder.insert_imm(FieldIdx::from_u32(0), val);

compiler/rustc_const_eval/src/const_eval/type_info.rs

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
6161
// Fill all fields of the `TypeInfo` struct.
6262
for (idx, field) in ty_struct.fields.iter_enumerated() {
6363
let field_dest = self.project_field(dest, idx)?;
64-
let ptr_bit_width = || self.tcx.data_layout.pointer_size().bits();
6564
match field.name {
6665
sym::kind => {
6766
let variant_index = match ty.kind() {
@@ -115,33 +114,19 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
115114
self.project_downcast_named(&field_dest, sym::Char)?;
116115
variant
117116
}
118-
ty::Int(int_ty) => {
119-
let (variant, variant_place) =
117+
ty::Int(_) => {
118+
let (variant, _variant_place) =
120119
self.project_downcast_named(&field_dest, sym::Int)?;
121-
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
122-
self.write_int_type_info(
123-
place,
124-
int_ty.bit_width().unwrap_or_else(/* isize */ ptr_bit_width),
125-
true,
126-
)?;
127120
variant
128121
}
129-
ty::Uint(uint_ty) => {
130-
let (variant, variant_place) =
122+
ty::Uint(_) => {
123+
let (variant, _variant_place) =
131124
self.project_downcast_named(&field_dest, sym::Int)?;
132-
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
133-
self.write_int_type_info(
134-
place,
135-
uint_ty.bit_width().unwrap_or_else(/* usize */ ptr_bit_width),
136-
false,
137-
)?;
138125
variant
139126
}
140-
ty::Float(float_ty) => {
141-
let (variant, variant_place) =
127+
ty::Float(_) => {
128+
let (variant, _variant_place) =
142129
self.project_downcast_named(&field_dest, sym::Float)?;
143-
let place = self.project_field(&variant_place, FieldIdx::ZERO)?;
144-
self.write_float_type_info(place, float_ty.bit_width())?;
145130
variant
146131
}
147132
ty::Str => {
@@ -316,48 +301,6 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
316301
interp_ok(())
317302
}
318303

319-
fn write_int_type_info(
320-
&mut self,
321-
place: impl Writeable<'tcx, CtfeProvenance>,
322-
bit_width: u64,
323-
signed: bool,
324-
) -> InterpResult<'tcx> {
325-
for (field_idx, field) in
326-
place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated()
327-
{
328-
let field_place = self.project_field(&place, field_idx)?;
329-
match field.name {
330-
sym::bits => self.write_scalar(
331-
Scalar::from_u32(bit_width.try_into().expect("bit_width overflowed")),
332-
&field_place,
333-
)?,
334-
sym::signed => self.write_scalar(Scalar::from_bool(signed), &field_place)?,
335-
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
336-
}
337-
}
338-
interp_ok(())
339-
}
340-
341-
fn write_float_type_info(
342-
&mut self,
343-
place: impl Writeable<'tcx, CtfeProvenance>,
344-
bit_width: u64,
345-
) -> InterpResult<'tcx> {
346-
for (field_idx, field) in
347-
place.layout().ty.ty_adt_def().unwrap().non_enum_variant().fields.iter_enumerated()
348-
{
349-
let field_place = self.project_field(&place, field_idx)?;
350-
match field.name {
351-
sym::bits => self.write_scalar(
352-
Scalar::from_u32(bit_width.try_into().expect("bit_width overflowed")),
353-
&field_place,
354-
)?,
355-
other => span_bug!(self.tcx.def_span(field.did), "unimplemented field {other}"),
356-
}
357-
}
358-
interp_ok(())
359-
}
360-
361304
pub(crate) fn write_reference_type_info(
362305
&mut self,
363306
place: impl Writeable<'tcx, CtfeProvenance>,

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use tracing::instrument;
1313

1414
use super::{HirPlaceholderCollector, ItemCtxt, bad_placeholder};
1515
use crate::check::wfcheck::check_static_item;
16+
use crate::diagnostics::ParamInTyOfConstParam;
1617
use crate::hir_ty_lowering::HirTyLowerer;
1718

1819
mod opaque;
@@ -239,8 +240,19 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
239240
}
240241

241242
Node::GenericParam(param) => match &param.kind {
242-
GenericParamKind::Type { default: Some(ty), .. }
243-
| GenericParamKind::Const { ty, .. } => icx.lower_ty(ty),
243+
GenericParamKind::Type { default: Some(ty), .. } => icx.lower_ty(ty),
244+
GenericParamKind::Const { ty, .. } => {
245+
let lowered_ty = icx.lower_ty(ty);
246+
if !tcx.features().generic_const_parameter_types() && lowered_ty.has_param() {
247+
let guar = tcx
248+
.dcx()
249+
.create_err(ParamInTyOfConstParam { span: ty.span, ty: lowered_ty })
250+
.emit();
251+
Ty::new_error(tcx, guar)
252+
} else {
253+
lowered_ty
254+
}
255+
}
244256
x => bug!("unexpected non-type Node::GenericParam: {:?}", x),
245257
},
246258

compiler/rustc_hir_analysis/src/diagnostics.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,3 +2144,12 @@ pub(crate) struct OnlyStructsCanBeViewedAdt<'tcx> {
21442144
pub article: &'static str,
21452145
pub kind: &'static str,
21462146
}
2147+
2148+
#[derive(Diagnostic)]
2149+
#[diag("the type of const parameters must not depend on other generic parameters", code = E0770)]
2150+
pub(crate) struct ParamInTyOfConstParam<'tcx> {
2151+
#[primary_span]
2152+
#[label("the type `{$ty}` must not depend on other generic parameter")]
2153+
pub(crate) span: Span,
2154+
pub(crate) ty: Ty<'tcx>,
2155+
}

compiler/rustc_infer/src/infer/context.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,21 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
6464
fn get_solver_region_constraint(
6565
&self,
6666
) -> rustc_type_ir::region_constraint::RegionConstraint<TyCtxt<'tcx>> {
67-
self.inner.borrow().solver_region_constraint_storage.get_constraint()
67+
self.inner.borrow().solver_region_constraint_storage.get_unspanned_constraint()
6868
}
6969

7070
fn overwrite_solver_region_constraint(
7171
&self,
7272
constraint: rustc_type_ir::region_constraint::RegionConstraint<TyCtxt<'tcx>>,
73+
span: Span,
7374
) {
7475
let mut inner = self.inner.borrow_mut();
7576
use rustc_data_structures::undo_log::UndoLogs;
7677

7778
use crate::infer::UndoLog;
7879
let old_constraint = inner.solver_region_constraint_storage.get_constraint();
7980
inner.undo_log.push(UndoLog::OverwriteSolverRegionConstraint { old_constraint });
80-
inner.solver_region_constraint_storage.overwrite_solver_region_constraint(constraint);
81+
inner.solver_region_constraint_storage.overwrite(constraint, span);
8182
}
8283

8384
fn universe_of_ty(&self, vid: ty::TyVid) -> Option<ty::UniverseIndex> {
@@ -331,14 +332,15 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
331332
fn register_solver_region_constraint(
332333
&self,
333334
c: rustc_type_ir::region_constraint::RegionConstraint<TyCtxt<'tcx>>,
335+
span: Span,
334336
) {
335337
let mut inner = self.inner.borrow_mut();
336338
use rustc_data_structures::undo_log::UndoLogs;
337339

338340
use crate::infer::UndoLog;
339341
let previous_was_and = inner.solver_region_constraint_storage.is_and();
340342
inner.undo_log.push(UndoLog::PushSolverRegionConstraint { previous_was_and });
341-
inner.solver_region_constraint_storage.push(c);
343+
inner.solver_region_constraint_storage.push(c, span);
342344
}
343345

344346
fn register_ty_outlives(&self, ty: Ty<'tcx>, r: ty::Region<'tcx>, span: Span) {

0 commit comments

Comments
 (0)