Remove Session methods that duplicate DiagCtxt methods.

Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
This commit is contained in:
Nicholas Nethercote 2023-12-18 22:21:37 +11:00
parent 870a5d957b
commit 620a1e4c2f
4 changed files with 15 additions and 15 deletions

View File

@ -636,11 +636,11 @@ fn read_inner(sess: &Session, path: &io::Result<(Option<PathBuf>, Vec<String>)>)
match path { match path {
Ok((_, warnings)) => { Ok((_, warnings)) => {
for warning in warnings { for warning in warnings {
sess.warn(warning.clone()); sess.dcx().warn(warning.clone());
} }
}, },
Err(error) => { Err(error) => {
sess.err(format!("error finding Clippy's configuration file: {error}")); sess.dcx().err(format!("error finding Clippy's configuration file: {error}"));
}, },
} }
@ -652,7 +652,7 @@ fn read_inner(sess: &Session, path: &io::Result<(Option<PathBuf>, Vec<String>)>)
Ok((Some(path), _)) => match sess.source_map().load_file(path) { Ok((Some(path), _)) => match sess.source_map().load_file(path) {
Ok(file) => deserialize(&file), Ok(file) => deserialize(&file),
Err(error) => { Err(error) => {
sess.err(format!("failed to read `{}`: {error}", path.display())); sess.dcx().err(format!("failed to read `{}`: {error}", path.display()));
TryConf::default() TryConf::default()
}, },
}, },
@ -663,14 +663,14 @@ fn read_inner(sess: &Session, path: &io::Result<(Option<PathBuf>, Vec<String>)>)
// all conf errors are non-fatal, we just use the default conf in case of error // all conf errors are non-fatal, we just use the default conf in case of error
for error in errors { for error in errors {
sess.span_err( sess.dcx().span_err(
error.span, error.span,
format!("error reading Clippy's configuration file: {}", error.message), format!("error reading Clippy's configuration file: {}", error.message),
); );
} }
for warning in warnings { for warning in warnings {
sess.span_warn( sess.dcx().span_warn(
warning.span, warning.span,
format!("error reading Clippy's configuration file: {}", warning.message), format!("error reading Clippy's configuration file: {}", warning.message),
); );

View File

@ -83,7 +83,7 @@ pub fn read_cargo(&mut self, sess: &Session) {
(None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv], (None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv],
(Some(clippy_msrv), Some(cargo_msrv)) => { (Some(clippy_msrv), Some(cargo_msrv)) => {
if clippy_msrv != cargo_msrv { if clippy_msrv != cargo_msrv {
sess.warn(format!( sess.dcx().warn(format!(
"the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{clippy_msrv}` from `clippy.toml`" "the MSRV in `clippy.toml` and `Cargo.toml` differ; using `{clippy_msrv}` from `clippy.toml`"
)); ));
} }
@ -106,7 +106,7 @@ fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option<RustcVersion> {
if let Some(msrv_attr) = msrv_attrs.next() { if let Some(msrv_attr) = msrv_attrs.next() {
if let Some(duplicate) = msrv_attrs.last() { if let Some(duplicate) = msrv_attrs.last() {
sess.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times") sess.dcx().struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
.span_note(msrv_attr.span, "first definition found here") .span_note(msrv_attr.span, "first definition found here")
.emit(); .emit();
} }
@ -116,9 +116,9 @@ fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option<RustcVersion> {
return Some(version); return Some(version);
} }
sess.span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version")); sess.dcx().span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version"));
} else { } else {
sess.span_err(msrv_attr.span, "bad clippy attribute"); sess.dcx().span_err(msrv_attr.span, "bad clippy attribute");
} }
} }

View File

@ -153,7 +153,7 @@ fn check_fn(
if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, &self.msrv) { if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, &self.msrv) {
if cx.tcx.is_const_fn_raw(def_id.to_def_id()) { if cx.tcx.is_const_fn_raw(def_id.to_def_id()) {
cx.tcx.sess.span_err(span, err); cx.tcx.dcx().span_err(span, err);
} }
} else { } else {
span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`"); span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`");

View File

@ -76,12 +76,12 @@ pub fn get_attr<'a>(
}) })
.map_or_else( .map_or_else(
|| { || {
sess.span_err(attr_segments[1].ident.span, "usage of unknown attribute"); sess.dcx().span_err(attr_segments[1].ident.span, "usage of unknown attribute");
false false
}, },
|deprecation_status| { |deprecation_status| {
let mut diag = let mut diag =
sess.struct_span_err(attr_segments[1].ident.span, "usage of deprecated attribute"); sess.dcx().struct_span_err(attr_segments[1].ident.span, "usage of deprecated attribute");
match *deprecation_status { match *deprecation_status {
DeprecationStatus::Deprecated => { DeprecationStatus::Deprecated => {
diag.emit(); diag.emit();
@ -116,10 +116,10 @@ fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[ast::Attribute], name: &'
if let Ok(value) = FromStr::from_str(value.as_str()) { if let Ok(value) = FromStr::from_str(value.as_str()) {
f(value); f(value);
} else { } else {
sess.span_err(attr.span, "not a number"); sess.dcx().span_err(attr.span, "not a number");
} }
} else { } else {
sess.span_err(attr.span, "bad clippy attribute"); sess.dcx().span_err(attr.span, "bad clippy attribute");
} }
} }
} }
@ -132,7 +132,7 @@ pub fn get_unique_attr<'a>(
let mut unique_attr: Option<&ast::Attribute> = None; let mut unique_attr: Option<&ast::Attribute> = None;
for attr in get_attr(sess, attrs, name) { for attr in get_attr(sess, attrs, name) {
if let Some(duplicate) = unique_attr { if let Some(duplicate) = unique_attr {
sess.struct_span_err(attr.span, format!("`{name}` is defined multiple times")) sess.dcx().struct_span_err(attr.span, format!("`{name}` is defined multiple times"))
.span_note(duplicate.span, "first definition found here") .span_note(duplicate.span, "first definition found here")
.emit(); .emit();
} else { } else {