From 620a1e4c2fdea7f4282679fb68abc34823f99bea Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 22:21:37 +1100 Subject: [PATCH] Remove `Session` methods that duplicate `DiagCtxt` methods. Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access. --- clippy_config/src/conf.rs | 10 +++++----- clippy_config/src/msrvs.rs | 8 ++++---- clippy_lints/src/missing_const_for_fn.rs | 2 +- clippy_utils/src/attrs.rs | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/clippy_config/src/conf.rs b/clippy_config/src/conf.rs index 88611eb7087..3cf4377002a 100644 --- a/clippy_config/src/conf.rs +++ b/clippy_config/src/conf.rs @@ -636,11 +636,11 @@ fn read_inner(sess: &Session, path: &io::Result<(Option, Vec)>) match path { Ok((_, warnings)) => { for warning in warnings { - sess.warn(warning.clone()); + sess.dcx().warn(warning.clone()); } }, 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, Vec)>) Ok((Some(path), _)) => match sess.source_map().load_file(path) { Ok(file) => deserialize(&file), Err(error) => { - sess.err(format!("failed to read `{}`: {error}", path.display())); + sess.dcx().err(format!("failed to read `{}`: {error}", path.display())); TryConf::default() }, }, @@ -663,14 +663,14 @@ fn read_inner(sess: &Session, path: &io::Result<(Option, Vec)>) // all conf errors are non-fatal, we just use the default conf in case of error for error in errors { - sess.span_err( + sess.dcx().span_err( error.span, format!("error reading Clippy's configuration file: {}", error.message), ); } for warning in warnings { - sess.span_warn( + sess.dcx().span_warn( warning.span, format!("error reading Clippy's configuration file: {}", warning.message), ); diff --git a/clippy_config/src/msrvs.rs b/clippy_config/src/msrvs.rs index b3ef666e306..13e61e5a032 100644 --- a/clippy_config/src/msrvs.rs +++ b/clippy_config/src/msrvs.rs @@ -83,7 +83,7 @@ pub fn read_cargo(&mut self, sess: &Session) { (None, Some(cargo_msrv)) => self.stack = vec![cargo_msrv], (Some(clippy_msrv), Some(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`" )); } @@ -106,7 +106,7 @@ fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option { if let Some(msrv_attr) = msrv_attrs.next() { 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") .emit(); } @@ -116,9 +116,9 @@ fn parse_attr(sess: &Session, attrs: &[Attribute]) -> Option { 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 { - sess.span_err(msrv_attr.span, "bad clippy attribute"); + sess.dcx().span_err(msrv_attr.span, "bad clippy attribute"); } } diff --git a/clippy_lints/src/missing_const_for_fn.rs b/clippy_lints/src/missing_const_for_fn.rs index acaa6be3009..9ba19e0a865 100644 --- a/clippy_lints/src/missing_const_for_fn.rs +++ b/clippy_lints/src/missing_const_for_fn.rs @@ -153,7 +153,7 @@ fn check_fn( 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()) { - cx.tcx.sess.span_err(span, err); + cx.tcx.dcx().span_err(span, err); } } else { span_lint(cx, MISSING_CONST_FOR_FN, span, "this could be a `const fn`"); diff --git a/clippy_utils/src/attrs.rs b/clippy_utils/src/attrs.rs index 51771f78d4f..46c96fad884 100644 --- a/clippy_utils/src/attrs.rs +++ b/clippy_utils/src/attrs.rs @@ -76,12 +76,12 @@ pub fn get_attr<'a>( }) .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 }, |deprecation_status| { 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 { DeprecationStatus::Deprecated => { diag.emit(); @@ -116,10 +116,10 @@ fn parse_attrs(sess: &Session, attrs: &[ast::Attribute], name: &' if let Ok(value) = FromStr::from_str(value.as_str()) { f(value); } else { - sess.span_err(attr.span, "not a number"); + sess.dcx().span_err(attr.span, "not a number"); } } 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; for attr in get_attr(sess, attrs, name) { 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") .emit(); } else {