Skip to content

Commit a138e9d

Browse files
committed
expand: Get rid of resolve_macro_path
It was used to choose whether to apply derive markers like `#[rustc_copy_clone_marker]` or not, but it was called before all the data required for resolution is available, so it could work incorrectly in some corner cases (like user-defined derives name `Copy` or `Eq`). Delay the decision about markers until the proper resolution results are available instead.
1 parent 62a1f5d commit a138e9d

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

src/librustc_resolve/macros.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,6 @@ impl<'a> base::Resolver for Resolver<'a> {
242242
Ok(Some(ext))
243243
}
244244

245-
fn resolve_macro_path(&mut self, path: &ast::Path, kind: MacroKind, invoc_id: Mark,
246-
derives_in_scope: Vec<ast::Path>, force: bool)
247-
-> Result<Lrc<SyntaxExtension>, Determinacy> {
248-
let parent_scope = self.invoc_parent_scope(invoc_id, derives_in_scope);
249-
Ok(self.resolve_macro_to_res(path, kind, &parent_scope, false, force)?.1)
250-
}
251-
252245
fn check_unused_macros(&self) {
253246
for (&node_id, &span) in self.unused_macros.iter() {
254247
self.session.buffer_lint(

src/libsyntax/ext/base.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,6 @@ pub trait Resolver {
680680

681681
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force: bool)
682682
-> Result<Option<Lrc<SyntaxExtension>>, Determinacy>;
683-
fn resolve_macro_path(&mut self, path: &ast::Path, kind: MacroKind, invoc_id: Mark,
684-
derives_in_scope: Vec<ast::Path>, force: bool)
685-
-> Result<Lrc<SyntaxExtension>, Determinacy>;
686683

687684
fn check_unused_macros(&self);
688685
}

src/libsyntax/ext/expand.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ pub enum InvocationKind {
208208
Derive {
209209
path: Path,
210210
item: Annotatable,
211+
item_with_markers: Annotatable,
211212
},
212213
}
213214

@@ -362,19 +363,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
362363

363364
derives.reserve(traits.len());
364365
invocations.reserve(traits.len());
365-
for path in &traits {
366+
for path in traits {
366367
let mark = Mark::fresh(self.cx.current_expansion.mark);
367368
derives.push(mark);
368-
let item = match self.cx.resolver.resolve_macro_path(
369-
path, MacroKind::Derive, Mark::root(), Vec::new(), false) {
370-
Ok(ext) => match ext.kind {
371-
SyntaxExtensionKind::LegacyDerive(..) => item_with_markers.clone(),
372-
_ => item.clone(),
373-
},
374-
_ => item.clone(),
375-
};
376369
invocations.push(Invocation {
377-
kind: InvocationKind::Derive { path: path.clone(), item },
370+
kind: InvocationKind::Derive {
371+
path,
372+
item: item.clone(),
373+
item_with_markers: item_with_markers.clone(),
374+
},
378375
fragment_kind: invoc.fragment_kind,
379376
expansion_data: ExpansionData {
380377
mark,
@@ -737,7 +734,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
737734
ext: &SyntaxExtension)
738735
-> Option<AstFragment> {
739736
let (path, item) = match invoc.kind {
740-
InvocationKind::Derive { path, item } => (path, item),
737+
InvocationKind::Derive { path, item, item_with_markers } => match ext.kind {
738+
SyntaxExtensionKind::LegacyDerive(..) => (path, item_with_markers),
739+
_ => (path, item),
740+
}
741741
_ => unreachable!(),
742742
};
743743
if !item.derive_allowed() {

0 commit comments

Comments
 (0)