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> {
match args.name_value().and_then(|nv| nv.value_as_str()) {
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(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_macro_transparency, Normal,
template!(NameValueStr: "transparent|semitransparent|opaque"), ErrorFollowing,
template!(NameValueStr: "transparent|semiopaque|opaque"), ErrorFollowing,
EncodeCrossCrate::Yes, "used internally for testing macro hygiene",
),
rustc_attr!(

View file

@ -2007,16 +2007,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
result,
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 {
if transparency == Transparency::SemiTransparent {
if transparency == Transparency::SemiOpaque {
result = Some(mark);
} else {
break;
}
}
debug!(
"resolve_crate_root: found semi-transparent mark {:?} {:?}",
"resolve_crate_root: found semi-opaque mark {:?} {:?}",
result,
result.map(|r| r.expn_data())
);

View file

@ -63,10 +63,10 @@ struct SyntaxContextData {
outer_expn: ExpnId,
outer_transparency: Transparency,
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,
/// 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.
dollar_crate_name: Symbol,
}
@ -75,14 +75,14 @@ impl SyntaxContextData {
fn new(
(parent, outer_expn, outer_transparency): SyntaxContextKey,
opaque: SyntaxContext,
opaque_and_semitransparent: SyntaxContext,
opaque_and_semiopaque: SyntaxContext,
) -> SyntaxContextData {
SyntaxContextData {
outer_expn,
outer_transparency,
parent,
opaque,
opaque_and_semitransparent,
opaque_and_semiopaque,
dollar_crate_name: kw::DollarCrate,
}
}
@ -93,7 +93,7 @@ impl SyntaxContextData {
outer_transparency: Transparency::Opaque,
parent: SyntaxContext::root(),
opaque: SyntaxContext::root(),
opaque_and_semitransparent: SyntaxContext::root(),
opaque_and_semiopaque: SyntaxContext::root(),
dollar_crate_name: kw::DollarCrate,
}
}
@ -204,13 +204,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,
@ -218,7 +218,7 @@ pub enum Transparency {
impl Transparency {
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 {
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 {
@ -559,7 +559,7 @@ impl HygieneData {
}
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)
} else {
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_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,
// and `parent_opaque_and_semitransparent` == `parent` if the expn contains only opaques
// and semi-transparents.
// and `parent_opaque_and_semiopaque` == `parent` if the expn contains only (semi-)opaques.
let parent_opaque = self.syntax_context_data[parent.0 as usize].opaque;
let parent_opaque_and_semitransparent =
self.syntax_context_data[parent.0 as usize].opaque_and_semitransparent;
let parent_opaque_and_semiopaque =
self.syntax_context_data[parent.0 as usize].opaque_and_semiopaque;
// Evaluate opaque and semi-transparent versions of the new syntax context.
let (opaque, opaque_and_semitransparent) = match transparency {
Transparency::Transparent => (parent_opaque, parent_opaque_and_semitransparent),
Transparency::SemiTransparent => (
// Evaluate opaque and semi-opaque versions of the new syntax context.
let (opaque, opaque_and_semiopaque) = match transparency {
Transparency::Transparent => (parent_opaque, parent_opaque_and_semiopaque),
Transparency::SemiOpaque => (
parent_opaque,
// Will be the same as `ctxt` if the expn chain contains only opaques and semi-transparents.
self.alloc_ctxt(parent_opaque_and_semitransparent, expn_id, transparency),
// Will be the same as `ctxt` if the expn chain contains only (semi-)opaques.
self.alloc_ctxt(parent_opaque_and_semiopaque, expn_id, transparency),
),
Transparency::Opaque => (
// Will be the same as `ctxt` if the expn chain contains only opaques.
self.alloc_ctxt(parent_opaque, expn_id, transparency),
// Will be the same as `ctxt` if the expn chain contains only opaques and semi-transparents.
self.alloc_ctxt(parent_opaque_and_semitransparent, expn_id, transparency),
// Will be the same as `ctxt` if the expn chain contains only (semi-)opaques.
self.alloc_ctxt(parent_opaque_and_semiopaque, expn_id, transparency),
),
};
// Fill the full data, now that we have it.
self.syntax_context_data[ctxt.as_u32() as usize] =
SyntaxContextData::new(key, opaque, opaque_and_semitransparent);
SyntaxContextData::new(key, opaque, opaque_and_semiopaque);
ctxt
}
}

View file

@ -1117,7 +1117,7 @@ impl Span {
/// Equivalent of `Span::mixed_site` from the proc macro API,
/// except that the location is taken from the `self` 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

View file

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

View file

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

View file

@ -4,17 +4,17 @@ error[E0425]: cannot find value `Opaque` in this scope
LL | Opaque;
| ^^^^^^ 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
|
LL | struct SemiTransparent;
| ----------------------- similarly named unit struct `SemiTransparent` defined here
LL | struct SemiOpaque;
| ------------------ similarly named unit struct `SemiOpaque` defined here
...
LL | semitransparent;
| ^^^^^^^^^^^^^^^
LL | semiopaque;
| ^^^^^^^^^^
| |
| 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`
--> $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:
#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)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque)
#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)
#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)
#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)
#1: parent: #0, outer_mark: (crate0::{{expn1}}, Opaque)
#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)
#5: parent: #0, outer_mark: (crate0::{{expn3}}, Opaque)
#6: parent: #0, outer_mark: (crate0::{{expn4}}, Opaque)
#7: parent: #4, outer_mark: (crate0::{{expn4}}, Transparent)
#8: parent: #5, outer_mark: (crate0::{{expn4}}, SemiTransparent)
#8: parent: #5, outer_mark: (crate0::{{expn4}}, SemiOpaque)
*/