Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE when attempting to split error message that contains " found" before "expected" into lines #31173

Closed
tormol opened this issue Jan 25, 2016 · 7 comments · Fixed by #34907
Closed
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@tormol
Copy link
Contributor

tormol commented Jan 25, 2016

In librustc::session::split_msg_into_multiline().

With the error "type mismatch resolving for<'r> <F2 as core::ops::FnOnce<(&'r mut core::option::Option<T>, found_opts::FoundOpt)>>::Output == core::result::Result<(), collections::string::String>: expected type parameter, found ()",

it finds the " found" in " found_opts::" before " found ()".

Then pos1 becomes (182, 191) and pos2= (91, 97), which makes &msg[pos1.1..pos2.0] at line 360 fail.

@durka
Copy link
Contributor

durka commented Jan 25, 2016

Kind of unfortunate that the formatting is done by splitting on substrings. It seems like it would be better to either include the line breaks in the error message from the start, or to do the substring search before substituting in user input.

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 26, 2016
@cuviper
Copy link
Member

cuviper commented Feb 26, 2016

I ran into this using a closure that captured a local called found. I minimized mine to:

fn main() {
    let found = false;
    (0..10).filter(|i| found)
}

If I change that to unfound, the successfully wrapped error is:

found.rs:3:5: 3:32 error: mismatched types:
 expected `()`,
    found `core::iter::Filter<core::ops::Range<_>, [closure@found.rs:3:20: 3:31 unfound:_]>`
(expected (),
    found struct `core::iter::Filter`) [E0308]
found.rs:3     (0..10).filter(|i| unfound)
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
found.rs:3:5: 3:32 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error

@cuviper
Copy link
Member

cuviper commented Feb 28, 2016

It's hard to tell from out-of-date PR diffs, but I found #19870 (comment) -- it sounds like it started out printing newlines at the error source, then @nrc thought this was fragile and asked for expected/found substring matching.

I don't understand why that was preferred though, as this issue reveals how fraught substring-matching can be. Even if we resolve the ICE of slicing backwards, I fear it may still be imprecise about finding the right "expected" and "found" pieces.

@cuviper
Copy link
Member

cuviper commented Feb 28, 2016

For example, this isn't an ICE, but it's still wrapped incorrectly:

fn main() {
    let expected = false;
    (0..10).filter(|i| expected)
}
expected.rs:3:5: 3:33 error: mismatched types:
 expected `()`,
    found `core::iter::Filter<core::ops::Range<_>, [closure@expected.rs:3:20: 3:32
 expected:_]>` (expected (),
    found struct `core::iter::Filter`) [E0308]
expected.rs:3     (0..10).filter(|i| expected)
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
expected.rs:3:5: 3:33 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error

@nrc
Copy link
Member

nrc commented Mar 14, 2016

I don't recall what the earlier approach was and why I thought it was fragile. Probably to avoid mixing error formatting with error production. I agree substring matching is a bit gross.

I think the proper fix here is for the error producing code to provide a struct with the expected/found values and then the error handler should format these (i.e., stick in the newlines, etc.). This should be easier now that errors are more structured.

@durka durka mentioned this issue Apr 27, 2016
10 tasks
@sophiajt
Copy link
Contributor

sophiajt commented Apr 27, 2016

With #32756 this is what I see for @cuviper 's examples:

error: mismatched types [--explain E0308]
 --> tmp/quickie.rs:3:5
3 |>     (0..10).filter(|i| expected)
  |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found struct `std::iter::Filter`
note: expected type `()`
note:    found type `std::iter::Filter<std::ops::Range<_>, [closure@tmp/quickie.rs:3:20: 3:32 expected:_]>`

error: aborting due to previous error
error: mismatched types [--explain E0308]
 --> tmp/quickie2.rs:3:5
3 |>     (0..10).filter(|i| found)
  |>     ^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found struct `std::iter::Filter`
note: expected type `()`
note:    found type `std::iter::Filter<std::ops::Range<_>, [closure@tmp/quickie2.rs:3:20: 3:29 found:_]>`

error: aborting due to previous error
error: unresolved name `unfound`. Did you mean `found`? [--explain E0425]
 --> tmp/quickie2.rs:3:24
3 |>     (0..10).filter(|i| unfound)
  |>                        ^^^^^^^

error: mismatched types [--explain E0308]
 --> tmp/quickie2.rs:3:5
3 |>     (0..10).filter(|i| unfound)
  |>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found struct `std::iter::Filter`
note: expected type `()`
note:    found type `std::iter::Filter<std::ops::Range<_>, [closure@tmp/quickie2.rs:3:20: 3:31]>`

@cuviper
Copy link
Member

cuviper commented Apr 27, 2016

For the unfound case, it should have been changed everywhere so you don't get that "unresolved name". Anyway, it sure looks like they're all splitting correctly - yay!

@arielb1 arielb1 self-assigned this Jul 8, 2016
arielb1 added a commit to arielb1/rust that referenced this issue Jul 20, 2016
Unfortunately, projection errors do not come with a nice set of
mismatched types. This is because the type equality check occurs
within a higher-ranked context. Therefore, only the type error
is reported. This is ugly but was always the situation.

I will introduce better errors for the lower-ranked case in
another commit.

Fixes the last known occurence of rust-lang#31173
arielb1 added a commit to arielb1/rust that referenced this issue Jul 22, 2016
Unfortunately, projection errors do not come with a nice set of
mismatched types. This is because the type equality check occurs
within a higher-ranked context. Therefore, only the type error
is reported. This is ugly but was always the situation.

I will introduce better errors for the lower-ranked case in
another commit.

Fixes the last known occurence of rust-lang#31173
bors added a commit that referenced this issue Jul 22, 2016
Centralize and clean type error reporting

Refactors the code that handles type errors to be cleaner and fixes various edge cases.

This made the already-bad "type mismatch resolving" error message somewhat uglier. I want to fix that in another commit before this PR is merged.

Fixes #31173

r? @jonathandturner, cc @nikomatsakis
bors added a commit that referenced this issue Jul 27, 2016
Centralize and clean type error reporting

Refactors the code that handles type errors to be cleaner and fixes various edge cases.

This made the already-bad "type mismatch resolving" error message somewhat uglier. I want to fix that in another commit before this PR is merged.

Fixes #31173

r? @jonathandturner, cc @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants