-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Fix ICE in rustdoc when merging generic and where bounds of an Fn with an output #63937
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> { | |
match ty { | ||
clean::Generic(s) => params.entry(s).or_default() | ||
.extend(bounds), | ||
t => tybounds.push((t, ty_bounds(bounds))), | ||
t => tybounds.push((t, bounds)), | ||
} | ||
} | ||
WP::RegionPredicate { lifetime, bounds } => { | ||
|
@@ -45,11 +45,6 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> { | |
} | ||
} | ||
|
||
// Simplify the type parameter bounds on all the generics | ||
let mut params = params.into_iter().map(|(k, v)| { | ||
(k, ty_bounds(v)) | ||
}).collect::<BTreeMap<_, _>>(); | ||
|
||
// Look for equality predicates on associated types that can be merged into | ||
// general bound predicates | ||
equalities.retain(|&(ref lhs, ref rhs)| { | ||
|
@@ -73,7 +68,7 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> { | |
// And finally, let's reassemble everything | ||
let mut clauses = Vec::new(); | ||
clauses.extend(lifetimes.into_iter().map(|(lt, bounds)| { | ||
WP::RegionPredicate { lifetime: lt, bounds: bounds } | ||
WP::RegionPredicate { lifetime: lt, bounds } | ||
})); | ||
clauses.extend(params.into_iter().map(|(k, v)| { | ||
WP::BoundPredicate { | ||
|
@@ -82,10 +77,10 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> { | |
} | ||
})); | ||
clauses.extend(tybounds.into_iter().map(|(ty, bounds)| { | ||
WP::BoundPredicate { ty: ty, bounds: bounds } | ||
WP::BoundPredicate { ty, bounds } | ||
})); | ||
clauses.extend(equalities.into_iter().map(|(lhs, rhs)| { | ||
WP::EqPredicate { lhs: lhs, rhs: rhs } | ||
WP::EqPredicate { lhs, rhs } | ||
})); | ||
clauses | ||
} | ||
|
@@ -122,9 +117,9 @@ pub fn merge_bounds( | |
}, | ||
}); | ||
} | ||
PP::Parenthesized { ref mut output, .. } => { | ||
assert!(output.is_none()); | ||
if *rhs != clean::Type::Tuple(Vec::new()) { | ||
PP::Parenthesized { ref mut output, .. } => match output { | ||
Some(o) => assert_eq!(o, rhs), | ||
None => if *rhs != clean::Type::Tuple(Vec::new()) { | ||
*output = Some(rhs.clone()); | ||
} | ||
} | ||
|
@@ -137,18 +132,14 @@ pub fn ty_params(mut params: Vec<clean::GenericParamDef>) -> Vec<clean::GenericP | |
for param in &mut params { | ||
match param.kind { | ||
clean::GenericParamDefKind::Type { ref mut bounds, .. } => { | ||
*bounds = ty_bounds(mem::take(bounds)); | ||
*bounds = mem::take(bounds); | ||
} | ||
_ => panic!("expected only type parameters"), | ||
} | ||
} | ||
params | ||
} | ||
|
||
fn ty_bounds(bounds: Vec<clean::GenericBound>) -> Vec<clean::GenericBound> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seemed like pointless noise, so I removed it. If this was setup for future work, let me know so I can add a comment explaining that for future readers 😃 |
||
bounds | ||
} | ||
|
||
fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, | ||
trait_: DefId) -> bool { | ||
if child == trait_ { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// compile-flags: -Cmetadata=aux | ||
|
||
pub trait Trait { | ||
} | ||
|
||
pub struct Struct<F> | ||
{ | ||
_p: ::std::marker::PhantomData<F>, | ||
} | ||
|
||
impl<F: Fn() -> u32> | ||
Trait for Struct<F> | ||
where | ||
F: Fn() -> u32, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I run format on this? Also, does this test need a comment saying it's a regression test, or is its existence enough? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existence alone is fine. |
||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// aux-build:issue-57180.rs | ||
|
||
extern crate issue_57180; | ||
use issue_57180::Trait; | ||
|
||
fn main() { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
ty_bounds
was a nop, just a pass-through, this transform seemed to just be added noise and should be safe to remove.