Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hygiene: Rename semi-transparent to semi-opaque #139084

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/transparency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`"));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,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!(
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,16 +1998,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())
);
Expand Down
47 changes: 23 additions & 24 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ pub 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,
}
Expand All @@ -78,14 +78,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,
}
}
Expand All @@ -96,7 +96,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,
}
}
Expand Down Expand Up @@ -207,21 +207,21 @@ 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,
}

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 }
}
}

Expand Down Expand Up @@ -469,7 +469,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 {
Expand Down Expand Up @@ -562,7 +562,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)
Expand Down Expand Up @@ -608,33 +608,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
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,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
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,7 @@ symbols! {
select_unpredictable,
self_in_typedefs,
self_struct_ctor,
semiopaque,
semitransparent,
sha2,
sha3,
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/hygiene/rustc-macro-transparency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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`
}
12 changes: 6 additions & 6 deletions tests/ui/hygiene/rustc-macro-transparency.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/hygiene/unpretty-debug.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
6 changes: 3 additions & 3 deletions tests/ui/proc-macro/meta-macro-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/nonterminal-token-hygiene.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Loading