Auto merge of #43532 - petrochenkov:pgargs, r=nikomatsakis

Desugar parenthesized generic arguments in HIR

Fixes ICE in https://github.com/rust-lang/rust/issues/43431 and maybe some other similar issues.

r? @eddyb
This commit is contained in:
bors 2017-08-24 03:48:25 +00:00
commit a12e4f8098
18 changed files with 266 additions and 440 deletions

View file

@ -1794,16 +1794,14 @@ impl Clean<Type> for hir::Ty {
let mut lt_substs = FxHashMap();
for (i, ty_param) in generics.ty_params.iter().enumerate() {
let ty_param_def = Def::TyParam(cx.tcx.hir.local_def_id(ty_param.id));
if let Some(ty) = provided_params.types().get(i).cloned()
.cloned() {
if let Some(ty) = provided_params.types.get(i).cloned() {
ty_substs.insert(ty_param_def, ty.unwrap().clean(cx));
} else if let Some(default) = ty_param.default.clone() {
ty_substs.insert(ty_param_def, default.unwrap().clean(cx));
}
}
for (i, lt_param) in generics.lifetimes.iter().enumerate() {
if let Some(lt) = provided_params.lifetimes().get(i).cloned()
.cloned() {
if let Some(lt) = provided_params.lifetimes.get(i).cloned() {
if !lt.is_elided() {
lt_substs.insert(lt_param.lifetime.id, lt.clean(cx));
}
@ -2314,24 +2312,21 @@ pub enum PathParameters {
impl Clean<PathParameters> for hir::PathParameters {
fn clean(&self, cx: &DocContext) -> PathParameters {
match *self {
hir::AngleBracketedParameters(ref data) => {
PathParameters::AngleBracketed {
lifetimes: if data.lifetimes.iter().all(|lt| lt.is_elided()) {
vec![]
} else {
data.lifetimes.clean(cx)
},
types: data.types.clean(cx),
bindings: data.bindings.clean(cx),
}
if self.parenthesized {
let output = self.bindings[0].ty.clean(cx);
PathParameters::Parenthesized {
inputs: self.inputs().clean(cx),
output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None }
}
hir::ParenthesizedParameters(ref data) => {
PathParameters::Parenthesized {
inputs: data.inputs.clean(cx),
output: data.output.clean(cx),
}
} else {
PathParameters::AngleBracketed {
lifetimes: if self.lifetimes.iter().all(|lt| lt.is_elided()) {
vec![]
} else {
self.lifetimes.clean(cx)
},
types: self.types.clean(cx),
bindings: self.bindings.clean(cx),
}
}
}