Skip to content

Commit 88f3114

Browse files
committed
Auto merge of rust-lang#131724 - matthiaskrgr:rollup-ntgkkk8, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#130608 (Implemented `FromStr` for `CString` and `TryFrom<CString>` for `String`) - rust-lang#130635 (Add `&pin (mut|const) T` type position sugar) - rust-lang#130747 (improve error messages for `C-cmse-nonsecure-entry` functions) - rust-lang#131137 (Add 1.82 release notes) - rust-lang#131328 (Remove unnecessary sorts in `rustc_hir_analysis`) - rust-lang#131496 (Stabilise `const_make_ascii`.) - rust-lang#131706 (Fix two const-hacks) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 785c830 + 83252bd commit 88f3114

File tree

50 files changed

+1125
-184
lines changed

Some content is hidden

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

50 files changed

+1125
-184
lines changed

RELEASES.md

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

compiler/rustc_ast/src/ast.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{cmp, fmt, mem};
2323

2424
pub use GenericArgs::*;
2525
pub use UnsafeSource::*;
26-
pub use rustc_ast_ir::{Movability, Mutability};
26+
pub use rustc_ast_ir::{Movability, Mutability, Pinnedness};
2727
use rustc_data_structures::packed::Pu128;
2828
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2929
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -2161,6 +2161,10 @@ pub enum TyKind {
21612161
Ptr(MutTy),
21622162
/// A reference (`&'a T` or `&'a mut T`).
21632163
Ref(Option<Lifetime>, MutTy),
2164+
/// A pinned reference (`&'a pin const T` or `&'a pin mut T`).
2165+
///
2166+
/// Desugars into `Pin<&'a T>` or `Pin<&'a mut T>`.
2167+
PinnedRef(Option<Lifetime>, MutTy),
21642168
/// A bare function (e.g., `fn(usize) -> bool`).
21652169
BareFn(P<BareFnTy>),
21662170
/// The never type (`!`).
@@ -2501,7 +2505,10 @@ impl Param {
25012505
if ident.name == kw::SelfLower {
25022506
return match self.ty.kind {
25032507
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
2504-
TyKind::Ref(lt, MutTy { ref ty, mutbl }) if ty.kind.is_implicit_self() => {
2508+
TyKind::Ref(lt, MutTy { ref ty, mutbl })
2509+
| TyKind::PinnedRef(lt, MutTy { ref ty, mutbl })
2510+
if ty.kind.is_implicit_self() =>
2511+
{
25052512
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
25062513
}
25072514
_ => Some(respan(

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub fn walk_ty<T: MutVisitor>(vis: &mut T, ty: &mut P<Ty>) {
485485
}
486486
TyKind::Slice(ty) => vis.visit_ty(ty),
487487
TyKind::Ptr(mt) => vis.visit_mt(mt),
488-
TyKind::Ref(lt, mt) => {
488+
TyKind::Ref(lt, mt) | TyKind::PinnedRef(lt, mt) => {
489489
visit_opt(lt, |lt| vis.visit_lifetime(lt));
490490
vis.visit_mt(mt);
491491
}

compiler/rustc_ast/src/util/classify.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
247247
break (mac.args.delim == Delimiter::Brace).then_some(mac);
248248
}
249249

250-
ast::TyKind::Ptr(mut_ty) | ast::TyKind::Ref(_, mut_ty) => {
250+
ast::TyKind::Ptr(mut_ty)
251+
| ast::TyKind::Ref(_, mut_ty)
252+
| ast::TyKind::PinnedRef(_, mut_ty) => {
251253
ty = &mut_ty.ty;
252254
}
253255

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) -> V::Result {
499499
match kind {
500500
TyKind::Slice(ty) | TyKind::Paren(ty) => try_visit!(visitor.visit_ty(ty)),
501501
TyKind::Ptr(MutTy { ty, mutbl: _ }) => try_visit!(visitor.visit_ty(ty)),
502-
TyKind::Ref(opt_lifetime, MutTy { ty, mutbl: _ }) => {
502+
TyKind::Ref(opt_lifetime, MutTy { ty, mutbl: _ })
503+
| TyKind::PinnedRef(opt_lifetime, MutTy { ty, mutbl: _ }) => {
503504
visit_opt!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Ref);
504505
try_visit!(visitor.visit_ty(ty));
505506
}

compiler/rustc_ast_ir/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,10 @@ impl Mutability {
7979
matches!(self, Self::Not)
8080
}
8181
}
82+
83+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
84+
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))]
85+
pub enum Pinnedness {
86+
Not,
87+
Pinned,
88+
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
640640
self.lower_span(span),
641641
Some(self.allow_gen_future.clone()),
642642
);
643-
let resume_ty = self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span);
643+
let resume_ty =
644+
self.make_lang_item_qpath(hir::LangItem::ResumeTy, unstable_span, None);
644645
let input_ty = hir::Ty {
645646
hir_id: self.next_id(),
646647
kind: hir::TyKind::Path(resume_ty),
@@ -2065,7 +2066,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20652066
lang_item: hir::LangItem,
20662067
name: Symbol,
20672068
) -> hir::Expr<'hir> {
2068-
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span));
2069+
let qpath = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
20692070
let path = hir::ExprKind::Path(hir::QPath::TypeRelative(
20702071
self.arena.alloc(self.ty(span, hir::TyKind::Path(qpath))),
20712072
self.arena.alloc(hir::PathSegment::new(

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
5555
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5656
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
5757
use rustc_hir::{
58-
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, MissingLifetimeKind, ParamName,
59-
TraitCandidate,
58+
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem, MissingLifetimeKind,
59+
ParamName, TraitCandidate,
6060
};
6161
use rustc_index::{Idx, IndexSlice, IndexVec};
6262
use rustc_macros::extension;
@@ -765,8 +765,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
765765
res
766766
}
767767

768-
fn make_lang_item_qpath(&mut self, lang_item: hir::LangItem, span: Span) -> hir::QPath<'hir> {
769-
hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, None))
768+
fn make_lang_item_qpath(
769+
&mut self,
770+
lang_item: hir::LangItem,
771+
span: Span,
772+
args: Option<&'hir hir::GenericArgs<'hir>>,
773+
) -> hir::QPath<'hir> {
774+
hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, args))
770775
}
771776

