Skip to content
/ rust Public
forked from rust-lang/rust

Commit 19a647d

Browse files
committed
Auto merge of rust-lang#114646 - matthiaskrgr:rollup-xf7qnmn, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#113939 (open pidfd in child process and send to the parent via SOCK_SEQPACKET+CMSG) - rust-lang#114548 (Migrate a trait selection error to use diagnostic translation) - rust-lang#114606 (fix: not insert missing lifetime for `ConstParamTy`) - rust-lang#114634 (Mention riscv64-linux-android support in Android documentation) - rust-lang#114638 (Remove old RPITIT tests (revisions were removed)) - rust-lang#114641 (Rename copying `ascii::Char` methods from `as_` to `to_`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8838c73 + 83da317 commit 19a647d

File tree

84 files changed

+272
-1625
lines changed

Some content is hidden

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

84 files changed

+272
-1625
lines changed

compiler/rustc_middle/src/ty/closure.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::fmt::Write;
77

88
use crate::query::Providers;
99
use rustc_data_structures::fx::FxIndexMap;
10+
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
1011
use rustc_hir::def_id::{DefId, LocalDefId};
1112
use rustc_hir::{self as hir, LangItem};
1213
use rustc_span::def_id::LocalDefIdMap;
@@ -89,10 +90,18 @@ pub enum ClosureKind {
8990
FnOnce,
9091
}
9192

92-
impl<'tcx> ClosureKind {
93+
impl ClosureKind {
9394
/// This is the initial value used when doing upvar inference.
9495
pub const LATTICE_BOTTOM: ClosureKind = ClosureKind::Fn;
9596

97+
pub const fn as_str(self) -> &'static str {
98+
match self {
99+
ClosureKind::Fn => "Fn",
100+
ClosureKind::FnMut => "FnMut",
101+
ClosureKind::FnOnce => "FnOnce",
102+
}
103+
}
104+
96105
/// Returns `true` if a type that impls this closure kind
97106
/// must also implement `other`.
98107
pub fn extends(self, other: ty::ClosureKind) -> bool {
@@ -115,7 +124,7 @@ impl<'tcx> ClosureKind {
115124

116125
/// Returns the representative scalar type for this closure kind.
117126
/// See `Ty::to_opt_closure_kind` for more details.
118-
pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
127+
pub fn to_ty<'tcx>(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
119128
match self {
120129
ClosureKind::Fn => tcx.types.i8,
121130
ClosureKind::FnMut => tcx.types.i16,
@@ -124,6 +133,12 @@ impl<'tcx> ClosureKind {
124133
}
125134
}
126135

136+
impl IntoDiagnosticArg for ClosureKind {
137+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
138+
DiagnosticArgValue::Str(self.as_str().into())
139+
}
140+
}
141+
127142
/// A composite describing a `Place` that is captured by a closure.
128143
#[derive(PartialEq, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
129144
#[derive(TypeFoldable, TypeVisitable)]

compiler/rustc_middle/src/ty/print/pretty.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2875,11 +2875,7 @@ define_print_and_forward_display! {
28752875
}
28762876

28772877
ty::ClosureKind {
2878-
match *self {
2879-
ty::ClosureKind::Fn => p!("Fn"),
2880-
ty::ClosureKind::FnMut => p!("FnMut"),
2881-
ty::ClosureKind::FnOnce => p!("FnOnce"),
2882-
}
2878+
p!(write("{}", self.as_str()))
28832879
}
28842880

28852881
ty::Predicate<'tcx> {

