Avoid duplicated errors for generic arguments in macro paths

This commit is contained in:
Vadim Petrochenkov 2017-07-25 00:33:15 +03:00
parent 128f565dae
commit 1e8a7f68e9
3 changed files with 16 additions and 49 deletions

View File

@ -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<Def, Determinacy> {
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<Def, Determinacy> {
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();

View File

@ -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,

View File

@ -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::<T>!();
| ^^^^^
error: generic arguments in macro path
--> $DIR/macro-ty-params.rs:18:8
|
18 | foo::<T>!();
| ^^^^^
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