Skip to content

Commit 8c9ef3a

Browse files
committed
Fix suggestion span involving wrongly placed generic arg on enum variants
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. .
1 parent 6683f13 commit 8c9ef3a

File tree

1 file changed

+5
-3
lines changed
  • compiler/rustc_hir_analysis/src/astconv

1 file changed

+5
-3
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_middle::ty::{
3636
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
3737
use rustc_span::edit_distance::find_best_match_for_name;
3838
use rustc_span::symbol::{kw, Ident, Symbol};
39-
use rustc_span::{sym, Span, DUMMY_SP};
39+
use rustc_span::{sym, BytePos, Span, DUMMY_SP};
4040
use rustc_target::spec::abi;
4141
use rustc_trait_selection::traits::wf::object_region_bounds;
4242
use rustc_trait_selection::traits::{self, NormalizeExt, ObligationCtxt};
@@ -1275,8 +1275,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12751275
return;
12761276
};
12771277
// Get the span of the generics args *including* the leading `::`.
1278-
let args_span =
1279-
assoc_segment.ident.span.shrink_to_hi().to(args.span_ext);
1278+
// We do so by stretching args.span_ext to the left by 2. Earlier
1279+
// it was done based on the end of assoc segment but that sometimes
1280+
// led to impossible spans and caused issues like #116473
1281+
let args_span = args.span_ext.with_lo(args.span_ext.lo() - BytePos(2));
12801282
if tcx.generics_of(adt_def.did()).count() == 0 {
12811283
// FIXME(estebank): we could also verify that the arguments being
12821284
// work for the `enum`, instead of just looking if it takes *any*.

0 commit comments

Comments
 (0)