Skip to content

Commit 6602a23

Browse files
committed
Auto merge of rust-lang#3938 - rust-lang:rustup-2024-10-04, r=RalfJung
Automatic Rustup
2 parents bf71d65 + dc88a6a commit 6602a23

File tree

298 files changed

+4253
-1739
lines changed

Some content is hidden

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

298 files changed

+4253
-1739
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,13 @@ package.json
8686
## Rustdoc GUI tests
8787
tests/rustdoc-gui/src/**.lock
8888

89+
## direnv
90+
.envrc
91+
.direnv/
92+
93+
## nix
94+
flake.nix
95+
flake.lock
96+
default.nix
97+
8998
# Before adding new lines, see the comment at the top.

Cargo.lock

+26
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ dependencies = [
199199
"object 0.36.4",
200200
]
201201

202+
[[package]]
203+
name = "arrayref"
204+
version = "0.3.7"
205+
source = "registry+https://github.com/rust-lang/crates.io-index"
206+
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
207+
202208
[[package]]
203209
name = "arrayvec"
204210
version = "0.7.6"
@@ -262,6 +268,19 @@ version = "2.6.0"
262268
source = "registry+https://github.com/rust-lang/crates.io-index"
263269
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
264270

271+
[[package]]
272+
name = "blake3"
273+
version = "1.5.2"
274+
source = "registry+https://github.com/rust-lang/crates.io-index"
275+
checksum = "3d08263faac5cde2a4d52b513dadb80846023aade56fcd8fc99ba73ba8050e92"
276+
dependencies = [
277+
"arrayref",
278+
"arrayvec",
279+
"cc",
280+
"cfg-if",
281+
"constant_time_eq",
282+
]
283+
265284
[[package]]
266285
name = "block-buffer"
267286
version = "0.10.4"
@@ -722,6 +741,12 @@ dependencies = [
722741
"windows-sys 0.52.0",
723742
]
724743

744+
[[package]]
745+
name = "constant_time_eq"
746+
version = "0.3.0"
747+
source = "registry+https://github.com/rust-lang/crates.io-index"
748+
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
749+
725750
[[package]]
726751
name = "core-foundation-sys"
727752
version = "0.8.7"
@@ -4378,6 +4403,7 @@ dependencies = [
43784403
name = "rustc_span"
43794404
version = "0.0.0"
43804405
dependencies = [
4406+
"blake3",
43814407
"derive-where",
43824408
"indexmap",
43834409
"itoa",

compiler/rustc_ast_lowering/src/item.rs

-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
286286
parent: this.local_def_id(id),
287287
in_assoc_ty: false,
288288
},
289-
fn_kind: None,
290289
}),
291290
},
292291
);
@@ -983,7 +982,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
983982
parent: this.local_def_id(i.id),
984983
in_assoc_ty: true,
985984
},
986-
fn_kind: None,
987985
});
988986
hir::ImplItemKind::Type(ty)
989987
}

compiler/rustc_ast_lowering/src/lib.rs

+41-46
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,7 @@ enum ImplTraitContext {
288288
/// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually
289289
/// equivalent to a new opaque type like `type T = impl Debug; fn foo() -> T`.
290290
///
291-
OpaqueTy {
292-
origin: hir::OpaqueTyOrigin,
293-
/// Only used to change the lifetime capture rules, since
294-
/// RPITIT captures all in scope, RPIT does not.
295-
fn_kind: Option<FnDeclKind>,
296-
},
291+
OpaqueTy { origin: hir::OpaqueTyOrigin },
297292
/// `impl Trait` is unstably accepted in this position.
298293
FeatureGated(ImplTraitPosition, Symbol),
299294
/// `impl Trait` is not accepted in this position.
@@ -1404,14 +1399,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14041399
TyKind::ImplTrait(def_node_id, bounds) => {
14051400
let span = t.span;
14061401
match itctx {
1407-
ImplTraitContext::OpaqueTy { origin, fn_kind } => self.lower_opaque_impl_trait(
1408-
span,
1409-
origin,
1410-
*def_node_id,
1411-
bounds,
1412-
fn_kind,
1413-
itctx,
1414-
),
1402+
ImplTraitContext::OpaqueTy { origin } => {
1403+
self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
1404+
}
14151405
ImplTraitContext::Universal => {
14161406
if let Some(span) = bounds.iter().find_map(|bound| match *bound {
14171407
ast::GenericBound::Use(_, span) => Some(span),
@@ -1513,7 +1503,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15131503
origin: hir::OpaqueTyOrigin,
15141504
opaque_ty_node_id: NodeId,
15151505
bounds: &GenericBounds,
1516-
fn_kind: Option<FnDeclKind>,
15171506
itctx: ImplTraitContext,
15181507
) -> hir::TyKind<'hir> {
15191508
// Make sure we know that some funky desugaring has been going on here.
@@ -1555,11 +1544,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15551544
.map(|(ident, id, _)| Lifetime { id, ident })
15561545
.collect()
15571546
}
1558-
hir::OpaqueTyOrigin::FnReturn(..) => {
1559-
if matches!(
1560-
fn_kind.expect("expected RPITs to be lowered with a FnKind"),
1561-
FnDeclKind::Impl | FnDeclKind::Trait
1562-
) || self.tcx.features().lifetime_capture_rules_2024
1547+
hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl, .. } => {
1548+
if in_trait_or_impl.is_some()
1549+
|| self.tcx.features().lifetime_capture_rules_2024
15631550
|| span.at_least_rust_2024()
15641551
{
15651552
// return-position impl trait in trait was decided to capture all
@@ -1576,37 +1563,29 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15761563
lifetime_collector::lifetimes_in_bounds(self.resolver, bounds)
15771564
}
15781565
}
1579-
hir::OpaqueTyOrigin::AsyncFn(..) => {
1566+
hir::OpaqueTyOrigin::AsyncFn { .. } => {
15801567
unreachable!("should be using `lower_async_fn_ret_ty`")
15811568
}
15821569
}
15831570
};
15841571
debug!(?captured_lifetimes_to_duplicate);
15851572

1586-
match fn_kind {
1587-
// Deny `use<>` on RPITIT in trait/trait-impl for now.
1588-
Some(FnDeclKind::Trait | FnDeclKind::Impl) => {
1573+
// Feature gate for RPITIT + use<..>
1574+
match origin {
1575+
rustc_hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl: Some(_), .. } => {
15891576
if let Some(span) = bounds.iter().find_map(|bound| match *bound {
15901577
ast::GenericBound::Use(_, span) => Some(span),
15911578
_ => None,
15921579
}) {
15931580
self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnRpitit { span });
15941581
}
15951582
}
1596-
None
1597-
| Some(
1598-
FnDeclKind::Fn
1599-
| FnDeclKind::Inherent
1600-
| FnDeclKind::ExternFn
1601-
| FnDeclKind::Closure
1602-
| FnDeclKind::Pointer,
1603-
) => {}
1583+
_ => {}
16041584
}
16051585

16061586
self.lower_opaque_inner(
16071587
opaque_ty_node_id,
16081588
origin,
1609-
matches!(fn_kind, Some(FnDeclKind::Trait)),
16101589
captured_lifetimes_to_duplicate,
16111590
span,
16121591
opaque_ty_span,
@@ -1618,7 +1597,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16181597
&mut self,
16191598
opaque_ty_node_id: NodeId,
16201599
origin: hir::OpaqueTyOrigin,
1621-
in_trait: bool,
16221600
captured_lifetimes_to_duplicate: FxIndexSet<Lifetime>,
16231601
span: Span,
16241602
opaque_ty_span: Span,
@@ -1747,7 +1725,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17471725
bounds,
17481726
origin,
17491727
lifetime_mapping,
1750-
in_trait,
17511728
};
17521729

17531730
// Generate an `type Foo = impl Trait;` declaration.
@@ -1776,7 +1753,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17761753
hir::TyKind::OpaqueDef(
17771754
hir::ItemId { owner_id: hir::OwnerId { def_id: opaque_ty_def_id } },
17781755
generic_args,
1779-
in_trait,
17801756
)
17811757
}
17821758

@@ -1864,12 +1840,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18641840
None => match &decl.output {
18651841
FnRetTy::Ty(ty) => {
18661842
let itctx = match kind {
1867-
FnDeclKind::Fn
1868-
| FnDeclKind::Inherent
1869-
| FnDeclKind::Trait
1870-
| FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
1871-
origin: hir::OpaqueTyOrigin::FnReturn(self.local_def_id(fn_node_id)),
1872-
fn_kind: Some(kind),
1843+
FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
1844+
origin: hir::OpaqueTyOrigin::FnReturn {
1845+
parent: self.local_def_id(fn_node_id),
1846+
in_trait_or_impl: None,
1847+
},
1848+
},
1849+
FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
1850+
origin: hir::OpaqueTyOrigin::FnReturn {
1851+
parent: self.local_def_id(fn_node_id),
1852+
in_trait_or_impl: Some(hir::RpitContext::Trait),
1853+
},
1854+
},
1855+
FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
1856+
origin: hir::OpaqueTyOrigin::FnReturn {
1857+
parent: self.local_def_id(fn_node_id),
1858+
in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
1859+
},
18731860
},
18741861
FnDeclKind::ExternFn => {
18751862
ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
@@ -1951,10 +1938,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19511938
.map(|(ident, id, _)| Lifetime { id, ident })
19521939
.collect();
19531940

1941+
let in_trait_or_impl = match fn_kind {
1942+
FnDeclKind::Trait => Some(hir::RpitContext::Trait),
1943+
FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
1944+
FnDeclKind::Fn | FnDeclKind::Inherent => None,
1945+
FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
1946+
};
1947+
19541948
let opaque_ty_ref = self.lower_opaque_inner(
19551949
opaque_ty_node_id,
1956-
hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
1957-
matches!(fn_kind, FnDeclKind::Trait),
1950+
hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
19581951
captured_lifetimes,
19591952
span,
19601953
opaque_ty_span,
@@ -1964,8 +1957,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19641957
coro,
19651958
opaque_ty_span,
19661959
ImplTraitContext::OpaqueTy {
1967-
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1968-
fn_kind: Some(fn_kind),
1960+
origin: hir::OpaqueTyOrigin::FnReturn {
1961+
parent: fn_def_id,
1962+
in_trait_or_impl,
1963+
},
19691964
},
19701965
);
19711966
arena_vec![this; bound]

0 commit comments

Comments
 (0)