Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #138595

Merged
merged 40 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
49d2d5a
Extract `unescape` from `rustc_lexer` into its own crate
GuillaumeGomez Jan 31, 2025
b993f9c
Add `_value` methods to proc_macro lib
GuillaumeGomez Jan 31, 2025
615a9cd
Ignore duplicated dep for `literal-escaper`
GuillaumeGomez Jan 31, 2025
94f0f2b
Reexport `literal-escaper` from `rustc_lexer` to allow rust-analyzer …
GuillaumeGomez Jan 31, 2025
e256a21
Add `literal-escaper` and `rustc-std-workspace-std` to the allowed ru…
GuillaumeGomez Jan 31, 2025
d40ed63
Fix bootstrap `build_all` test
GuillaumeGomez Feb 3, 2025
3c33cbe
Add ui test for ensuring that users cannot use `literal-escaper` crat…
GuillaumeGomez Feb 6, 2025
c9ccec9
Initial STD support for Cygwin
Berrysoft Dec 26, 2024
e3e98c8
Fix `std::sys::unix::set_linger` for Cygwin
Mar 4, 2024
1aad114
Fix building for cygwin
Berrysoft Dec 29, 2024
886fb15
Update metadata for cygwin target
Berrysoft Feb 25, 2025
abcbd88
Revert changes for rtstartup
Berrysoft Feb 25, 2025
d24c6a2
Fix code style
Berrysoft Feb 25, 2025
7d80aaa
Remove std::os::cygwin::raw
Berrysoft Mar 7, 2025
268e734
Impl cygwin rand with getrandom
Berrysoft Mar 7, 2025
c3051b1
Unify cygwin & horizon random impl
Berrysoft Mar 7, 2025
b9fe8de
Readd os::cygwin::raw as pub(crate)
Berrysoft Mar 7, 2025
c3c02a5
Use __xpg_strerror_r on cygwin
Berrysoft Mar 7, 2025
9cab8c2
Remove stack overflow handler for cygwin
Berrysoft Mar 7, 2025
a9b536f
std: Mention clone-on-write mutation in Arc<T>
xizheyin Mar 11, 2025
bd385f3
Fix panic handler for cygwin
Berrysoft Mar 12, 2025
340a452
Stablize feature `anonymous_pipe`
NobodyXu Mar 1, 2025
6863a99
Mv os-specific trait impl of `Pipe*` into `std::os::*`
NobodyXu Mar 7, 2025
ae4a479
Improve upvar analysis for deref of child capture
compiler-errors Mar 14, 2025
ec4b3c2
Add test for new proc_macro literal methods
GuillaumeGomez Mar 16, 2025
417bfe2
Exclude `literal-escaper` from `library` workspace
GuillaumeGomez Mar 16, 2025
04c9956
Update Rust Foundation links in Readme
atouchet Mar 17, 2025
10bc5ac
Document `#![register_tool]`
jyn514 Mar 17, 2025
0d100d3
update change entry for #137147
onur-ozkan Mar 17, 2025
51e8309
Flatten and simplify some control flow
yotamofek Mar 16, 2025
4394f94
Only add `rustc_randomized_layouts` if the crate has it
GuillaumeGomez Mar 17, 2025
08dfbf4
Rollup merge of #136355 - GuillaumeGomez:proc-macro_add_value_retriev…
jhpratt Mar 17, 2025
b3b7a3b
Rollup merge of #137621 - Berrysoft:cygwin-std, r=joboet
jhpratt Mar 17, 2025
62c2a7b
Rollup merge of #137793 - NobodyXu:stablise-annoymous-pipe, r=joshtri…
jhpratt Mar 17, 2025
625278b
Rollup merge of #138341 - xizheyin:issue-138322, r=joboet
jhpratt Mar 17, 2025
e9f6e01
Rollup merge of #138517 - compiler-errors:better-child-capture, r=oli…
jhpratt Mar 17, 2025
72f95eb
Rollup merge of #138584 - atouchet:found, r=jieyouxu
jhpratt Mar 17, 2025
47d0c6b
Rollup merge of #138586 - jyn514:doc-register-tool, r=jieyouxu
jhpratt Mar 17, 2025
25a95e5
Rollup merge of #138590 - yotamofek:pr/flatten-ifs, r=fmease
jhpratt Mar 17, 2025
87b87b1
Rollup merge of #138592 - onur-ozkan:follow-up-137147, r=Kobzol
jhpratt Mar 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,13 @@ version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104"

