Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade examples #1375

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cargo-dylint/tests/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ fn license() {

#[test]
fn markdown_does_not_use_inline_links() {
let re = Regex::new(r"\[[^\]]*\]\(").unwrap();
// smoelius: Skip examples directory for now.
for entry in walkdir(false).with_extension("md") {
let entry = entry.unwrap();
Expand All @@ -305,7 +306,7 @@ fn markdown_does_not_use_inline_links() {
}
let markdown = read_to_string(path).unwrap();
assert!(
!Regex::new(r"\[[^\]]*\]\(").unwrap().is_match(&markdown),
!re.is_match(&markdown),
"`{}` uses inline links",
path.canonicalize().unwrap().to_string_lossy()
);
Expand Down Expand Up @@ -341,7 +342,7 @@ fn markdown_reference_links_are_sorted() {
fn markdown_reference_links_are_valid_and_used() {
const CODE: &str = "`[^`]*`";
const CODE_BLOCK: &str = "```([^`]|`[^`]|``[^`])*```";
let ref_re = Regex::new(&format!(r#"(?m){CODE}|{CODE_BLOCK}|\[([^\]]*)\]([^:]|$)"#)).unwrap();
let ref_re = Regex::new(&format!(r"(?m){CODE}|{CODE_BLOCK}|\[([^\]]*)\]([^:]|$)")).unwrap();
let link_re = Regex::new(r"(?m)^\[([^\]]*)\]:").unwrap();
for entry in walkdir(true).with_extension("md") {
let entry = entry.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub fn run<T: AsRef<OsStr>>(args: &[T]) -> Result<()> {
let rustflags = rustflags();
let paths = paths();

let rustc_args = rustc_args(args, &sysroot, &rustflags, &paths)?;
let rustc_args = rustc_args(args, sysroot.as_deref(), &rustflags, &paths)?;

let mut callbacks = Callbacks::new(paths);

Expand Down Expand Up @@ -381,7 +381,7 @@ fn paths() -> Vec<PathBuf> {

fn rustc_args<T: AsRef<OsStr>, U: AsRef<str>, V: AsRef<Path>>(
args: &[T],
sysroot: &Option<PathBuf>,
sysroot: Option<&Path>,
rustflags: &[U],
paths: &[V],
) -> Result<Vec<String>> {
Expand Down Expand Up @@ -437,7 +437,7 @@ mod test {
assert_eq!(
rustc_args(
&["--crate-name", "name"],
&None,
None,
&[] as &[&str],
&[] as &[&Path]
)
Expand All @@ -451,7 +451,7 @@ mod test {
assert_eq!(
rustc_args(
&["rustc", "--crate-name", "name"],
&None,
None,
&[] as &[&str],
&[] as &[&Path]
)
Expand All @@ -465,7 +465,7 @@ mod test {
assert_eq!(
rustc_args(
&["/bin/rustc", "--crate-name", "name"],
&None,
None,
&[] as &[&str],
&[] as &[&Path]
)
Expand Down
2 changes: 1 addition & 1 deletion dylint/src/package_options/revs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Revs {
}
}

impl<'revs> Iterator for RevIter<'revs> {
impl Iterator for RevIter<'_> {
type Item = Result<Rev>;

// smoelius: I think it is okay to ignore the `non_local_effect_before_error_return` warning
Expand Down
8 changes: 4 additions & 4 deletions examples/experimental/derive_opportunity/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/experimental/derive_opportunity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ name = "ui_ignore"
path = "ui_ignore/main.rs"

[dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a95afe2d0a2051d97b723b0b197393b7811bc4e4" }
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a109190d7060236e655fc75533373fa274ec5343" }
once_cell = "1.20"
serde = "1.0"

Expand Down
2 changes: 1 addition & 1 deletion examples/experimental/derive_opportunity/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-09-05"
channel = "nightly-2024-10-18"
components = ["llvm-tools-preview", "rustc-dev"]
2 changes: 1 addition & 1 deletion examples/experimental/derive_opportunity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct DeriveOpportunity<'tcx> {
transitively_applicable_macros_map: RefCell<FxHashMap<ty::Ty<'tcx>, FxHashSet<Macro>>>,
}

impl<'tcx> DeriveOpportunity<'tcx> {
impl DeriveOpportunity<'_> {
pub fn new() -> Self {
Self {
config: dylint_linting::config_or_default(env!("CARGO_PKG_NAME")),
Expand Down
8 changes: 4 additions & 4 deletions examples/experimental/missing_doc_comment_openai/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a95afe2d0a2051d97b723b0b197393b7811bc4e4" }
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a109190d7060236e655fc75533373fa274ec5343" }
curl = "0.4"
serde = "1.0"
serde_json = "1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-09-05"
channel = "nightly-2024-10-18"
components = ["llvm-tools-preview", "rustc-dev"]
8 changes: 4 additions & 4 deletions examples/general/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/general/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ members = [
]

[workspace.dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a95afe2d0a2051d97b723b0b197393b7811bc4e4" }
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a109190d7060236e655fc75533373fa274ec5343" }

[workspace.lints.rust.unexpected_cfgs]
level = "deny"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub struct Checker<'cx, 'tcx> {
item: &'tcx Item<'tcx>,
}

impl<'cx, 'tcx> Visitor<'tcx> for Checker<'cx, 'tcx> {
impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
type NestedFilter = nested_filter::OnlyBodies;

fn nested_visit_map(&mut self) -> Self::Map {
Expand Down
2 changes: 1 addition & 1 deletion examples/general/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-09-05"
channel = "nightly-2024-10-18"
components = ["llvm-tools-preview", "rustc-dev"]
8 changes: 4 additions & 4 deletions examples/restriction/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/restriction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = [
resolver = "2"

[workspace.dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a95afe2d0a2051d97b723b0b197393b7811bc4e4" }
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a109190d7060236e655fc75533373fa274ec5343" }

[workspace.lints.rust.unexpected_cfgs]
level = "deny"
Expand Down
4 changes: 2 additions & 2 deletions examples/restriction/inconsistent_qualification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct UseVisitor<'cx, 'tcx, 'syms> {
// smoelius: `visit_scope` is based on the source of:
// https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.get_enclosing_scope
// Does something similar already exist and I am just not seeing it?
impl<'cx, 'tcx, 'syms> UseVisitor<'cx, 'tcx, 'syms> {
impl<'tcx> UseVisitor<'_, 'tcx, '_> {
fn visit_scope(&mut self, node: Node<'tcx>) {
match node {
Node::Item(item) => self.visit_item(item),
Expand All @@ -142,7 +142,7 @@ enum PathMatch<'hir> {
Mod,
}

impl<'cx, 'tcx, 'syms> Visitor<'tcx> for UseVisitor<'cx, 'tcx, 'syms> {
impl<'tcx> Visitor<'tcx> for UseVisitor<'_, 'tcx, '_> {
type NestedFilter = rustc_middle::hir::nested_filter::All;

fn nested_visit_map(&mut self) -> Self::Map {
Expand Down
4 changes: 2 additions & 2 deletions examples/restriction/overscoped_allow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cargo_metadata::{
use clippy_utils::{diagnostics::span_lint_and_help, source::snippet_opt};
use dylint_internal::env::var;
use once_cell::sync::OnceCell;
use rustc_ast::ast::{Attribute, MetaItem, NestedMetaItem};
use rustc_ast::ast::{Attribute, MetaItem, MetaItemInner};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::{
Block, Expr, ExprKind, HirId, ImplItem, Item, ItemKind, Node, Stmt, StmtKind, CRATE_HIR_ID,
Expand Down Expand Up @@ -476,7 +476,7 @@ fn meta_item_for_diagnostic(attr: &Attribute, diagnostic: &Diagnostic) -> Option
{
items
.iter()
.filter_map(NestedMetaItem::meta_item)
.filter_map(MetaItemInner::meta_item)
.find(|meta_item| {
meta_item
.path
Expand Down
2 changes: 1 addition & 1 deletion examples/restriction/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-09-05"
channel = "nightly-2024-10-18"
components = ["llvm-tools-preview", "rustc-dev"]
2 changes: 1 addition & 1 deletion examples/restriction/suboptimal_pattern/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ struct DereferenceVisitor<'cx, 'tcx> {
explicit_deref: bool,
}

impl<'cx, 'tcx> Visitor<'tcx> for DereferenceVisitor<'cx, 'tcx> {
impl<'tcx> Visitor<'tcx> for DereferenceVisitor<'_, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
if self
.hir_ids
Expand Down
8 changes: 4 additions & 4 deletions examples/supplementary/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/supplementary/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ members = [
]

[workspace.dependencies]
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a95afe2d0a2051d97b723b0b197393b7811bc4e4" }
clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "a109190d7060236e655fc75533373fa274ec5343" }

[workspace.lints.rust.unexpected_cfgs]
level = "deny"
Expand Down
2 changes: 1 addition & 1 deletion examples/supplementary/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-09-05"
channel = "nightly-2024-10-18"
components = ["llvm-tools-preview", "rustc-dev"]
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ pub fn check_inherents(cx: &LateContext<'_>) {
.iter()
.flat_map(|type_path| def_path_res(cx.tcx, type_path))
.filter_map(|res| res.opt_def_id())
.flat_map(|def_id| cx.tcx.inherent_impls(def_id).unwrap());
.flat_map(|def_id| cx.tcx.inherent_impls(def_id));

let slice_incoherent_impl_def_ids = cx
.tcx
.incoherent_impls(SimplifiedType::Slice)
.unwrap()
.iter()
.filter(|&impl_def_id| {
// smoelius: Filter out cases like `core::slice::ascii::<impl [u8]>::trim_ascii`.
Expand All @@ -82,7 +81,7 @@ pub fn check_inherents(cx: &LateContext<'_>) {
matches!(ty.kind(), ty::Param(_))
});

let str_incoherent_impl_def_ids = cx.tcx.incoherent_impls(SimplifiedType::Str).unwrap();
let str_incoherent_impl_def_ids = cx.tcx.incoherent_impls(SimplifiedType::Str);

let impl_def_ids = type_path_impl_def_ids
.chain(slice_incoherent_impl_def_ids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const WATCHED_INHERENTS: &[&[&str]] = &[
&["core", "slice", "<impl [T]>", "iter"],
&["core", "slice", "<impl [T]>", "iter_mut"],
&["core", "str", "<impl str>", "as_bytes"],
&["core", "str", "<impl str>", "as_str"],
&["std", "ffi", "os_str", "OsStr", "as_encoded_bytes"],
&["std", "ffi", "os_str", "OsStr", "into_os_string"],
&["std", "ffi", "os_str", "OsStr", "new"],
Expand Down Expand Up @@ -131,6 +132,7 @@ const IGNORED_INHERENTS: &[&[&str]] = &[
&["alloc", "string", "String", "from_utf16_lossy"],
&["alloc", "string", "String", "from_utf16be_lossy"],
&["alloc", "string", "String", "from_utf16le_lossy"],
&["alloc", "string", "String", "from_utf8_lossy_owned"],
&["alloc", "string", "String", "leak"],
&["alloc", "vec", "Vec", "into_flattened"],
&["alloc", "vec", "Vec", "leak"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// run-rustfix

#![allow(unused_imports, unused_parens)]
// #![feature(os_str_bytes)]
#![feature(str_as_str)]

use std::{
borrow::{Borrow, BorrowMut},
Expand Down Expand Up @@ -65,6 +65,7 @@ fn main() {
let _ = Command::new("ls").args(["-a", "-l"]);
let _ = Command::new("ls").args(["-a", "-l"]);

let _ = std::fs::write("x", "");
let _ = std::fs::write("x", "");

let _ = os_str_or_bytes(osstr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// run-rustfix

#![allow(unused_imports, unused_parens)]
// #![feature(os_str_bytes)]
#![feature(str_as_str)]

use std::{
borrow::{Borrow, BorrowMut},
Expand Down Expand Up @@ -66,6 +66,7 @@ fn main() {
let _ = Command::new("ls").args(["-a", "-l"].iter_mut());

let _ = std::fs::write("x", "".as_bytes());
let _ = std::fs::write("x", "".as_str());

let _ = os_str_or_bytes(osstr.as_encoded_bytes());
let _ = is_empty_os(osstring.clone().into_boxed_os_str().into_os_string());
Expand Down
Loading