Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9c67cec

Browse files
committed
Auto merge of rust-lang#138595 - jhpratt:rollup-09pvfzu, r=jhpratt
Rollup of 9 pull requests Successful merges: - rust-lang#136355 (Add `*_value` methods to proc_macro lib) - rust-lang#137621 (Add std support to cygwin target) - rust-lang#137793 (Stablize anonymous pipe) - rust-lang#138341 (std: Mention clone-on-write mutation in Arc<T>) - rust-lang#138517 (Improve upvar analysis for deref of child capture) - rust-lang#138584 (Update Rust Foundation links in Readme) - rust-lang#138586 (Document `#![register_tool]`) - rust-lang#138590 (Flatten and simplify some control flow 🫓) - rust-lang#138592 (update change entry for rust-lang#137147) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9bad8ac + 87b87b1 commit 9c67cec

File tree

88 files changed

+1025
-341
lines changed

Some content is hidden

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

88 files changed

+1025
-341
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,13 @@ version = "0.7.4"
20822082
source = "registry+https://github.com/rust-lang/crates.io-index"
20832083
checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"
20842084

2085+
[[package]]
2086+
name = "literal-escaper"
2087+
version = "0.0.0"
2088+
dependencies = [
2089+
"rustc-std-workspace-std 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2090+
]
2091+
20852092
[[package]]
20862093
name = "lld-wrapper"
20872094
version = "0.1.0"
@@ -3148,6 +3155,12 @@ version = "1.0.1"
31483155
name = "rustc-std-workspace-std"
31493156
version = "1.0.1"
31503157