compiler/rustc_resolve/src/late/diagnostics.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
24042404
should_continue = suggest(err, false, span, message, sugg);
24052405
}
24062406
}
2407-
LifetimeRibKind::Item => break,
2407+
LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break,
24082408
_ => {}
24092409
}
24102410
if !should_continue {
@@ -2510,7 +2510,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
25102510
.lifetime_ribs
25112511
.iter()
25122512
.rev()
2513-
.take_while(|rib| !matches!(rib.kind, LifetimeRibKind::Item))
2513+
.take_while(|rib| {
2514+
!matches!(rib.kind, LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy)
2515+
})
25142516
.flat_map(|rib| rib.bindings.iter())
25152517
.map(|(&ident, &res)| (ident, res))
25162518
.filter(|(ident, _)| ident.name != kw::UnderscoreLifetime)

compiler/rustc_trait_selection/messages.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ trait_selection_adjust_signature_remove_borrow = consider adjusting the signatur
88
*[other] arguments
99
}
1010
11+
trait_selection_closure_fn_mut_label = closure is `FnMut` because it mutates the variable `{$place}` here
12+
13+
trait_selection_closure_fn_once_label = closure is `FnOnce` because it moves the variable `{$place}` out of its environment
14+
15+
trait_selection_closure_kind_mismatch = expected a closure that implements the `{$expected}` trait, but this closure only implements `{$found}`
16+
.label = this closure implements `{$found}`, not `{$expected}`
17+
18+
trait_selection_closure_kind_requirement = the requirement to implement `{$expected}` derives from here
19+
1120
trait_selection_dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries}
1221
1322
trait_selection_empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]`

compiler/rustc_trait_selection/src/errors.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::{
44
SubdiagnosticMessage,
55
};
66
use rustc_macros::Diagnostic;
7-
use rustc_middle::ty::{self, PolyTraitRef, Ty};
7+
use rustc_middle::ty::{self, ClosureKind, PolyTraitRef, Ty};
88
use rustc_span::{Span, Symbol};
99

1010
#[derive(Diagnostic)]
@@ -131,3 +131,37 @@ impl AddToDiagnostic for AdjustSignatureBorrow {
131131
}
132132
}
133133
}
134+
135+
#[derive(Diagnostic)]
136+
#[diag(trait_selection_closure_kind_mismatch, code = "E0525")]
137+
pub struct ClosureKindMismatch {
138+
#[primary_span]
139+
#[label]
140+
pub closure_span: Span,
141+
pub expected: ClosureKind,
142+
pub found: ClosureKind,
143+
#[label(trait_selection_closure_kind_requirement)]
144+
pub cause_span: Span,
145+
146+
#[subdiagnostic]
147+
pub fn_once_label: Option<ClosureFnOnceLabel>,
148+
149+
#[subdiagnostic]
150+
pub fn_mut_label: Option<ClosureFnMutLabel>,
151+
}
152+
153+
#[derive(Subdiagnostic)]
154+
#[label(trait_selection_closure_fn_once_label)]
155+
pub struct ClosureFnOnceLabel {
156+
#[primary_span]
157+
pub span: Span,
158+
pub place: String,
159+
}
160+
161+
#[derive(Subdiagnostic)]
162+
#[label(trait_selection_closure_fn_mut_label)]
163+
pub struct ClosureFnMutLabel {
164+
#[primary_span]
165+
pub span: Span,
166+
pub place: String,
167+
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+17-33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::{
77
ObligationCauseCode, ObligationCtxt, OutputTypeParameterMismatch, Overflow,
88
PredicateObligation, SelectionError, TraitNotObjectSafe,
99
};
10+
use crate::errors::{ClosureFnMutLabel, ClosureFnOnceLabel, ClosureKindMismatch};
1011
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
1112
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1213
use crate::infer::{self, InferCtxt};
@@ -3121,55 +3122,38 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31213122
kind: ty::ClosureKind,
31223123
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
31233124
let closure_span = self.tcx.def_span(closure_def_id);
3124-
let mut err = struct_span_err!(
3125-
self.tcx.sess,
3126-
closure_span,
3127-
E0525,
3128-
"expected a closure that implements the `{}` trait, \
3129-
but this closure only implements `{}`",
3130-
kind,
3131-
found_kind
3132-
);
31333125

3134-
err.span_label(
3126+
let mut err = ClosureKindMismatch {
31353127
closure_span,
3136-
format!("this closure implements `{found_kind}`, not `{kind}`"),
3137-
);
3138-
err.span_label(
3139-
obligation.cause.span,
3140-
format!("the requirement to implement `{kind}` derives from here"),
3141-
);
3128+
expected: kind,
3129+
found: found_kind,
3130+
cause_span: obligation.cause.span,
3131+
fn_once_label: None,
3132+
fn_mut_label: None,
3133+
};
31423134

31433135
// Additional context information explaining why the closure only implements
31443136
// a particular trait.
31453137
if let Some(typeck_results) = &self.typeck_results {
31463138
let hir_id = self.tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
31473139
match (found_kind, typeck_results.closure_kind_origins().get(hir_id)) {
31483140
(ty::ClosureKind::FnOnce, Some((span, place))) => {
3149-
err.span_label(
3150-
*span,
3151-
format!(
3152-
"closure is `FnOnce` because it moves the \
3153-
variable `{}` out of its environment",
3154-
ty::place_to_string_for_capture(self.tcx, place)
3155-
),
3156-
);
3141+
err.fn_once_label = Some(ClosureFnOnceLabel {
3142+
span: *span,
3143+
place: ty::place_to_string_for_capture(self.tcx, &place),
3144+
})
31573145
}
31583146
(ty::ClosureKind::FnMut, Some((span, place))) => {
3159-
err.span_label(
3160-
*span,
3161-
format!(
3162-
"closure is `FnMut` because it mutates the \
3163-
variable `{}` here",
3164-
ty::place_to_string_for_capture(self.tcx, place)
3165-
),
3166-
);
3147+
err.fn_mut_label = Some(ClosureFnMutLabel {
3148+
span: *span,
3149+
place: ty::place_to_string_for_capture(self.tcx, &place),
3150+
})
31673151
}
31683152
_ => {}
31693153
}
31703154
}
31713155

3172-
err
3156+
self.tcx.sess.create_err(err)
31733157
}
31743158

31753159
fn report_type_parameter_mismatch_cyclic_type_error(

library/core/src/ascii/ascii_char.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,14 @@ impl AsciiChar {
518518
/// Gets this ASCII character as a byte.
519519
#[unstable(feature = "ascii_char", issue = "110998")]
520520
#[inline]
521-
pub const fn as_u8(self) -> u8 {
521+
pub const fn to_u8(self) -> u8 {
522522
self as u8
523523
}
524524

525525
/// Gets this ASCII character as a `char` Unicode Scalar Value.
526526
#[unstable(feature = "ascii_char", issue = "110998")]
527527
#[inline]
528-
pub const fn as_char(self) -> char {
528+
pub const fn to_char(self) -> char {
529529
self as u8 as char
530530
}
531531

library/core/src/escape.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ impl<const N: usize> EscapeIterInner<N> {
9595
}
9696

9797
pub fn next(&mut self) -> Option<u8> {
98-
self.alive.next().map(|i| self.data[usize::from(i)].as_u8())
98+
self.alive.next().map(|i| self.data[usize::from(i)].to_u8())
9999
}
100100

101101
pub fn next_back(&mut self) -> Option<u8> {
102-
self.alive.next_back().map(|i| self.data[usize::from(i)].as_u8())
102+
self.alive.next_back().map(|i| self.data[usize::from(i)].to_u8())
103103
}
104104

105105
pub fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {

0 commit comments

Comments
 (0)