Skip to content

Commit 7716d1a

Browse files
committed
Auto merge of rust-lang#126949 - compiler-errors:rollup-2ma9x7n, r=compiler-errors
Rollup of 9 pull requests Successful merges: - rust-lang#126326 (Un-unsafe the `StableOrd` trait) - rust-lang#126618 (Mark assoc tys live only if the corresponding trait is live) - rust-lang#126724 (Fix a span in `parse_ty_bare_fn`.) - rust-lang#126746 (Deny `use<>` for RPITITs) - rust-lang#126868 (not use offset when there is not ends with brace) - rust-lang#126884 (Do not ICE when suggesting dereferencing closure arg) - rust-lang#126915 (Don't suggest awaiting in closure patterns) - rust-lang#126916 (Specify target specific linker for `riscv64gc-gnu` job) - rust-lang#126926 (Tweak a confusing comment in `create_match_candidates`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d929a42 + a765000 commit 7716d1a

File tree

46 files changed

+530
-129
lines changed

Some content is hidden

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

46 files changed

+530
-129
lines changed

Diff for: compiler/rustc_abi/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,13 @@ pub struct Size {
427427
raw: u64,
428428
}
429429

430-
// Safety: Ord is implement as just comparing numerical values and numerical values
431-
// are not changed by (de-)serialization.
432430
#[cfg(feature = "nightly")]
433-
unsafe impl StableOrd for Size {
431+
impl StableOrd for Size {
434432
const CAN_USE_UNSTABLE_SORT: bool = true;
433+
434+
// `Ord` is implemented as just comparing numerical values and numerical values
435+
// are not changed by (de-)serialization.
436+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
435437
}
436438

437439
// This is debug-printed a lot in larger structs, don't waste too much space there

Diff for: compiler/rustc_ast/src/ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,8 @@ pub struct BareFnTy {
21262126
pub ext: Extern,
21272127
pub generic_params: ThinVec<GenericParam>,
21282128
pub decl: P<FnDecl>,
2129-
/// Span of the `fn(...) -> ...` part.
2129+
/// Span of the `[unsafe] [extern] fn(...) -> ...` part, i.e. everything
2130+
/// after the generic params (if there are any, e.g. `for<'a>`).
21302131
pub decl_span: Span,
21312132
}
21322133

Diff for: compiler/rustc_ast_lowering/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ ast_lowering_never_pattern_with_guard =
130130
131131
ast_lowering_no_precise_captures_on_apit = `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
132132
133+
ast_lowering_no_precise_captures_on_rpitit = `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
134+
.note = currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
135+
133136
ast_lowering_previously_used_here = previously used here
134137
135138
ast_lowering_register1 = register `{$reg1_name}`

Diff for: compiler/rustc_ast_lowering/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ pub(crate) struct NoPreciseCapturesOnApit {
424424
pub span: Span,
425425
}
426426

427+
#[derive(Diagnostic)]
428+
#[diag(ast_lowering_no_precise_captures_on_rpitit)]
429+
#[note]
430+
pub(crate) struct NoPreciseCapturesOnRpitit {
431+
#[primary_span]
432+
pub span: Span,
433+
}
434+
427435
#[derive(Diagnostic)]
428436
#[diag(ast_lowering_yield_in_closure)]
429437
pub(crate) struct YieldInClosure {

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15941594
};
15951595
debug!(?captured_lifetimes_to_duplicate);
15961596

1597+
match fn_kind {
1598+
// Deny `use<>` on RPITIT in trait/trait-impl for now.
1599+
Some(FnDeclKind::Trait | FnDeclKind::Impl) => {
1600+
if let Some(span) = bounds.iter().find_map(|bound| match *bound {
1601+
ast::GenericBound::Use(_, span) => Some(span),
1602+
_ => None,
1603+
}) {
1604+
self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnRpitit { span });
1605+
}
1606+
}
1607+
None
1608+
| Some(
1609+
FnDeclKind::Fn
1610+
| FnDeclKind::Inherent
1611+
| FnDeclKind::ExternFn
1612+
| FnDeclKind::Closure
1613+
| FnDeclKind::Pointer,
1614+
) => {}
1615+
}
1616+
15971617
self.lower_opaque_inner(
15981618
opaque_ty_node_id,
15991619
origin,

Diff for: compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,9 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
11511151
// Get the arguments for the found method, only specifying that `Self` is the receiver type.
11521152
let Some(possible_rcvr_ty) = typeck_results.node_type_opt(rcvr.hir_id) else { return };
11531153
let args = GenericArgs::for_item(tcx, method_def_id, |param, _| {
1154-
if param.index == 0 {
1154+
if let ty::GenericParamDefKind::Lifetime = param.kind {
1155+
tcx.lifetimes.re_erased.into()
1156+
} else if param.index == 0 && param.name == kw::SelfUpper {
11551157
possible_rcvr_ty.into()
11561158
} else if param.index == closure_param.index {
11571159
closure_ty.into()
@@ -1168,7 +1170,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> {
11681170
Obligation::misc(tcx, span, self.mir_def_id(), self.param_env, pred)
11691171
}));
11701172

1171-
if ocx.select_all_or_error().is_empty() {
1173+
if ocx.select_all_or_error().is_empty() && count > 0 {
11721174
diag.span_suggestion_verbose(
11731175
tcx.hir().body(*body).value.peel_blocks().span.shrink_to_lo(),
11741176
"dereference the return value",

Diff for: compiler/rustc_data_structures/src/stable_hasher.rs

+54-17
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,21 @@ pub trait ToStableHashKey<HCX> {
238238
/// The associated constant `CAN_USE_UNSTABLE_SORT` denotes whether
239239
/// unstable sorting can be used for this type. Set to true if and
240240
/// only if `a == b` implies `a` and `b` are fully indistinguishable.
241-
pub unsafe trait StableOrd: Ord {
241+
pub trait StableOrd: Ord {
242242
const CAN_USE_UNSTABLE_SORT: bool;
243+
244+
/// Marker to ensure that implementors have carefully considered
245+
/// whether their `Ord` implementation obeys this trait's contract.
246+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: ();
243247
}
244248

245-
unsafe impl<T: StableOrd> StableOrd for &T {
249+
impl<T: StableOrd> StableOrd for &T {
246250
const CAN_USE_UNSTABLE_SORT: bool = T::CAN_USE_UNSTABLE_SORT;
251+
252+
// Ordering of a reference is exactly that of the referent, and since
253+
// the ordering of the referet is stable so must be the ordering of the
254+
// reference.
255+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
247256
}
248257

249258
/// This is a companion trait to `StableOrd`. Some types like `Symbol` can be
@@ -290,8 +299,12 @@ macro_rules! impl_stable_traits_for_trivial_type {
290299
}
291300
}
292301

293-
unsafe impl $crate::stable_hasher::StableOrd for $t {
302+
impl $crate::stable_hasher::StableOrd for $t {
294303
const CAN_USE_UNSTABLE_SORT: bool = true;
304+
305+
// Encoding and decoding doesn't change the bytes of trivial types
306+
// and `Ord::cmp` depends only on those bytes.
307+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
295308
}
296309
};
297310
}
@@ -327,8 +340,12 @@ impl<CTX> HashStable<CTX> for Hash128 {
327340
}
328341
}
329342

330-
unsafe impl StableOrd for Hash128 {
343+
impl StableOrd for Hash128 {
331344
const CAN_USE_UNSTABLE_SORT: bool = true;
345+
346+
// Encoding and decoding doesn't change the bytes of `Hash128`
347+
// and `Ord::cmp` depends only on those bytes.
348+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
332349
}
333350

334351
impl<CTX> HashStable<CTX> for ! {
@@ -392,8 +409,12 @@ impl<T1: HashStable<CTX>, T2: HashStable<CTX>, CTX> HashStable<CTX> for (T1, T2)
392409
}
393410
}
394411

395-
unsafe impl<T1: StableOrd, T2: StableOrd> StableOrd for (T1, T2) {
412+
impl<T1: StableOrd, T2: StableOrd> StableOrd for (T1, T2) {
396413
const CAN_USE_UNSTABLE_SORT: bool = T1::CAN_USE_UNSTABLE_SORT && T2::CAN_USE_UNSTABLE_SORT;
414+
415+
// Ordering of tuples is a pure function of their elements' ordering, and since
416+
// the ordering of each element is stable so must be the ordering of the tuple.
417+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
397418
}
398419

399420
impl<T1, T2, T3, CTX> HashStable<CTX> for (T1, T2, T3)
@@ -410,9 +431,13 @@ where
410431
}
411432
}
412433

413-
unsafe impl<T1: StableOrd, T2: StableOrd, T3: StableOrd> StableOrd for (T1, T2, T3) {
434+
impl<T1: StableOrd, T2: StableOrd, T3: StableOrd> StableOrd for (T1, T2, T3) {
414435
const CAN_USE_UNSTABLE_SORT: bool =
415436
T1::CAN_USE_UNSTABLE_SORT && T2::CAN_USE_UNSTABLE_SORT && T3::CAN_USE_UNSTABLE_SORT;
437+
438+
// Ordering of tuples is a pure function of their elements' ordering, and since
439+
// the ordering of each element is stable so must be the ordering of the tuple.
440+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
416441
}
417442

418443
impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4)
@@ -431,13 +456,15 @@ where
431456
}
432457
}
433458

434-
unsafe impl<T1: StableOrd, T2: StableOrd, T3: StableOrd, T4: StableOrd> StableOrd
435-
for (T1, T2, T3, T4)
436-
{
459+
impl<T1: StableOrd, T2: StableOrd, T3: StableOrd, T4: StableOrd> StableOrd for (T1, T2, T3, T4) {
437460
const CAN_USE_UNSTABLE_SORT: bool = T1::CAN_USE_UNSTABLE_SORT
438461
&& T2::CAN_USE_UNSTABLE_SORT
439462
&& T3::CAN_USE_UNSTABLE_SORT
440463
&& T4::CAN_USE_UNSTABLE_SORT;
464+
465+
// Ordering of tuples is a pure function of their elements' ordering, and since
466+
// the ordering of each element is stable so must be the ordering of the tuple.
467+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
441468
}
442469

443470
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for [T] {
@@ -530,8 +557,12 @@ impl<CTX> HashStable<CTX> for str {
530557
}
531558
}
532559

533-
unsafe impl StableOrd for &str {
560+
impl StableOrd for &str {
534561
const CAN_USE_UNSTABLE_SORT: bool = true;
562+
563+
// Encoding and decoding doesn't change the bytes of string slices
564+
// and `Ord::cmp` depends only on those bytes.
565+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
535566
}
536567

537568
impl<CTX> HashStable<CTX> for String {
@@ -541,10 +572,12 @@ impl<CTX> HashStable<CTX> for String {
541572
}
542573
}
543574

544-
// Safety: String comparison only depends on their contents and the
545-
// contents are not changed by (de-)serialization.
546-
unsafe impl StableOrd for String {
575+
impl StableOrd for String {
547576
const CAN_USE_UNSTABLE_SORT: bool = true;
577+
578+
// String comparison only depends on their contents and the
579+
// contents are not changed by (de-)serialization.
580+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
548581
}
549582

550583
impl<HCX> ToStableHashKey<HCX> for String {
@@ -570,9 +603,11 @@ impl<CTX> HashStable<CTX> for bool {
570603
}
571604
}
572605

573-
// Safety: sort order of bools is not changed by (de-)serialization.
574-
unsafe impl StableOrd for bool {
606+
impl StableOrd for bool {
575607
const CAN_USE_UNSTABLE_SORT: bool = true;
608+
609+
// sort order of bools is not changed by (de-)serialization.
610+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
576611
}
577612

578613
impl<T, CTX> HashStable<CTX> for Option<T>
@@ -590,9 +625,11 @@ where
590625
}
591626
}
592627

593-
// Safety: the Option wrapper does not add instability to comparison.
594-
unsafe impl<T: StableOrd> StableOrd for Option<T> {
628+
impl<T: StableOrd> StableOrd for Option<T> {
595629
const CAN_USE_UNSTABLE_SORT: bool = T::CAN_USE_UNSTABLE_SORT;
630+
631+
// the Option wrapper does not add instability to comparison.
632+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
596633
}
597634

598635
impl<T1, T2, CTX> HashStable<CTX> for Result<T1, T2>

Diff for: compiler/rustc_hir/src/hir_id.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,12 @@ impl ItemLocalId {
165165
pub const INVALID: ItemLocalId = ItemLocalId::MAX;
166166
}
167167

168-
// Safety: Ord is implement as just comparing the ItemLocalId's numerical
169-
// values and these are not changed by (de-)serialization.
170-
unsafe impl StableOrd for ItemLocalId {
168+
impl StableOrd for ItemLocalId {
171169
const CAN_USE_UNSTABLE_SORT: bool = true;
170+
171+
// `Ord` is implemented as just comparing the ItemLocalId's numerical
172+
// values and these are not changed by (de-)serialization.
173+
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
172174
}
173175

174176
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,18 @@ fn missing_items_err(
211211
.collect::<Vec<_>>()
212212
.join("`, `");
213213

214-
// `Span` before impl block closing brace.
215-
let hi = full_impl_span.hi() - BytePos(1);
216-
// Point at the place right before the closing brace of the relevant `impl` to suggest
217-
// adding the associated item at the end of its body.
218-
let sugg_sp = full_impl_span.with_lo(hi).with_hi(hi);
214+
let sugg_sp = if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(full_impl_span)
215+
&& snippet.ends_with("}")
216+
{
217+
// `Span` before impl block closing brace.
218+
let hi = full_impl_span.hi() - BytePos(1);
219+
// Point at the place right before the closing brace of the relevant `impl` to suggest
220+
// adding the associated item at the end of its body.
221+
full_impl_span.with_lo(hi).with_hi(hi)
222+
} else {
223+
full_impl_span.shrink_to_hi()
224+
};
225+
219226
// Obtain the level of indentation ending in `sugg_sp`.
220227
let padding =
221228
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());

Diff for: compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
209209
}
210210
(Some(ty), _) if self.same_type_modulo_infer(ty, exp_found.found) => match cause.code()
211211
{
212-
ObligationCauseCode::Pattern { span: Some(then_span), .. } => {
213-
Some(ConsiderAddingAwait::FutureSugg { span: then_span.shrink_to_hi() })
212+
ObligationCauseCode::Pattern { span: Some(then_span), origin_expr, .. } => {
213+
origin_expr.then_some(ConsiderAddingAwait::FutureSugg {
214+
span: then_span.shrink_to_hi(),
215+
})
214216
}
215217
ObligationCauseCode::IfExpression(box IfExpressionCause { then_id, .. }) => {
216218
let then_span = self.find_block_span_from_hir_id(*then_id);

Diff for: compiler/rustc_mir_build/src/build/matches/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
358358
where
359359
'a: 'pat,
360360
{
361-
// Assemble a list of candidates: there is one candidate per pattern,
362-
// which means there may be more than one candidate *per arm*.
361+
// Assemble the initial list of candidates. These top-level candidates
362+
// are 1:1 with the original match arms, but other parts of match
363+
// lowering also introduce subcandidates (for subpatterns), and will
364+
// also flatten candidates in some cases. So in general a list of
365+
// candidates does _not_ necessarily correspond to a list of arms.
363366
arms.iter()
364367
.copied()
365368
.map(|arm| {

Diff for: compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl<'a> Parser<'a> {
608608
self.dcx().emit_err(FnPointerCannotBeAsync { span: whole_span, qualifier: span });
609609
}
610610
// FIXME(gen_blocks): emit a similar error for `gen fn()`
611-
let decl_span = span_start.to(self.token.span);
611+
let decl_span = span_start.to(self.prev_token.span);
612612
Ok(TyKind::BareFn(P(BareFnTy { ext, safety, generic_params: params, decl, decl_span })))
613613
}
614614

0 commit comments

Comments
 (0)