Skip to content

Commit 98a4878

Browse files
committed
Auto merge of rust-lang#138114 - compiler-errors:rollup-7xr4b69, r=compiler-errors
Rollup of 25 pull requests Successful merges: - rust-lang#135733 (Implement `&pin const self` and `&pin mut self` sugars) - rust-lang#135895 (Document workings of successors more clearly) - rust-lang#136922 (Pattern types: Avoid having to handle an Option for range ends in the type system or the HIR) - rust-lang#137303 (Remove `MaybeForgetReturn` suggestion) - rust-lang#137327 (Undeprecate env::home_dir) - rust-lang#137358 (Match Ergonomics 2024: add context and examples to the unstable book) - rust-lang#137534 ([rustdoc] hide item that is not marked as doc(inline) and whose src is doc(hidden)) - rust-lang#137565 (Try to point of macro expansion from resolver and method errors if it involves macro var) - rust-lang#137637 (Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck) - rust-lang#137643 (Add DWARF test case for non-C-like `repr128` enums) - rust-lang#137744 (Re-add `Clone`-derive on `Thir`) - rust-lang#137758 (fix usage of ty decl macro fragments in attributes) - rust-lang#137764 (Ensure that negative auto impls are always applicable) - rust-lang#137772 (Fix char count in `Display` for `ByteStr`) - rust-lang#137798 (ci: use ubuntu 24 on arm large runner) - rust-lang#137802 (miri native-call support: all previously exposed provenance is accessible to the callee) - rust-lang#137805 (adjust Layout debug printing to match the internal field name) - rust-lang#137808 (Do not require that unsafe fields lack drop glue) - rust-lang#137820 (Clarify why InhabitedPredicate::instantiate_opt exists) - rust-lang#137825 (Provide more context on resolve error caused from incorrect RTN) - rust-lang#137834 (rustc_fluent_macro: use CARGO_CRATE_NAME instead of CARGO_PKG_NAME) - rust-lang#137868 (Add minimal platform support documentation for powerpc-unknown-linux-gnuspe) - rust-lang#137910 (Improve error message for `AsyncFn` trait failure for RPIT) - rust-lang#137920 (interpret/provenance_map: consistently use range_is_empty) - rust-lang#138038 (Update `compiler-builtins` to 0.1.151) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b74da96 + 071bc46 commit 98a4878

File tree

169 files changed

+2253
-1099
lines changed

Some content is hidden

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

169 files changed

+2253
-1099
lines changed

compiler/rustc_abi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ where
18121812
f.debug_struct("Layout")
18131813
.field("size", size)
18141814
.field("align", align)
1815-
.field("abi", backend_repr)
1815+
.field("backend_repr", backend_repr)
18161816
.field("fields", fields)
18171817
.field("largest_niche", largest_niche)
18181818
.field("uninhabited", uninhabited)

