Skip to content

Errors with the same span print the span once - #5798

Closed
recrack wants to merge 1 commit into
rust-lang:incomingfrom
recrack:multiple-errors
Closed

Errors with the same span print the span once#5798
recrack wants to merge 1 commit into
rust-lang:incomingfrom
recrack:multiple-errors

Conversation

@recrack

Copy link
Copy Markdown

Fix#4569.

@recrack

Copy link
Copy Markdown
Author
  • Source code 1
fn main() {
foo::bar::baz();
zoo::xar::caz();
}

before:

foo3.rs:2:5: 2:18 error: unresolved name
foo3.rs:2 foo::bar::baz();
^~~~~~~~~~~~~
foo3.rs:2:5: 2:18 error: use of undeclared module `foo::bar`
foo3.rs:2 foo::bar::baz();
^~~~~~~~~~~~~
foo3.rs:2:5: 2:18 error: unresolved name: `foo::bar::baz`.
foo3.rs:2 foo::bar::baz();
^~~~~~~~~~~~~
foo3.rs:3:5: 3:18 error: unresolved name
foo3.rs:3 zoo::xar::caz();
^~~~~~~~~~~~~
foo3.rs:3:5: 3:18 error: use of undeclared module `zoo::xar`
foo3.rs:3 zoo::xar::caz();
^~~~~~~~~~~~~
foo3.rs:3:5: 3:18 error: unresolved name: `zoo::xar::caz`.
foo3.rs:3 zoo::xar::caz();
^~~~~~~~~~~~~
error: aborting due to 6 previous errors

after:

foo3.rs:2:5: 2:18 error: unresolved name
foo3.rs:2:5: 2:18 error: use of undeclared module `foo::bar`
foo3.rs:2:5: 2:18 error: unresolved name: `foo::bar::baz`.
foo3.rs:2 foo::bar::baz();
^~~~~~~~~~~~~
foo3.rs:3:5: 3:18 error: unresolved name
foo3.rs:3:5: 3:18 error: use of undeclared module `zoo::xar`
foo3.rs:3:5: 3:18 error: unresolved name: `zoo::xar::caz`.
foo3.rs:3 zoo::xar::caz();
^~~~~~~~~~~~~
error: aborting due to 6 previous errors
  • Source code 2
macro_rules! test(
($arg:ident) => (foo::$arg);
)
fn main() {
test!(bar);
}

before:

y.rs:2:21: 2:30 error: unresolved name
y.rs:2 ($arg:ident) => (foo::$arg);
^~~~~~~~~
y.rs:1:0: 3:1 note: in expansion of test!
y.rs:6:4: 6:15 note: expansion site
y.rs:2:21: 2:30 error: use of undeclared module `foo`
y.rs:2 ($arg:ident) => (foo::$arg);
^~~~~~~~~
y.rs:1:0: 3:1 note: in expansion of test!
y.rs:6:4: 6:15 note: expansion site
y.rs:2:21: 2:30 error: unresolved name: `foo::bar`.
y.rs:2 ($arg:ident) => (foo::$arg);
^~~~~~~~~
y.rs:1:0: 3:1 note: in expansion of test!
y.rs:6:4: 6:15 note: expansion site
error: aborting due to 3 previous errors

after:

y.rs:2:21: 2:30 error: unresolved name
y.rs:2:21: 2:30 error: use of undeclared module `foo`
y.rs:2:21: 2:30 error: unresolved name: `foo::bar`.
y.rs:2 ($arg:ident) => (foo::$arg);
^~~~~~~~~
y.rs:1:0: 3:1 note: in expansion of test!
y.rs:6:4: 6:15 note: expansion site
error: aborting due to 3 previous errors

@bstrie

Copy link
Copy Markdown
Contributor

Awesome! Though I'd like to get a dev in here to confirm that they like this change wrt how notes get pushed to the end. In particular, how does this change handle borrowing errors, where the error itself is followed by a note like "loan of foo granted here" ? I hadn't considered this when I originally opened #4569, it may not even have been implemented back then.

@graydon

Copy link
Copy Markdown
Contributor

I generally like this a lot. I'm not sure, as @bstrie mentions, how well this plays with borrow-check errors. Can you try a couple of those to see?

@recrack

Copy link
Copy Markdown
Author

@bstrie , @graydon

Do you mean kind of this test?
i tested a couple of codes. ( code from github.com/mozilla/rust/issue )

before

borrowck-insert-during-each.rs:27:4: 27:5 error: loan of dereference of mutable & pointer as mutable conflicts with prior loan
borrowck-insert-during-each.rs:27 f.n.insert(*a); //~ ERROR conflicts with prior loan
^
borrowck-insert-during-each.rs:26:5: 26:6 note: prior loan as mutable granted here
borrowck-insert-during-each.rs:26 do f.foo |a| { //~ NOTE prior loan as mutable granted here
^
error: aborting due to previous error

after ( note: prior loan as mutable granted here )

borrowck-insert-during-each.rs:26:5: 26:6 note: prior loan as mutable granted here
borrowck-insert-during-each.rs:26 do f.foo |a| { //~ NOTE prior loan as mutable granted here
^
borrowck-insert-during-each.rs:27:4: 27:5 error: loan of dereference of mutable & pointer as mutable conflicts with prior loan
borrowck-insert-during-each.rs:27 f.n.insert(*a); //~ ERROR conflicts with prior loan
^
error: aborting due to previous error
  • loan.rs
struct MyStruct { numbers: int } impl MyStruct { fn takes_mut_self(&mut self, _x:int) {} fn takes_self(&self) ⟶ int { 42 fn also_takes_mut_self(&mut self) { self.takes_mut_self(self.takes_self()); } } fn main() {} 

before

loan.rs:11:28: 11:32 error: loan of dereference of mutable & pointer as immutable conflicts with prior loan
loan.rs:11 self.takes_mut_self(self.takes_self());
^~~~
loan.rs:11:8: 11:12 note: prior loan as mutable granted here
loan.rs:11 self.takes_mut_self(self.takes_self());
^~~~
error: aborting due to previous error

after ( note: prior loan as mutable granted here )

loan.rs:11:8: 11:12 note: prior loan as mutable granted here
loan.rs:11 self.takes_mut_self(self.takes_self());
^~~~
loan.rs:11:28: 11:32 error: loan of dereference of mutable & pointer as immutable conflicts with prior loan
loan.rs:11 self.takes_mut_self(self.takes_self());
^~~~
error: aborting due to previous error

@bstrie

Copy link
Copy Markdown
Contributor

Hm, that definitely seems problematic. Is it difficult to have those notes printed after the errors rather than before them?

@graydon

Copy link
Copy Markdown
Contributor

Yeah. Maybe I don't understand the structure of the patch, but I wonder the same question: can notes come after errors? Or does that undermine the whole logic of consolidating messages?

@recrack

Copy link
Copy Markdown
Author

@bstrie , @graydon
Thank you for your comment! :)
i will check "notes come after errors".

@recrack

Copy link
Copy Markdown
Author

@bstrie , @graydon

what kind of error message style do you want?

  • Original Error Message
note.rs:8:32: 8:33 error: obsolete syntax: `/` lifetime notation
note.rs:8 fn next2(self) -> B/&self { let B { a: a } = self; B { a: a } }
^
note: instead of `&foo/bar`, write `&'foo bar`; instead of `bar/&foo`, write `&bar<'foo>
error: aborting due to previous error
  • Style 1
note.rs:8:32: 8:33 error: obsolete syntax: `/` lifetime notation
note.rs:8 fn next2(self) -> B/&self { let B { a: a } = self; B { a: a } }
^
error: aborting due to previous error
note: instead of `&foo/bar`, write `&'foo bar`; instead of `bar/&foo`, write `&bar<'foo>
  • Style 2
note.rs:8:32: 8:33 error: obsolete syntax: `/` lifetime notation
note.rs:8 fn next2(self) -> B/&self { let B { a: a } = self; B { a: a } }
^
note: instead of `&foo/bar`, write `&'foo bar`; instead of `bar/&foo`, write `&bar<'foo>
error: aborting due to previous error

@recrack

Copy link
Copy Markdown
Author

I changed the order.

like this.(Style 2)

note.rs:8:32: 8:33 error: obsolete syntax: `/` lifetime notation
note.rs:8 fn next2(self) -> B/&self { let B { a: a } = self; B { a: a } }
^
note: instead of `&foo/bar`, write `&'foo bar`; instead of `bar/&foo`, write `&bar<'foo>
error: aborting due to previous error

@recrack

Copy link
Copy Markdown
Author

r? @brson

@brson

Copy link
Copy Markdown
Contributor

Thanks @recrack. Sorry for the delay.

@recrack

Copy link
Copy Markdown
Author

@brson re-r?
I updated print error message case.

Fixed. Compile-test fail case.

failures:
[compile-fail] /home/ymin/share/rust/rustmozilla/src/test/compile-fail/deref-non-pointer.rs
[compile-fail] /home/ymin/share/rust/rustmozilla/src/test/compile-fail/for-loop-decl.rs
[compile-fail] /home/ymin/share/rust/rustmozilla/src/test/compile-fail/issue-2370-2.rs
[compile-fail] /home/ymin/share/rust/rustmozilla/src/test/compile-fail/issue-2370.rs
result: FAILED. 582 passed; 4 failed; 43 ignored
  • Original Log Message
compile-fail/issue-2370.rs:18:11: 18:16 error: can only dereference structs with one anonymous field
compile-fail/issue-2370.rs:18 error!(*nyan);
^~~~~
note: in expansion of fmt!
<core-macros>:6:24: 6:43 note: expansion site
<core-macros>:4:4: 11:5 note: in expansion of error!
compile-fail/issue-2370.rs:18:4: 18:18 note: expansion site
error: aborting due to previous error
  • Before ( My old error message )
compile-fail/issue-2370.rs:18:11: 18:16 error: internal compiler error: 0'th deref is of a non-deref'able type `cat`
compile-fail/issue-2370.rs:18 error!(*nyan);
^~~~~
note: in expansion of fmt!
<core-macros>:6:24: 6:43 note: expansion site
<core-macros>:4:4: 11:5 note: in expansion of error!
compile-fail/issue-2370.rs:18:4: 18:18 note: expansion site
  • After (My new error message )
compile-fail/issue-2370.rs:18:11: 18:16 error: can only dereference structs with one anonymous field
compile-fail/issue-2370.rs:18:11: 18:16 error: internal compiler error: 0'th deref is of a non-deref'able type `cat`
compile-fail/issue-2370.rs:18 error!(*nyan);
^~~~~
note: in expansion of fmt!
<core-macros>:6:24: 6:43 note: expansion site
<core-macros>:4:4: 11:5 note: in expansion of error!
/home/ymin/share/rust/rustmozilla/src/test/compile-fail/issue-2370.rs:18:4: 18:18 note: expansion site
error: aborting due to 2 previous errors

bors added a commit that referenced this pull request Apr 18, 2013
@borsbors closed this Apr 18, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jul 17, 2020
Add test for `needless_range_loop` issue
Closesrust-lang#2277
This was fixed when we fixedrust-lang#2542.
changelog: none
U007D pushed a commit to U007D/rust-mos that referenced this pull request Aug 21, 2026
5798: Introduce Label
r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@recrack@bstrie@graydon@brson@bors@vibe-vacation