Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Don't follow include! expansion to origin #149

Merged
merged 2 commits into from
Mar 15, 2017

Conversation

RReverser
Copy link
Contributor

@RReverser RReverser commented Mar 10, 2017

include! errors are special in the sense that caller side is not useful for reporting all the syntax / type errors originating in included file (as you're getting tons of messages pointing to the same line where include!(...) occurs).

This change adds special case that keeps errors bound to their original location if it was include!d.

Before:
screen shot 2017-03-10 at 14 07 10

After:
screen shot 2017-03-10 at 14 06 10

include! errors are special in the sense that caller side is usually not useful for reporting all the syntax / type errors originating in included file (as you're getting tons of messages pointing to the same line where include!(...) occurs).

This change adds special case that keeps errors bound to their original location if it was include!d.
@KalitaAlexey
Copy link
Member

Hello @RReverser,
I need to check it before I can merge it.
Thank you for this.

@RReverser
Copy link
Contributor Author

@KalitaAlexey Sure, let me know if you find anything.

@KalitaAlexey
Copy link
Member

Could you provide an example?
I have no time now for imaging it itself.

@RReverser
Copy link
Contributor Author

RReverser commented Mar 13, 2017

Well just any include!("somefile.rs") where somefile.rs is garbage (has syntax or type errors on various lines).

@KalitaAlexey
Copy link
Member

@RReverser,
I checked it twice.

First time

build.rs:

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::Path;

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    let dest_path = Path::new(&out_dir).join("hello.rs");
    let mut f = File::create(&dest_path).unwrap();

    f.write_all(b"
        pub dfn message() -> &'static str {
            \"Hello, World!\"
        }
    ").unwrap();
}

main.rs:

include!(concat!(env!("OUT_DIR"), "/hello.rs"));

fn main() {
    let x = 5;
    let y = 6;
    let u = 7;
}

It showed errors in hello.rs.

Second time

main.rs:

include!("f.rs");

fn main() {
    let x = 5;
    let y = 6;
    let u = 7;
}

f.rs:

s

It showed errors in f.rs.


So I don't know what problem you have.

@RReverser
Copy link
Contributor Author

Oh right, syntax errors originate in correct place because otherwise include! can't even parse that file, it's type checker and other errors that don't.

screen shot 2017-03-13 at 15 39 57

@RReverser
Copy link
Contributor Author

Example with multiple errors
screen shot 2017-03-13 at 15 43 42

@KalitaAlexey
Copy link
Member

@RReverser,
I will check it.
Thanks.

@KalitaAlexey KalitaAlexey merged commit da4cbac into editor-rs:master Mar 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants