Skip to content

Commit c9537a9

Browse files
committed
Auto merge of rust-lang#148202 - Zalathar:rollup-2eriuc3, r=Zalathar
Rollup of 14 pull requests Successful merges: - rust-lang#144936 (CFI: Fix types that implement Fn, FnMut, or FnOnce) - rust-lang#147185 (repr(transparent): do not consider repr(C) types to be 1-ZST) - rust-lang#147840 (Rework unsizing coercions in the new solver) - rust-lang#147915 (Update target maintainers android.md) - rust-lang#148013 (1.91.0 release notes) - rust-lang#148044 (compiletest: show output in debug logging) - rust-lang#148057 (tests/ui/sanitizer/hwaddress.rs: Run on aarch64 and remove cgu hack) - rust-lang#148139 (Add `coverage` scope for controlling paths in code coverage) - rust-lang#148154 (Add a mailmap entry) - rust-lang#148158 (ci: loongarch64: use medium code model to avoid relocation overflows) - rust-lang#148166 (Re-enable macro-stepping test for AArch64) - rust-lang#148172 (rustc-dev-guide subtree update) - rust-lang#148175 (Fix typos: duplicate words in comments) - rust-lang#148186 (rustdoc-search: add an integration test for CCI) Failed merges: - rust-lang#147935 (Add LLVM realtime sanitizer) r? `@ghost` `@rustbot` modify labels: rollup
2 parents df984ed + 21a1573 commit c9537a9

File tree

67 files changed

+1368
-201
lines changed

Some content is hidden

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

67 files changed

+1368
-201
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ Valerii Lashmanov <vflashm@gmail.com>
680680
Vitali Haravy <HumaneProgrammer@gmail.com> Vitali Haravy <humaneprogrammer@gmail.com>
681681
Vitaly Shukela <vi0oss@gmail.com>
682682
Waffle Lapkin <waffle.lapkin@gmail.com>
683+
Waffle Lapkin <waffle.lapkin@gmail.com> <Waffle Lapkin>
683684
Waffle Lapkin <waffle.lapkin@gmail.com> <waffle.lapkin@tasking.com>
684685
Weihang Lo <me@weihanglo.tw>
685686
Weihang Lo <me@weihanglo.tw> <weihanglo@users.noreply.github.com>

RELEASES.md

Lines changed: 211 additions & 0 deletions
Large diffs are not rendered by default.

compiler/rustc_ast_pretty/src/pp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl Printer {
298298
}
299299
}
300300

