-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
The following code fails to compile, even though all types are known
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=8de9e57e8de5cd8f2896f422d693f453
pub fn f(s: &str) {
let mut it = s.split(|c: char| c == ',').fuse();
let t = it.next().unwrap().parse::<usize>().unwrap();
}
Compiling playground v0.0.1 (/playground)
error[E0282]: type annotations needed
--> src/main.rs:3:13
|
3 | let t = it.next().unwrap().parse::<usize>().unwrap();
| ^^^^^^^^^^^^^^^^^^ cannot infer type for `T`
|
= note: type must be known at this point
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
talchas commentedon Feb 16, 2019
Bisecting releases says it worked in 1.12.0, broke in 1.13.0
jonas-schievink commentedon Feb 16, 2019
Technically a stable regression, so marking as such - even though nobody seems to have been hit by it. It does pretty clearly look like a bug though.
ExpHP commentedon Feb 19, 2019
Ran
cargo-bisect-rustc
on the nightlies:3c5a0fa...e9bc1ba
This is still a pretty broad range...
jonas-schievink commentedon Feb 19, 2019
Only thing in that range that touches the typesystem seems to be #35883
Mark-Simulacrum commentedon Feb 19, 2019
May also be related to #35656
jonas-schievink commentedon Feb 19, 2019
Ah, I missed that one. That might be more likely, yeah (since specialization might now be involved, but before wasn't).
pnkfelix commentedon Feb 28, 2019
triage, P-medium. (Not a soundness issue, and appears to have a straight-forward if annoying work-around of introducing a local with an explicit type.) Leaving nominated label for discussion at next T-compiler meeting.
pnkfelix commentedon Feb 28, 2019
Discussed briefuly at T-compiler meeting. assigning to self in attempt to ensure this doesn't just get lost. (I don't want to leave it nominated for discussion again at next week's meeting.)
pnkfelix commentedon Sep 23, 2019
I would like to double-check the running hypothesis that this was caused by the addition of
FusedIterator
in PR #35656 .I briefly attempted to make a standalone test case that does not rely on
core::str
norcore::iter
by transcribing the relevant traits and structure definitions, but the pieces here are pretty gnarly.Anyway, while investigating the behavior of the test itself, here are some potentially interesting observations:
fuse()
call yields a variant that compiles successfully: playsplit
with achar
argument also yields a variant that compiles successfully: playcore::str::pattern
are definedFnMut(char) -> bool
in the impl declarationimpl<'a, F> Pattern<'a> for F where F: FnMut(char) -> bool
estebank commentedon Dec 10, 2019
The output from #65951 might shed some light:
Auto merge of #65951 - estebank:type-inference-error, r=<try>
Auto merge of #65951 - estebank:type-inference-error, r=nikomatsakis
SeeSpring commentedon Mar 11, 2020
Seems to be due to specialization
Minimized version below
Playground
Spoonbender commentedon Mar 23, 2022
Triage: original issue seems resolved, as the example provided in the original post now compiles. The latest example still won't compile.