Auto merge of #143461 - folkertdev:cfg-select-builtin-macro, r=petrochenkov
make `cfg_select` a builtin macro
tracking issue: https://github.com/rust-lang/rust/issues/115585
This parses mostly the same as the `macro cfg_select` version, except:
1. wrapping in double brackets is no longer supported (or needed): `cfg_select {{ /* ... */ }}` is now rejected.
2. in an expression context, the rhs is no longer wrapped in a block, so that this now works:
```rust
fn main() {
println!(cfg_select! {
unix => { "foo" }
_ => { "bar" }
});
}
```
3. a single wildcard rule is now supported: `cfg_select { _ => 1 }` now works
I've also added an error if none of the rules evaluate to true, and warnings for any arms that follow the `_` wildcard rule.
cc `@traviscross` if I'm missing any feature that should/should not be included
r? `@petrochenkov` for the macro logic details
diff --git a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs
index 22b7f5a..56fd12e 100644
--- a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs
+++ b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs
@@ -489,6 +489,14 @@
fn complexity_exceeded(&self) -> Result<(), Self::Error> {
Err(())
}
+
+ fn report_mixed_deref_pat_ctors(
+ &self,
+ _deref_pat: &DeconstructedPat<'_>,
+ _normal_pat: &DeconstructedPat<'_>,
+ ) {
+ // FIXME(deref_patterns): This could report an error comparable to the one in rustc.
+ }
}
impl fmt::Debug for MatchCheckCtx<'_> {
diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs
index 3fa2bfb..107da6a 100644
--- a/crates/hir-ty/src/layout.rs
+++ b/crates/hir-ty/src/layout.rs
@@ -261,7 +261,7 @@
}
// Potentially-wide pointers.
TyKind::Ref(_, _, pointee) | TyKind::Raw(_, pointee) => {
- let mut data_ptr = scalar_unit(dl, Primitive::Pointer(AddressSpace::DATA));
+ let mut data_ptr = scalar_unit(dl, Primitive::Pointer(AddressSpace::ZERO));
if matches!(ty.kind(Interner), TyKind::Ref(..)) {
data_ptr.valid_range_mut().start = 1;
}
@@ -285,7 +285,7 @@
scalar_unit(dl, Primitive::Int(dl.ptr_sized_integer(), false))
}
TyKind::Dyn(..) => {
- let mut vtable = scalar_unit(dl, Primitive::Pointer(AddressSpace::DATA));
+ let mut vtable = scalar_unit(dl, Primitive::Pointer(AddressSpace::ZERO));
vtable.valid_range_mut().start = 1;
vtable
}
diff --git a/crates/hir-ty/src/layout/target.rs b/crates/hir-ty/src/layout/target.rs
index e1e1c44..88c33ec 100644
--- a/crates/hir-ty/src/layout/target.rs
+++ b/crates/hir-ty/src/layout/target.rs
@@ -2,7 +2,7 @@
use base_db::Crate;
use hir_def::layout::TargetDataLayout;
-use rustc_abi::{AlignFromBytesError, TargetDataLayoutErrors};
+use rustc_abi::{AlignFromBytesError, TargetDataLayoutErrors, AddressSpace};
use triomphe::Arc;
use crate::db::HirDatabase;
@@ -12,7 +12,7 @@
krate: Crate,
) -> Result<Arc<TargetDataLayout>, Arc<str>> {
match &krate.workspace_data(db).data_layout {
- Ok(it) => match TargetDataLayout::parse_from_llvm_datalayout_string(it) {
+ Ok(it) => match TargetDataLayout::parse_from_llvm_datalayout_string(it, AddressSpace::ZERO) {
Ok(it) => Ok(Arc::new(it)),
Err(e) => {
Err(match e {
@@ -39,6 +39,7 @@
target,
} => format!(r#"inconsistent target specification: "data-layout" claims pointers are {pointer_size}-bit, while "target-pointer-width" is `{target}`"#),
TargetDataLayoutErrors::InvalidBitsSize { err } => err,
+ TargetDataLayoutErrors::UnknownPointerSpecification { err } => format!(r#"use of unknown pointer specifer in "data-layout": {err}"#),
}.into())
}
},
diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs
index 1ec55a8..55fada1 100644
--- a/crates/hir-ty/src/mir/eval.rs
+++ b/crates/hir-ty/src/mir/eval.rs
@@ -630,7 +630,7 @@
Ok(target_data_layout) => target_data_layout,
Err(e) => return Err(MirEvalError::TargetDataLayoutNotAvailable(e)),
};
- let cached_ptr_size = target_data_layout.pointer_size.bytes_usize();
+ let cached_ptr_size = target_data_layout.pointer_size().bytes_usize();
Ok(Evaluator {
target_data_layout,
stack: vec![0],
diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs
index 347da4e..6820f99 100644
--- a/crates/ide/src/file_structure.rs
+++ b/crates/ide/src/file_structure.rs
@@ -329,7 +329,7 @@
#[deprecated]
fn obsolete() {}
-#[deprecated(note = "for awhile")]
+#[deprecated(note = "for a while")]
fn very_obsolete() {}
// region: Some region name
@@ -608,8 +608,8 @@
StructureNode {
parent: None,
label: "very_obsolete",
- navigation_range: 511..524,
- node_range: 473..529,
+ navigation_range: 512..525,
+ node_range: 473..530,
kind: SymbolKind(
Function,
),
@@ -621,8 +621,8 @@
StructureNode {
parent: None,
label: "Some region name",
- navigation_range: 531..558,
- node_range: 531..558,
+ navigation_range: 532..559,
+ node_range: 532..559,
kind: Region,
detail: None,
deprecated: false,
@@ -630,8 +630,8 @@
StructureNode {
parent: None,
label: "m",
- navigation_range: 598..599,
- node_range: 573..636,
+ navigation_range: 599..600,
+ node_range: 574..637,
kind: SymbolKind(
Module,
),
@@ -643,8 +643,8 @@
22,
),
label: "dontpanic",
- navigation_range: 573..593,
- node_range: 573..593,
+ navigation_range: 574..594,
+ node_range: 574..594,
kind: Region,
detail: None,
deprecated: false,
@@ -654,8 +654,8 @@
22,
),
label: "f",
- navigation_range: 605..606,
- node_range: 602..611,
+ navigation_range: 606..607,
+ node_range: 603..612,
kind: SymbolKind(
Function,
),
@@ -669,8 +669,8 @@
22,
),
label: "g",
- navigation_range: 628..629,
- node_range: 612..634,
+ navigation_range: 629..630,
+ node_range: 613..635,
kind: SymbolKind(
Function,
),
@@ -682,8 +682,8 @@
StructureNode {
parent: None,
label: "extern \"C\"",
- navigation_range: 638..648,
- node_range: 638..651,
+ navigation_range: 639..649,
+ node_range: 639..652,
kind: ExternBlock,
detail: None,
deprecated: false,
@@ -691,8 +691,8 @@
StructureNode {
parent: None,
label: "let_statements",
- navigation_range: 656..670,
- node_range: 653..813,
+ navigation_range: 657..671,
+ node_range: 654..814,
kind: SymbolKind(
Function,
),
@@ -706,8 +706,8 @@
27,
),
label: "x",
- navigation_range: 683..684,
- node_range: 679..690,
+ navigation_range: 684..685,
+ node_range: 680..691,
kind: SymbolKind(
Local,
),
@@ -719,8 +719,8 @@
27,
),
label: "mut y",
- navigation_range: 699..704,
- node_range: 695..709,
+ navigation_range: 700..705,
+ node_range: 696..710,
kind: SymbolKind(
Local,
),
@@ -732,8 +732,8 @@
27,
),
label: "Foo { .. }",
- navigation_range: 718..740,
- node_range: 714..753,
+ navigation_range: 719..741,
+ node_range: 715..754,
kind: SymbolKind(
Local,
),
@@ -745,8 +745,8 @@
27,
),
label: "_",
- navigation_range: 803..804,
- node_range: 799..811,
+ navigation_range: 804..805,
+ node_range: 800..812,
kind: SymbolKind(
Local,
),
diff --git a/crates/parser/src/lexed_str.rs b/crates/parser/src/lexed_str.rs
index e6c92de..bff9acd 100644
--- a/crates/parser/src/lexed_str.rs
+++ b/crates/parser/src/lexed_str.rs
@@ -11,8 +11,8 @@
use std::ops;
use rustc_literal_escaper::{
- EscapeError, Mode, unescape_byte, unescape_byte_str, unescape_c_str, unescape_char,
- unescape_str,
+ unescape_byte, unescape_byte_str, unescape_c_str, unescape_char, unescape_str, EscapeError,
+ Mode,
};
use crate::{
@@ -44,7 +44,9 @@
// Re-create the tokenizer from scratch every token because `GuardedStrPrefix` is one token in the lexer
// but we want to split it to two in edition <2024.
- while let Some(token) = rustc_lexer::tokenize(&text[conv.offset..]).next() {
+ while let Some(token) =
+ rustc_lexer::tokenize(&text[conv.offset..], rustc_lexer::FrontmatterAllowed::No).next()
+ {
let token_text = &text[conv.offset..][..token.len as usize];
conv.extend_token(&token.kind, token_text);
@@ -58,7 +60,7 @@
return None;
}
- let token = rustc_lexer::tokenize(text).next()?;
+ let token = rustc_lexer::tokenize(text, rustc_lexer::FrontmatterAllowed::No).next()?;
if token.len as usize != text.len() {
return None;
}
diff --git a/crates/proc-macro-srv/src/server_impl.rs b/crates/proc-macro-srv/src/server_impl.rs
index dd576f2..662f625 100644
--- a/crates/proc-macro-srv/src/server_impl.rs
+++ b/crates/proc-macro-srv/src/server_impl.rs
@@ -121,7 +121,7 @@
use proc_macro::bridge::LitKind;
use rustc_lexer::{LiteralKind, Token, TokenKind};
- let mut tokens = rustc_lexer::tokenize(s);
+ let mut tokens = rustc_lexer::tokenize(s, rustc_lexer::FrontmatterAllowed::No);
let minus_or_lit = tokens.next().unwrap_or(Token { kind: TokenKind::Eof, len: 0 });
let lit = if minus_or_lit.kind == TokenKind::Minus {
diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs
index d258c5d..37f83f6 100644
--- a/crates/rust-analyzer/src/cli/scip.rs
+++ b/crates/rust-analyzer/src/cli/scip.rs
@@ -25,7 +25,7 @@
eprintln!("Generating SCIP start...");
let now = Instant::now();
- let no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}"));
+ let no_progress = &|s| eprintln!("rust-analyzer: Loading {s}");
let root =
vfs::AbsPathBuf::assert_utf8(std::env::current_dir()?.join(&self.path)).normalize();
diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs
index 14574a6..4412338 100644
--- a/crates/tt/src/lib.rs
+++ b/crates/tt/src/lib.rs
@@ -579,7 +579,7 @@
{
use rustc_lexer::LiteralKind;
- let token = rustc_lexer::tokenize(text).next_tuple();
+ let token = rustc_lexer::tokenize(text, rustc_lexer::FrontmatterAllowed::No).next_tuple();
let Some((rustc_lexer::Token {
kind: rustc_lexer::TokenKind::Literal { kind, suffix_start },
..