3158+
[[package]]
3159+
name = "rustc-std-workspace-std"
3160+
version = "1.0.1"
3161+
source = "registry+https://github.com/rust-lang/crates.io-index"
3162+
checksum = "aba676a20abe46e5b0f1b0deae474aaaf31407e6c71147159890574599da04ef"
3163+
31513164
[[package]]
31523165
name = "rustc_abi"
31533166
version = "0.0.0"
@@ -3186,6 +3199,7 @@ name = "rustc_ast"
31863199
version = "0.0.0"
31873200
dependencies = [
31883201
"bitflags",
3202+
"literal-escaper",
31893203
"memchr",
31903204
"rustc_ast_ir",
31913205
"rustc_data_structures",
@@ -3895,6 +3909,7 @@ name = "rustc_lexer"
38953909
version = "0.0.0"
38963910
dependencies = [
38973911
"expect-test",
3912+
"literal-escaper",
38983913
"memchr",
38993914
"unicode-properties",
39003915
"unicode-xid",
@@ -4157,6 +4172,7 @@ name = "rustc_parse"
41574172
version = "0.0.0"
41584173
dependencies = [
41594174
"bitflags",
4175+
"literal-escaper",
41604176
"rustc_ast",
41614177
"rustc_ast_pretty",
41624178
"rustc_data_structures",
@@ -4179,6 +4195,7 @@ dependencies = [
41794195
name = "rustc_parse_format"
41804196
version = "0.0.0"
41814197
dependencies = [
4198+
"literal-escaper",
41824199
"rustc_index",
41834200
"rustc_lexer",
41844201
]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and
6767
trademarks and logos (the "Rust Trademarks").
6868

6969
If you want to use these names or brands, please read the
70-
[media guide][media-guide].
70+
[Rust language trademark policy][trademark-policy].
7171

7272
Third-party logos may be subject to third-party copyrights and trademarks. See
7373
[Licenses][policies-licenses] for details.
7474

75-
[rust-foundation]: https://foundation.rust-lang.org/
76-
[media-guide]: https://foundation.rust-lang.org/policies/logo-policy-and-media-guide/
75+
[rust-foundation]: https://rustfoundation.org/
76+
[trademark-policy]: https://rustfoundation.org/policy/rust-trademark-policy/
7777
[policies-licenses]: https://www.rust-lang.org/policies/licenses

compiler/rustc_ast/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9+
literal-escaper = { path = "../../library/literal-escaper" }
910
memchr = "2.7.4"
1011
rustc_ast_ir = { path = "../rustc_ast_ir" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_ast/src/util/literal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::{ascii, fmt, str};
44

5-
use rustc_lexer::unescape::{
5+
use literal_escaper::{
66
MixedUnit, Mode, byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode,
77
};
88
use rustc_span::{Span, Symbol, kw, sym};

compiler/rustc_borrowck/src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,19 +2479,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
24792479
let body = self.body;
24802480
for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) {
24812481
let local_decl = &body.local_decls[local];
2482-
let lint_root = match &body.source_scopes[local_decl.source_info.scope].local_data {
2483-
ClearCrossCrate::Set(data) => data.lint_root,
2484-
_ => continue,
2482+
let ClearCrossCrate::Set(SourceScopeLocalData { lint_root, .. }) =
2483+
body.source_scopes[local_decl.source_info.scope].local_data
2484+
else {
2485+
continue;
24852486
};
24862487

24872488
// Skip over locals that begin with an underscore or have no name
2488-
match self.local_names[local] {
2489-
Some(name) => {
2490-
if name.as_str().starts_with('_') {
2491-
continue;
2492-
}
2493-
}
2494-
None => continue,
2489+
if self.local_names[local].is_none_or(|name| name.as_str().starts_with('_')) {
2490+
continue;
24952491
}
24962492

24972493
let span = local_decl.source_info.span;

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDef
153153
}
154154

155155
// If `#[link_section]` is missing, then nothing to verify
156-
let attrs = tcx.codegen_fn_attrs(id);
157-
if attrs.link_section.is_none() {
156+
let Some(link_section) = tcx.codegen_fn_attrs(id).link_section else {
158157
return;
159-
}
158+
};
160159

161160
// For the wasm32 target statics with `#[link_section]` other than `.init_array`
162161
// are placed into custom sections of the final output file, but this isn't like
@@ -182,11 +181,8 @@ pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDef
182181
// continue to work, but would no longer be necessary.
183182

184183
if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
185-
&& alloc.inner().provenance().ptrs().len() != 0
186-
&& attrs
187-
.link_section
188-
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
189-
.unwrap()
184+
&& !alloc.inner().provenance().ptrs().is_empty()
185+
&& !link_section.as_str().starts_with(".init_array")
190186
{
191187
let msg = "statics with a custom `#[link_section]` must be a \
192188
simple list of bytes on the wasm target with no \

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,30 +1532,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15321532
if self.may_coerce(blk_ty, *elem_ty)
15331533
&& blk.stmts.is_empty()
15341534
&& blk.rules == hir::BlockCheckMode::DefaultBlock
1535+
&& let source_map = self.tcx.sess.source_map()
1536+
&& let Ok(snippet) = source_map.span_to_snippet(blk.span)
1537+
&& snippet.starts_with('{')
1538+
&& snippet.ends_with('}')
15351539
{
1536-
let source_map = self.tcx.sess.source_map();
1537-
if let Ok(snippet) = source_map.span_to_snippet(blk.span) {
1538-
if snippet.starts_with('{') && snippet.ends_with('}') {
1539-
diag.multipart_suggestion_verbose(
1540-
"to create an array, use square brackets instead of curly braces",
1541-
vec![
1542-
(
1543-
blk.span
1544-
.shrink_to_lo()
1545-
.with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)),
1546-
"[".to_string(),
1547-
),
1548-
(
1549-
blk.span
1550-
.shrink_to_hi()
1551-
.with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)),
1552-
"]".to_string(),
1553-
),
1554-
],
1555-
Applicability::MachineApplicable,
1556-
);
1557-
}
1558-
}
1540+
diag.multipart_suggestion_verbose(
1541+
"to create an array, use square brackets instead of curly braces",
1542+
vec![
1543+
(
1544+
blk.span
1545+
.shrink_to_lo()
1546+
.with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)),
1547+
"[".to_string(),
1548+
),
1549+
(
1550+
blk.span
1551+
.shrink_to_hi()
1552+
.with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)),
1553+
"]".to_string(),
1554+
),
1555+
],
1556+
Applicability::MachineApplicable,
1557+
);
15591558
}
15601559
}
15611560
}

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,8 +1862,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18621862
///
18631863
/// (1.) Are we borrowing data owned by the parent closure? We can determine if
18641864
/// that is the case by checking if the parent capture is by move, EXCEPT if we
1865-
/// apply a deref projection, which means we're reborrowing a reference that we
1866-
/// captured by move.
1865+
/// apply a deref projection of an immutable reference, reborrows of immutable
1866+
/// references which aren't restricted to the LUB of the lifetimes of the deref
1867+
/// chain. This is why `&'short mut &'long T` can be reborrowed as `&'long T`.
18671868
///
18681869
/// ```rust
18691870
/// let x = &1i32; // Let's call this lifetime `'1`.
@@ -1902,10 +1903,22 @@ fn should_reborrow_from_env_of_parent_coroutine_closure<'tcx>(
19021903
) -> bool {
19031904
// (1.)
19041905
(!parent_capture.is_by_ref()
1905-
&& !matches!(
1906-
child_capture.place.projections.get(parent_capture.place.projections.len()),
1907-
Some(Projection { kind: ProjectionKind::Deref, .. })
1908-
))
1906+
// This is just inlined `place.deref_tys()` but truncated to just
1907+
// the child projections. Namely, look for a `&T` deref, since we
1908+
// can always extend `&'short mut &'long T` to `&'long T`.
1909+
&& !child_capture
1910+
.place
1911+
.projections
1912+
.iter()
1913+
.enumerate()
1914+
.skip(parent_capture.place.projections.len())
1915+
.any(|(idx, proj)| {
1916+
matches!(proj.kind, ProjectionKind::Deref)
1917+
&& matches!(
1918+
child_capture.place.ty_before_projection(idx).kind(),
1919+
ty::Ref(.., ty::Mutability::Not)
1920+
)
1921+
}))
19091922
// (2.)
19101923
|| matches!(child_capture.info.capture_kind, UpvarCapture::ByRef(ty::BorrowKind::Mutable))
19111924
}

compiler/rustc_lexer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Rust lexer used by rustc. No stability guarantees are provided.
1616
[dependencies]
1717
memchr = "2.7.4"
1818
unicode-xid = "0.2.0"
19+
literal-escaper = { path = "../../library/literal-escaper" }
1920

2021
[dependencies.unicode-properties]
2122
version = "0.1.0"

compiler/rustc_lexer/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
// tidy-alphabetical-end
2727

2828
mod cursor;
29-
pub mod unescape;
3029

3130
#[cfg(test)]
3231
mod tests;
3332

33+
// FIXME: This is needed for rust-analyzer. Remove this dependency once rust-analyzer uses
34+
// `literal-escaper`.
35+
pub use literal_escaper as unescape;
3436
use unicode_properties::UnicodeEmoji;
3537
pub use unicode_xid::UNICODE_VERSION as UNICODE_XID_VERSION;
3638

0 commit comments

Comments
 (0)