Skip to content

Commit cbd3ad6

Browse files
committed
Avoid unnecessary rustc_span::DUMMY_SP usage.
In some cases `DUMMY_SP` is already imported. In other cases this commit adds the necessary import, in files where `DUMMY_SP` is used more than once.
1 parent 6e1f7b5 commit cbd3ad6

File tree

14 files changed

+38
-51
lines changed

14 files changed

+38
-51
lines changed

compiler/rustc_ast_pretty/src/pprust/tests.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::*;
33
use rustc_ast as ast;
44
use rustc_span::create_default_session_globals_then;
55
use rustc_span::symbol::Ident;
6+
use rustc_span::DUMMY_SP;
67
use thin_vec::ThinVec;
78

89
fn fun_to_string(
@@ -28,10 +29,7 @@ fn test_fun_to_string() {
2829
create_default_session_globals_then(|| {
2930
let abba_ident = Ident::from_str("abba");
3031

31-
let decl = ast::FnDecl {
32-
inputs: ThinVec::new(),
33-
output: ast::FnRetTy::Default(rustc_span::DUMMY_SP),
34-
};
32+
let decl = ast::FnDecl { inputs: ThinVec::new(), output: ast::FnRetTy::Default(DUMMY_SP) };
3533
let generics = ast::Generics::default();
3634
assert_eq!(
3735
fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics),
@@ -48,15 +46,15 @@ fn test_variant_to_string() {
4846
let var = ast::Variant {
4947
ident,
5048
vis: ast::Visibility {
51-
span: rustc_span::DUMMY_SP,
49+
span: DUMMY_SP,
5250
kind: ast::VisibilityKind::Inherited,
5351
tokens: None,
5452
},
5553
attrs: ast::AttrVec::new(),
5654
id: ast::DUMMY_NODE_ID,
5755
data: ast::VariantData::Unit(ast::DUMMY_NODE_ID),
5856
disr_expr: None,
59-
span: rustc_span::DUMMY_SP,
57+
span: DUMMY_SP,
6058
is_placeholder: false,
6159
};
6260

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfK
88
use rustc_expand::base::ExtCtxt;
99
use rustc_span::source_map::respan;
1010
use rustc_span::symbol::{kw, Ident, Symbol};
11-
use rustc_span::Span;
12-
use rustc_span::DUMMY_SP;
11+
use rustc_span::{Span, DUMMY_SP};
1312
use thin_vec::ThinVec;
1413

1514
/// A path, e.g., `::std::option::Option::<i32>` (global). Has support

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
3737
// from the trait itself that *shouldn't* be shown as the source of
3838
// an obligation and instead be skipped. Otherwise we'd use
3939
// `tcx.def_span(def_id);`
40-
let span = rustc_span::DUMMY_SP;
40+
let span = DUMMY_SP;
4141

4242
result.predicates =
4343
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((

compiler/rustc_hir_typeck/src/coercion.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
5858
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeAndMut};
5959
use rustc_session::parse::feature_err;
6060
use rustc_span::symbol::sym;
61-
use rustc_span::DesugaringKind;
61+
use rustc_span::{DesugaringKind, DUMMY_SP};
6262
use rustc_target::spec::abi::Abi;
6363
use rustc_trait_selection::infer::InferCtxtExt as _;
6464
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
@@ -1054,7 +1054,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10541054
let source = self.resolve_vars_with_obligations(expr_ty);
10551055
debug!("coercion::can_with_predicates({:?} -> {:?})", source, target);
10561056

1057-
let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable);
1057+
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
10581058
// We don't ever need two-phase here since we throw out the result of the coercion
10591059
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
10601060
self.probe(|_| {
@@ -1071,11 +1071,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10711071
/// how many dereference steps needed to achieve `expr_ty <: target`. If
10721072
/// it's not possible, return `None`.
10731073
pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
1074-
let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable);
1074+
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
10751075
// We don't ever need two-phase here since we throw out the result of the coercion
10761076
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
10771077
coerce
1078-
.autoderef(rustc_span::DUMMY_SP, expr_ty)
1078+
.autoderef(DUMMY_SP, expr_ty)
10791079
.find_map(|(ty, steps)| self.probe(|_| coerce.unify(ty, target)).ok().map(|_| steps))
10801080
}
10811081

@@ -1086,7 +1086,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10861086
/// trait or region sub-obligations. (presumably we could, but it's not
10871087
/// particularly important for diagnostics...)
10881088
pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
1089-
self.autoderef(rustc_span::DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
1089+
self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
10901090
self.infcx
10911091
.type_implements_trait(
10921092
self.tcx.lang_items().deref_mut_trait()?,

compiler/rustc_hir_typeck/src/fallback.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::{
77
use rustc_hir::def_id::CRATE_DEF_ID;
88
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
99
use rustc_middle::ty::{self, Ty};
10-
use rustc_span::sym;
10+
use rustc_span::{sym, DUMMY_SP};
1111

1212
enum DivergingFallbackBehavior {
1313
/// Always fallback to `()` (aka "always spontaneous decay")
@@ -131,7 +131,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
131131
// that field is only used for type fallback diagnostics.
132132
for effect in unsolved_effects {
133133
let expected = self.tcx.consts.true_;
134-
let cause = self.misc(rustc_span::DUMMY_SP);
134+
let cause = self.misc(DUMMY_SP);
135135
match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) {
136136
Ok(InferOk { obligations, value: () }) => {
137137
self.register_predicates(obligations);
@@ -194,11 +194,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
194194
};
195195
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
196196

197-
let span = self
198-
.infcx
199-
.type_var_origin(ty)
200-
.map(|origin| origin.span)
201-
.unwrap_or(rustc_span::DUMMY_SP);
197+
let span = self.infcx.type_var_origin(ty).map(|origin| origin.span).unwrap_or(DUMMY_SP);
202198
self.demand_eqtype(span, ty, fallback);
203199
self.fallback_has_occurred.set(true);
204200
true

compiler/rustc_hir_typeck/src/method/confirm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
173173
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
174174
return Ty::new_error_with_message(
175175
self.tcx,
176-
rustc_span::DUMMY_SP,
176+
DUMMY_SP,
177177
format!("failed autoderef {}", pick.autoderefs),
178178
);
179179
};
@@ -614,7 +614,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
614614
let span = predicates
615615
.iter()
616616
.find_map(|(p, span)| if p == pred { Some(span) } else { None })
617-
.unwrap_or(rustc_span::DUMMY_SP);
617+
.unwrap_or(DUMMY_SP);
618618
Some((trait_pred, span))
619619
}
620620
_ => None,

compiler/rustc_hir_typeck/src/method/suggest.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1827,21 +1827,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18271827
has_unsuggestable_args = true;
18281828
match arg.unpack() {
18291829
GenericArgKind::Lifetime(_) => self
1830-
.next_region_var(RegionVariableOrigin::MiscVariable(
1831-
rustc_span::DUMMY_SP,
1832-
))
1830+
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
18331831
.into(),
18341832
GenericArgKind::Type(_) => self
18351833
.next_ty_var(TypeVariableOrigin {
1836-
span: rustc_span::DUMMY_SP,
1834+
span: DUMMY_SP,
18371835
kind: TypeVariableOriginKind::MiscVariable,
18381836
})
18391837
.into(),
18401838
GenericArgKind::Const(arg) => self
18411839
.next_const_var(
18421840
arg.ty(),
18431841
ConstVariableOrigin {
1844-
span: rustc_span::DUMMY_SP,
1842+
span: DUMMY_SP,
18451843
kind: ConstVariableOriginKind::MiscVariable,
18461844
},
18471845
)
@@ -2741,7 +2739,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27412739
let SelfSource::QPath(ty) = self_source else {
27422740
return;
27432741
};
2744-
for (deref_ty, _) in self.autoderef(rustc_span::DUMMY_SP, rcvr_ty).skip(1) {
2742+
for (deref_ty, _) in self.autoderef(DUMMY_SP, rcvr_ty).skip(1) {
27452743
if let Ok(pick) = self.probe_for_name(
27462744
Mode::Path,
27472745
item_name,

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::{self, InferConst};
2222
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgsRef};
2323
use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults};
2424
use rustc_span::symbol::{kw, sym, Ident};
25-
use rustc_span::{BytePos, Span};
25+
use rustc_span::{BytePos, Span, DUMMY_SP};
2626
use std::borrow::Cow;
2727
use std::iter;
2828

@@ -518,15 +518,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
518518
GenericArgKind::Lifetime(_) => bug!("unexpected lifetime"),
519519
GenericArgKind::Type(_) => self
520520
.next_ty_var(TypeVariableOrigin {
521-
span: rustc_span::DUMMY_SP,
521+
span: DUMMY_SP,
522522
kind: TypeVariableOriginKind::MiscVariable,
523523
})
524524
.into(),
525525
GenericArgKind::Const(arg) => self
526526
.next_const_var(
527527
arg.ty(),
528528
ConstVariableOrigin {
529-
span: rustc_span::DUMMY_SP,
529+
span: DUMMY_SP,
530530
kind: ConstVariableOriginKind::MiscVariable,
531531
},
532532
)

compiler/rustc_mir_transform/src/gvn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ impl<'tcx> VnState<'_, 'tcx> {
12031203
// not give the same value as the former mention.
12041204
&& value.is_deterministic()
12051205
{
1206-
return Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_: value });
1206+
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: value });
12071207
}
12081208

12091209
let op = self.evaluated[index].as_ref()?;
@@ -1220,7 +1220,7 @@ impl<'tcx> VnState<'_, 'tcx> {
12201220
assert!(!value.may_have_provenance(self.tcx, op.layout.size));
12211221

12221222
let const_ = Const::Val(value, op.layout.ty);
1223-
Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ })
1223+
Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_ })
12241224
}
12251225

12261226
/// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`,

compiler/rustc_parse/src/parser/item.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1974,11 +1974,8 @@ impl<'a> Parser<'a> {
19741974
} else if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() {
19751975
let snapshot = self.create_snapshot_for_diagnostic();
19761976
let err = if self.check_fn_front_matter(false, Case::Sensitive) {
1977-
let inherited_vis = Visibility {
1978-
span: rustc_span::DUMMY_SP,
1979-
kind: VisibilityKind::Inherited,
1980-
tokens: None,
1981-
};
1977+
let inherited_vis =
1978+
Visibility { span: DUMMY_SP, kind: VisibilityKind::Inherited, tokens: None };
19821979
// We use `parse_fn` to get a span for the function
19831980
let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true };
19841981
match self.parse_fn(

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
//! In this case we try to build an abstract representation of this constant using
99
//! `thir_abstract_const` which can then be checked for structural equality with other
1010
//! generic constants mentioned in the `caller_bounds` of the current environment.
11+
1112
use rustc_hir::def::DefKind;
1213
use rustc_infer::infer::InferCtxt;
1314
use rustc_middle::mir::interpret::ErrorHandled;
14-
1515
use rustc_middle::traits::ObligationCause;
1616
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
1717
use rustc_middle::ty::{self, TyCtxt, TypeVisitable, TypeVisitableExt, TypeVisitor};
18-
19-
use rustc_span::Span;
18+
use rustc_span::{Span, DUMMY_SP};
2019

2120
use crate::traits::ObligationCtxt;
2221

@@ -116,12 +115,12 @@ pub fn is_const_evaluatable<'tcx>(
116115
tcx.dcx()
117116
.struct_span_fatal(
118117
// Slightly better span than just using `span` alone
119-
if span == rustc_span::DUMMY_SP { tcx.def_span(uv.def) } else { span },
118+
if span == DUMMY_SP { tcx.def_span(uv.def) } else { span },
120119
"failed to evaluate generic const expression",
121120
)
122121
.with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`")
123122
.with_span_suggestion_verbose(
124-
rustc_span::DUMMY_SP,
123+
DUMMY_SP,
125124
"consider enabling this feature",
126125
"#![feature(generic_const_exprs)]\n",
127126
rustc_errors::Applicability::MaybeIncorrect,

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl Item {
400400

401401
pub(crate) fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span {
402402
span_of_fragments(&self.attrs.doc_strings)
403-
.unwrap_or_else(|| self.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner()))
403+
.unwrap_or_else(|| self.span(tcx).map_or(DUMMY_SP, |span| span.inner()))
404404
}
405405

406406
/// Combine all doc strings into a single value handling indentation and newlines as needed.

src/librustdoc/html/render/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use rustc_middle::ty::{self, TyCtxt};
5656
use rustc_session::RustcVersion;
5757
use rustc_span::{
5858
symbol::{sym, Symbol},
59-
BytePos, FileName, RealFileName,
59+
BytePos, FileName, RealFileName, DUMMY_SP,
6060
};
6161
use serde::ser::SerializeMap;
6262
use serde::{Serialize, Serializer};
@@ -2439,7 +2439,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
24392439
let contents = match fs::read_to_string(&path) {
24402440
Ok(contents) => contents,
24412441
Err(err) => {
2442-
let span = item.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner());
2442+
let span = item.span(tcx).map_or(DUMMY_SP, |span| span.inner());
24432443
tcx.dcx().span_err(span, format!("failed to read file {}: {err}", path.display()));
24442444
return false;
24452445
}
@@ -2520,7 +2520,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
25202520
file.start_pos + BytePos(byte_max),
25212521
))
25222522
})()
2523-
.unwrap_or(rustc_span::DUMMY_SP);
2523+
.unwrap_or(DUMMY_SP);
25242524

25252525
let mut decoration_info = FxHashMap::default();
25262526
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);

src/tools/clippy/clippy_lints/src/non_copy_const.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId};
1818
use rustc_middle::ty::adjustment::Adjust;
1919
use rustc_middle::ty::{self, Ty, TyCtxt};
2020
use rustc_session::impl_lint_pass;
21-
use rustc_span::{sym, InnerSpan, Span};
21+
use rustc_span::{sym, DUMMY_SP, InnerSpan, Span};
2222
use rustc_target::abi::VariantIdx;
2323

2424
// FIXME: this is a correctness problem but there's no suitable
@@ -290,14 +290,14 @@ impl NonCopyConst {
290290
promoted: None,
291291
};
292292
let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx);
293-
let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP);
293+
let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, DUMMY_SP);
294294
self.is_value_unfrozen_raw(cx, result, ty)
295295
}
296296

297297
fn is_value_unfrozen_expr<'tcx>(&self, cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool {
298298
let args = cx.typeck_results().node_args(hir_id);
299299

300-
let result = Self::const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), rustc_span::DUMMY_SP);
300+
let result = Self::const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), DUMMY_SP);
301301
self.is_value_unfrozen_raw(cx, result, ty)
302302
}
303303

0 commit comments

Comments
 (0)