Merge from rust-lang/rust

This commit is contained in:
Laurențiu Nicola 2025-04-28 11:06:53 +03:00
commit 6225bb9c44
15 changed files with 69 additions and 219 deletions

43
Cargo.lock generated
View file

@ -1112,9 +1112,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.171"
version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "libloading"
@ -1502,6 +1502,7 @@ dependencies = [
"edition",
"expect-test",
"ra-ap-rustc_lexer",
"rustc-literal-escaper",
"stdx",
"tracing",
]
@ -1742,9 +1743,9 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_abi"
version = "0.100.0"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1651b0f7e8c3eb7c27a88f39d277e69c32bfe58e3be174d286c1a24d6a7a4d8"
checksum = "912228bd8ed3beff1f6f9e5e2d4b37c0827ba3e2070060bf3858a311d0e29e30"
dependencies = [
"bitflags 2.9.0",
"ra-ap-rustc_hashes",
@ -1754,18 +1755,18 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_hashes"
version = "0.100.0"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bcd85e93dc0ea850bcfe7957a115957df799ccbc9eea488bdee5ec6780d212b"
checksum = "ba520764daf057a9d963fa769f4762eaf87ac5d4900ae76195eeead64cd35afd"
dependencies = [
"rustc-stable-hash",
]
[[package]]
name = "ra-ap-rustc_index"
version = "0.100.0"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b295fc0640cd9fe0ecab872ee4a17a96f90a3998ec9f0c4765e9b8415c12cc"
checksum = "b76b5f9ee55f2d0e5a65bea23f6d738893349ce8d3d17a6720933e647ab04978"
dependencies = [
"ra-ap-rustc_index_macros",
"smallvec",
@ -1773,9 +1774,9 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_index_macros"
version = "0.100.0"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c675f4257023aa933882906f13802cae287e88cc39ab13cbb96809083db0c801"
checksum = "ddd972eb1face2fcaa0d94c01d97862fb955b5561d4f5932003bce8a6cadd8c6"
dependencies = [
"proc-macro2",
"quote",
@ -1784,9 +1785,9 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_lexer"
version = "0.100.0"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8358702c2a510ea84ba5801ddc047d9ad9520902cfb0e6173277610cdce2c9c"
checksum = "ba3a9876456fb2521097deef33ddeac1c18260c8eafb68054d986f8b9d6ce9fa"
dependencies = [
"memchr",
"unicode-properties",
@ -1795,19 +1796,19 @@ dependencies = [
[[package]]
name = "ra-ap-rustc_parse_format"
version = "0.100.0"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98f402011d46732c35c47bfd111dec0495747fef2ec900ddee7fe15d78449a7"
checksum = "8e85de58dfcc60a5f9d5ec0157a657e3f84abd8f22c8a0c4d707cfb42c9011f4"
dependencies = [
"ra-ap-rustc_index",
"ra-ap-rustc_lexer",
"rustc-literal-escaper",
]
[[package]]
name = "ra-ap-rustc_pattern_analysis"
version = "0.100.0"
version = "0.110.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef3ff73fa4653252ffe1d1e9177a446f49ef46d97140e4816b7ff2dad59ed53"
checksum = "ceadf9db550db67deff7eff2e2765109b860c9d7e5bdfca144863020289c823d"
dependencies = [
"ra-ap-rustc_index",
"rustc-hash 2.1.1",
@ -1996,6 +1997,12 @@ version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
[[package]]
name = "rustc-literal-escaper"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0041b6238913c41fe704213a4a9329e2f685a156d1781998128b4149c230ad04"
[[package]]
name = "rustc-stable-hash"
version = "0.1.2"
@ -2253,10 +2260,10 @@ dependencies = [
"expect-test",
"itertools 0.14.0",
"parser",
"ra-ap-rustc_lexer",
"rayon",
"rowan",
"rustc-hash 2.1.1",
"rustc-literal-escaper",
"rustc_apfloat",
"smol_str",
"stdx",

View file

@ -85,11 +85,11 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }
edition = { path = "./crates/edition", version = "0.0.0" }
ra-ap-rustc_lexer = { version = "0.100", default-features = false }
ra-ap-rustc_parse_format = { version = "0.100", default-features = false }
ra-ap-rustc_index = { version = "0.100", default-features = false }
ra-ap-rustc_abi = { version = "0.100", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.100", default-features = false }
ra-ap-rustc_lexer = { version = "0.110", default-features = false }
ra-ap-rustc_parse_format = { version = "0.110", default-features = false }
ra-ap-rustc_index = { version = "0.110", default-features = false }
ra-ap-rustc_abi = { version = "0.110", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.110", default-features = false }
# local crates that aren't published to crates.io. These should not have versions.
@ -132,11 +132,12 @@ pulldown-cmark-to-cmark = "10.0.4"
pulldown-cmark = { version = "0.9.6", default-features = false }
rayon = "1.10.0"
salsa = "0.20.0"
rustc-hash = "2.1.1"
semver = "1.0.26"
serde = { version = "1.0.219" }
serde_derive = { version = "1.0.219" }
serde_json = "1.0.140"
rustc-hash = "2.1.1"
rustc-literal-escaper = "0.0.2"
smallvec = { version = "1.14.0", features = [
"const_new",
"union",

View file

@ -137,7 +137,7 @@ pub enum FormatAlignment {
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FormatCount {
/// `{:5}` or `{:.5}`
Literal(usize),
Literal(u16),
/// `{:.*}`, `{:.5$}`, or `{:a$}`, etc.
Argument(FormatArgPosition),
}

View file

@ -665,10 +665,6 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
rustc_attr!(TEST, rustc_abi, Normal, template!(List: "field1, field2, ..."), WarnFollowing),
rustc_attr!(TEST, rustc_regions, Normal, template!(Word), WarnFollowing),
rustc_attr!(
TEST, rustc_error, Normal,
template!(Word, List: "delayed_bug_from_inside_query"), WarnFollowingWordOnly
),
rustc_attr!(TEST, rustc_dump_user_args, Normal, template!(Word), WarnFollowing),
rustc_attr!(TEST, rustc_evaluate_where_clauses, Normal, template!(Word), WarnFollowing),
rustc_attr!(

View file

@ -3789,35 +3789,6 @@ The tracking issue for this feature is: [#64797]
[#64797]: https://github.com/rust-lang/rust/issues/64797
------------------------
"##,
default_severity: Severity::Allow,
warn_since: None,
deny_since: None,
},
Lint {
label: "cfg_boolean_literals",
description: r##"# `cfg_boolean_literals`
The tracking issue for this feature is: [#131204]
[#131204]: https://github.com/rust-lang/rust/issues/131204
------------------------
The `cfg_boolean_literals` feature makes it possible to use the `true`/`false`
literal as cfg predicate. They always evaluate to true/false respectively.
## Examples
```rust
#![feature(cfg_boolean_literals)]
#[cfg(true)]
const A: i32 = 5;
#[cfg(all(false))]
const A: i32 = 58 * 89;
```
"##,
default_severity: Severity::Allow,
warn_since: None,

View file

@ -6704,109 +6704,14 @@ pub fn foo() {}
#[test]
fn hover_feature() {
check(
r#"#![feature(intrinsics$0)]"#,
expect![[r#"
*intrinsics*
```
intrinsics
```
___
# `intrinsics`
The tracking issue for this feature is: None.
Intrinsics are rarely intended to be stable directly, but are usually
exported in some sort of stable manner. Prefer using the stable interfaces to
the intrinsic directly when you can.
------------------------
## Intrinsics with fallback logic
Many intrinsics can be written in pure rust, albeit inefficiently or without supporting
some features that only exist on some backends. Backends can simply not implement those
intrinsics without causing any code miscompilations or failures to compile.
All intrinsic fallback bodies are automatically made cross-crate inlineable (like `#[inline]`)
by the codegen backend, but not the MIR inliner.
```rust
#![feature(intrinsics)]
#![allow(internal_features)]
#[rustc_intrinsic]
const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
```
Since these are just regular functions, it is perfectly ok to create the intrinsic twice:
```rust
#![feature(intrinsics)]
#![allow(internal_features)]
#[rustc_intrinsic]
const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
mod foo {
#[rustc_intrinsic]
const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {
panic!("noisy const dealloc")
}
}
```
The behaviour on backends that override the intrinsic is exactly the same. On other
backends, the intrinsic behaviour depends on which implementation is called, just like
with any regular function.
## Intrinsics lowered to MIR instructions
Various intrinsics have native MIR operations that they correspond to. Instead of requiring
backends to implement both the intrinsic and the MIR operation, the `lower_intrinsics` pass
will convert the calls to the MIR operation. Backends do not need to know about these intrinsics
at all. These intrinsics only make sense without a body, and can either be declared as a "rust-intrinsic"
or as a `#[rustc_intrinsic]`. The body is never used, as calls to the intrinsic do not exist
anymore after MIR analyses.
## Intrinsics without fallback logic
These must be implemented by all backends.
### `#[rustc_intrinsic]` declarations
These are written like intrinsics with fallback bodies, but the body is irrelevant.
Use `loop {}` for the body or call the intrinsic recursively and add
`#[rustc_intrinsic_must_be_overridden]` to the function to ensure that backends don't
invoke the body.
### Legacy extern ABI based intrinsics
These are imported as if they were FFI functions, with the special
`rust-intrinsic` ABI. For example, if one was in a freestanding
context, but wished to be able to `transmute` between types, and
perform efficient pointer arithmetic, one would import those functions
via a declaration like
```rust
#![feature(intrinsics)]
#![allow(internal_features)]
# fn main() {}
extern "rust-intrinsic" {
fn transmute<T, U>(x: T) -> U;
fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
}
```
As with any other FFI functions, these are by default always `unsafe` to call.
You can add `#[rustc_safe_intrinsic]` to the intrinsic to make it safe to call.
"#]],
let (analysis, position) = fixture::position(r#"#![feature(intrinsics$0)]"#);
analysis
.hover(
&HoverConfig { links_in_hover: true, ..HOVER_BASE_CONFIG },
FileRange { file_id: position.file_id, range: TextRange::empty(position.offset) },
)
.unwrap()
.unwrap();
}
#[test]

View file

@ -14,6 +14,7 @@ rust-version.workspace = true
[dependencies]
drop_bomb = "0.1.5"
ra-ap-rustc_lexer.workspace = true
rustc-literal-escaper.workspace = true
tracing = { workspace = true, optional = true }
edition.workspace = true

View file

@ -10,7 +10,7 @@
use std::ops;
use rustc_lexer::unescape::{EscapeError, Mode};
use rustc_literal_escaper::{EscapeError, Mode, unescape_byte, unescape_char, unescape_mixed, unescape_unicode};
use crate::{
Edition,
@ -282,7 +282,7 @@ impl<'a> Converter<'a> {
let text = &self.res.text[self.offset + 1..][..len - 1];
let i = text.rfind('\'').unwrap();
let text = &text[..i];
if let Err(e) = rustc_lexer::unescape::unescape_char(text) {
if let Err(e) = unescape_char(text) {
err = error_to_diagnostic_message(e, Mode::Char);
}
}
@ -295,7 +295,7 @@ impl<'a> Converter<'a> {
let text = &self.res.text[self.offset + 2..][..len - 2];
let i = text.rfind('\'').unwrap();
let text = &text[..i];
if let Err(e) = rustc_lexer::unescape::unescape_byte(text) {
if let Err(e) = unescape_byte(text) {
err = error_to_diagnostic_message(e, Mode::Byte);
}
}
@ -402,14 +402,14 @@ fn unescape_string_error_message(text: &str, mode: Mode) -> &'static str {
let mut error_message = "";
match mode {
Mode::CStr => {
rustc_lexer::unescape::unescape_mixed(text, mode, &mut |_, res| {
unescape_mixed(text, mode, &mut |_, res| {
if let Err(e) = res {
error_message = error_to_diagnostic_message(e, mode);
}
});
}
Mode::ByteStr | Mode::Str => {
rustc_lexer::unescape::unescape_unicode(text, mode, &mut |_, res| {
unescape_unicode(text, mode, &mut |_, res| {
if let Err(e) = res {
error_message = error_to_diagnostic_message(e, mode);
}

View file

@ -11,7 +11,7 @@ use std::{
use intern::Symbol;
use proc_macro::bridge::{self, server};
use span::{FIXUP_ERASED_FILE_AST_ID_MARKER, FileId, Span};
use span::{FIXUP_ERASED_FILE_AST_ID_MARKER, Span};
use tt::{TextRange, TextSize};
use crate::server_impl::{TopSubtree, literal_kind_to_internal, token_stream::TokenStreamBuilder};
@ -27,10 +27,6 @@ mod tt {
type TokenStream = crate::server_impl::TokenStream<Span>;
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct SourceFile {
file_id: FileId,
}
pub struct FreeFunctions;
pub struct RaSpanServer {
@ -46,7 +42,6 @@ pub struct RaSpanServer {
impl server::Types for RaSpanServer {
type FreeFunctions = FreeFunctions;
type TokenStream = TokenStream;
type SourceFile = SourceFile;
type Span = Span;
type Symbol = Symbol;
}
@ -245,25 +240,17 @@ impl server::TokenStream for RaSpanServer {
}
}
impl server::SourceFile for RaSpanServer {
fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool {
file1 == file2
}
fn path(&mut self, _file: &Self::SourceFile) -> String {
// FIXME
String::new()
}
fn is_real(&mut self, _file: &Self::SourceFile) -> bool {
true
}
}
impl server::Span for RaSpanServer {
fn debug(&mut self, span: Self::Span) -> String {
format!("{:?}", span)
}
fn source_file(&mut self, span: Self::Span) -> Self::SourceFile {
SourceFile { file_id: span.anchor.file_id.file_id() }
fn file(&mut self, _: Self::Span) -> String {
// FIXME
String::new()
}
fn local_file(&mut self, _: Self::Span) -> Option<String> {
// FIXME
None
}
fn save_span(&mut self, _span: Self::Span) -> usize {
// FIXME, quote is incompatible with third-party tools

View file

@ -24,8 +24,6 @@ type Literal = tt::Literal;
type Span = tt::TokenId;
type TokenStream = crate::server_impl::TokenStream<Span>;
#[derive(Clone)]
pub struct SourceFile;
pub struct FreeFunctions;
pub struct TokenIdServer {
@ -37,7 +35,6 @@ pub struct TokenIdServer {
impl server::Types for TokenIdServer {
type FreeFunctions = FreeFunctions;
type TokenStream = TokenStream;
type SourceFile = SourceFile;
type Span = Span;
type Symbol = Symbol;
}
@ -223,24 +220,15 @@ impl server::TokenStream for TokenIdServer {
}
}
impl server::SourceFile for TokenIdServer {
fn eq(&mut self, _file1: &Self::SourceFile, _file2: &Self::SourceFile) -> bool {
true
}
fn path(&mut self, _file: &Self::SourceFile) -> String {
String::new()
}
fn is_real(&mut self, _file: &Self::SourceFile) -> bool {
true
}
}
impl server::Span for TokenIdServer {
fn debug(&mut self, span: Self::Span) -> String {
format!("{:?}", span.0)
}
fn source_file(&mut self, _span: Self::Span) -> Self::SourceFile {
SourceFile {}
fn file(&mut self, _span: Self::Span) -> String {
String::new()
}
fn local_file(&mut self, _span: Self::Span) -> Option<String> {
None
}
fn save_span(&mut self, _span: Self::Span) -> usize {
0

View file

@ -97,6 +97,7 @@ fn test_fn_like_macro_clone_raw_ident() {
}
#[test]
#[cfg(not(bootstrap))]
fn test_fn_like_fn_like_span_join() {
assert_expand(
"fn_like_span_join",
@ -111,6 +112,7 @@ fn test_fn_like_fn_like_span_join() {
}
#[test]
#[cfg(not(bootstrap))]
fn test_fn_like_fn_like_span_ops() {
assert_expand(
"fn_like_span_ops",

View file

@ -16,12 +16,11 @@ either.workspace = true
itertools.workspace = true
rowan = "=0.15.15"
rustc-hash.workspace = true
rustc-literal-escaper.workspace = true
smol_str.workspace = true
triomphe.workspace = true
tracing.workspace = true
ra-ap-rustc_lexer.workspace = true
parser.workspace = true
stdx.workspace = true

View file

@ -2,7 +2,7 @@
use std::{borrow::Cow, num::ParseIntError};
use rustc_lexer::unescape::{
use rustc_literal_escaper::{
EscapeError, MixedUnit, Mode, unescape_byte, unescape_char, unescape_mixed, unescape_unicode,
};
use stdx::always;

View file

@ -19,13 +19,6 @@
//! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256>
//! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md>
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
#[cfg(not(feature = "in-rust-tree"))]
extern crate ra_ap_rustc_lexer as rustc_lexer;
#[cfg(feature = "in-rust-tree")]
extern crate rustc_lexer;
mod parsing;
mod ptr;
mod syntax_error;
@ -64,7 +57,7 @@ pub use rowan::{
Direction, GreenNode, NodeOrToken, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent,
api::Preorder,
};
pub use rustc_lexer::unescape;
pub use rustc_literal_escaper as unescape;
pub use smol_str::{SmolStr, SmolStrBuilder, ToSmolStr, format_smolstr};
/// `Parse` is the result of the parsing: a syntax tree and a collection of

View file

@ -6,7 +6,7 @@ mod block;
use itertools::Itertools;
use rowan::Direction;
use rustc_lexer::unescape::{self, Mode, unescape_mixed, unescape_unicode};
use rustc_literal_escaper::{self, EscapeError, Mode, unescape_mixed, unescape_unicode};
use crate::{
AstNode, SyntaxError,
@ -46,8 +46,8 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) {
}
}
fn rustc_unescape_error_to_string(err: unescape::EscapeError) -> (&'static str, bool) {
use unescape::EscapeError as EE;
fn rustc_unescape_error_to_string(err: EscapeError) -> (&'static str, bool) {
use rustc_literal_escaper::EscapeError as EE;
#[rustfmt::skip]
let err_message = match err {
@ -129,7 +129,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
let text = token.text();
// FIXME: lift this lambda refactor to `fn` (https://github.com/rust-lang/rust-analyzer/pull/2834#discussion_r366199205)
let mut push_err = |prefix_len, off, err: unescape::EscapeError| {
let mut push_err = |prefix_len, off, err: EscapeError| {
let off = token.text_range().start() + TextSize::try_from(off + prefix_len).unwrap();
let (message, is_err) = rustc_unescape_error_to_string(err);
// FIXME: Emit lexer warnings