Skip to content

Commit 8e52fa8

Browse files
committed
Auto merge of #98566 - matthiaskrgr:rollup-43etyls, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #97389 (Improve memory ordering diagnostics) - #97780 (Check ADT field is well-formed before checking it is sized) - #98530 (compiletest: add issue number param to `known-bug`) - #98556 (Fix builds on Windows (closes #98546)) - #98561 (Fix spelling in SAFETY comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents bd2e51a + 54b81dd commit 8e52fa8

32 files changed

+405
-364
lines changed

compiler/rustc_lint/src/types.rs

+66-82
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_attr as attr;
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::Applicability;
66
use rustc_hir as hir;
7-
use rustc_hir::def_id::DefId;
87
use rustc_hir::{is_range_literal, Expr, ExprKind, Node};
98
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, SizeSkeleton};
109
use rustc_middle::ty::subst::SubstsRef;
@@ -1483,39 +1482,32 @@ impl InvalidAtomicOrdering {
14831482
None
14841483
}
14851484

1486-
fn matches_ordering(cx: &LateContext<'_>, did: DefId, orderings: &[Symbol]) -> bool {
1485+
fn match_ordering(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option<Symbol> {
1486+
let ExprKind::Path(ref ord_qpath) = ord_arg.kind else { return None };
1487+
let did = cx.qpath_res(ord_qpath, ord_arg.hir_id).opt_def_id()?;
14871488
let tcx = cx.tcx;
14881489
let atomic_ordering = tcx.get_diagnostic_item(sym::Ordering);
1489-
orderings.iter().any(|ordering| {
1490-
tcx.item_name(did) == *ordering && {
1491-
let parent = tcx.parent(did);
1492-
Some(parent) == atomic_ordering
1493-
// needed in case this is a ctor, not a variant
1494-
|| tcx.opt_parent(parent) == atomic_ordering
1495-
}
1496-
})
1497-
}
1498-
1499-
fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option<DefId> {
1500-
if let ExprKind::Path(ref ord_qpath) = ord_arg.kind {
1501-
cx.qpath_res(ord_qpath, ord_arg.hir_id).opt_def_id()
1502-
} else {
1503-
None
1504-
}
1490+
let name = tcx.item_name(did);
1491+
let parent = tcx.parent(did);
1492+
[sym::Relaxed, sym::Release, sym::Acquire, sym::AcqRel, sym::SeqCst].into_iter().find(
1493+
|&ordering| {
1494+
name == ordering
1495+
&& (Some(parent) == atomic_ordering
1496+
// needed in case this is a ctor, not a variant
1497+
|| tcx.opt_parent(parent) == atomic_ordering)
1498+
},
1499+
)
15051500
}
15061501

15071502
fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) {
1508-
use rustc_hir::def::{DefKind, Res};
1509-
use rustc_hir::QPath;
15101503
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::load, sym::store])
15111504
&& let Some((ordering_arg, invalid_ordering)) = match method {
15121505
sym::load => Some((&args[1], sym::Release)),
15131506
sym::store => Some((&args[2], sym::Acquire)),
15141507
_ => None,
15151508
}
1516-
&& let ExprKind::Path(QPath::Resolved(_, path)) = ordering_arg.kind
1517-
&& let Res::Def(DefKind::Ctor(..), ctor_id) = path.res
1518-
&& Self::matches_ordering(cx, ctor_id, &[invalid_ordering, sym::AcqRel])
1509+
&& let Some(ordering) = Self::match_ordering(cx, ordering_arg)
1510+
&& (ordering == invalid_ordering || ordering == sym::AcqRel)
15191511
{
15201512
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, ordering_arg.span, |diag| {
15211513
if method == sym::load {
@@ -1537,9 +1529,7 @@ impl InvalidAtomicOrdering {
15371529
&& let ExprKind::Path(ref func_qpath) = func.kind
15381530
&& let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id()
15391531
&& matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::fence | sym::compiler_fence))
1540-
&& let ExprKind::Path(ref ordering_qpath) = &args[0].kind
1541-
&& let Some(ordering_def_id) = cx.qpath_res(ordering_qpath, args[0].hir_id).opt_def_id()
1542-
&& Self::matches_ordering(cx, ordering_def_id, &[sym::Relaxed])
1532+
&& Self::match_ordering(cx, &args[0]) == Some(sym::Relaxed)
15431533
{
15441534
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, args[0].span, |diag| {
15451535
diag.build("memory fences cannot have `Relaxed` ordering")
@@ -1550,62 +1540,56 @@ impl InvalidAtomicOrdering {
15501540
}
15511541

15521542
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
1553-
if let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak])
1554-
&& let Some((success_order_arg, failure_order_arg)) = match method {
1555-
sym::fetch_update => Some((&args[1], &args[2])),
1556-
sym::compare_exchange | sym::compare_exchange_weak => Some((&args[3], &args[4])),
1557-
_ => None,
1558-
}
1559-
&& let Some(fail_ordering_def_id) = Self::opt_ordering_defid(cx, failure_order_arg)
1560-
{
1561-
// Helper type holding on to some checking and error reporting data. Has
1562-
// - (success ordering,
1563-
// - list of failure orderings forbidden by the success order,
1564-
// - suggestion message)
1565-
type OrdLintInfo = (Symbol, &'static [Symbol], &'static str);
1566-
const RELAXED: OrdLintInfo = (sym::Relaxed, &[sym::SeqCst, sym::Acquire], "ordering mode `Relaxed`");
1567-
const ACQUIRE: OrdLintInfo = (sym::Acquire, &[sym::SeqCst], "ordering modes `Acquire` or `Relaxed`");
1568-
const SEQ_CST: OrdLintInfo = (sym::SeqCst, &[], "ordering modes `Acquire`, `SeqCst` or `Relaxed`");
1569-
const RELEASE: OrdLintInfo = (sym::Release, RELAXED.1, RELAXED.2);
1570-
const ACQREL: OrdLintInfo = (sym::AcqRel, ACQUIRE.1, ACQUIRE.2);
1571-
const SEARCH: [OrdLintInfo; 5] = [RELAXED, ACQUIRE, SEQ_CST, RELEASE, ACQREL];
1572-
1573-
let success_lint_info = Self::opt_ordering_defid(cx, success_order_arg)
1574-
.and_then(|success_ord_def_id| -> Option<OrdLintInfo> {
1575-
SEARCH
1576-
.iter()
1577-
.copied()
1578-
.find(|(ordering, ..)| {
1579-
Self::matches_ordering(cx, success_ord_def_id, &[*ordering])
1580-
})
1581-
});
1582-
if Self::matches_ordering(cx, fail_ordering_def_id, &[sym::Release, sym::AcqRel]) {
1583-
// If we don't know the success order is, use what we'd suggest
1584-
// if it were maximally permissive.
1585-
let suggested = success_lint_info.unwrap_or(SEQ_CST).2;
1586-
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, failure_order_arg.span, |diag| {
1587-
let msg = format!(
1588-
"{}'s failure ordering may not be `Release` or `AcqRel`",
1589-
method,
1590-
);
1591-
diag.build(&msg)
1592-
.help(&format!("consider using {} instead", suggested))
1593-
.emit();
1594-
});
1595-
} else if let Some((success_ord, bad_ords_given_success, suggested)) = success_lint_info {
1596-
if Self::matches_ordering(cx, fail_ordering_def_id, bad_ords_given_success) {
1597-
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, failure_order_arg.span, |diag| {
1598-
let msg = format!(
1599-
"{}'s failure ordering may not be stronger than the success ordering of `{}`",
1600-
method,
1601-
success_ord,
1602-
);
1603-
diag.build(&msg)
1604-
.help(&format!("consider using {} instead", suggested))
1605-
.emit();
1606-
});
1607-
}
1608-
}
1543+
let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak])
1544+
else {return };
1545+
1546+
let (success_order_arg, fail_order_arg) = match method {
1547+
sym::fetch_update => (&args[1], &args[2]),
1548+
sym::compare_exchange | sym::compare_exchange_weak => (&args[3], &args[4]),
1549+
_ => return,
1550+
};
1551+
1552+
let Some(fail_ordering) = Self::match_ordering(cx, fail_order_arg) else { return };
1553+
1554+
if matches!(fail_ordering, sym::Release | sym::AcqRel) {
1555+
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, fail_order_arg.span, |diag| {
1556+
diag.build(&format!(
1557+
"`{method}`'s failure ordering may not be `Release` or `AcqRel`, \
1558+
since a failed `{method}` does not result in a write",
1559+
))
1560+
.span_label(fail_order_arg.span, "invalid failure ordering")
1561+
.help("consider using `Acquire` or `Relaxed` failure ordering instead")
1562+
.emit();
1563+
});
1564+
}
1565+
1566+
let Some(success_ordering) = Self::match_ordering(cx, success_order_arg) else { return };
1567+
1568+
if matches!(
1569+
(success_ordering, fail_ordering),
1570+
(sym::Relaxed | sym::Release, sym::Acquire)
1571+
| (sym::Relaxed | sym::Release | sym::Acquire | sym::AcqRel, sym::SeqCst)
1572+
) {
1573+
let success_suggestion =
1574+
if success_ordering == sym::Release && fail_ordering == sym::Acquire {
1575+
sym::AcqRel
1576+
} else {
1577+
fail_ordering
1578+
};
1579+
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, success_order_arg.span, |diag| {
1580+
diag.build(&format!(
1581+
"`{method}`'s success ordering must be at least as strong as its failure ordering"
1582+
))
1583+
.span_label(fail_order_arg.span, format!("`{fail_ordering}` failure ordering"))
1584+
.span_label(success_order_arg.span, format!("`{success_ordering}` success ordering"))
1585+
.span_suggestion_short(
1586+
success_order_arg.span,
1587+
format!("consider using `{success_suggestion}` success ordering instead"),
1588+
format!("std::sync::atomic::Ordering::{success_suggestion}"),
1589+
Applicability::MaybeIncorrect,
1590+
)
1591+
.emit();
1592+
});
16091593
}
16101594
}
16111595
}

