Skip to content

Commit d658809

Browse files
committed
Auto merge of #33471 - birkenfeld:issue-33464, r=jseyfried
resolve: do not modify span of non-importable name This span modification is probably leftover from a time when import spans were assigned differently. With this change, error spans for the following are properly reported: ``` use abc::one_el; use abc::{a, bbb, cccccc}; use a_very_long_name::{el, el2}; ``` before (spans only): ``` x.rs:3 use abc::one_el; ^~~ x.rs:4 use abc::{a, bbb, cccccc}; ^~~ x.rs:4 use abc::{a, bbb, cccccc}; ^~~ x.rs:4 use abc::{a, bbb, cccccc}; ^~~ (internal compiler error: unprintable span) (internal compiler error: unprintable span) ``` after: ``` x.rs:3 use abc::one_el; ^~~~~~~~~~~ x.rs:4 use abc::{a, bbb, cccccc}; ^ x.rs:4 use abc::{a, bbb, cccccc}; ^~~ x.rs:4 use abc::{a, bbb, cccccc}; ^~~~~~ x.rs:5 use a_very_long_name::{el, el2}; ^~ x.rs:5 use a_very_long_name::{el, el2}; ^~~ ``` Fixes: #33464
2 parents 3585321 + b62e7ff commit d658809

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Diff for: src/librustc_resolve/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use rustc::util::nodemap::{NodeMap, NodeSet, FnvHashMap, FnvHashSet};
5757
use syntax::ext::mtwt;
5858
use syntax::ast::{self, FloatTy};
5959
use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy};
60-
use syntax::codemap::{self, Span, Pos};
60+
use syntax::codemap::{self, Span};
6161
use syntax::errors::DiagnosticBuilder;
6262
use syntax::parse::token::{self, keywords};
6363
use syntax::util::lev_distance::find_best_match_for_name;
@@ -1260,10 +1260,7 @@ impl<'a> Resolver<'a> {
12601260
Failed(None) => {
12611261
let segment_name = name.as_str();
12621262
let module_name = module_to_string(search_module);
1263-
let mut span = span;
12641263
let msg = if "???" == &module_name {
1265-
span.hi = span.lo + Pos::from_usize(segment_name.len());
1266-
12671264
match search_parent_externals(name, &self.current_module) {
12681265
Some(module) => {
12691266
let path_str = names_to_string(module_path);

Diff for: src/test/compile-fail/issue-33464.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Make sure that the spans of import errors are correct.
12+
13+
use abc::one_el;
14+
//~^ ERROR 13:5: 13:16
15+
use abc::{a, bbb, cccccc};
16+
//~^ ERROR 15:11: 15:12
17+
//~^^ ERROR 15:14: 15:17
18+
//~^^^ ERROR 15:19: 15:25
19+
use a_very_long_name::{el, el2};
20+
//~^ ERROR 19:24: 19:26
21+
//~^^ ERROR 19:28: 19:31
22+
23+
fn main() {}

0 commit comments

Comments
 (0)