compiler/rustc_ast/src/ast.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,8 @@ pub enum SelfKind {
26412641
Value(Mutability),
26422642
/// `&'lt self`, `&'lt mut self`
26432643
Region(Option<Lifetime>, Mutability),
2644+
/// `&'lt pin const self`, `&'lt pin mut self`
2645+
Pinned(Option<Lifetime>, Mutability),
26442646
/// `self: TYPE`, `mut self: TYPE`
26452647
Explicit(P<Ty>, Mutability),
26462648
}
@@ -2650,6 +2652,8 @@ impl SelfKind {
26502652
match self {
26512653
SelfKind::Region(None, mutbl) => mutbl.ref_prefix_str().to_string(),
26522654
SelfKind::Region(Some(lt), mutbl) => format!("&{lt} {}", mutbl.prefix_str()),
2655+
SelfKind::Pinned(None, mutbl) => format!("&pin {}", mutbl.ptr_str()),
2656+
SelfKind::Pinned(Some(lt), mutbl) => format!("&{lt} pin {}", mutbl.ptr_str()),
26532657
SelfKind::Value(_) | SelfKind::Explicit(_, _) => {
26542658
unreachable!("if we had an explicit self, we wouldn't be here")
26552659
}
@@ -2666,11 +2670,13 @@ impl Param {
26662670
if ident.name == kw::SelfLower {
26672671
return match self.ty.kind {
26682672
TyKind::ImplicitSelf => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
2669-
TyKind::Ref(lt, MutTy { ref ty, mutbl })
2670-
| TyKind::PinnedRef(lt, MutTy { ref ty, mutbl })
2673+
TyKind::Ref(lt, MutTy { ref ty, mutbl }) if ty.kind.is_implicit_self() => {
2674+
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
2675+
}
2676+
TyKind::PinnedRef(lt, MutTy { ref ty, mutbl })
26712677
if ty.kind.is_implicit_self() =>
26722678
{
2673-
Some(respan(self.pat.span, SelfKind::Region(lt, mutbl)))
2679+
Some(respan(self.pat.span, SelfKind::Pinned(lt, mutbl)))
26742680
}
26752681
_ => Some(respan(
26762682
self.pat.span.to(self.ty.span),
@@ -2712,6 +2718,15 @@ impl Param {
27122718
tokens: None,
27132719
}),
27142720
),
2721+
SelfKind::Pinned(lt, mutbl) => (
2722+
mutbl,
2723+
P(Ty {
2724+
id: DUMMY_NODE_ID,
2725+
kind: TyKind::PinnedRef(lt, MutTy { ty: infer_ty, mutbl }),
2726+
span,
2727+
tokens: None,
2728+
}),
2729+
),
27152730
};
27162731
Param {
27172732
attrs,

compiler/rustc_ast_lowering/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct LoweringContext<'a, 'hir> {
136136

137137
allow_try_trait: Arc<[Symbol]>,
138138
allow_gen_future: Arc<[Symbol]>,
139+
allow_pattern_type: Arc<[Symbol]>,
139140
allow_async_iterator: Arc<[Symbol]>,
140141
allow_for_await: Arc<[Symbol]>,
141142
allow_async_fn_traits: Arc<[Symbol]>,
@@ -176,6 +177,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
176177
impl_trait_defs: Vec::new(),
177178
impl_trait_bounds: Vec::new(),
178179
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
180+
allow_pattern_type: [sym::pattern_types, sym::pattern_type_range_trait].into(),
179181
allow_gen_future: if tcx.features().async_fn_track_caller() {
180182
[sym::gen_future, sym::closure_track_caller].into()
181183
} else {
@@ -926,7 +928,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
926928
if let Some(first_char) = constraint.ident.as_str().chars().next()
927929
&& first_char.is_ascii_lowercase()
928930
{
929-
tracing::info!(?data, ?data.inputs);
930931
let err = match (&data.inputs[..], &data.output) {
931932
([_, ..], FnRetTy::Default(_)) => {
932933
errors::BadReturnTypeNotation::Inputs { span: data.inputs_span }
@@ -1365,7 +1366,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13651366
}
13661367
}
13671368
TyKind::Pat(ty, pat) => {
1368-
hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_ty_pat(pat))
1369+
hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_ty_pat(pat, ty.span))
13691370
}
13701371
TyKind::MacCall(_) => {
13711372
span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")

compiler/rustc_ast_lowering/src/pat.rs

+112-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::sync::Arc;
33
use rustc_ast::ptr::P;
44
use rustc_ast::*;
55
use rustc_data_structures::stack::ensure_sufficient_stack;
6-
use rustc_hir as hir;
7-
use rustc_hir::def::Res;
6+
use rustc_hir::def::{DefKind, Res};
7+
use rustc_hir::{self as hir, LangItem};
88
use rustc_middle::span_bug;
99
use rustc_span::source_map::{Spanned, respan};
10-
use rustc_span::{Ident, Span};
10+
use rustc_span::{DesugaringKind, Ident, Span, kw};
1111

1212
use super::errors::{
1313
ArbitraryExpressionInPattern, ExtraDoubleDot, MisplacedDoubleDot, SubTupleBinding,
@@ -430,22 +430,124 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
430430
self.arena.alloc(hir::PatExpr { hir_id: self.lower_node_id(expr.id), span, kind })
431431
}
432432

433-
pub(crate) fn lower_ty_pat(&mut self, pattern: &TyPat) -> &'hir hir::TyPat<'hir> {
434-
self.arena.alloc(self.lower_ty_pat_mut(pattern))
433+
pub(crate) fn lower_ty_pat(
434+
&mut self,
435+
pattern: &TyPat,
436+
base_type: Span,
437+
) -> &'hir hir::TyPat<'hir> {
438+
self.arena.alloc(self.lower_ty_pat_mut(pattern, base_type))
435439
}
436440

437-
fn lower_ty_pat_mut(&mut self, pattern: &TyPat) -> hir::TyPat<'hir> {
441+
fn lower_ty_pat_mut(&mut self, pattern: &TyPat, base_type: Span) -> hir::TyPat<'hir> {
438442
// loop here to avoid recursion
439443
let pat_hir_id = self.lower_node_id(pattern.id);
440444
let node = match &pattern.kind {
441-
TyPatKind::Range(e1, e2, Spanned { node: end, .. }) => hir::TyPatKind::Range(
442-
e1.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)),
443-
e2.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)),
444-
self.lower_range_end(end, e2.is_some()),
445+
TyPatKind::Range(e1, e2, Spanned { node: end, span }) => hir::TyPatKind::Range(
446+
e1.as_deref().map(|e| self.lower_anon_const_to_const_arg(e)).unwrap_or_else(|| {
447+
self.lower_ty_pat_range_end(
448+
hir::LangItem::RangeMin,
449+
span.shrink_to_lo(),
450+
base_type,
451+
)
452+
}),
453+
e2.as_deref()
454+
.map(|e| match end {
455+
RangeEnd::Included(..) => self.lower_anon_const_to_const_arg(e),
456+
RangeEnd::Excluded => self.lower_excluded_range_end(e),
457+
})
458+
.unwrap_or_else(|| {
459+
self.lower_ty_pat_range_end(
460+
hir::LangItem::RangeMax,
461+
span.shrink_to_hi(),
462+
base_type,
463+
)
464+
}),
445465
),
446466
TyPatKind::Err(guar) => hir::TyPatKind::Err(*guar),
447467
};
448468

449469
hir::TyPat { hir_id: pat_hir_id, kind: node, span: self.lower_span(pattern.span) }
450470
}
471+
472+
/// Lowers the range end of an exclusive range (`2..5`) to an inclusive range 2..=(5 - 1).
473+
/// This way the type system doesn't have to handle the distinction between inclusive/exclusive ranges.
474+
fn lower_excluded_range_end(&mut self, e: &AnonConst) -> &'hir hir::ConstArg<'hir> {
475+
let span = self.lower_span(e.value.span);
476+
let unstable_span = self.mark_span_with_reason(
477+
DesugaringKind::PatTyRange,
478+
span,
479+
Some(Arc::clone(&self.allow_pattern_type)),
480+
);
481+
let anon_const = self.with_new_scopes(span, |this| {
482+
let def_id = this.local_def_id(e.id);
483+
let hir_id = this.lower_node_id(e.id);
484+
let body = this.lower_body(|this| {
485+
// Need to use a custom function as we can't just subtract `1` from a `char`.
486+
let kind = hir::ExprKind::Path(this.make_lang_item_qpath(
487+
hir::LangItem::RangeSub,
488+
unstable_span,
489+
None,
490+
));
491+
let fn_def = this.arena.alloc(hir::Expr { hir_id: this.next_id(), kind, span });
492+
let args = this.arena.alloc([this.lower_expr_mut(&e.value)]);
493+
(
494+
&[],
495+
hir::Expr {
496+
hir_id: this.next_id(),
497+
kind: hir::ExprKind::Call(fn_def, args),
498+
span,
499+
},
500+
)
501+
});
502+
hir::AnonConst { def_id, hir_id, body, span }
503+
});
504+
self.arena.alloc(hir::ConstArg {
505+
hir_id: self.next_id(),
506+
kind: hir::ConstArgKind::Anon(self.arena.alloc(anon_const)),
507+
})
508+
}
509+
510+
/// When a range has no end specified (`1..` or `1..=`) or no start specified (`..5` or `..=5`),
511+
/// we instead use a constant of the MAX/MIN of the type.
512+
/// This way the type system does not have to handle the lack of a start/end.
513+
fn lower_ty_pat_range_end(
514+
&mut self,
515+
lang_item: LangItem,
516+
span: Span,
517+
base_type: Span,
518+
) -> &'hir hir::ConstArg<'hir> {
519+
let parent_def_id = self.current_hir_id_owner.def_id;
520+
let node_id = self.next_node_id();
521+
522+
// Add a definition for the in-band const def.
523+
// We're generating a range end that didn't exist in the AST,
524+
// so the def collector didn't create the def ahead of time. That's why we have to do
525+
// it here.
526+
let def_id = self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, span);
527+
let hir_id = self.lower_node_id(node_id);
528+
529+
let unstable_span = self.mark_span_with_reason(
530+
DesugaringKind::PatTyRange,
531+
self.lower_span(span),
532+
Some(Arc::clone(&self.allow_pattern_type)),
533+
);
534+
let span = self.lower_span(base_type);
535+
536+
let path_expr = hir::Expr {
537+
hir_id: self.next_id(),
538+
kind: hir::ExprKind::Path(self.make_lang_item_qpath(lang_item, unstable_span, None)),
539+
span,
540+
};
541+
542+
let ct = self.with_new_scopes(span, |this| {
543+
self.arena.alloc(hir::AnonConst {
544+
def_id,
545+
hir_id,
546+
body: this.lower_body(|_this| (&[], path_expr)),
547+
span,
548+
})
549+
});
550+
let hir_id = self.next_id();
551+
self.arena.alloc(hir::ConstArg { kind: hir::ConstArgKind::Anon(ct), hir_id })
552+
}
451553
}

compiler/rustc_ast_lowering/src/path.rs

-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
268268
}
269269
GenericArgs::Parenthesized(data) => match generic_args_mode {
270270
GenericArgsMode::ReturnTypeNotation => {
271-
tracing::info!(?data, ?data.inputs);
272271
let err = match (&data.inputs[..], &data.output) {
273272
([_, ..], FnRetTy::Default(_)) => {
274273
BadReturnTypeNotation::Inputs { span: data.inputs_span }

compiler/rustc_ast_pretty/src/pprust/state.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,13 @@ impl<'a> State<'a> {
17831783
self.print_mutability(*m, false);
17841784
self.word("self")
17851785
}
1786+
SelfKind::Pinned(lt, m) => {
1787+
self.word("&");
1788+
self.print_opt_lifetime(lt);
1789+
self.word("pin ");
1790+
self.print_mutability(*m, true);
1791+
self.word("self")
1792+
}
17861793
SelfKind::Explicit(typ, m) => {
17871794
self.print_mutability(*m, false);
17881795
self.word("self");

compiler/rustc_attr_parsing/src/parser.rs

+9
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,15 @@ impl<'a> MetaItemListParserContext<'a> {
473473
{
474474
self.inside_delimiters.next();
475475
return Some(MetaItemOrLitParser::Lit(lit));
476+
} else if let Some(TokenTree::Delimited(.., Delimiter::Invisible(_), inner_tokens)) =
477+
self.inside_delimiters.peek()
478+
{
479+
self.inside_delimiters.next();
480+
return MetaItemListParserContext {
481+
inside_delimiters: inner_tokens.iter().peekable(),
482+
dcx: self.dcx,
483+
}
484+
.next();
476485
}
477486

478487
// or a path.

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2120,8 +2120,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
21202120
//
21212121
// Note that other checks (such as denying `dyn Send` -> `dyn
21222122
// Debug`) are in `rustc_hir_typeck`.
2123-
if let ty::Dynamic(src_tty, _src_lt, _) = *src_tail.kind()
2124-
&& let ty::Dynamic(dst_tty, dst_lt, _) = *dst_tail.kind()
2123+
if let ty::Dynamic(src_tty, _src_lt, ty::Dyn) = *src_tail.kind()
2124+
&& let ty::Dynamic(dst_tty, dst_lt, ty::Dyn) = *dst_tail.kind()
21252125
&& src_tty.principal().is_some()
21262126
&& dst_tty.principal().is_some()
21272127
{

compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
-compiler_builtins = { version = "=0.1.150", features = ['rustc-dep-of-std'] }
20-
+compiler_builtins = { version = "=0.1.150", features = ['rustc-dep-of-std', 'no-f16-f128'] }
19+
-compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std'] }
20+
+compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

2222
[dev-dependencies]
2323
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

compiler/rustc_const_eval/src/interpret/memory.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -955,18 +955,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
955955

956956
/// Handle the effect an FFI call might have on the state of allocations.
957957
/// This overapproximates the modifications which external code might make to memory:
958-
/// We set all reachable allocations as initialized, mark all provenances as exposed
958+
/// We set all reachable allocations as initialized, mark all reachable provenances as exposed
959959
/// and overwrite them with `Provenance::WILDCARD`.
960-
pub fn prepare_for_native_call(
961-
&mut self,
962-
id: AllocId,
963-
initial_prov: M::Provenance,
964-
) -> InterpResult<'tcx> {
965-
// Expose provenance of the root allocation.
966-
M::expose_provenance(self, initial_prov)?;
967-
960+
///
961+
/// The allocations in `ids` are assumed to be already exposed.
962+
pub fn prepare_for_native_call(&mut self, ids: Vec<AllocId>) -> InterpResult<'tcx> {
968963
let mut done = FxHashSet::default();
969-
let mut todo = vec![id];
964+
let mut todo = ids;
970965
while let Some(id) = todo.pop() {
971966
if !done.insert(id) {
972967
// We already saw this allocation before, don't process it again.

compiler/rustc_data_structures/src/marker.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::alloc::Allocator;
2+
13
#[rustc_on_unimplemented(message = "`{Self}` doesn't implement `DynSend`. \
24
Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Send`")]
35
// This is an auto trait for types which can be sent across threads if `sync::is_dyn_thread_safe()`
@@ -28,8 +30,8 @@ impls_dyn_send_neg!(
2830
[*const T where T: ?Sized]
2931
[*mut T where T: ?Sized]
3032
[std::ptr::NonNull<T> where T: ?Sized]
31-
[std::rc::Rc<T> where T: ?Sized]
32-
[std::rc::Weak<T> where T: ?Sized]
33+
[std::rc::Rc<T, A> where T: ?Sized, A: Allocator]
34+
[std::rc::Weak<T, A> where T: ?Sized, A: Allocator]
3335
[std::sync::MutexGuard<'_, T> where T: ?Sized]
3436
[std::sync::RwLockReadGuard<'_, T> where T: ?Sized]
3537
[std::sync::RwLockWriteGuard<'_, T> where T: ?Sized]
@@ -96,8 +98,8 @@ impls_dyn_sync_neg!(
9698
[std::cell::RefCell<T> where T: ?Sized]
9799
[std::cell::UnsafeCell<T> where T: ?Sized]
98100
[std::ptr::NonNull<T> where T: ?Sized]
99-
[std::rc::Rc<T> where T: ?Sized]
100-
[std::rc::Weak<T> where T: ?Sized]
101+
[std::rc::Rc<T, A> where T: ?Sized, A: Allocator]
102+
[std::rc::Weak<T, A> where T: ?Sized, A: Allocator]
101103
[std::cell::OnceCell<T> where T]
102104
[std::sync::mpsc::Receiver<T> where T]
103105
[std::sync::mpsc::Sender<T> where T]

compiler/rustc_errors/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,6 @@ pub enum StashKey {
626626
MaybeFruTypo,
627627
CallAssocMethod,
628628
AssociatedTypeSuggestion,
629-
MaybeForgetReturn,
630629
/// Query cycle detected, stashing in favor of a better error.
631630
Cycle,
632631
UndeterminedMacroResolution,

compiler/rustc_fluent_macro/src/fluent.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ fn failed(crate_name: &Ident) -> proc_macro::TokenStream {
7878

7979
/// See [rustc_fluent_macro::fluent_messages].
8080
pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
81-
let crate_name = std::env::var("CARGO_PKG_NAME")
82-
// If `CARGO_PKG_NAME` is missing, then we're probably running in a test, so use
81+
let crate_name = std::env::var("CARGO_CRATE_NAME")
82+
// If `CARGO_CRATE_NAME` is missing, then we're probably running in a test, so use
8383
// `no_crate`.
8484
.unwrap_or_else(|_| "no_crate".to_string())
8585
.replace("rustc_", "");

compiler/rustc_hir/src/hir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ pub struct PatField<'hir> {
16001600
pub span: Span,
16011601
}
16021602

1603-
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
1603+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic, Hash, Eq, Encodable, Decodable)]
16041604
pub enum RangeEnd {
16051605
Included,
16061606
Excluded,
@@ -1668,7 +1668,7 @@ pub enum PatExprKind<'hir> {
16681668
#[derive(Debug, Clone, Copy, HashStable_Generic)]
16691669
pub enum TyPatKind<'hir> {
16701670
/// A range pattern (e.g., `1..=2` or `1..2`).
1671-
Range(Option<&'hir ConstArg<'hir>>, Option<&'hir ConstArg<'hir>>, RangeEnd),
1671+
Range(&'hir ConstArg<'hir>, &'hir ConstArg<'hir>),
16721672

16731673
/// A placeholder for a pattern that wasn't well formed in some way.
16741674
Err(ErrorGuaranteed),

0 commit comments

Comments
 (0)