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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 7 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 5 deletions
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(

0 commit comments

Comments
 (0)