mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2026-03-15 20:07:55 +00:00
Merge ref '44a5b55557c2' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.
Upstream ref: rust-lang/rust@44a5b55557
Filtered ref: rust-lang/rust-analyzer@d2e7b71402
Upstream diff: 548e586795...44a5b55557
This merge was created using https://github.com/rust-lang/josh-sync.
This commit is contained in:
commit
318545f9d4
@ -61,7 +61,7 @@ impl Expander {
|
||||
pub(super) fn hygiene_for_range(&self, db: &dyn DefDatabase, range: TextRange) -> HygieneId {
|
||||
match self.span_map.as_ref() {
|
||||
hir_expand::span_map::SpanMapRef::ExpansionSpanMap(span_map) => {
|
||||
HygieneId::new(span_map.span_at(range.start()).ctx.opaque_and_semitransparent(db))
|
||||
HygieneId::new(span_map.span_at(range.start()).ctx.opaque_and_semiopaque(db))
|
||||
}
|
||||
hir_expand::span_map::SpanMapRef::RealSpanMap(_) => HygieneId::ROOT,
|
||||
}
|
||||
|
||||
@ -2546,7 +2546,7 @@ impl<'db> ExprCollector<'db> {
|
||||
// Therefore, if we got to the rib of its declaration, give up its hygiene
|
||||
// and use its parent expansion.
|
||||
|
||||
hygiene_id = HygieneId::new(parent_ctx.opaque_and_semitransparent(self.db));
|
||||
hygiene_id = HygieneId::new(parent_ctx.opaque_and_semiopaque(self.db));
|
||||
hygiene_info = parent_ctx.outer_expn(self.db).map(|expansion| {
|
||||
let expansion = self.db.lookup_intern_macro_call(expansion.into());
|
||||
(parent_ctx.parent(self.db), expansion.def)
|
||||
|
||||
@ -936,7 +936,7 @@ fn handle_macro_def_scope(
|
||||
// A macro is allowed to refer to variables from before its declaration.
|
||||
// Therefore, if we got to the rib of its declaration, give up its hygiene
|
||||
// and use its parent expansion.
|
||||
*hygiene_id = HygieneId::new(parent_ctx.opaque_and_semitransparent(db));
|
||||
*hygiene_id = HygieneId::new(parent_ctx.opaque_and_semiopaque(db));
|
||||
*hygiene_info = parent_ctx.outer_expn(db).map(|expansion| {
|
||||
let expansion = db.lookup_intern_macro_call(expansion.into());
|
||||
(parent_ctx.parent(db), expansion.def)
|
||||
|
||||
@ -100,7 +100,8 @@ impl DeclarativeMacroExpander {
|
||||
{
|
||||
match &*value {
|
||||
"transparent" => ControlFlow::Break(Transparency::Transparent),
|
||||
"semitransparent" => ControlFlow::Break(Transparency::SemiTransparent),
|
||||
// "semitransparent" is for old rustc versions.
|
||||
"semiopaque" | "semitransparent" => ControlFlow::Break(Transparency::SemiOpaque),
|
||||
"opaque" => ControlFlow::Break(Transparency::Opaque),
|
||||
_ => ControlFlow::Continue(()),
|
||||
}
|
||||
@ -140,7 +141,7 @@ impl DeclarativeMacroExpander {
|
||||
)),
|
||||
},
|
||||
transparency(ast::AnyHasAttrs::from(macro_rules))
|
||||
.unwrap_or(Transparency::SemiTransparent),
|
||||
.unwrap_or(Transparency::SemiOpaque),
|
||||
),
|
||||
ast::Macro::MacroDef(macro_def) => (
|
||||
match macro_def.body() {
|
||||
|
||||
@ -54,7 +54,7 @@ pub fn span_with_mixed_site_ctxt(
|
||||
expn_id: MacroCallId,
|
||||
edition: Edition,
|
||||
) -> Span {
|
||||
span_with_ctxt_from_mark(db, span, expn_id, Transparency::SemiTransparent, edition)
|
||||
span_with_ctxt_from_mark(db, span, expn_id, Transparency::SemiOpaque, edition)
|
||||
}
|
||||
|
||||
fn span_with_ctxt_from_mark(
|
||||
@ -82,7 +82,7 @@ pub(super) fn apply_mark(
|
||||
}
|
||||
|
||||
let call_site_ctxt = db.lookup_intern_macro_call(call_id.into()).ctxt;
|
||||
let mut call_site_ctxt = if transparency == Transparency::SemiTransparent {
|
||||
let mut call_site_ctxt = if transparency == Transparency::SemiOpaque {
|
||||
call_site_ctxt.normalize_to_macros_2_0(db)
|
||||
} else {
|
||||
call_site_ctxt.normalize_to_macro_rules(db)
|
||||
@ -117,16 +117,16 @@ fn apply_mark_internal(
|
||||
let call_id = Some(call_id);
|
||||
|
||||
let mut opaque = ctxt.opaque(db);
|
||||
let mut opaque_and_semitransparent = ctxt.opaque_and_semitransparent(db);
|
||||
let mut opaque_and_semiopaque = ctxt.opaque_and_semiopaque(db);
|
||||
|
||||
if transparency >= Transparency::Opaque {
|
||||
let parent = opaque;
|
||||
opaque = SyntaxContext::new(db, call_id, transparency, edition, parent, identity, identity);
|
||||
}
|
||||
|
||||
if transparency >= Transparency::SemiTransparent {
|
||||
let parent = opaque_and_semitransparent;
|
||||
opaque_and_semitransparent =
|
||||
if transparency >= Transparency::SemiOpaque {
|
||||
let parent = opaque_and_semiopaque;
|
||||
opaque_and_semiopaque =
|
||||
SyntaxContext::new(db, call_id, transparency, edition, parent, |_| opaque, identity);
|
||||
}
|
||||
|
||||
@ -138,6 +138,6 @@ fn apply_mark_internal(
|
||||
edition,
|
||||
parent,
|
||||
|_| opaque,
|
||||
|_| opaque_and_semitransparent,
|
||||
|_| opaque_and_semiopaque,
|
||||
)
|
||||
}
|
||||
|
||||
@ -429,7 +429,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
|
||||
rustc_attr!(rustc_proc_macro_decls, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
|
||||
rustc_attr!(
|
||||
rustc_macro_transparency, Normal,
|
||||
template!(NameValueStr: "transparent|semitransparent|opaque"), ErrorFollowing,
|
||||
template!(NameValueStr: "transparent|semiopaque|opaque"), ErrorFollowing,
|
||||
"used internally for testing macro hygiene",
|
||||
),
|
||||
|
||||
|
||||
@ -401,8 +401,8 @@ pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContext) -> O
|
||||
result_mark = Some(mark);
|
||||
iter.next();
|
||||
}
|
||||
// Then find the last semi-transparent mark from the end if it exists.
|
||||
while let Some((mark, Transparency::SemiTransparent)) = iter.next() {
|
||||
// Then find the last semi-opaque mark from the end if it exists.
|
||||
while let Some((mark, Transparency::SemiOpaque)) = iter.next() {
|
||||
result_mark = Some(mark);
|
||||
}
|
||||
|
||||
|
||||
@ -3708,7 +3708,7 @@ fn main() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macro_semitransparent_hygiene() {
|
||||
fn macro_semiopaque_hygiene() {
|
||||
check_types(
|
||||
r#"
|
||||
macro_rules! m {
|
||||
|
||||
@ -1808,5 +1808,5 @@ pub(crate) fn name_hygiene(db: &dyn HirDatabase, name: InFile<&SyntaxNode>) -> H
|
||||
};
|
||||
let span_map = db.expansion_span_map(macro_file);
|
||||
let ctx = span_map.span_at(name.value.text_range().start()).ctx;
|
||||
HygieneId::new(ctx.opaque_and_semitransparent(db))
|
||||
HygieneId::new(ctx.opaque_and_semiopaque(db))
|
||||
}
|
||||
|
||||
@ -442,7 +442,6 @@ define_symbols! {
|
||||
rustc_skip_array_during_method_dispatch,
|
||||
rustc_skip_during_method_dispatch,
|
||||
rustc_force_inline,
|
||||
semitransparent,
|
||||
shl_assign,
|
||||
shl,
|
||||
shr_assign,
|
||||
|
||||
@ -46,7 +46,7 @@ const _: () = {
|
||||
edition: Edition,
|
||||
parent: SyntaxContext,
|
||||
opaque: SyntaxContext,
|
||||
opaque_and_semitransparent: SyntaxContext,
|
||||
opaque_and_semiopaque: SyntaxContext,
|
||||
}
|
||||
|
||||
impl PartialEq for SyntaxContextData {
|
||||
@ -214,7 +214,7 @@ const _: () = {
|
||||
edition: T2,
|
||||
parent: T3,
|
||||
opaque: impl FnOnce(SyntaxContext) -> SyntaxContext,
|
||||
opaque_and_semitransparent: impl FnOnce(SyntaxContext) -> SyntaxContext,
|
||||
opaque_and_semiopaque: impl FnOnce(SyntaxContext) -> SyntaxContext,
|
||||
) -> Self
|
||||
where
|
||||
Db: ?Sized + salsa::Database,
|
||||
@ -241,7 +241,7 @@ const _: () = {
|
||||
edition: zalsa_::interned::Lookup::into_owned(data.2),
|
||||
parent: zalsa_::interned::Lookup::into_owned(data.3),
|
||||
opaque: opaque(zalsa_::FromId::from_id(id)),
|
||||
opaque_and_semitransparent: opaque_and_semitransparent(
|
||||
opaque_and_semiopaque: opaque_and_semiopaque(
|
||||
zalsa_::FromId::from_id(id),
|
||||
),
|
||||
},
|
||||
@ -301,7 +301,7 @@ const _: () = {
|
||||
}
|
||||
}
|
||||
|
||||
/// This context, but with all transparent and semi-transparent expansions filtered away.
|
||||
/// This context, but with all transparent and semi-opaque expansions filtered away.
|
||||
pub fn opaque<Db>(self, db: &'db Db) -> SyntaxContext
|
||||
where
|
||||
Db: ?Sized + zalsa_::Database,
|
||||
@ -317,7 +317,7 @@ const _: () = {
|
||||
}
|
||||
|
||||
/// This context, but with all transparent expansions filtered away.
|
||||
pub fn opaque_and_semitransparent<Db>(self, db: &'db Db) -> SyntaxContext
|
||||
pub fn opaque_and_semiopaque<Db>(self, db: &'db Db) -> SyntaxContext
|
||||
where
|
||||
Db: ?Sized + zalsa_::Database,
|
||||
{
|
||||
@ -325,7 +325,7 @@ const _: () = {
|
||||
Some(id) => {
|
||||
let zalsa = db.zalsa();
|
||||
let fields = SyntaxContext::ingredient(zalsa).data(zalsa, id);
|
||||
fields.opaque_and_semitransparent
|
||||
fields.opaque_and_semiopaque
|
||||
}
|
||||
None => self,
|
||||
}
|
||||
@ -405,7 +405,7 @@ impl<'db> SyntaxContext {
|
||||
|
||||
#[inline]
|
||||
pub fn normalize_to_macro_rules(self, db: &'db dyn salsa::Database) -> SyntaxContext {
|
||||
self.opaque_and_semitransparent(db)
|
||||
self.opaque_and_semiopaque(db)
|
||||
}
|
||||
|
||||
pub fn is_opaque(self, db: &'db dyn salsa::Database) -> bool {
|
||||
@ -476,13 +476,13 @@ pub enum Transparency {
|
||||
/// Identifier produced by a transparent expansion is always resolved at call-site.
|
||||
/// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this.
|
||||
Transparent,
|
||||
/// Identifier produced by a semi-transparent expansion may be resolved
|
||||
/// Identifier produced by a semi-opaque expansion may be resolved
|
||||
/// either at call-site or at definition-site.
|
||||
/// If it's a local variable, label or `$crate` then it's resolved at def-site.
|
||||
/// Otherwise it's resolved at call-site.
|
||||
/// `macro_rules` macros behave like this, built-in macros currently behave like this too,
|
||||
/// but that's an implementation detail.
|
||||
SemiTransparent,
|
||||
SemiOpaque,
|
||||
/// Identifier produced by an opaque expansion is always resolved at definition-site.
|
||||
/// Def-site spans in procedural macros, identifiers from `macro` by default use this.
|
||||
Opaque,
|
||||
|
||||
@ -546,11 +546,11 @@ pub mod ptr {
|
||||
// endregion:non_null
|
||||
|
||||
// region:addr_of
|
||||
#[rustc_macro_transparency = "semitransparent"]
|
||||
#[rustc_macro_transparency = "semiopaque"]
|
||||
pub macro addr_of($place:expr) {
|
||||
&raw const $place
|
||||
}
|
||||
#[rustc_macro_transparency = "semitransparent"]
|
||||
#[rustc_macro_transparency = "semiopaque"]
|
||||
pub macro addr_of_mut($place:expr) {
|
||||
&raw mut $place
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user