301-
// This is is where `BoxMarker`s are produced.
301+
// This is where `BoxMarker`s are produced.
302302
fn scan_begin(&mut self, token: BeginToken) -> BoxMarker {
303303
if self.scan_stack.is_empty() {
304304
self.left_total = 1;
@@ -310,7 +310,7 @@ impl Printer {
310310
BoxMarker
311311
}
312312

313-
// This is is where `BoxMarker`s are consumed.
313+
// This is where `BoxMarker`s are consumed.
314314
fn scan_end(&mut self, b: BoxMarker) {
315315
if self.scan_stack.is_empty() {
316316
self.print_end();

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl GlobalFileTable {
128128
for file in all_files {
129129
raw_file_table.entry(file.stable_id).or_insert_with(|| {
130130
file.name
131-
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
131+
.for_scope(tcx.sess, RemapPathScopeComponents::COVERAGE)
132132
.to_string_lossy()
133133
.into_owned()
134134
});
@@ -147,7 +147,7 @@ impl GlobalFileTable {
147147
.sess
148148
.opts
149149
.working_dir
150-
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
150+
.for_scope(tcx.sess, RemapPathScopeComponents::COVERAGE)
151151
.to_string_lossy();
152152
table.push(base_dir.as_ref());
153153

compiler/rustc_const_eval/src/interpret/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl EnteredTraceSpan for tracing::span::EnteredSpan {
121121
/// ### `tracing_separate_thread` parameter
122122
///
123123
/// This macro was introduced to obtain better traces of Miri without impacting release performance.
124-
/// Miri saves traces using the the `tracing_chrome` `tracing::Layer` so that they can be visualized
124+
/// Miri saves traces using the `tracing_chrome` `tracing::Layer` so that they can be visualized
125125
/// in <https://ui.perfetto.dev>. To instruct `tracing_chrome` to put some spans on a separate trace
126126
/// thread/line than other spans when viewed in <https://ui.perfetto.dev>, you can pass
127127
/// `tracing_separate_thread = tracing::field::Empty` to the tracing macros. This is useful to

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use rustc_hir::def::{CtorKind, DefKind};
1212
use rustc_hir::{LangItem, Node, attrs, find_attr, intravisit};
1313
use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt};
1414
use rustc_infer::traits::{Obligation, ObligationCauseCode, WellFormedLoc};
15-
use rustc_lint_defs::builtin::{
16-
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, UNSUPPORTED_CALLING_CONVENTIONS,
17-
};
15+
use rustc_lint_defs::builtin::{REPR_TRANSPARENT_NON_ZST_FIELDS, UNSUPPORTED_CALLING_CONVENTIONS};
1816
use rustc_middle::hir::nested_filter;
1917
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
2018
use rustc_middle::middle::stability::EvalResult;
@@ -1509,31 +1507,46 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
15091507
}
15101508

15111509
let typing_env = ty::TypingEnv::non_body_analysis(tcx, adt.did());
1512-
// For each field, figure out if it's known to have "trivial" layout (i.e., is a 1-ZST), with
1513-
// "known" respecting #[non_exhaustive] attributes.
1510+
// For each field, figure out if it has "trivial" layout (i.e., is a 1-ZST).
1511+
// Even some 1-ZST fields are not allowed though, if they have `non_exhaustive` or private
1512+
// fields or `repr(C)`. We call those fields "unsuited".
1513+
struct FieldInfo<'tcx> {
1514+
span: Span,
1515+
trivial: bool,
1516+
unsuited: Option<UnsuitedInfo<'tcx>>,
1517+
}
1518+
struct UnsuitedInfo<'tcx> {
1519+
/// The source of the problem, a type that is found somewhere within the field type.
1520+
ty: Ty<'tcx>,
1521+
reason: UnsuitedReason,
1522+
}
1523+
enum UnsuitedReason {
1524+
NonExhaustive,
1525+
PrivateField,
1526+
ReprC,
1527+
}
1528+
15141529
let field_infos = adt.all_fields().map(|field| {
15151530
let ty = field.ty(tcx, GenericArgs::identity_for_item(tcx, field.did));
15161531
let layout = tcx.layout_of(typing_env.as_query_input(ty));
15171532
// We are currently checking the type this field came from, so it must be local
15181533
let span = tcx.hir_span_if_local(field.did).unwrap();
15191534
let trivial = layout.is_ok_and(|layout| layout.is_1zst());
15201535
if !trivial {
1521-
return (span, trivial, None);
1536+
// No need to even compute `unsuited`.
1537+
return FieldInfo { span, trivial, unsuited: None };
15221538
}
1523-
// Even some 1-ZST fields are not allowed though, if they have `non_exhaustive`.
15241539

1525-
fn check_non_exhaustive<'tcx>(
1540+
fn check_unsuited<'tcx>(
15261541
tcx: TyCtxt<'tcx>,
15271542
typing_env: ty::TypingEnv<'tcx>,
1528-
t: Ty<'tcx>,
1529-
) -> ControlFlow<(&'static str, DefId, GenericArgsRef<'tcx>, bool)> {
1543+
ty: Ty<'tcx>,
1544+
) -> ControlFlow<UnsuitedInfo<'tcx>> {
15301545
// We can encounter projections during traversal, so ensure the type is normalized.
1531-
let t = tcx.try_normalize_erasing_regions(typing_env, t).unwrap_or(t);
1532-
match t.kind() {
1533-
ty::Tuple(list) => {
1534-
list.iter().try_for_each(|t| check_non_exhaustive(tcx, typing_env, t))
1535-
}
1536-
ty::Array(ty, _) => check_non_exhaustive(tcx, typing_env, *ty),
1546+
let ty = tcx.try_normalize_erasing_regions(typing_env, ty).unwrap_or(ty);
1547+
match ty.kind() {
1548+
ty::Tuple(list) => list.iter().try_for_each(|t| check_unsuited(tcx, typing_env, t)),
1549+
ty::Array(ty, _) => check_unsuited(tcx, typing_env, *ty),
15371550
ty::Adt(def, args) => {
15381551
if !def.did().is_local()
15391552
&& !find_attr!(
@@ -1548,28 +1561,36 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
15481561
.any(ty::VariantDef::is_field_list_non_exhaustive);
15491562
let has_priv = def.all_fields().any(|f| !f.vis.is_public());
15501563
if non_exhaustive || has_priv {
1551-
return ControlFlow::Break((
1552-
def.descr(),
1553-
def.did(),
1554-
args,
1555-
non_exhaustive,
1556-
));
1564+
return ControlFlow::Break(UnsuitedInfo {
1565+
ty,
1566+
reason: if non_exhaustive {
1567+
UnsuitedReason::NonExhaustive
1568+
} else {
1569+
UnsuitedReason::PrivateField
1570+
},
1571+
});
15571572
}
15581573
}
1574+
if def.repr().c() {
1575+
return ControlFlow::Break(UnsuitedInfo {
1576+
ty,
1577+
reason: UnsuitedReason::ReprC,
1578+
});
1579+
}
15591580
def.all_fields()
15601581
.map(|field| field.ty(tcx, args))
1561-
.try_for_each(|t| check_non_exhaustive(tcx, typing_env, t))
1582+
.try_for_each(|t| check_unsuited(tcx, typing_env, t))
15621583
}
15631584
_ => ControlFlow::Continue(()),
15641585
}
15651586
}
15661587

1567-
(span, trivial, check_non_exhaustive(tcx, typing_env, ty).break_value())
1588+
FieldInfo { span, trivial, unsuited: check_unsuited(tcx, typing_env, ty).break_value() }
15681589
});
15691590

15701591
let non_trivial_fields = field_infos
15711592
.clone()
1572-
.filter_map(|(span, trivial, _non_exhaustive)| if !trivial { Some(span) } else { None });
1593+
.filter_map(|field| if !field.trivial { Some(field.span) } else { None });
15731594
let non_trivial_count = non_trivial_fields.clone().count();
15741595
if non_trivial_count >= 2 {
15751596
bad_non_zero_sized_fields(
@@ -1581,36 +1602,40 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
15811602
);
15821603
return;
15831604
}
1584-
let mut prev_non_exhaustive_1zst = false;
1585-
for (span, _trivial, non_exhaustive_1zst) in field_infos {
1586-
if let Some((descr, def_id, args, non_exhaustive)) = non_exhaustive_1zst {
1605+
1606+
let mut prev_unsuited_1zst = false;
1607+
for field in field_infos {
1608+
if let Some(unsuited) = field.unsuited {
1609+
assert!(field.trivial);
15871610
// If there are any non-trivial fields, then there can be no non-exhaustive 1-zsts.
15881611
// Otherwise, it's only an issue if there's >1 non-exhaustive 1-zst.
1589-
if non_trivial_count > 0 || prev_non_exhaustive_1zst {
1612+
if non_trivial_count > 0 || prev_unsuited_1zst {
15901613
tcx.node_span_lint(
1591-
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
1614+
REPR_TRANSPARENT_NON_ZST_FIELDS,
15921615
tcx.local_def_id_to_hir_id(adt.did().expect_local()),
1593-
span,
1616+
field.span,
15941617
|lint| {
1618+
let title = match unsuited.reason {
1619+
UnsuitedReason::NonExhaustive => "external non-exhaustive types",
1620+
UnsuitedReason::PrivateField => "external types with private fields",
1621+
UnsuitedReason::ReprC => "`repr(C)` types",
1622+
};
15951623
lint.primary_message(
1596-
"zero-sized fields in `repr(transparent)` cannot \
1597-
contain external non-exhaustive types",
1624+
format!("zero-sized fields in `repr(transparent)` cannot contain {title}"),
15981625
);
1599-
let note = if non_exhaustive {
1600-
"is marked with `#[non_exhaustive]`"
1601-
} else {
1602-
"contains private fields"
1626+
let note = match unsuited.reason {
1627+
UnsuitedReason::NonExhaustive => "is marked with `#[non_exhaustive]`, so it could become non-zero-sized in the future.",
1628+
UnsuitedReason::PrivateField => "contains private fields, so it could become non-zero-sized in the future.",
1629+
UnsuitedReason::ReprC => "is a `#[repr(C)]` type, so it is not guaranteed to be zero-sized on all targets.",
16031630
};
1604-
let field_ty = tcx.def_path_str_with_args(def_id, args);
16051631
lint.note(format!(
1606-
"this {descr} contains `{field_ty}`, which {note}, \
1607-
and makes it not a breaking change to become \
1608-
non-zero-sized in the future."
1632+
"this field contains `{field_ty}`, which {note}",
1633+
field_ty = unsuited.ty,
16091634
));
16101635
},
1611-
)
1636+
);
16121637
} else {
1613-
prev_non_exhaustive_1zst = true;
1638+
prev_unsuited_1zst = true;
16141639
}
16151640
}
16161641
}

0 commit comments

Comments
 (0)