Rollup merge of #139084 - petrochenkov:transpaque, r=davidtwco

hygiene: Rename semi-transparent to semi-opaque

"Semi-transparent" is just too damn long for a name, especially when used multiple times on a single line, it bothered me when working on #139083.

An optimist sees a macro as semi-opaque, a pessimist sees it as semi-transparent.
Or is it the other way round?
This commit is contained in:
Matthias Krüger 2025-04-17 00:14:24 +02:00 committed by GitHub
commit 9842698be5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 48 additions and 48 deletions

View file

@ -20,7 +20,7 @@ impl SingleAttributeParser for TransparencyParser {
fn convert(cx: &AcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind> { fn convert(cx: &AcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind> {
match args.name_value().and_then(|nv| nv.value_as_str()) { match args.name_value().and_then(|nv| nv.value_as_str()) {
Some(sym::transparent) => Some(Transparency::Transparent), Some(sym::transparent) => Some(Transparency::Transparent),
Some(sym::semitransparent) => Some(Transparency::SemiTransparent), Some(sym::semiopaque | sym::semitransparent) => Some(Transparency::SemiOpaque),
Some(sym::opaque) => Some(Transparency::Opaque), Some(sym::opaque) => Some(Transparency::Opaque),
Some(other) => { Some(other) => {
cx.dcx().span_err(cx.attr_span, format!("unknown macro transparency: `{other}`")); cx.dcx().span_err(cx.attr_span, format!("unknown macro transparency: `{other}`"));

View file

@ -767,7 +767,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
), ),
rustc_attr!( rustc_attr!(
rustc_macro_transparency, Normal, rustc_macro_transparency, Normal,
template!(NameValueStr: "transparent|semitransparent|opaque"), ErrorFollowing, template!(NameValueStr: "transparent|semiopaque|opaque"), ErrorFollowing,
EncodeCrossCrate::Yes, "used internally for testing macro hygiene", EncodeCrossCrate::Yes, "used internally for testing macro hygiene",
), ),
rustc_attr!( rustc_attr!(

View file

@ -2007,16 +2007,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
result, result,
result.map(|r| r.expn_data()) result.map(|r| r.expn_data())
); );
// Then find the last semi-transparent mark from the end if it exists. // Then find the last semi-opaque mark from the end if it exists.
for (mark, transparency) in iter { for (mark, transparency) in iter {
if transparency == Transparency::SemiTransparent { if transparency == Transparency::SemiOpaque {
result = Some(mark); result = Some(mark);
} else { } else {
break; break;
} }
} }
debug!( debug!(
"resolve_crate_root: found semi-transparent mark {:?} {:?}", "resolve_crate_root: found semi-opaque mark {:?} {:?}",
result, result,
result.map(|r| r.expn_data()) result.map(|r| r.expn_data())
); );

View file

@ -63,10 +63,10 @@ struct SyntaxContextData {
outer_expn: ExpnId, outer_expn: ExpnId,
outer_transparency: Transparency, outer_transparency: Transparency,
parent: SyntaxContext, parent: SyntaxContext,
/// This context, but with all transparent and semi-transparent expansions filtered away. /// This context, but with all transparent and semi-opaque expansions filtered away.
opaque: SyntaxContext, opaque: SyntaxContext,
/// This context, but with all transparent expansions filtered away. /// This context, but with all transparent expansions filtered away.
opaque_and_semitransparent: SyntaxContext, opaque_and_semiopaque: SyntaxContext,
/// Name of the crate to which `$crate` with this context would resolve. /// Name of the crate to which `$crate` with this context would resolve.
dollar_crate_name: Symbol, dollar_crate_name: Symbol,
} }
@ -75,14 +75,14 @@ impl SyntaxContextData {
fn new( fn new(
(parent, outer_expn, outer_transparency): SyntaxContextKey, (parent, outer_expn, outer_transparency): SyntaxContextKey,
opaque: SyntaxContext, opaque: SyntaxContext,
opaque_and_semitransparent: SyntaxContext, opaque_and_semiopaque: SyntaxContext,
) -> SyntaxContextData { ) -> SyntaxContextData {
SyntaxContextData { SyntaxContextData {
outer_expn, outer_expn,
outer_transparency, outer_transparency,
parent, parent,
opaque, opaque,
opaque_and_semitransparent, opaque_and_semiopaque,
dollar_crate_name: kw::DollarCrate, dollar_crate_name: kw::DollarCrate,
} }
} }
@ -93,7 +93,7 @@ impl SyntaxContextData {
outer_transparency: Transparency::Opaque, outer_transparency: Transparency::Opaque,
parent: SyntaxContext::root(), parent: SyntaxContext::root(),
opaque: SyntaxContext::root(), opaque: SyntaxContext::root(),
opaque_and_semitransparent: SyntaxContext::root(), opaque_and_semiopaque: SyntaxContext::root(),
dollar_crate_name: kw::DollarCrate, dollar_crate_name: kw::DollarCrate,
} }
} }
@ -204,13 +204,13 @@ pub enum Transparency {
/// Identifier produced by a transparent expansion is always resolved at call-site. /// 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. /// Call-site spans in procedural macros, hygiene opt-out in `macro` should use this.
Transparent, 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. /// either at call-site or at definition-site.
/// If it's a local variable, label or `$crate` then it's resolved at def-site. /// If it's a local variable, label or `$crate` then it's resolved at def-site.
/// Otherwise it's resolved at call-site. /// Otherwise it's resolved at call-site.
/// `macro_rules` macros behave like this, built-in macros currently behave like this too, /// `macro_rules` macros behave like this, built-in macros currently behave like this too,
/// but that's an implementation detail. /// but that's an implementation detail.
SemiTransparent, SemiOpaque,
/// Identifier produced by an opaque expansion is always resolved at definition-site. /// 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. /// Def-site spans in procedural macros, identifiers from `macro` by default use this.
Opaque, Opaque,
@ -218,7 +218,7 @@ pub enum Transparency {
impl Transparency { impl Transparency {
pub fn fallback(macro_rules: bool) -> Self { pub fn fallback(macro_rules: bool) -> Self {
if macro_rules { Transparency::SemiTransparent } else { Transparency::Opaque } if macro_rules { Transparency::SemiOpaque } else { Transparency::Opaque }
} }
} }
@ -466,7 +466,7 @@ impl HygieneData {
fn normalize_to_macro_rules(&self, ctxt: SyntaxContext) -> SyntaxContext { fn normalize_to_macro_rules(&self, ctxt: SyntaxContext) -> SyntaxContext {
debug_assert!(!self.syntax_context_data[ctxt.0 as usize].is_decode_placeholder()); debug_assert!(!self.syntax_context_data[ctxt.0 as usize].is_decode_placeholder());
self.syntax_context_data[ctxt.0 as usize].opaque_and_semitransparent self.syntax_context_data[ctxt.0 as usize].opaque_and_semiopaque
} }
fn outer_expn(&self, ctxt: SyntaxContext) -> ExpnId { fn outer_expn(&self, ctxt: SyntaxContext) -> ExpnId {
@ -559,7 +559,7 @@ impl HygieneData {
} }
let call_site_ctxt = self.expn_data(expn_id).call_site.ctxt(); let call_site_ctxt = self.expn_data(expn_id).call_site.ctxt();
let mut call_site_ctxt = if transparency == Transparency::SemiTransparent { let mut call_site_ctxt = if transparency == Transparency::SemiOpaque {
self.normalize_to_macros_2_0(call_site_ctxt) self.normalize_to_macros_2_0(call_site_ctxt)
} else { } else {
self.normalize_to_macro_rules(call_site_ctxt) self.normalize_to_macro_rules(call_site_ctxt)
@ -605,33 +605,32 @@ impl HygieneData {
self.syntax_context_data.push(SyntaxContextData::decode_placeholder()); self.syntax_context_data.push(SyntaxContextData::decode_placeholder());
self.syntax_context_map.insert(key, ctxt); self.syntax_context_map.insert(key, ctxt);
// Opaque and semi-transparent versions of the parent. Note that they may be equal to the // Opaque and semi-opaque versions of the parent. Note that they may be equal to the
// parent itself. E.g. `parent_opaque` == `parent` if the expn chain contains only opaques, // parent itself. E.g. `parent_opaque` == `parent` if the expn chain contains only opaques,
// and `parent_opaque_and_semitransparent` == `parent` if the expn contains only opaques // and `parent_opaque_and_semiopaque` == `parent` if the expn contains only (semi-)opaques.
// and semi-transparents.
let parent_opaque = self.syntax_context_data[parent.0 as usize].opaque; let parent_opaque = self.syntax_context_data[parent.0 as usize].opaque;
let parent_opaque_and_semitransparent = let parent_opaque_and_semiopaque =
self.syntax_context_data[parent.0 as usize].opaque_and_semitransparent; self.syntax_context_data[parent.0 as usize].opaque_and_semiopaque;
// Evaluate opaque and semi-transparent versions of the new syntax context. // Evaluate opaque and semi-opaque versions of the new syntax context.
let (opaque, opaque_and_semitransparent) = match transparency { let (opaque, opaque_and_semiopaque) = match transparency {
Transparency::Transparent => (parent_opaque, parent_opaque_and_semitransparent), Transparency::Transparent => (parent_opaque, parent_opaque_and_semiopaque),
Transparency::SemiTransparent => ( Transparency::SemiOpaque => (
parent_opaque, parent_opaque,
// Will be the same as `ctxt` if the expn chain contains only opaques and semi-transparents. // Will be the same as `ctxt` if the expn chain contains only (semi-)opaques.
self.alloc_ctxt(parent_opaque_and_semitransparent, expn_id, transparency), self.alloc_ctxt(parent_opaque_and_semiopaque, expn_id, transparency),
), ),
Transparency::Opaque => ( Transparency::Opaque => (
// Will be the same as `ctxt` if the expn chain contains only opaques. // Will be the same as `ctxt` if the expn chain contains only opaques.
self.alloc_ctxt(parent_opaque, expn_id, transparency), self.alloc_ctxt(parent_opaque, expn_id, transparency),
// Will be the same as `ctxt` if the expn chain contains only opaques and semi-transparents. // Will be the same as `ctxt` if the expn chain contains only (semi-)opaques.
self.alloc_ctxt(parent_opaque_and_semitransparent, expn_id, transparency), self.alloc_ctxt(parent_opaque_and_semiopaque, expn_id, transparency),
), ),
}; };
// Fill the full data, now that we have it. // Fill the full data, now that we have it.
self.syntax_context_data[ctxt.as_u32() as usize] = self.syntax_context_data[ctxt.as_u32() as usize] =
SyntaxContextData::new(key, opaque, opaque_and_semitransparent); SyntaxContextData::new(key, opaque, opaque_and_semiopaque);
ctxt ctxt
} }
} }

View file

@ -1117,7 +1117,7 @@ impl Span {
/// Equivalent of `Span::mixed_site` from the proc macro API, /// Equivalent of `Span::mixed_site` from the proc macro API,
/// except that the location is taken from the `self` span. /// except that the location is taken from the `self` span.
pub fn with_mixed_site_ctxt(self, expn_id: ExpnId) -> Span { pub fn with_mixed_site_ctxt(self, expn_id: ExpnId) -> Span {
self.with_ctxt_from_mark(expn_id, Transparency::SemiTransparent) self.with_ctxt_from_mark(expn_id, Transparency::SemiOpaque)
} }
/// Produces a span with the same location as `self` and context produced by a macro with the /// Produces a span with the same location as `self` and context produced by a macro with the

View file

@ -1882,6 +1882,7 @@ symbols! {
select_unpredictable, select_unpredictable,
self_in_typedefs, self_in_typedefs,
self_struct_ctor, self_struct_ctor,
semiopaque,
semitransparent, semitransparent,
sha2, sha2,
sha3, sha3,

View file

@ -6,9 +6,9 @@ macro transparent() {
let transparent = 0; let transparent = 0;
} }
#[rustc_macro_transparency = "semitransparent"] #[rustc_macro_transparency = "semitransparent"]
macro semitransparent() { macro semiopaque() {
struct SemiTransparent; struct SemiOpaque;
let semitransparent = 0; let semiopaque = 0;
} }
#[rustc_macro_transparency = "opaque"] #[rustc_macro_transparency = "opaque"]
macro opaque() { macro opaque() {
@ -18,14 +18,14 @@ macro opaque() {
fn main() { fn main() {
transparent!(); transparent!();
semitransparent!(); semiopaque!();
opaque!(); opaque!();
Transparent; // OK Transparent; // OK
SemiTransparent; // OK SemiOpaque; // OK
Opaque; //~ ERROR cannot find value `Opaque` in this scope Opaque; //~ ERROR cannot find value `Opaque` in this scope
transparent; // OK transparent; // OK
semitransparent; //~ ERROR expected value, found macro `semitransparent` semiopaque; //~ ERROR expected value, found macro `semiopaque`
opaque; //~ ERROR expected value, found macro `opaque` opaque; //~ ERROR expected value, found macro `opaque`
} }

View file

@ -4,17 +4,17 @@ error[E0425]: cannot find value `Opaque` in this scope
LL | Opaque; LL | Opaque;
| ^^^^^^ not found in this scope | ^^^^^^ not found in this scope
error[E0423]: expected value, found macro `semitransparent` error[E0423]: expected value, found macro `semiopaque`
--> $DIR/rustc-macro-transparency.rs:29:5 --> $DIR/rustc-macro-transparency.rs:29:5
| |
LL | struct SemiTransparent; LL | struct SemiOpaque;
| ----------------------- similarly named unit struct `SemiTransparent` defined here | ------------------ similarly named unit struct `SemiOpaque` defined here
... ...
LL | semitransparent; LL | semiopaque;
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^
| | | |
| not a value | not a value
| help: a unit struct with a similar name exists: `SemiTransparent` | help: a unit struct with a similar name exists (notice the capitalization): `SemiOpaque`
error[E0423]: expected value, found macro `opaque` error[E0423]: expected value, found macro `opaque`
--> $DIR/rustc-macro-transparency.rs:30:5 --> $DIR/rustc-macro-transparency.rs:30:5

View file

@ -24,5 +24,5 @@ crate0::{{expn1}}: parent: crate0::{{expn0}}, call_site_ctxt: #0, def_site_ctxt:
SyntaxContexts: SyntaxContexts:
#0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque) #0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, SemiTransparent) #1: parent: #0, outer_mark: (crate0::{{expn1}}, SemiOpaque)
*/ */

View file

@ -60,11 +60,11 @@ SyntaxContexts:
#0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque) #0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque) #1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque)
#2: parent: #0, outer_mark: (crate0::{{expn1}}, Transparent) #2: parent: #0, outer_mark: (crate0::{{expn1}}, Transparent)
#3: parent: #0, outer_mark: (crate0::{{expn2}}, SemiTransparent) #3: parent: #0, outer_mark: (crate0::{{expn2}}, SemiOpaque)
#4: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque) #4: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque)
#5: parent: #3, outer_mark: (crate0::{{expn3}}, Transparent) #5: parent: #3, outer_mark: (crate0::{{expn3}}, Transparent)
#6: parent: #0, outer_mark: (crate0::{{expn3}}, SemiTransparent) #6: parent: #0, outer_mark: (crate0::{{expn3}}, SemiOpaque)
#7: parent: #0, outer_mark: (crate0::{{expn4}}, Opaque) #7: parent: #0, outer_mark: (crate0::{{expn4}}, Opaque)
#8: parent: #4, outer_mark: (crate0::{{expn4}}, Transparent) #8: parent: #4, outer_mark: (crate0::{{expn4}}, Transparent)
#9: parent: #4, outer_mark: (crate0::{{expn4}}, SemiTransparent) #9: parent: #4, outer_mark: (crate0::{{expn4}}, SemiOpaque)
*/ */

View file

@ -82,10 +82,10 @@ SyntaxContexts:
#0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque) #0: parent: #0, outer_mark: (crate0::{{expn0}}, Opaque)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque) #1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque)
#2: parent: #0, outer_mark: (crate0::{{expn1}}, Transparent) #2: parent: #0, outer_mark: (crate0::{{expn1}}, Transparent)
#3: parent: #0, outer_mark: (crate0::{{expn2}}, SemiTransparent) #3: parent: #0, outer_mark: (crate0::{{expn2}}, SemiOpaque)
#4: parent: #3, outer_mark: (crate0::{{expn3}}, Opaque) #4: parent: #3, outer_mark: (crate0::{{expn3}}, Opaque)
#5: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque) #5: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque)
#6: parent: #0, outer_mark: (crate0::{{expn4}}, Opaque) #6: parent: #0, outer_mark: (crate0::{{expn4}}, Opaque)
#7: parent: #4, outer_mark: (crate0::{{expn4}}, Transparent) #7: parent: #4, outer_mark: (crate0::{{expn4}}, Transparent)
#8: parent: #5, outer_mark: (crate0::{{expn4}}, SemiTransparent) #8: parent: #5, outer_mark: (crate0::{{expn4}}, SemiOpaque)
*/ */