Skip to content

Commit 6e8abb5

Browse files
committed
Auto merge of rust-lang#138956 - jhpratt:rollup-6g7ppwd, r=jhpratt
Rollup of 11 pull requests Successful merges: - rust-lang#138128 (Stabilize `#![feature(precise_capturing_in_traits)]`) - rust-lang#138834 (Group test diffs by stage in post-merge analysis) - rust-lang#138867 (linker: Fix staticlib naming for UEFI) - rust-lang#138874 (Batch mark waiters as unblocked when resuming in the deadlock handler) - rust-lang#138875 (Trusty: Fix build for anonymous pipes and std::sys::process) - rust-lang#138877 (Ignore doctests only in specified targets) - rust-lang#138885 (Fix ui pattern_types test for big-endian platforms) - rust-lang#138905 (Add target maintainer information for powerpc64-unknown-linux-musl) - rust-lang#138911 (Allow defining opaques in statics and consts) - rust-lang#138917 (rustdoc: remove useless `Symbol::is_empty` checks.) - rust-lang#138945 (Override PartialOrd methods for bool) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 068609c + deb987b commit 6e8abb5

File tree

66 files changed

+632
-413
lines changed

Some content is hidden

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

66 files changed

+632
-413
lines changed

compiler/rustc_ast/src/ast.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3535,6 +3535,7 @@ pub struct StaticItem {
35353535
pub safety: Safety,
35363536
pub mutability: Mutability,
35373537
pub expr: Option<P<Expr>>,
3538+
pub define_opaque: Option<ThinVec<(NodeId, Path)>>,
35383539
}
35393540

35403541
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -3543,6 +3544,7 @@ pub struct ConstItem {
35433544
pub generics: Generics,
35443545
pub ty: P<Ty>,
35453546
pub expr: Option<P<Expr>>,
3547+
pub define_opaque: Option<ThinVec<(NodeId, Path)>>,
35463548
}
35473549

35483550
// Adding a new variant? Please update `test_item` in `tests/ui/macros/stringify.rs`.

compiler/rustc_ast/src/mut_visit.rs

+38-16
Original file line numberDiff line numberDiff line change
@@ -987,10 +987,7 @@ fn walk_fn<T: MutVisitor>(vis: &mut T, kind: FnKind<'_>) {
987987
}
988988
vis.visit_span(span);
989989

