Skip to content

Type inference regression #38535

Closed
servo/servo
#14689
@SimonSapin

Description

@SimonSapin

Servo compiles with rustc 71c06a5 2016-12-18, but not with 439c312 2016-12-21. Diff: 71c06a5...439c312

The style crate fails to build with:

error[E0282]: unable to infer enough type information about `E`
  --> /home/simon/projects/servo/components/style/font_face.rs:65:9
   |
65 |         try!(self.family.to_css(dest));
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `E`
   |
   = note: type annotations or generic parameter binding required
   = note: this error originates in a macro outside of the current crate

The to_css method being called here is:

impl ToCss for FontFamily {
    fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
        // ...
    }
}

Its return type is std::fmt::Result which is type Result = std::result::Result<(), std::fmt::Error>;. This call is in another impl of the same method of the same trait:

impl ToCss for FontFaceRule {
    fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
        try!(dest.write_str("@font-face { font-family: "));
        try!(self.family.to_css(dest));
        try!(dest.write_str(";"));

        // ...
    }
}

Adding an explicit type annotation works around this error, but only to uncover another very similar one, then another. The third one was in code generated by serde’s derive(Serialize), so I gave up that approach.

        let r: fmt::Result = self.family.to_css(dest);
        try!(r);

So far I haven’t managed to reduce a test case smaller than "most of Servo", sorry.

I’m suspicious of 6ea1fbb (which is part of #38099) because it’s commit message mentions inference. I’m not building a compiler #38099 to confirm.

Metadata

Metadata

Assignees

Labels

A-type-systemArea: Type systemP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions