Skip to content

Commit 27374a0

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 63f70b3 commit 27374a0

File tree

13 files changed

+35
-53
lines changed

13 files changed

+35
-53
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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
5959
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt};
6060
use rustc_session::parse::feature_err;
6161
use rustc_span::symbol::sym;
62-
use rustc_span::DesugaringKind;
63-
use rustc_span::{BytePos, Span};
62+
use rustc_span::{BytePos, DesugaringKind, Span, DUMMY_SP};
6463
use rustc_target::spec::abi::Abi;
6564
use rustc_trait_selection::infer::InferCtxtExt as _;
6665
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
@@ -1045,7 +1044,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10451044
let source = self.resolve_vars_with_obligations(expr_ty);
10461045
debug!("coercion::can_with_predicates({:?} -> {:?})", source, target);
10471046

1048-
let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable);
1047+
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
10491048
// We don't ever need two-phase here since we throw out the result of the coercion
10501049
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
10511050
self.probe(|_| {
@@ -1062,11 +1061,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10621061
/// how many dereference steps needed to achieve `expr_ty <: target`. If
10631062
/// it's not possible, return `None`.
10641063
pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
1065-
let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable);
1064+
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
10661065
// We don't ever need two-phase here since we throw out the result of the coercion
10671066
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
10681067
coerce
1069-
.autoderef(rustc_span::DUMMY_SP, expr_ty)
1068+
.autoderef(DUMMY_SP, expr_ty)
10701069
.find_map(|(ty, steps)| self.probe(|_| coerce.unify(ty, target)).ok().map(|_| steps))
10711070
}
10721071

@@ -1077,7 +1076,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10771076
/// trait or region sub-obligations. (presumably we could, but it's not
10781077
/// particularly important for diagnostics...)
10791078
pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
1080-
self.autoderef(rustc_span::DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
1079+
self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
10811080
self.infcx
10821081
.type_implements_trait(
10831082
self.tcx.lang_items().deref_mut_trait()?,

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_data_structures::{
55
};
66
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
77
use rustc_middle::ty::{self, Ty};
8+
use rustc_span::DUMMY_SP;
89

910
#[derive(Copy, Clone)]
1011
pub enum DivergingFallbackBehavior {
@@ -102,7 +103,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
102103
// that field is only used for type fallback diagnostics.
103104
for effect in unsolved_effects {
104105
let expected = self.tcx.consts.true_;
105-
let cause = self.misc(rustc_span::DUMMY_SP);
106+
let cause = self.misc(DUMMY_SP);
106107
match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) {
107108
Ok(InferOk { obligations, value: () }) => {
108109
self.register_predicates(obligations);
@@ -165,11 +166,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
165166
};
166167
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
167168

168-
let span = self
169-
.infcx
170-
.type_var_origin(ty)
171-
.map(|origin| origin.span)
172-
.unwrap_or(rustc_span::DUMMY_SP);
169+
let span = self.infcx.type_var_origin(ty).map(|origin| origin.span).unwrap_or(DUMMY_SP);
173170
self.demand_eqtype(span, ty, fallback);
174171
self.fallback_has_occurred.set(true);
175172
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
};
@@ -608,7 +608,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
608608
let span = predicates
609609
.iter()
610610
.find_map(|(p, span)| if p == pred { Some(span) } else { None })
611-
.unwrap_or(rustc_span::DUMMY_SP);
611+
.unwrap_or(DUMMY_SP);
612612
Some((trait_pred, span))
613613
}
614614
_ => None,

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,23 +1844,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18441844
has_unsuggestable_args = true;
18451845
match arg.unpack() {
18461846
GenericArgKind::Lifetime(_) => self
1847-
.next_region_var(RegionVariableOrigin::MiscVariable(
1848-
rustc_span::DUMMY_SP,
1849-
))
1847+
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
18501848
.into(),
18511849
GenericArgKind::Type(_) => self
18521850
.next_ty_var(TypeVariableOrigin {
1853-
span: rustc_span::DUMMY_SP,
1851+
span: DUMMY_SP,
18541852
param_def_id: None,
18551853
})
18561854
.into(),
18571855
GenericArgKind::Const(arg) => self
18581856
.next_const_var(
18591857
arg.ty(),
1860-
ConstVariableOrigin {
1861-
span: rustc_span::DUMMY_SP,
1862-
param_def_id: None,
1863-
},
1858+
ConstVariableOrigin { span: DUMMY_SP, param_def_id: None },
18641859
)
18651860
.into(),
18661861
}
@@ -2758,7 +2753,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27582753
let SelfSource::QPath(ty) = self_source else {
27592754
return;
27602755
};
2761-
for (deref_ty, _) in self.autoderef(rustc_span::DUMMY_SP, rcvr_ty).skip(1) {
2756+
for (deref_ty, _) in self.autoderef(DUMMY_SP, rcvr_ty).skip(1) {
27622757
if let Ok(pick) = self.probe_for_name(
27632758
Mode::Path,
27642759
item_name,

compiler/rustc_mir_transform/src/gvn.rs

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

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

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

12251225
/// 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
@@ -1968,11 +1968,8 @@ impl<'a> Parser<'a> {
19681968
} else if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() {
19691969
let snapshot = self.create_snapshot_for_diagnostic();
19701970
let err = if self.check_fn_front_matter(false, Case::Sensitive) {
1971-
let inherited_vis = Visibility {
1972-
span: rustc_span::DUMMY_SP,
1973-
kind: VisibilityKind::Inherited,
1974-
tokens: None,
1975-
};
1971+
let inherited_vis =
1972+
Visibility { span: DUMMY_SP, kind: VisibilityKind::Inherited, tokens: None };
19761973
// We use `parse_fn` to get a span for the function
19771974
let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true };
19781975
match self.parse_fn(

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

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

0 commit comments

Comments
 (0)