990-
for (id, path) in define_opaque.iter_mut().flatten() {
991-
vis.visit_id(id);
992-
vis.visit_path(path)
993-
}
990+
walk_define_opaques(vis, define_opaque);
994991
}
995992
FnKind::Closure(binder, coroutine_kind, decl, body) => {
996993
vis.visit_closure_binder(binder);
@@ -1258,12 +1255,19 @@ impl WalkItemKind for ItemKind {
12581255
match self {
12591256
ItemKind::ExternCrate(_orig_name) => {}
12601257
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
1261-
ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => {
1258+
ItemKind::Static(box StaticItem {
1259+
ty,
1260+
safety: _,
1261+
mutability: _,
1262+
expr,
1263+
define_opaque,
1264+
}) => {
12621265
vis.visit_ty(ty);
12631266
visit_opt(expr, |expr| vis.visit_expr(expr));
1267+
walk_define_opaques(vis, define_opaque);
12641268
}
12651269
ItemKind::Const(item) => {
1266-
visit_const_item(item, vis);
1270+
walk_const_item(vis, item);
12671271
}
12681272
ItemKind::Fn(func) => {
12691273
vis.visit_fn(FnKind::Fn(FnCtxt::Free, ident, visibility, &mut *func), span, id);
@@ -1384,7 +1388,7 @@ impl WalkItemKind for AssocItemKind {
13841388
) {
13851389
match self {
13861390
AssocItemKind::Const(item) => {
1387-
visit_const_item(item, visitor);
1391+
walk_const_item(visitor, item);
13881392
}
13891393
AssocItemKind::Fn(func) => {
13901394
visitor.visit_fn(
@@ -1444,14 +1448,13 @@ impl WalkItemKind for AssocItemKind {
14441448
}
14451449
}
14461450

1447-
fn visit_const_item<T: MutVisitor>(
1448-
ConstItem { defaultness, generics, ty, expr }: &mut ConstItem,
1449-
visitor: &mut T,
1450-
) {
1451-
visit_defaultness(visitor, defaultness);
1452-
visitor.visit_generics(generics);
1453-
visitor.visit_ty(ty);
1454-
visit_opt(expr, |expr| visitor.visit_expr(expr));
1451+
fn walk_const_item<T: MutVisitor>(vis: &mut T, item: &mut ConstItem) {
1452+
let ConstItem { defaultness, generics, ty, expr, define_opaque } = item;
1453+
visit_defaultness(vis, defaultness);
1454+
vis.visit_generics(generics);
1455+
vis.visit_ty(ty);
1456+
visit_opt(expr, |expr| vis.visit_expr(expr));
1457+
walk_define_opaques(vis, define_opaque);
14551458
}
14561459

14571460
fn walk_fn_header<T: MutVisitor>(vis: &mut T, header: &mut FnHeader) {
@@ -1528,9 +1531,16 @@ impl WalkItemKind for ForeignItemKind {
15281531
visitor: &mut impl MutVisitor,
15291532
) {
15301533
match self {
1531-
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
1534+
ForeignItemKind::Static(box StaticItem {
1535+
ty,
1536+
mutability: _,
1537+
expr,
1538+
safety: _,
1539+
define_opaque,
1540+
}) => {
15321541
visitor.visit_ty(ty);
15331542
visit_opt(expr, |expr| visitor.visit_expr(expr));
1543+
walk_define_opaques(visitor, define_opaque);
15341544
}
15351545
ForeignItemKind::Fn(func) => {
15361546
visitor.visit_fn(
@@ -1931,6 +1941,18 @@ fn walk_capture_by<T: MutVisitor>(vis: &mut T, capture_by: &mut CaptureBy) {
19311941
}
19321942
}
19331943

1944+
fn walk_define_opaques<T: MutVisitor>(
1945+
vis: &mut T,
1946+
define_opaque: &mut Option<ThinVec<(NodeId, Path)>>,
1947+
) {
1948+
if let Some(define_opaque) = define_opaque {
1949+
for (id, path) in define_opaque {
1950+
vis.visit_id(id);
1951+
vis.visit_path(path)
1952+
}
1953+
}
1954+
}
1955+
19341956
/// Some value for the AST node that is valid but possibly meaningless. Similar
19351957
/// to `Default` but not intended for wide use. The value will never be used
19361958
/// meaningfully, it exists just to support unwinding in `visit_clobber` in the

compiler/rustc_ast/src/visit.rs

+46-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
pub use rustc_ast_ir::visit::VisitorResult;
1717
pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list};
1818
use rustc_span::{Ident, Span};
19+
use thin_vec::ThinVec;
1920

2021
use crate::ast::*;
2122
use crate::ptr::P;
@@ -371,14 +372,28 @@ impl WalkItemKind for ItemKind {
371372
match self {
372373
ItemKind::ExternCrate(_rename) => {}
373374
ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, id, false)),
374-
ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => {
375+
ItemKind::Static(box StaticItem {
376+
ty,
377+
safety: _,
378+
mutability: _,
379+
expr,
380+
define_opaque,
381+
}) => {
375382
try_visit!(visitor.visit_ty(ty));
376383
visit_opt!(visitor, visit_expr, expr);
384+
try_visit!(walk_define_opaques(visitor, define_opaque));
377385
}
378-
ItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
386+
ItemKind::Const(box ConstItem {
387+
defaultness: _,
388+
generics,
389+
ty,
390+
expr,
391+
define_opaque,
392+
}) => {
379393
try_visit!(visitor.visit_generics(generics));
380394
try_visit!(visitor.visit_ty(ty));
381395
visit_opt!(visitor, visit_expr, expr);
396+
try_visit!(walk_define_opaques(visitor, define_opaque));
382397
}
383398
ItemKind::Fn(func) => {
384399
let kind = FnKind::Fn(FnCtxt::Free, ident, vis, &*func);
@@ -734,9 +749,16 @@ impl WalkItemKind for ForeignItemKind {
734749
visitor: &mut V,
735750
) -> V::Result {
736751
match self {
737-
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
752+
ForeignItemKind::Static(box StaticItem {
753+
ty,
754+
mutability: _,
755+
expr,
756+
safety: _,
757+
define_opaque,
758+
}) => {
738759
try_visit!(visitor.visit_ty(ty));
739760
visit_opt!(visitor, visit_expr, expr);
761+
try_visit!(walk_define_opaques(visitor, define_opaque));
740762
}
741763
ForeignItemKind::Fn(func) => {
742764
let kind = FnKind::Fn(FnCtxt::Foreign, ident, vis, &*func);
@@ -912,9 +934,7 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
912934
try_visit!(visitor.visit_fn_decl(decl));
913935
visit_opt!(visitor, visit_contract, contract);
914936
visit_opt!(visitor, visit_block, body);
915-
for (id, path) in define_opaque.iter().flatten() {
916-
try_visit!(visitor.visit_path(path, *id))
917-
}
937+
try_visit!(walk_define_opaques(visitor, define_opaque));
918938
}
919939
FnKind::Closure(binder, coroutine_kind, decl, body) => {
920940
try_visit!(visitor.visit_closure_binder(binder));
@@ -938,10 +958,17 @@ impl WalkItemKind for AssocItemKind {
938958
visitor: &mut V,
939959
) -> V::Result {
940960
match self {
941-
AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
961+
AssocItemKind::Const(box ConstItem {
962+
defaultness: _,
963+
generics,
964+
ty,
965+
expr,
966+
define_opaque,
967+
}) => {
942968
try_visit!(visitor.visit_generics(generics));
943969
try_visit!(visitor.visit_ty(ty));
944970
visit_opt!(visitor, visit_expr, expr);
971+
try_visit!(walk_define_opaques(visitor, define_opaque));
945972
}
946973
AssocItemKind::Fn(func) => {
947974
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, vis, &*func);
@@ -1342,3 +1369,15 @@ pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -
13421369
}
13431370
V::Result::output()
13441371
}
1372+
1373+
fn walk_define_opaques<'a, V: Visitor<'a>>(
1374+
visitor: &mut V,
1375+
define_opaque: &'a Option<ThinVec<(NodeId, Path)>>,
1376+
) -> V::Result {
1377+
if let Some(define_opaque) = define_opaque {
1378+
for (id, path) in define_opaque {
1379+
try_visit!(visitor.visit_path(path, *id));
1380+
}
1381+
}
1382+
V::Result::output()
1383+
}

compiler/rustc_ast_lowering/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ ast_lowering_never_pattern_with_guard =
141141
142142
ast_lowering_no_precise_captures_on_apit = `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
143143
144-
ast_lowering_no_precise_captures_on_rpitit = `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
145-
.note = currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
146-
147144
ast_lowering_previously_used_here = previously used here
148145
149146
ast_lowering_register1 = register `{$reg1_name}`

compiler/rustc_ast_lowering/src/errors.rs

-8
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,6 @@ pub(crate) struct NoPreciseCapturesOnApit {
444444
pub span: Span,
445445
}
446446

447-
#[derive(Diagnostic)]
448-
#[diag(ast_lowering_no_precise_captures_on_rpitit)]
449-
#[note]
450-
pub(crate) struct NoPreciseCapturesOnRpitit {
451-
#[primary_span]
452-
pub span: Span,
453-
}
454-
455447
#[derive(Diagnostic)]
456448
#[diag(ast_lowering_yield_in_closure)]
457449
pub(crate) struct YieldInClosure {

compiler/rustc_ast_lowering/src/item.rs

+54-18
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
184184

185185
self.lower_use_tree(use_tree, &prefix, id, vis_span, attrs)
186186
}
187-
ItemKind::Static(box ast::StaticItem { ty: t, safety: _, mutability: m, expr: e }) => {
187+
ItemKind::Static(box ast::StaticItem {
188+
ty: t,
189+
safety: _,
190+
mutability: m,
191+
expr: e,
192+
define_opaque,
193+
}) => {
188194
debug_assert_ne!(ident.name, kw::Empty);
189195
let ident = self.lower_ident(ident);
190196
let (ty, body_id) =
191197
self.lower_const_item(t, span, e.as_deref(), ImplTraitPosition::StaticTy);
198+
self.lower_define_opaque(hir_id, define_opaque);
192199
hir::ItemKind::Static(ident, ty, *m, body_id)
193200
}
194-
ItemKind::Const(box ast::ConstItem { generics, ty, expr, .. }) => {
201+
ItemKind::Const(box ast::ConstItem { generics, ty, expr, define_opaque, .. }) => {
195202
debug_assert_ne!(ident.name, kw::Empty);
196203
let ident = self.lower_ident(ident);
197204
let (generics, (ty, body_id)) = self.lower_generics(
@@ -202,6 +209,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
202209
this.lower_const_item(ty, span, expr.as_deref(), ImplTraitPosition::ConstTy)
203210
},
204211
);
212+
self.lower_define_opaque(hir_id, &define_opaque);
205213
hir::ItemKind::Const(ident, ty, generics, body_id)
206214
}
207215
ItemKind::Fn(box Fn {
@@ -239,7 +247,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
239247
header: this.lower_fn_header(*header, hir::Safety::Safe, attrs),
240248
span: this.lower_span(*fn_sig_span),
241249
};
242-
this.lower_define_opaque(hir_id, &define_opaque);
250+
this.lower_define_opaque(hir_id, define_opaque);
243251
let ident = this.lower_ident(ident);
244252
hir::ItemKind::Fn {
245253
ident,
@@ -645,7 +653,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
645653
owner_id,
646654
ident: self.lower_ident(i.ident),
647655
kind: match &i.kind {
648-
ForeignItemKind::Fn(box Fn { sig, generics, .. }) => {
656+
ForeignItemKind::Fn(box Fn { sig, generics, define_opaque, .. }) => {
649657
let fdec = &sig.decl;
650658
let itctx = ImplTraitContext::Universal;
651659
let (generics, (decl, fn_args)) =
@@ -666,17 +674,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
666674
// Unmarked safety in unsafe block defaults to unsafe.
667675
let header = self.lower_fn_header(sig.header, hir::Safety::Unsafe, attrs);
668676

677+
if define_opaque.is_some() {
678+
self.dcx().span_err(i.span, "foreign functions cannot define opaque types");
679+
}
680+
669681
hir::ForeignItemKind::Fn(
670682
hir::FnSig { header, decl, span: self.lower_span(sig.span) },
671683
fn_args,
672684
generics,
673685
)
674686
}
675-
ForeignItemKind::Static(box StaticItem { ty, mutability, expr: _, safety }) => {
687+
ForeignItemKind::Static(box StaticItem {
688+
ty,
689+
mutability,
690+
expr: _,
691+
safety,
692+
define_opaque,
693+
}) => {
676694
let ty = self
677695
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
678696
let safety = self.lower_safety(*safety, hir::Safety::Unsafe);
679697

698+
if define_opaque.is_some() {
699+
self.dcx().span_err(i.span, "foreign statics cannot define opaque types");
700+
}
701+
680702
hir::ForeignItemKind::Static(ty, *mutability, safety)
681703
}
682704
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
@@ -784,7 +806,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
784806
let trait_item_def_id = hir_id.expect_owner();
785807

786808
let (generics, kind, has_default) = match &i.kind {
787-
AssocItemKind::Const(box ConstItem { generics, ty, expr, .. }) => {
809+
AssocItemKind::Const(box ConstItem { generics, ty, expr, define_opaque, .. }) => {
788810
let (generics, kind) = self.lower_generics(
789811
generics,
790812
i.id,
@@ -797,6 +819,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
797819
hir::TraitItemKind::Const(ty, body)
798820
},
799821
);
822+
823+
if define_opaque.is_some() {
824+
if expr.is_some() {
825+
self.lower_define_opaque(hir_id, &define_opaque);
826+
} else {
827+
self.dcx().span_err(
828+
i.span,
829+
"only trait consts with default bodies can define opaque types",
830+
);
831+
}
832+
}
833+
800834
(generics, kind, expr.is_some())
801835
}
802836
AssocItemKind::Fn(box Fn { sig, generics, body: None, define_opaque, .. }) => {
@@ -938,18 +972,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
938972
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
939973

940974
let (generics, kind) = match &i.kind {
941-
AssocItemKind::Const(box ConstItem { generics, ty, expr, .. }) => self.lower_generics(
942-
generics,
943-
i.id,
944-
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
945-
|this| {
946-
let ty =
947-
this.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
948-
let body = this.lower_const_body(i.span, expr.as_deref());
949-
950-
hir::ImplItemKind::Const(ty, body)
951-
},
952-
),
975+
AssocItemKind::Const(box ConstItem { generics, ty, expr, define_opaque, .. }) => self
976+
.lower_generics(
977+
generics,
978+
i.id,
979+
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
980+
|this| {
981+
let ty = this
982+
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
983+
let body = this.lower_const_body(i.span, expr.as_deref());
984+
this.lower_define_opaque(hir_id, &define_opaque);
985+
986+
hir::ImplItemKind::Const(ty, body)
987+
},
988+
),
953989
AssocItemKind::Fn(box Fn { sig, generics, body, contract, define_opaque, .. }) => {
954990
let body_id = self.lower_maybe_coroutine_body(
955991
sig.span,

0 commit comments

Comments
 (0)