compiler/rustc_middle/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub enum ObligationCauseCode<'tcx> {
406406
QuestionMark,
407407

408408
/// Well-formed checking. If a `WellFormedLoc` is provided,
409-
/// then it will be used to eprform HIR-based wf checking
409+
/// then it will be used to perform HIR-based wf checking
410410
/// after an error occurs, in order to generate a more precise error span.
411411
/// This is purely for diagnostic purposes - it is always
412412
/// correct to use `MiscObligation` instead, or to specify

compiler/rustc_typeck/src/check/wfcheck.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,15 @@ fn check_type_defn<'tcx, F>(
990990
let packed = tcx.adt_def(item.def_id).repr().packed();
991991

992992
for variant in &variants {
993+
// All field types must be well-formed.
994+
for field in &variant.fields {
995+
fcx.register_wf_obligation(
996+
field.ty.into(),
997+
field.span,
998+
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(field.def_id))),
999+
)
1000+
}
1001+
9931002
// For DST, or when drop needs to copy things around, all
9941003
// intermediate types must be sized.
9951004
let needs_drop_copy = || {
@@ -1006,6 +1015,7 @@ fn check_type_defn<'tcx, F>(
10061015
}
10071016
}
10081017
};
1018+
// All fields (except for possibly the last) should be sized.
10091019
let all_sized = all_sized || variant.fields.is_empty() || needs_drop_copy();
10101020
let unsized_len = if all_sized { 0 } else { 1 };
10111021
for (idx, field) in
@@ -1030,15 +1040,6 @@ fn check_type_defn<'tcx, F>(
10301040
);
10311041
}
10321042

