mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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.
This commit is contained in:
parent
63f70b3d10
commit
27374a0214
@ -3,6 +3,7 @@ use super::*;
|
||||
use rustc_ast as ast;
|
||||
use rustc_span::create_default_session_globals_then;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::DUMMY_SP;
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
fn fun_to_string(
|
||||
@ -28,10 +29,7 @@ fn test_fun_to_string() {
|
||||
create_default_session_globals_then(|| {
|
||||
let abba_ident = Ident::from_str("abba");
|
||||
|
||||
let decl = ast::FnDecl {
|
||||
inputs: ThinVec::new(),
|
||||
output: ast::FnRetTy::Default(rustc_span::DUMMY_SP),
|
||||
};
|
||||
let decl = ast::FnDecl { inputs: ThinVec::new(), output: ast::FnRetTy::Default(DUMMY_SP) };
|
||||
let generics = ast::Generics::default();
|
||||
assert_eq!(
|
||||
fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics),
|
||||
@ -48,7 +46,7 @@ fn test_variant_to_string() {
|
||||
let var = ast::Variant {
|
||||
ident,
|
||||
vis: ast::Visibility {
|
||||
span: rustc_span::DUMMY_SP,
|
||||
span: DUMMY_SP,
|
||||
kind: ast::VisibilityKind::Inherited,
|
||||
tokens: None,
|
||||
},
|
||||
@ -56,7 +54,7 @@ fn test_variant_to_string() {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
data: ast::VariantData::Unit(ast::DUMMY_NODE_ID),
|
||||
disr_expr: None,
|
||||
span: rustc_span::DUMMY_SP,
|
||||
span: DUMMY_SP,
|
||||
is_placeholder: false,
|
||||
};
|
||||
|
||||
|
@ -8,8 +8,7 @@ use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfK
|
||||
use rustc_expand::base::ExtCtxt;
|
||||
use rustc_span::source_map::respan;
|
||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
/// A path, e.g., `::std::option::Option::<i32>` (global). Has support
|
||||
|
@ -37,7 +37,7 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
|
||||
// from the trait itself that *shouldn't* be shown as the source of
|
||||
// an obligation and instead be skipped. Otherwise we'd use
|
||||
// `tcx.def_span(def_id);`
|
||||
let span = rustc_span::DUMMY_SP;
|
||||
let span = DUMMY_SP;
|
||||
|
||||
result.predicates =
|
||||
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
|
||||
|
@ -59,8 +59,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
|
||||
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::DesugaringKind;
|
||||
use rustc_span::{BytePos, Span};
|
||||
use rustc_span::{BytePos, DesugaringKind, Span, DUMMY_SP};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use rustc_trait_selection::infer::InferCtxtExt as _;
|
||||
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
|
||||
@ -1045,7 +1044,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let source = self.resolve_vars_with_obligations(expr_ty);
|
||||
debug!("coercion::can_with_predicates({:?} -> {:?})", source, target);
|
||||
|
||||
let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable);
|
||||
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
|
||||
// We don't ever need two-phase here since we throw out the result of the coercion
|
||||
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
|
||||
self.probe(|_| {
|
||||
@ -1062,11 +1061,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// how many dereference steps needed to achieve `expr_ty <: target`. If
|
||||
/// it's not possible, return `None`.
|
||||
pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
|
||||
let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable);
|
||||
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
|
||||
// We don't ever need two-phase here since we throw out the result of the coercion
|
||||
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
|
||||
coerce
|
||||
.autoderef(rustc_span::DUMMY_SP, expr_ty)
|
||||
.autoderef(DUMMY_SP, expr_ty)
|
||||
.find_map(|(ty, steps)| self.probe(|_| coerce.unify(ty, target)).ok().map(|_| steps))
|
||||
}
|
||||
|
||||
@ -1077,7 +1076,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
/// trait or region sub-obligations. (presumably we could, but it's not
|
||||
/// particularly important for diagnostics...)
|
||||
pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
self.autoderef(rustc_span::DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
|
||||
self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
|
||||
self.infcx
|
||||
.type_implements_trait(
|
||||
self.tcx.lang_items().deref_mut_trait()?,
|
||||
|
@ -5,6 +5,7 @@ use rustc_data_structures::{
|
||||
};
|
||||
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum DivergingFallbackBehavior {
|
||||
@ -102,7 +103,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
||||
// that field is only used for type fallback diagnostics.
|
||||
for effect in unsolved_effects {
|
||||
let expected = self.tcx.consts.true_;
|
||||
let cause = self.misc(rustc_span::DUMMY_SP);
|
||||
let cause = self.misc(DUMMY_SP);
|
||||
match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) {
|
||||
Ok(InferOk { obligations, value: () }) => {
|
||||
self.register_predicates(obligations);
|
||||
@ -165,11 +166,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
||||
};
|
||||
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
|
||||
|
||||
let span = self
|
||||
.infcx
|
||||
.type_var_origin(ty)
|
||||
.map(|origin| origin.span)
|
||||
.unwrap_or(rustc_span::DUMMY_SP);
|
||||
let span = self.infcx.type_var_origin(ty).map(|origin| origin.span).unwrap_or(DUMMY_SP);
|
||||
self.demand_eqtype(span, ty, fallback);
|
||||
self.fallback_has_occurred.set(true);
|
||||
true
|
||||
|
@ -173,7 +173,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
|
||||
return Ty::new_error_with_message(
|
||||
self.tcx,
|
||||
rustc_span::DUMMY_SP,
|
||||
DUMMY_SP,
|
||||
format!("failed autoderef {}", pick.autoderefs),
|
||||
);
|
||||
};
|
||||
@ -608,7 +608,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||
let span = predicates
|
||||
.iter()
|
||||
.find_map(|(p, span)| if p == pred { Some(span) } else { None })
|
||||
.unwrap_or(rustc_span::DUMMY_SP);
|
||||
.unwrap_or(DUMMY_SP);
|
||||
Some((trait_pred, span))
|
||||
}
|
||||
_ => None,
|
||||
|
@ -1844,23 +1844,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
has_unsuggestable_args = true;
|
||||
match arg.unpack() {
|
||||
GenericArgKind::Lifetime(_) => self
|
||||
.next_region_var(RegionVariableOrigin::MiscVariable(
|
||||
rustc_span::DUMMY_SP,
|
||||
))
|
||||
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
|
||||
.into(),
|
||||
GenericArgKind::Type(_) => self
|
||||
.next_ty_var(TypeVariableOrigin {
|
||||
span: rustc_span::DUMMY_SP,
|
||||
span: DUMMY_SP,
|
||||
param_def_id: None,
|
||||
})
|
||||
.into(),
|
||||
GenericArgKind::Const(arg) => self
|
||||
.next_const_var(
|
||||
arg.ty(),
|
||||
ConstVariableOrigin {
|
||||
span: rustc_span::DUMMY_SP,
|
||||
param_def_id: None,
|
||||
},
|
||||
ConstVariableOrigin { span: DUMMY_SP, param_def_id: None },
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
@ -2758,7 +2753,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let SelfSource::QPath(ty) = self_source else {
|
||||
return;
|
||||
};
|
||||
for (deref_ty, _) in self.autoderef(rustc_span::DUMMY_SP, rcvr_ty).skip(1) {
|
||||
for (deref_ty, _) in self.autoderef(DUMMY_SP, rcvr_ty).skip(1) {
|
||||
if let Ok(pick) = self.probe_for_name(
|
||||
Mode::Path,
|
||||
item_name,
|
||||
|
@ -1202,7 +1202,7 @@ impl<'tcx> VnState<'_, 'tcx> {
|
||||
// not give the same value as the former mention.
|
||||
&& value.is_deterministic()
|
||||
{
|
||||
return Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_: value });
|
||||
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: value });
|
||||
}
|
||||
|
||||
let op = self.evaluated[index].as_ref()?;
|
||||
@ -1219,7 +1219,7 @@ impl<'tcx> VnState<'_, 'tcx> {
|
||||
assert!(!value.may_have_provenance(self.tcx, op.layout.size));
|
||||
|
||||
let const_ = Const::Val(value, op.layout.ty);
|
||||
Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ })
|
||||
Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_ })
|
||||
}
|
||||
|
||||
/// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`,
|
||||
|
@ -1968,11 +1968,8 @@ impl<'a> Parser<'a> {
|
||||
} else if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() {
|
||||
let snapshot = self.create_snapshot_for_diagnostic();
|
||||
let err = if self.check_fn_front_matter(false, Case::Sensitive) {
|
||||
let inherited_vis = Visibility {
|
||||
span: rustc_span::DUMMY_SP,
|
||||
kind: VisibilityKind::Inherited,
|
||||
tokens: None,
|
||||
};
|
||||
let inherited_vis =
|
||||
Visibility { span: DUMMY_SP, kind: VisibilityKind::Inherited, tokens: None };
|
||||
// We use `parse_fn` to get a span for the function
|
||||
let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true };
|
||||
match self.parse_fn(
|
||||
|
@ -8,15 +8,14 @@
|
||||
//! In this case we try to build an abstract representation of this constant using
|
||||
//! `thir_abstract_const` which can then be checked for structural equality with other
|
||||
//! generic constants mentioned in the `caller_bounds` of the current environment.
|
||||
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitable, TypeVisitableExt, TypeVisitor};
|
||||
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
use crate::traits::ObligationCtxt;
|
||||
|
||||
@ -116,12 +115,12 @@ pub fn is_const_evaluatable<'tcx>(
|
||||
tcx.dcx()
|
||||
.struct_span_fatal(
|
||||
// Slightly better span than just using `span` alone
|
||||
if span == rustc_span::DUMMY_SP { tcx.def_span(uv.def) } else { span },
|
||||
if span == DUMMY_SP { tcx.def_span(uv.def) } else { span },
|
||||
"failed to evaluate generic const expression",
|
||||
)
|
||||
.with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`")
|
||||
.with_span_suggestion_verbose(
|
||||
rustc_span::DUMMY_SP,
|
||||
DUMMY_SP,
|
||||
"consider enabling this feature",
|
||||
"#![feature(generic_const_exprs)]\n",
|
||||
rustc_errors::Applicability::MaybeIncorrect,
|
||||
|
@ -408,7 +408,7 @@ impl Item {
|
||||
|
||||
pub(crate) fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span {
|
||||
span_of_fragments(&self.attrs.doc_strings)
|
||||
.unwrap_or_else(|| self.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner()))
|
||||
.unwrap_or_else(|| self.span(tcx).map_or(DUMMY_SP, |span| span.inner()))
|
||||
}
|
||||
|
||||
/// Combine all doc strings into a single value handling indentation and newlines as needed.
|
||||
|
@ -56,7 +56,7 @@ use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_session::RustcVersion;
|
||||
use rustc_span::{
|
||||
symbol::{sym, Symbol},
|
||||
BytePos, FileName, RealFileName,
|
||||
BytePos, FileName, RealFileName, DUMMY_SP,
|
||||
};
|
||||
use serde::ser::SerializeMap;
|
||||
use serde::{Serialize, Serializer};
|
||||
@ -2414,7 +2414,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
|
||||
let contents = match fs::read_to_string(&path) {
|
||||
Ok(contents) => contents,
|
||||
Err(err) => {
|
||||
let span = item.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner());
|
||||
let span = item.span(tcx).map_or(DUMMY_SP, |span| span.inner());
|
||||
tcx.dcx().span_err(span, format!("failed to read file {}: {err}", path.display()));
|
||||
return false;
|
||||
}
|
||||
@ -2495,7 +2495,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
|
||||
file.start_pos + BytePos(byte_max),
|
||||
))
|
||||
})()
|
||||
.unwrap_or(rustc_span::DUMMY_SP);
|
||||
.unwrap_or(DUMMY_SP);
|
||||
|
||||
let mut decoration_info = FxHashMap::default();
|
||||
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);
|
||||
|
@ -18,7 +18,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId};
|
||||
use rustc_middle::ty::adjustment::Adjust;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::impl_lint_pass;
|
||||
use rustc_span::{sym, InnerSpan, Span};
|
||||
use rustc_span::{sym, DUMMY_SP, InnerSpan, Span};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
||||
// FIXME: this is a correctness problem but there's no suitable
|
||||
@ -290,9 +290,7 @@ impl NonCopyConst {
|
||||
promoted: None,
|
||||
};
|
||||
let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx);
|
||||
let result = cx
|
||||
.tcx
|
||||
.const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP);
|
||||
let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, DUMMY_SP);
|
||||
self.is_value_unfrozen_raw(cx, result, ty)
|
||||
}
|
||||
|
||||
@ -303,7 +301,7 @@ impl NonCopyConst {
|
||||
cx.tcx,
|
||||
cx.param_env,
|
||||
ty::UnevaluatedConst::new(def_id, args),
|
||||
rustc_span::DUMMY_SP,
|
||||
DUMMY_SP,
|
||||
);
|
||||
self.is_value_unfrozen_raw(cx, result, ty)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user