[[package]]
name = "literal-escaper"
version = "0.0.0"
dependencies = [
"rustc-std-workspace-std 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "lld-wrapper"
version = "0.1.0"
Expand Down Expand Up @@ -3148,6 +3155,12 @@ version = "1.0.1"
name = "rustc-std-workspace-std"
version = "1.0.1"

[[package]]
name = "rustc-std-workspace-std"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aba676a20abe46e5b0f1b0deae474aaaf31407e6c71147159890574599da04ef"

[[package]]
name = "rustc_abi"
version = "0.0.0"
Expand Down Expand Up @@ -3186,6 +3199,7 @@ name = "rustc_ast"
version = "0.0.0"
dependencies = [
"bitflags",
"literal-escaper",
"memchr",
"rustc_ast_ir",
"rustc_data_structures",
Expand Down Expand Up @@ -3895,6 +3909,7 @@ name = "rustc_lexer"
version = "0.0.0"
dependencies = [
"expect-test",
"literal-escaper",
"memchr",
"unicode-properties",
"unicode-xid",
Expand Down Expand Up @@ -4157,6 +4172,7 @@ name = "rustc_parse"
version = "0.0.0"
dependencies = [
"bitflags",
"literal-escaper",
"rustc_ast",
"rustc_ast_pretty",
"rustc_data_structures",
Expand All @@ -4179,6 +4195,7 @@ dependencies = [
name = "rustc_parse_format"
version = "0.0.0"
dependencies = [
"literal-escaper",
"rustc_index",
"rustc_lexer",
]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT), and
trademarks and logos (the "Rust Trademarks").

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

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

[rust-foundation]: https://foundation.rust-lang.org/
[media-guide]: https://foundation.rust-lang.org/policies/logo-policy-and-media-guide/
[rust-foundation]: https://rustfoundation.org/
[trademark-policy]: https://rustfoundation.org/policy/rust-trademark-policy/
[policies-licenses]: https://www.rust-lang.org/policies/licenses
1 change: 1 addition & 0 deletions compiler/rustc_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2024"
[dependencies]
# tidy-alphabetical-start
bitflags = "2.4.1"
literal-escaper = { path = "../../library/literal-escaper" }
memchr = "2.7.4"
rustc_ast_ir = { path = "../rustc_ast_ir" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/util/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{ascii, fmt, str};

use rustc_lexer::unescape::{
use literal_escaper::{
MixedUnit, Mode, byte_from_char, unescape_byte, unescape_char, unescape_mixed, unescape_unicode,
};
use rustc_span::{Span, Symbol, kw, sym};
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2479,19 +2479,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
let body = self.body;
for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) {
let local_decl = &body.local_decls[local];
let lint_root = match &body.source_scopes[local_decl.source_info.scope].local_data {
ClearCrossCrate::Set(data) => data.lint_root,
_ => continue,
let ClearCrossCrate::Set(SourceScopeLocalData { lint_root, .. }) =
body.source_scopes[local_decl.source_info.scope].local_data
else {
continue;
};

// Skip over locals that begin with an underscore or have no name
match self.local_names[local] {
Some(name) => {
if name.as_str().starts_with('_') {
continue;
}
}
None => continue,
if self.local_names[local].is_none_or(|name| name.as_str().starts_with('_')) {
continue;
}

let span = local_decl.source_info.span;
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDef
}

// If `#[link_section]` is missing, then nothing to verify
let attrs = tcx.codegen_fn_attrs(id);
if attrs.link_section.is_none() {
let Some(link_section) = tcx.codegen_fn_attrs(id).link_section else {
return;
}
};

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

if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
&& alloc.inner().provenance().ptrs().len() != 0
&& attrs
.link_section
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
.unwrap()
&& !alloc.inner().provenance().ptrs().is_empty()
&& !link_section.as_str().starts_with(".init_array")
{
let msg = "statics with a custom `#[link_section]` must be a \
simple list of bytes on the wasm target with no \
Expand Down
45 changes: 22 additions & 23 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1532,30 +1532,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.may_coerce(blk_ty, *elem_ty)
&& blk.stmts.is_empty()
&& blk.rules == hir::BlockCheckMode::DefaultBlock
&& let source_map = self.tcx.sess.source_map()
&& let Ok(snippet) = source_map.span_to_snippet(blk.span)
&& snippet.starts_with('{')
&& snippet.ends_with('}')
{
let source_map = self.tcx.sess.source_map();
if let Ok(snippet) = source_map.span_to_snippet(blk.span) {
if snippet.starts_with('{') && snippet.ends_with('}') {
diag.multipart_suggestion_verbose(
"to create an array, use square brackets instead of curly braces",
vec![
(
blk.span
.shrink_to_lo()
.with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)),
"[".to_string(),
),
(
blk.span
.shrink_to_hi()
.with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)),
"]".to_string(),
),
],
Applicability::MachineApplicable,
);
}
}
diag.multipart_suggestion_verbose(
"to create an array, use square brackets instead of curly braces",
vec![
(
blk.span
.shrink_to_lo()
.with_hi(rustc_span::BytePos(blk.span.lo().0 + 1)),
"[".to_string(),
),
(
blk.span
.shrink_to_hi()
.with_lo(rustc_span::BytePos(blk.span.hi().0 - 1)),
"]".to_string(),
),
],
Applicability::MachineApplicable,
);
}
}
}
Expand Down
25 changes: 19 additions & 6 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1862,8 +1862,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
///
/// (1.) Are we borrowing data owned by the parent closure? We can determine if
/// that is the case by checking if the parent capture is by move, EXCEPT if we
/// apply a deref projection, which means we're reborrowing a reference that we
/// captured by move.
/// apply a deref projection of an immutable reference, reborrows of immutable
/// references which aren't restricted to the LUB of the lifetimes of the deref
/// chain. This is why `&'short mut &'long T` can be reborrowed as `&'long T`.
///
/// ```rust
/// let x = &1i32; // Let's call this lifetime `'1`.
Expand Down Expand Up @@ -1902,10 +1903,22 @@ fn should_reborrow_from_env_of_parent_coroutine_closure<'tcx>(
) -> bool {
// (1.)
(!parent_capture.is_by_ref()
&& !matches!(
child_capture.place.projections.get(parent_capture.place.projections.len()),
Some(Projection { kind: ProjectionKind::Deref, .. })
))
// This is just inlined `place.deref_tys()` but truncated to just
// the child projections. Namely, look for a `&T` deref, since we
// can always extend `&'short mut &'long T` to `&'long T`.
&& !child_capture
.place
.projections
.iter()
.enumerate()
.skip(parent_capture.place.projections.len())
.any(|(idx, proj)| {
matches!(proj.kind, ProjectionKind::Deref)
&& matches!(
child_capture.place.ty_before_projection(idx).kind(),
ty::Ref(.., ty::Mutability::Not)
)
}))
// (2.)
|| matches!(child_capture.info.capture_kind, UpvarCapture::ByRef(ty::BorrowKind::Mutable))
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Rust lexer used by rustc. No stability guarantees are provided.
[dependencies]
memchr = "2.7.4"
unicode-xid = "0.2.0"
literal-escaper = { path = "../../library/literal-escaper" }

[dependencies.unicode-properties]
version = "0.1.0"
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
// tidy-alphabetical-end

mod cursor;
pub mod unescape;

#[cfg(test)]
mod tests;

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

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,8 @@ fn analyze_attr(attr: &impl AttributeExt, state: &mut AnalyzeAttrState<'_>) -> b
}
}
}
} else if attr.path().starts_with(&[sym::diagnostic]) && attr.path().len() == 2 {
should_encode =
rustc_feature::is_stable_diagnostic_attribute(attr.path()[1], state.features);
} else if let &[sym::diagnostic, seg] = &*attr.path() {
should_encode = rustc_feature::is_stable_diagnostic_attribute(seg, state.features);
} else {
should_encode = true;
}
Expand Down
42 changes: 18 additions & 24 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,21 +641,19 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
}
}

