From 1e8a7f68e9c8dea677390b84fa72476ddb4bf1ca Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 25 Jul 2017 00:33:15 +0300 Subject: [PATCH] Avoid duplicated errors for generic arguments in macro paths --- src/librustc_resolve/macros.rs | 19 ++++++++--- src/libsyntax/ext/base.rs | 2 +- src/test/ui/span/macro-ty-params.stderr | 44 +------------------------ 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index f8f9b27f148..4d4f6aadce4 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -385,12 +385,21 @@ impl<'a> Resolver<'a> { fn resolve_macro_to_def(&mut self, scope: Mark, path: &ast::Path, kind: MacroKind, force: bool) -> Result { - let ast::Path { ref segments, span } = *path; - segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| { - self.session.span_err(segment.parameters.as_ref().unwrap().span(), - "generic arguments in macro path"); - }); + let def = self.resolve_macro_to_def_inner(scope, path, kind, force); + if def != Err(Determinacy::Undetermined) { + // Do not report duplicated errors on every undetermined resolution. + path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| { + self.session.span_err(segment.parameters.as_ref().unwrap().span(), + "generic arguments in macro path"); + }); + } + def + } + fn resolve_macro_to_def_inner(&mut self, scope: Mark, path: &ast::Path, + kind: MacroKind, force: bool) + -> Result { + let ast::Path { ref segments, span } = *path; let path: Vec<_> = segments.iter().map(|seg| respan(seg.span, seg.identifier)).collect(); let invocation = self.invocations[&scope]; self.current_module = invocation.module.get(); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 4881170c1d1..7eeafa72c68 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -608,7 +608,7 @@ pub trait Resolver { fn check_unused_macros(&self); } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq)] pub enum Determinacy { Determined, Undetermined, diff --git a/src/test/ui/span/macro-ty-params.stderr b/src/test/ui/span/macro-ty-params.stderr index ff3847ce1fa..f7115a04826 100644 --- a/src/test/ui/span/macro-ty-params.stderr +++ b/src/test/ui/span/macro-ty-params.stderr @@ -16,47 +16,5 @@ error: generic arguments in macro path 26 | m!(MyTrait<>); | ^^ -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:26:15 - | -26 | m!(MyTrait<>); - | ^^ - -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:26:15 - | -26 | m!(MyTrait<>); - | ^^ - -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:22:8 - | -22 | foo::<>!(); - | ^^^^ - -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:18:8 - | -18 | foo::!(); - | ^^^^^ - -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:18:8 - | -18 | foo::!(); - | ^^^^^ - -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:22:8 - | -22 | foo::<>!(); - | ^^^^ - -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:26:15 - | -26 | m!(MyTrait<>); - | ^^ - -error: aborting due to 10 previous errors +error: aborting due to 3 previous errors