1033-
// All field types must be well-formed.
1034-
for field in &variant.fields {
1035-
fcx.register_wf_obligation(
1036-
field.ty.into(),
1037-
field.span,
1038-
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(field.def_id))),
1039-
)
1040-
}
1041-
10421043
// Explicit `enum` discriminant values must const-evaluate successfully.
10431044
if let Some(discr_def_id) = variant.explicit_discr {
10441045
let discr_substs = InternalSubsts::identity_for_item(tcx, discr_def_id.to_def_id());

library/core/src/num/nonzero.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ macro_rules! nonzero_leading_trailing_zeros {
213213
without modifying the original"]
214214
#[inline]
215215
pub const fn leading_zeros(self) -> u32 {
216-
// SAFETY: since `self` can not be zero it is safe to call ctlz_nonzero
216+
// SAFETY: since `self` cannot be zero, it is safe to call `ctlz_nonzero`.
217217
unsafe { intrinsics::ctlz_nonzero(self.0 as $Uint) as u32 }
218218
}
219219

@@ -237,7 +237,7 @@ macro_rules! nonzero_leading_trailing_zeros {
237237
without modifying the original"]
238238
#[inline]
239239
pub const fn trailing_zeros(self) -> u32 {
240-
// SAFETY: since `self` can not be zero it is safe to call cttz_nonzero
240+
// SAFETY: since `self` cannot be zero, it is safe to call `cttz_nonzero`.
241241
unsafe { intrinsics::cttz_nonzero(self.0 as $Uint) as u32 }
242242
}
243243

src/bootstrap/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
160160
// files in the tarball are in the past, so it doesn't trigger a
161161
// rebuild.
162162
let now = filetime::FileTime::from_system_time(std::time::SystemTime::now());
163-
let llvm_config = llvm_root.join("bin/llvm-config");
163+
let llvm_config = llvm_root.join("bin").join(exe("llvm-config", builder.config.build));
164164
t!(filetime::set_file_times(&llvm_config, now, now));
165165

166166
let llvm_lib = llvm_root.join("lib");

src/test/ui/chalkify/bugs/async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: unknown
33
// compile-flags: -Z chalk --edition=2021
44

55
fn main() -> () {}

src/test/ui/generic-associated-types/bugs/issue-80626.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #80626
33

44
// This should pass, but it requires `Sized` to be coinductive.
55

src/test/ui/generic-associated-types/bugs/issue-80626.stderr

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ error[E0275]: overflow evaluating the requirement `LinkedList<A>: Sized`
44
LL | Next(A::Allocated<Self>)
55
| ^^^^^^^^^^^^^^^^^^
66
|
7-
= note: no field of an enum variant may have a dynamically sized type
8-
= help: change the field's type to have a statically known size
9-
help: borrowed types always have a statically known size
7+
note: required by a bound in `Allocator::Allocated`
8+
--> $DIR/issue-80626.rs:9:20
109
|
11-
LL | Next(&A::Allocated<Self>)
12-
| +
13-
help: the `Box` type always has a statically known size and allocates its contents in the heap
14-
|
15-
LL | Next(Box<A::Allocated<Self>>)
16-
| ++++ +
10+
LL | type Allocated<T>;
11+
| ^ required by this bound in `Allocator::Allocated`
1712

1813
error: aborting due to previous error
1914

src/test/ui/generic-associated-types/bugs/issue-86218.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #86218
33

44
// This should pass, but seems to run into a TAIT issue.
55

src/test/ui/generic-associated-types/bugs/issue-87735.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #87735, #88526
33

44
// This should pass, but we need an extension of implied bounds (probably).
55

src/test/ui/generic-associated-types/bugs/issue-87748.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #87748
33

44
// This should pass, but unnormalized input args aren't treated as implied.
55

src/test/ui/generic-associated-types/bugs/issue-87755.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #87755
33

44
// This should pass.
55

src/test/ui/generic-associated-types/bugs/issue-87803.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #87803
33

44
// This should pass, but using a type alias vs a reference directly
55
// changes late-bound -> early-bound.

src/test/ui/generic-associated-types/bugs/issue-88382.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #88382
33

44
// This should pass, but has a missed normalization due to HRTB.
55

src/test/ui/generic-associated-types/bugs/issue-88460.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #88460
33

44
// This should pass, but has a missed normalization due to HRTB.
55

src/test/ui/generic-associated-types/bugs/issue-88526.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #88526
33

44
// This should pass, but requires more logic.
55

src/test/ui/generic-associated-types/bugs/issue-89008.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// check-fail
22
// edition:2021
3-
// known-bug
3+
// known-bug: #88908
44

55
// This should pass, but seems to run into a TAIT bug.
66

src/test/ui/hrtb/issue-95034.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// known-bug
1+
// known-bug: #95034
22
// failure-status: 101
33
// compile-flags: --edition=2021 --crate-type=lib
44
// rustc-env:RUST_BACKTRACE=0

src/test/ui/issues/issue-47511.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-fail
2-
// known-bug
2+
// known-bug: #47511
33

44
// Regression test for #47511: anonymous lifetimes can appear
55
// unconstrained in a return type, but only if they appear just once

0 commit comments

Comments
 (0)