Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9857284

Browse files
committedJan 19, 2025·
Auto merge of rust-lang#135715 - matthiaskrgr:rollup-9a18sxj, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#135641 ([rustdoc] Replace module list items `ul`/`li` with `dl`/`dd`/`dt` elements) - rust-lang#135703 (Disallow `A { .. }` if `A` has no fields) - rust-lang#135705 (Consolidate ad-hoc MIR lints into real pass-manager-based MIR lints) - rust-lang#135708 (Some random compiler nits) Failed merges: - rust-lang#135685 (Remove unused `item-row` CSS class) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 01706e1 + c87dd96 commit 9857284

File tree

64 files changed

+394
-353
lines changed

Some content is hidden

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

64 files changed

+394
-353
lines changed
 

‎compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,18 +1991,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19911991
adt_ty: Ty<'tcx>,
19921992
expected: Expectation<'tcx>,
19931993
expr: &hir::Expr<'_>,
1994-
span: Span,
1994+
path_span: Span,
19951995
variant: &'tcx ty::VariantDef,
19961996
hir_fields: &'tcx [hir::ExprField<'tcx>],
19971997
base_expr: &'tcx hir::StructTailExpr<'tcx>,
19981998
) {
19991999
let tcx = self.tcx;
20002000

2001-
let adt_ty = self.try_structurally_resolve_type(span, adt_ty);
2001+
let adt_ty = self.try_structurally_resolve_type(path_span, adt_ty);
20022002
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| {
20032003
self.fudge_inference_if_ok(|| {
20042004
let ocx = ObligationCtxt::new(self);
2005-
ocx.sup(&self.misc(span), self.param_env, expected, adt_ty)?;
2005+
ocx.sup(&self.misc(path_span), self.param_env, expected, adt_ty)?;
20062006
if !ocx.select_where_possible().is_empty() {
20072007
return Err(TypeError::Mismatch);
20082008
}
@@ -2012,11 +2012,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20122012
});
20132013
if let Some(adt_ty_hint) = adt_ty_hint {
20142014
// re-link the variables that the fudging above can create.
2015-
self.demand_eqtype(span, adt_ty_hint, adt_ty);
2015+
self.demand_eqtype(path_span, adt_ty_hint, adt_ty);
20162016
}
20172017

20182018
let ty::Adt(adt, args) = adt_ty.kind() else {
2019-
span_bug!(span, "non-ADT passed to check_expr_struct_fields");
2019+
span_bug!(path_span, "non-ADT passed to check_expr_struct_fields");
20202020
};
20212021
let adt_kind = adt.adt_kind();
20222022

@@ -2107,7 +2107,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21072107
if adt_kind == AdtKind::Union && hir_fields.len() != 1 {
21082108
struct_span_code_err!(
21092109
self.dcx(),
2110-
span,
2110+
path_span,
21112111
E0784,
21122112
"union expressions should have exactly one field",
21132113
)
@@ -2167,6 +2167,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21672167
});
21682168
return;
21692169
}
2170+
if variant.fields.is_empty() {
2171+
let mut err = self.dcx().struct_span_err(
2172+
span,
2173+
format!(
2174+
"`{adt_ty}` has no fields, `..` needs at least one default field in the \
2175+
struct definition",
2176+
),
2177+
);
2178+
err.span_label(path_span, "this type has no fields");
2179+
err.emit();
2180+
}
21702181
if !missing_mandatory_fields.is_empty() {
21712182
let s = pluralize!(missing_mandatory_fields.len());
21722183
let fields: Vec<_> =
@@ -2316,11 +2327,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23162327
.collect();
23172328

23182329
if !private_fields.is_empty() {
2319-
self.report_private_fields(adt_ty, span, expr.span, private_fields, hir_fields);
2330+
self.report_private_fields(
2331+
adt_ty,
2332+
path_span,
2333+
expr.span,
2334+
private_fields,
2335+
hir_fields,
2336+
);
23202337
} else {
23212338
self.report_missing_fields(
23222339
adt_ty,
2323-
span,
2340+
path_span,
23242341
remaining_fields,
23252342
variant,
23262343
hir_fields,

‎compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDef
8787
}
8888

8989
fn typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
90-
typeck_with_fallback(tcx, def_id, None)
90+
typeck_with_inspect(tcx, def_id, None)
9191
}
9292

9393
/// Same as `typeck` but `inspect` is invoked on evaluation of each root obligation.
@@ -99,11 +99,11 @@ pub fn inspect_typeck<'tcx>(
9999
def_id: LocalDefId,
100100
inspect: ObligationInspector<'tcx>,
101101
) -> &'tcx ty::TypeckResults<'tcx> {
102-
typeck_with_fallback(tcx, def_id, Some(inspect))
102+
typeck_with_inspect(tcx, def_id, Some(inspect))
103103
}
104104

105105
#[instrument(level = "debug", skip(tcx, inspector), ret)]
106-
fn typeck_with_fallback<'tcx>(
106+
fn typeck_with_inspect<'tcx>(
107107
tcx: TyCtxt<'tcx>,
108108
def_id: LocalDefId,
109109
inspector: Option<ObligationInspector<'tcx>>,

0 commit comments

Comments
 (0)
This repository has been archived.