Skip to content

Commit

Permalink
Do not emit invalid suggestion in E0191 when spans overlap
Browse files Browse the repository at this point in the history
Fix #115019.
  • Loading branch information
estebank committed Aug 22, 2023
1 parent bf766cd commit b86285a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 15 additions & 1 deletion compiler/rustc_hir_analysis/src/astconv/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,21 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
}
}
if !suggestions.is_empty() {
suggestions.sort_by_key(|&(span, _)| span);
// There are cases where one bound points to a span within another bound's span, like when
// you have code like the following (#115019), so we skip providing a suggestion in those
// cases to avoid having a malformed suggestion.
//
// pub struct Flatten<I> {
// inner: <IntoIterator<Item: IntoIterator<Item: >>::IntoIterator as Item>::core,
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// | ^^^^^^^^^^^^^^^^^^^^^
// | |
// | associated types `Item`, `IntoIter` must be specified
// associated types `Item`, `IntoIter` must be specified
// }
let overlaps = suggestions.windows(2).any(|pair| pair[0].0.overlaps(pair[1].0));
if !suggestions.is_empty() && !overlaps {
err.multipart_suggestion(
format!("specify the associated type{}", pluralize!(types_count)),
suggestions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ LL | inner: <IntoIterator<Item: IntoIterator<Item: >>::IntoIterator as Item>
| | |
| | associated types `Item`, `IntoIter` must be specified
| associated types `Item`, `IntoIter` must be specified
|
help: specify the associated types
|
LL | inner: <IntoIterator<Item: IntoIterator<Item: >, Item = Type, IntoIter = Type>IntoIterator<Item: , Item = Type, IntoIter = Type>>::IntoIterator as Item>::Core,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0223]: ambiguous associated type
--> $DIR/overlaping-bound-suggestion.rs:7:13
Expand Down

0 comments on commit b86285a

Please sign in to comment.