Skip to content

Commit

Permalink
Revert "Use typeck_results.node_type to resolve the type in suspici…
Browse files Browse the repository at this point in the history
…ous trait object lint (#349)"

This reverts commit 46705ba.
  • Loading branch information
thomcc committed Jul 6, 2023
1 parent 46705ba commit 95d7a0c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 66 deletions.
23 changes: 0 additions & 23 deletions plrust/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,28 +294,6 @@ mod tests {
assert!(res.is_err());
}

// Regression for #348
#[pg_test]
#[cfg(not(feature = "sandboxed"))]
#[search_path(@extschema@)]
fn plrust_rand_dep() {
let definition = r#"
CREATE FUNCTION rust_rand() RETURNS INT
IMMUTABLE STRICT
LANGUAGE PLRUST AS
$$
[dependencies]
rand = "0.8.5"
[code]
Ok(Some(rand::random()))
$$;
"#;
Spi::run(definition).unwrap();

let rand = Spi::get_one::<i32>("SELECT rust_rand()").unwrap();
assert!(rand.is_some());
}

#[pg_test]
#[search_path(@extschema@)]
fn plrust_returns_setof() -> spi::Result<()> {
Expand Down Expand Up @@ -1427,7 +1405,6 @@ pub mod pg_test {
owo-colors = "=3.5.0"
tokio = { version = "=1.19.2", features = ["rt", "net"]}
plutonium = "*"
rand = "*"
"#
.as_bytes(),
)
Expand Down
26 changes: 23 additions & 3 deletions plrustc/plrustc/src/lints/sus_trait_object.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hir::def::{DefKind, Res};
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty;
Expand Down Expand Up @@ -28,9 +29,28 @@ impl<'tcx> LateLintPass<'tcx> for PlrustSuspiciousTraitObject {
let hir::GenericArg::Type(ty) = arg else {
continue;
};
let typeck_results = cx.typeck_results();
let is_trait_obj =
matches!(typeck_results.node_type(ty.hir_id).kind(), ty::Dynamic(..));
let is_trait_obj = match &ty.kind {
hir::TyKind::TraitObject(..) => true,
hir::TyKind::Path(qpath) => {
let res = cx.qpath_res(qpath, ty.hir_id);
let did = match res {
Res::Def(DefKind::TyAlias | DefKind::AssocTy, def_id) => def_id,
Res::SelfTyAlias { alias_to, .. } => alias_to,
_ => continue,
};
let binder = cx.tcx.type_of(did);
let ty = binder.subst_identity();
if matches!(ty.kind(), ty::TyKind::Dynamic(..)) {
true
} else {
match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) {
Ok(t) => matches!(t.kind(), ty::TyKind::Dynamic(..)),
_ => false,
}
}
}
_ => false,
};
if is_trait_obj {
cx.lint(
PLRUST_SUSPICIOUS_TRAIT_OBJECT,
Expand Down
30 changes: 0 additions & 30 deletions plrustc/plrustc/uitests/sus_trait_object_gat.rs

This file was deleted.

10 changes: 0 additions & 10 deletions plrustc/plrustc/uitests/sus_trait_object_gat.stderr

This file was deleted.

0 comments on commit 95d7a0c

Please sign in to comment.