Skip to content

Commit 9c67cec

Browse files
committed
Auto merge of #138595 - jhpratt:rollup-09pvfzu, r=jhpratt
Rollup of 9 pull requests Successful merges: - #136355 (Add `*_value` methods to proc_macro lib) - #137621 (Add std support to cygwin target) - #137793 (Stablize anonymous pipe) - #138341 (std: Mention clone-on-write mutation in Arc<T>) - #138517 (Improve upvar analysis for deref of child capture) - #138584 (Update Rust Foundation links in Readme) - #138586 (Document `#![register_tool]`) - #138590 (Flatten and simplify some control flow 🫓) - #138592 (update change entry for #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

+17
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

+3-3
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

+1
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

+1-1
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

+6-10
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

+4-8
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

+22-23
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

+19-6
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

+1
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

+3-1
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

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,8 @@ fn analyze_attr(attr: &impl AttributeExt, state: &mut AnalyzeAttrState<'_>) -> b
843843
}
844844
}
845845
}
846-
} else if attr.path().starts_with(&[sym::diagnostic]) && attr.path().len() == 2 {
847-
should_encode =
848-
rustc_feature::is_stable_diagnostic_attribute(attr.path()[1], state.features);
846+
} else if let &[sym::diagnostic, seg] = &*attr.path() {
847+
should_encode = rustc_feature::is_stable_diagnostic_attribute(seg, state.features);
849848
} else {
850849
should_encode = true;
851850
}

compiler/rustc_middle/src/ty/diagnostics.rs

+18-24
Original file line numberDiff line numberDiff line change
@@ -641,21 +641,19 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
641641
}
642642
}
643643

644-
Alias(Projection, AliasTy { def_id, .. }) => {
645-
if self.tcx.def_kind(def_id) != DefKind::AssocTy {
646-
return ControlFlow::Break(());
647-
}
644+
Alias(Projection, AliasTy { def_id, .. })
645+
if self.tcx.def_kind(def_id) != DefKind::AssocTy =>
646+
{
647+
return ControlFlow::Break(());
648648
}
649649

650-
Param(param) => {
651-
// FIXME: It would be nice to make this not use string manipulation,
652-
// but it's pretty hard to do this, since `ty::ParamTy` is missing
653-
// sufficient info to determine if it is synthetic, and we don't
654-
// always have a convenient way of getting `ty::Generics` at the call
655-
// sites we invoke `IsSuggestable::is_suggestable`.
656-
if param.name.as_str().starts_with("impl ") {
657-
return ControlFlow::Break(());
658-
}
650+
// FIXME: It would be nice to make this not use string manipulation,
651+
// but it's pretty hard to do this, since `ty::ParamTy` is missing
652+
// sufficient info to determine if it is synthetic, and we don't
653+
// always have a convenient way of getting `ty::Generics` at the call
654+
// sites we invoke `IsSuggestable::is_suggestable`.
655+
Param(param) if param.name.as_str().starts_with("impl ") => {
656+
return ControlFlow::Break(());
659657
}
660658

661659
_ => {}
@@ -733,17 +731,13 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
733731
}
734732
}
735733

736-
Param(param) => {
737-
// FIXME: It would be nice to make this not use string manipulation,
738-
// but it's pretty hard to do this, since `ty::ParamTy` is missing
739-
// sufficient info to determine if it is synthetic, and we don't
740-
// always have a convenient way of getting `ty::Generics` at the call
741-
// sites we invoke `IsSuggestable::is_suggestable`.
742-
if param.name.as_str().starts_with("impl ") {
743-
return Err(());
744-
}
745-
746-
t
734+
// FIXME: It would be nice to make this not use string manipulation,
735+
// but it's pretty hard to do this, since `ty::ParamTy` is missing
736+
// sufficient info to determine if it is synthetic, and we don't
737+
// always have a convenient way of getting `ty::Generics` at the call
738+
// sites we invoke `IsSuggestable::is_suggestable`.
739+
Param(param) if param.name.as_str().starts_with("impl ") => {
740+
return Err(());
747741
}
748742

749743
_ => t,

compiler/rustc_parse/Cargo.toml

+1
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
rustc_ast = { path = "../rustc_ast" }
1011
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1112
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_parse/src/lexer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::ops::Range;
22

3+
use literal_escaper::{self, EscapeError, Mode};
34
use rustc_ast::ast::{self, AttrStyle};
45
use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind};
56
use rustc_ast::tokenstream::TokenStream;
67
use rustc_ast::util::unicode::contains_text_flow_control_chars;
78
use rustc_errors::codes::*;
89
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, StashKey};
9-
use rustc_lexer::unescape::{self, EscapeError, Mode};
1010
use rustc_lexer::{Base, Cursor, DocStyle, LiteralKind, RawStrError};
1111
use rustc_session::lint::BuiltinLintDiag;
1212
use rustc_session::lint::builtin::{
@@ -970,7 +970,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
970970
postfix_len: u32,
971971
) -> (token::LitKind, Symbol) {
972972
self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
973-
unescape::unescape_unicode(src, mode, &mut |span, result| {
973+
literal_escaper::unescape_unicode(src, mode, &mut |span, result| {
974974
callback(span, result.map(drop))
975975
})
976976
})
@@ -986,7 +986,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
986986
postfix_len: u32,
987987
) -> (token::LitKind, Symbol) {
988988
self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
989-
unescape::unescape_mixed(src, mode, &mut |span, result| {
989+
literal_escaper::unescape_mixed(src, mode, &mut |span, result| {
990990
callback(span, result.map(drop))
991991
})
992992
})

compiler/rustc_parse/src/lexer/unescape_error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::iter::once;
44
use std::ops::Range;
55

6+
use literal_escaper::{EscapeError, Mode};
67
use rustc_errors::{Applicability, DiagCtxtHandle, ErrorGuaranteed};
7-
use rustc_lexer::unescape::{EscapeError, Mode};
88
use rustc_span::{BytePos, Span};
99
use tracing::debug;
1010

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use core::ops::{Bound, ControlFlow};
66
use ast::mut_visit::{self, MutVisitor};
77
use ast::token::{IdentIsRaw, MetaVarKind};
88
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered};
9+
use literal_escaper::unescape_char;
910
use rustc_ast::ptr::P;
1011
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
1112
use rustc_ast::tokenstream::TokenTree;
@@ -21,7 +22,6 @@ use rustc_ast::{
2122
use rustc_ast_pretty::pprust;
2223
use rustc_data_structures::stack::ensure_sufficient_stack;
2324
use rustc_errors::{Applicability, Diag, PResult, StashKey, Subdiagnostic};
24-
use rustc_lexer::unescape::unescape_char;
2525
use rustc_macros::Subdiagnostic;
2626
use rustc_session::errors::{ExprParenthesesNeeded, report_lit_error};
2727
use rustc_session::lint::BuiltinLintDiag;

0 commit comments

Comments
 (0)