772777
fn make_lang_item_path(
@@ -1277,6 +1282,32 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12771282
let lifetime = self.lower_lifetime(&region);
12781283
hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
12791284
}
1285+
TyKind::PinnedRef(region, mt) => {
1286+
let region = region.unwrap_or_else(|| {
1287+
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1288+
self.resolver.get_lifetime_res(t.id)
1289+
{
1290+
debug_assert_eq!(start.plus(1), end);
1291+
start
1292+
} else {
1293+
self.next_node_id()
1294+
};
1295+
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1296+
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
1297+
});
1298+
let lifetime = self.lower_lifetime(&region);
1299+
let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
1300+
let span = self.lower_span(t.span);
1301+
let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1302+
let args = self.arena.alloc(hir::GenericArgs {
1303+
args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1304+
constraints: &[],
1305+
parenthesized: hir::GenericArgsParentheses::No,
1306+
span_ext: span,
1307+
});
1308+
let path = self.make_lang_item_qpath(LangItem::Pin, span, Some(args));
1309+
hir::TyKind::Path(path)
1310+
}
12801311
TyKind::BareFn(f) => {
12811312
let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
12821313
hir::TyKind::BareFn(self.arena.alloc(hir::BareFnTy {
@@ -1845,10 +1876,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18451876
// Given we are only considering `ImplicitSelf` types, we needn't consider
18461877
// the case where we have a mutable pattern to a reference as that would
18471878
// no longer be an `ImplicitSelf`.
1848-
TyKind::Ref(_, mt) if mt.ty.kind.is_implicit_self() => match mt.mutbl {
1849-
hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
1850-
hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
1851-
},
1879+
TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt)
1880+
if mt.ty.kind.is_implicit_self() =>
1881+
{
1882+
match mt.mutbl {
1883+
hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
1884+
hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
1885+
}
1886+
}
18521887
_ => hir::ImplicitSelfKind::None,
18531888
}
18541889
}),

compiler/rustc_ast_lowering/src/lifetime_collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
9595
visit::walk_ty(self, t);
9696
self.current_binders.pop();
9797
}
98-
TyKind::Ref(None, _) => {
98+
TyKind::Ref(None, _) | TyKind::PinnedRef(None, _) => {
9999
self.record_elided_anchor(t.id, t.span);
100100
visit::walk_ty(self, t);
101101
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
546546
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
547547
gate_all!(global_registration, "global registration is experimental");
548548
gate_all!(return_type_notation, "return type notation is experimental");
549+
gate_all!(pin_ergonomics, "pinned reference syntax is experimental");
549550

550551
if !visitor.features.never_patterns {
551552
if let Some(spans) = spans.get(&sym::never_patterns) {

0 commit comments

Comments
 (0)