Skip to content

Commit 1e8a7f6

Browse files
committed
Avoid duplicated errors for generic arguments in macro paths
1 parent 128f565 commit 1e8a7f6

File tree

3 files changed

+16
-49
lines changed

3 files changed

+16
-49
lines changed

src/librustc_resolve/macros.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,21 @@ impl<'a> Resolver<'a> {
385385

386386
fn resolve_macro_to_def(&mut self, scope: Mark, path: &ast::Path, kind: MacroKind, force: bool)
387387
-> Result<Def, Determinacy> {
388-
let ast::Path { ref segments, span } = *path;
389-
segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| {
390-
self.session.span_err(segment.parameters.as_ref().unwrap().span(),
391-
"generic arguments in macro path");
392-
});
388+
let def = self.resolve_macro_to_def_inner(scope, path, kind, force);
389+
if def != Err(Determinacy::Undetermined) {
390+
// Do not report duplicated errors on every undetermined resolution.
391+
path.segments.iter().find(|segment| segment.parameters.is_some()).map(|segment| {
392+
self.session.span_err(segment.parameters.as_ref().unwrap().span(),
393+
"generic arguments in macro path");
394+
});
395+
}
396+
def
397+
}
393398

399+
fn resolve_macro_to_def_inner(&mut self, scope: Mark, path: &ast::Path,
400+
kind: MacroKind, force: bool)
401+
-> Result<Def, Determinacy> {
402+
let ast::Path { ref segments, span } = *path;
394403
let path: Vec<_> = segments.iter().map(|seg| respan(seg.span, seg.identifier)).collect();
395404
let invocation = self.invocations[&scope];
396405
self.current_module = invocation.module.get();

src/libsyntax/ext/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ pub trait Resolver {
608608
fn check_unused_macros(&self);
609609
}
610610

611-
#[derive(Copy, Clone, Debug)]
611+
#[derive(Copy, Clone, Debug, PartialEq)]
612612
pub enum Determinacy {
613613
Determined,
614614
Undetermined,

src/test/ui/span/macro-ty-params.stderr

+1-43
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,5 @@ error: generic arguments in macro path
1616
26 | m!(MyTrait<>);
1717
| ^^
1818

19-
error: generic arguments in macro path
20-
--> $DIR/macro-ty-params.rs:26:15
21-
|
22-
26 | m!(MyTrait<>);
23-
| ^^
24-
25-
error: generic arguments in macro path
26-
--> $DIR/macro-ty-params.rs:26:15
27-
|
28-
26 | m!(MyTrait<>);
29-
| ^^
30-
31-
error: generic arguments in macro path
32-
--> $DIR/macro-ty-params.rs:22:8
33-
|
34-
22 | foo::<>!();
35-
| ^^^^
36-
37-
error: generic arguments in macro path
38-
--> $DIR/macro-ty-params.rs:18:8
39-
|
40-
18 | foo::<T>!();
41-
| ^^^^^
42-
43-
error: generic arguments in macro path
44-
--> $DIR/macro-ty-params.rs:18:8
45-
|
46-
18 | foo::<T>!();
47-
| ^^^^^
48-
49-
error: generic arguments in macro path
50-
--> $DIR/macro-ty-params.rs:22:8
51-
|
52-
22 | foo::<>!();
53-
| ^^^^
54-
55-
error: generic arguments in macro path
56-
--> $DIR/macro-ty-params.rs:26:15
57-
|
58-
26 | m!(MyTrait<>);
59-
| ^^
60-
61-
error: aborting due to 10 previous errors
19+
error: aborting due to 3 previous errors
6220

0 commit comments

Comments
 (0)