Skip to content

Commit

Permalink
Account for API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jan 11, 2024
1 parent 5697d96 commit 8661abd
Show file tree
Hide file tree
Showing 28 changed files with 54 additions and 41 deletions.
5 changes: 4 additions & 1 deletion examples/experimental/derive_opportunity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,10 @@ fn implements_trait_with_bounds<'tcx>(
];
if let ty::Adt(adt_def, _) = ty.kind() {
let param_env = param_env_with_bounds(cx.tcx, adt_def.did(), trait_id);
implements_trait_with_env(cx.tcx, param_env, ty, trait_id, &args)
// smoelius: I am not sure that `adt_def.did()` is the right thing to pass for the
// `callee_id` argument. This choice is based on:
// https://github.com/rust-lang/rust-clippy/blob/782520088f9c5a0274459060a6fdcd41301f35e2/clippy_lints/src/derive.rs#L453
implements_trait_with_env(cx.tcx, param_env, ty, trait_id, adt_def.did(), &args)
} else {
implements_trait(cx, ty, trait_id, &args)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/experimental/missing_doc_comment_openai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl MissingDocCommentOpenai {
impl<'tcx> LateLintPass<'tcx> for MissingDocCommentOpenai {
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
if std::env::var(OPENAI_API_KEY).is_err() {
cx.sess().warn(format!(
cx.sess().dcx().warn(format!(
"`missing_doc_comment_openai` suggestions are disabled because environment \
variable `{OPENAI_API_KEY}` is not set"
));
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDocCommentOpenai {
let response = match send_request(&api_key, &request) {
Ok(response) => response,
Err(error) => {
cx.sess().span_warn(fn_sig_span, error.to_string());
cx.sess().dcx().span_warn(fn_sig_span, error.to_string());
return None;
}
};
Expand All @@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDocCommentOpenai {
.first()
.and_then(|choice| extract_doc_comment(&choice.text))
.or_else(|| {
cx.sess().span_warn(
cx.sess().dcx().span_warn(
fn_sig_span,
format!("Could not extract doc comment from response: {response:#?}",),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ help: use the following suggestion from OpenAI
LL + /// A doc comment generated by OpenAI.
|

error: aborting due to previous error
error: aborting due to 1 previous error

19 changes: 13 additions & 6 deletions examples/general/await_holding_span_guard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ extern crate rustc_middle;

use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::match_def_path;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::{Body, CoroutineKind, CoroutineSource};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::CoroutineLayout;
use rustc_middle::ty::Adt;
Expand Down Expand Up @@ -86,11 +86,18 @@ const TRACING_SPAN_ENTER_GUARD: [&str; 3] = ["tracing", "span", "Entered"];
const TRACING_SPAN_ENTERED_GUARD: [&str; 3] = ["tracing", "span", "EnteredSpan"];

impl LateLintPass<'_> for AwaitHoldingSpanGuard {
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
use CoroutineSource::{Block, Closure, Fn};
if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind {
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ hir::Expr<'_>) {
if let hir::ExprKind::Closure(hir::Closure {
kind:
hir::ClosureKind::Coroutine(hir::CoroutineKind::Desugared(
hir::CoroutineDesugaring::Async,
_,
)),
def_id,
..
}) = expr.kind
{
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(*def_id) {
check_interior_types(cx, coroutine_layout);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/general/crate_wide_allow/ui/main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ LL | #![allow(clippy::assertions_on_constants)]
= note: `-D crate-wide-allow` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(crate_wide_allow)]`

error: aborting due to previous error
error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalEffectBeforeErrorReturn {
}

fn in_async_function(tcx: ty::TyCtxt<'_>, hir_id: rustc_hir::HirId) -> bool {
std::iter::once((hir_id, tcx.hir().get(hir_id)))
std::iter::once((hir_id, tcx.hir_node(hir_id)))
.chain(tcx.hir().parent_iter(hir_id))
.any(|(_, node)| {
node.fn_kind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ where
FnKind::ItemFn(ident, _, _) | FnKind::Method(ident, _) => format!("`{ident}`"),
FnKind::Closure => "closure".to_owned(),
};
self.cx.sess().warn(format!(
self.cx.sess().dcx().warn(format!(
"reached work limit ({}) while checking {}; set `{}.work_limit` in `dylint.toml` \
to override",
self.work_limit,
Expand Down
2 changes: 1 addition & 1 deletion examples/general/non_thread_safe_call_in_test/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl_lint_pass!(NonThreadSafeCallInTest => [NON_THREAD_SAFE_CALL_IN_TEST]);
impl<'tcx> LateLintPass<'tcx> for NonThreadSafeCallInTest {
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
if !cx.sess().opts.test {
cx.sess().warn(
cx.sess().dcx().warn(
"`non_thread_safe_call_in_test` is unlikely to be effective as `--test` was not \
passed to rustc",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl_lint_pass!(NonThreadSafeCallInTest => [NON_THREAD_SAFE_CALL_IN_TEST_PRE_EXP
impl EarlyLintPass for NonThreadSafeCallInTest {
fn check_crate(&mut self, cx: &EarlyContext, _crate: &Crate) {
if !cx.sess().opts.test {
cx.sess().warn(
cx.sess().dcx().warn(
"`non_thread_safe_call_in_test` is unlikely to be effective as `--test` was not \
passed to rustc",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ LL | fn foo() {
= note: `-D non-thread-safe-call-in-test` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(non_thread_safe_call_in_test)]`

error: aborting due to previous error
error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ LL | fn env_set_current_dir() {
= note: `-D non-thread-safe-call-in-test` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(non_thread_safe_call_in_test)]`

error: aborting due to previous error
error: aborting due to 1 previous error

6 changes: 3 additions & 3 deletions examples/restriction/inconsistent_qualification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentQualification {
.hir()
.parent_iter(hir_id)
.any(|(hir_id, _)| cx.tcx.hir().span(hir_id).in_derive_expansion());
let node = cx.tcx.hir().get(hir_id);
let node = cx.tcx.hir_node(hir_id);
if !matches!(
node,
Node::Item(Item {
Expand All @@ -94,7 +94,7 @@ impl<'tcx> LateLintPass<'tcx> for InconsistentQualification {
syms_mod: &syms_mod,
};
if let Some(enclosing_scope_hir_id) = enclosing_scope_hir_id {
let node = cx.tcx.hir().find(enclosing_scope_hir_id).unwrap();
let node = cx.tcx.hir_node(enclosing_scope_hir_id);
visitor.visit_scope(node);
current_hir_id = enclosing_scope_hir_id;
} else {
Expand Down Expand Up @@ -235,7 +235,7 @@ fn is_local(res: Res) -> bool {
}

fn get_owner(tcx: TyCtxt<'_>, hir_id: HirId) -> Option<OwnerNode<'_>> {
std::iter::once(tcx.hir().get(hir_id))
std::iter::once(tcx.hir_node(hir_id))
.chain(tcx.hir().parent_iter(hir_id).map(|(_, node)| node))
.find_map(Node::as_owner)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/restriction/misleading_variable_name/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn peel_try_unwrap_and_similar<'tcx>(
ExprKind::Match(scrutinee, _, MatchSource::TryDesugar(_)) => {
if let ExprKind::Call(
Expr {
kind: ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _, _)),
kind: ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _)),
..
},
[arg],
Expand Down
7 changes: 4 additions & 3 deletions examples/restriction/overscoped_allow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ pub fn register_lints(sess: &Session, lint_store: &mut LintStore) {
let diagnostics = match read_diagnostics() {
Ok(diagnostics) => diagnostics,
Err(error) => {
sess.warn(format!("`overscoped_allow` is disabled: {error:?}"));
sess.dcx()
.warn(format!("`overscoped_allow` is disabled: {error:?}"));
Vec::new()
}
};
Expand Down Expand Up @@ -393,7 +394,7 @@ fn local_path_from_span(cx: &LateContext<'_>, span: Span) -> Option<PathBuf> {
}

fn is_extern_crate_test(cx: &LateContext<'_>, hir_id: HirId) -> bool {
let node = cx.tcx.hir().get(hir_id);
let node = cx.tcx.hir_node(hir_id);
if let Node::Item(Item {
kind: ItemKind::ExternCrate(None),
ident,
Expand All @@ -408,7 +409,7 @@ fn is_extern_crate_test(cx: &LateContext<'_>, hir_id: HirId) -> bool {

// smoelius: `can_have_attrs` is not complete.
fn can_have_attrs(cx: &LateContext<'_>, hir_id: HirId) -> bool {
let node = cx.tcx.hir().get(hir_id);
let node = cx.tcx.hir_node(hir_id);

if matches!(node, Node::Item(_) | Node::TraitItem(_) | Node::ImplItem(_)) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion examples/restriction/overscoped_allow/ui_test/main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ LL | fn panic() {
= help: to override `-D warnings` add `#[allow(overscoped_allow)]`
= note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error
error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn get_filtered_ancestor<'hir>(
if_chain! {
if let ExprKind::Call(callee, _) = expr.kind;
if let ExprKind::Path(path) = &callee.kind;
if let QPath::LangItem(LangItem::IntoIterIntoIter, _, _) = path;
if let QPath::LangItem(LangItem::IntoIterIntoIter, _) = path;
then {
child_hir_id = hir_id;
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ LL | let _ = git2::Repository::clone(DYLINT_URL, tempfile::tempdir()?.path()
= note: `-D question-mark-in-expression` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(question_mark_in_expression)]`

error: aborting due to previous error
error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ LL | Ok(std::path::PathBuf::from(&std::env::var("PWD")?))
= note: `-D question-mark-in-expression` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(question_mark_in_expression)]`

error: aborting due to previous error
error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ LL | if !std::fs::read_to_string("Cargo.toml")?.is_empty() {
= note: `-D question-mark-in-expression` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(question_mark_in_expression)]`

error: aborting due to previous error
error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref());
= note: `-D ref-aware-redundant-closure-for-method-calls` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(ref_aware_redundant_closure_for_method_calls)]`

error: aborting due to previous error
error: aborting due to 1 previous error

2 changes: 1 addition & 1 deletion examples/restriction/try_io_result/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for TryIoResult {
if let ExprKind::Match(scrutinee, _, MatchSource::TryDesugar(_)) = expr.kind;
if let ExprKind::Call(callee, [arg]) = scrutinee.kind;
if let ExprKind::Path(path) = &callee.kind;
if matches!(path, QPath::LangItem(LangItem::TryTraitBranch, _, _));
if matches!(path, QPath::LangItem(LangItem::TryTraitBranch, _));
if let arg_ty = cx.typeck_results().node_type(arg.hir_id);
if is_io_result(cx, arg_ty);
let body_owner_hir_id = cx.tcx.hir().enclosing_body_owner(expr.hir_id);
Expand Down
2 changes: 1 addition & 1 deletion examples/restriction/try_io_result/ui/main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ LL | let _ = File::open("/dev/null")?;
= note: `-D try-io-result` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(try_io_result)]`

error: aborting due to previous error
error: aborting due to 1 previous error

5 changes: 2 additions & 3 deletions examples/supplementary/redundant_reference/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ impl<'tcx> LateLintPass<'tcx> for RedundantReference {
{
let item = cx.tcx.hir().expect_item(*local_def_id);
if_chain! {
if let ItemKind::Struct(VariantData::Struct(field_defs, _), _) = &item.kind;
if let Some(field_def) = field_defs
if let ItemKind::Struct(VariantData::Struct{fields, ..}, _) = &item.kind;
if let Some(field_def) = fields
.iter()
.find(|field_def| field_def.ident == *field);
let field_def_local_def_id = field_def.def_id;
Expand Down Expand Up @@ -217,7 +217,6 @@ impl<'tcx> LateLintPass<'tcx> for RedundantReference {
diag.help(format!(
"consider storing a copy of `.{field}.{subfield}`{lifetime_help}"
));
diag
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/supplementary/redundant_reference/ui/main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ LL | self.cx.tcx.hir()
= note: `-D redundant-reference` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(redundant_reference)]`

error: aborting due to previous error
error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ LL | self.bar.qux
= note: `-D redundant-reference` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(redundant_reference)]`

error: aborting due to previous error
error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn check_inherents(cx: &LateContext<'_>) {
return false;
}

let input_ty = cx.tcx.erase_late_bound_regions(fn_sig.input(0));
let output_ty = cx.tcx.erase_late_bound_regions(fn_sig.output());
let input_ty = fn_sig.input(0).skip_binder();
let output_ty = fn_sig.output().skip_binder();

if let Some(input_item_ty) = implements_trait_with_item(cx, input_ty, into_iterator_def_id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ const IGNORED_INHERENTS: &[&[&str]] = &[
&["core", "slice", "<impl [T]>", "as_chunks_unchecked_mut"],
&["core", "str", "<impl str>", "as_bytes_mut"],
&["core", "str", "<impl str>", "trim"],
&["core", "str", "<impl str>", "trim_ascii"],
&["core", "str", "<impl str>", "trim_ascii_end"],
&["core", "str", "<impl str>", "trim_ascii_start"],
&["core", "str", "<impl str>", "trim_end"],
&["core", "str", "<impl str>", "trim_left"],
&["core", "str", "<impl str>", "trim_right"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ LL | let _ = std::fs::write("x", vec![0]);
= note: `-D unnecessary-conversion-for-trait` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unnecessary_conversion_for_trait)]`

error: aborting due to previous error
error: aborting due to 1 previous error

0 comments on commit 8661abd

Please sign in to comment.