Alias(Projection, AliasTy { def_id, .. }) => {
if self.tcx.def_kind(def_id) != DefKind::AssocTy {
return ControlFlow::Break(());
}
Alias(Projection, AliasTy { def_id, .. })
if self.tcx.def_kind(def_id) != DefKind::AssocTy =>
{
return ControlFlow::Break(());
}

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

_ => {}
Expand Down Expand Up @@ -733,17 +731,13 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
}
}

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

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

_ => t,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2024"
[dependencies]
# tidy-alphabetical-start
bitflags = "2.4.1"
literal-escaper = { path = "../../library/literal-escaper" }
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_data_structures = { path = "../rustc_data_structures" }
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::ops::Range;

use literal_escaper::{self, EscapeError, Mode};
use rustc_ast::ast::{self, AttrStyle};
use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind};
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::util::unicode::contains_text_flow_control_chars;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, StashKey};
use rustc_lexer::unescape::{self, EscapeError, Mode};
use rustc_lexer::{Base, Cursor, DocStyle, LiteralKind, RawStrError};
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::lint::builtin::{
Expand Down Expand Up @@ -970,7 +970,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
postfix_len: u32,
) -> (token::LitKind, Symbol) {
self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
unescape::unescape_unicode(src, mode, &mut |span, result| {
literal_escaper::unescape_unicode(src, mode, &mut |span, result| {
callback(span, result.map(drop))
})
})
Expand All @@ -986,7 +986,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
postfix_len: u32,
) -> (token::LitKind, Symbol) {
self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
unescape::unescape_mixed(src, mode, &mut |span, result| {
literal_escaper::unescape_mixed(src, mode, &mut |span, result| {
callback(span, result.map(drop))
})
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::iter::once;
use std::ops::Range;

use literal_escaper::{EscapeError, Mode};
use rustc_errors::{Applicability, DiagCtxtHandle, ErrorGuaranteed};
use rustc_lexer::unescape::{EscapeError, Mode};
use rustc_span::{BytePos, Span};
use tracing::debug;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use core::ops::{Bound, ControlFlow};
use ast::mut_visit::{self, MutVisitor};
use ast::token::{IdentIsRaw, MetaVarKind};
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered};
use literal_escaper::unescape_char;
use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::TokenTree;
Expand All @@ -21,7 +22,6 @@ use rustc_ast::{
use rustc_ast_pretty::pprust;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::{Applicability, Diag, PResult, StashKey, Subdiagnostic};
use rustc_lexer::unescape::unescape_char;
use rustc_macros::Subdiagnostic;
use rustc_session::errors::{ExprParenthesesNeeded, report_lit_error};
use rustc_session::lint::BuiltinLintDiag;
Expand Down
Loading
Loading