Skip to content

Commit

Permalink
Fix suggestion span involving wrongly placed generic arg on enum vari…
Browse files Browse the repository at this point in the history
…ants

When the variant and the (wrongly placed) args are at vastly separated
source locations such as being in different macos or one in a macro and
the other somwhere outside of it, the arg spans we computed would
span the entire distance between such locations and were hence invalid.
.
  • Loading branch information
gurry committed Oct 8, 2023
1 parent 6683f13 commit 8c9ef3a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_middle::ty::{
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_span::{sym, Span, DUMMY_SP};
use rustc_span::{sym, BytePos, Span, DUMMY_SP};
use rustc_target::spec::abi;
use rustc_trait_selection::traits::wf::object_region_bounds;
use rustc_trait_selection::traits::{self, NormalizeExt, ObligationCtxt};
Expand Down Expand Up @@ -1275,8 +1275,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
return;
};
// Get the span of the generics args *including* the leading `::`.
let args_span =
assoc_segment.ident.span.shrink_to_hi().to(args.span_ext);
// We do so by stretching args.span_ext to the left by 2. Earlier
// it was done based on the end of assoc segment but that sometimes
// led to impossible spans and caused issues like #116473
let args_span = args.span_ext.with_lo(args.span_ext.lo() - BytePos(2));
if tcx.generics_of(adt_def.did()).count() == 0 {
// FIXME(estebank): we could also verify that the arguments being
// work for the `enum`, instead of just looking if it takes *any*.
Expand Down

0 comments on commit 8c9ef3a

Please sign in to comment.