Skip to content

Commit 70d290d

Browse files
committed
Auto merge of #161487 - JonathanBrouwer:rollup-gQdVO93, r=<try>
Rollup of 19 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple-1 try-job: aarch64-apple-2 try-job: x86_64-mingw-1 try-job: i686-msvc-1 try-job: i686-msvc-2
2 parents c656540 + c9db83f commit 70d290d

88 files changed

Lines changed: 1520 additions & 522 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ pub(crate) use precise_captures::*;
1717

1818
pub(crate) mod remove_or_use_generic;
1919

20+
#[derive(Diagnostic)]
21+
#[diag("complex const arguments must be placed inside of a `const` block")]
22+
pub(crate) struct ComplexConstArg {
23+
#[primary_span]
24+
pub span: Span,
25+
}
26+
2027
#[derive(Diagnostic)]
2128
#[diag("ambiguous associated {$assoc_kind} `{$assoc_ident}` in bounds of `{$qself}`")]
2229
pub(crate) struct AmbiguousAssocItem<'a> {
@@ -2144,3 +2151,12 @@ pub(crate) struct OnlyStructsCanBeViewedAdt<'tcx> {
21442151
pub article: &'static str,
21452152
pub kind: &'static str,
21462153
}
2154+
2155+
#[derive(Diagnostic)]
2156+
#[diag("the type of const parameters must not depend on other generic parameters", code = E0770)]
2157+
pub(crate) struct ParamInTyOfConstParam<'tcx> {
2158+
#[primary_span]
2159+
#[label("the type `{$ty}` must not depend on other generic parameter")]
2160+
pub(crate) span: Span,
2161+
pub(crate) ty: Ty<'tcx>,
2162+
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-file-filelength
2+
13
//! HIR ty lowering: Lowers type-system entities[^1] from the [HIR][hir] to
24
//! the [`rustc_middle::ty`] representation.
35
//!
@@ -2523,6 +2525,31 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25232525
ty::Const::new_value(tcx, valtree, ty)
25242526
}
25252527

2528+
fn try_recover_misrepresented_function_call(
2529+
&self,
2530+
hir_self_ty: &'tcx hir::Ty<'tcx>,
2531+
span: Span,
2532+
) -> Option<ErrorGuaranteed> {
2533+
// Only an enum can host a tuple-variant constructor (`<Option<u32>>::Some(..)`).
2534+
// For any other self type, a type-relative call is an associated function, not a
2535+
// constructor, and must be wrapped in `const { ... }`. We catch that here, before
2536+
// lowering the self type, so a generic struct/union written without its args
2537+
// (`FieldName::len()`, from `tracing`'s macros) reports this clear error instead
2538+
// of a spurious E0107 "missing generics" (#157152), and a primitive or foreign
2539+
// type reports it instead of an opaque downstream resolution error. Enums,
2540+
// aliases, `Self` and type parameters are let through: each may resolve to an
2541+
// enum, so they must reach constructor lowering.
2542+
let self_ty_res = match hir_self_ty.kind {
2543+
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => path.res,
2544+
_ => Res::Err,
2545+
};
2546+
matches!(
2547+
self_ty_res,
2548+
Res::Def(DefKind::Struct | DefKind::Union | DefKind::ForeignTy, _) | Res::PrimTy(_)
2549+
)
2550+
.then(|| self.dcx().emit_err(diagnostics::ComplexConstArg { span }))
2551+
}
2552+
25262553
fn lower_const_arg_tuple_call(
25272554
&self,
25282555
hir_id: HirId,
@@ -2543,6 +2570,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25432570
self.lower_resolved_const_path(opt_self_ty, path, hir_id)
25442571
}
25452572
hir::QPath::TypeRelative(hir_self_ty, segment) => {
2573+
if let Some(e) = self.try_recover_misrepresented_function_call(hir_self_ty, span) {
2574+
return ty::Const::new_error(tcx, e);
2575+
}
2576+
25462577
let self_ty = self.lower_ty(hir_self_ty);
25472578
match self.lower_type_relative_const_path(
25482579
self_ty,
@@ -2576,10 +2607,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25762607
(tcx.adt_def(parent_did), fn_args, parent_did)
25772608
}
25782609
_ => {
2579-
let e = self.dcx().span_err(
2580-
span,
2581-
"complex const arguments must be placed inside of a `const` block",
2582-
);
2610+
let e = self.dcx().emit_err(diagnostics::ComplexConstArg { span });
25832611
return Const::new_error(tcx, e);
25842612
}
25852613
};

0 commit comments

Comments
 (0)