clippy: fix warnings on modules outside components (#31567)

This commit is contained in:
eri 2024-03-08 00:42:39 +01:00 committed by GitHub
parent 3b19189896
commit 6c7fe31db1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 37 additions and 46 deletions

View file

@ -28,7 +28,7 @@ fn main() {
// Generate GL bindings. For now, we only support EGL.
if target.contains("android") {
let mut file = File::create(&dest.join("egl_bindings.rs")).unwrap();
let mut file = File::create(dest.join("egl_bindings.rs")).unwrap();
Registry::new(Api::Egl, (1, 5), Profile::Core, Fallbacks::All, [])
.write_bindings(gl_generator::StaticStructGenerator, &mut file)
.unwrap();
@ -38,6 +38,6 @@ fn main() {
let mut default_prefs = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
default_prefs.push("../../resources/prefs.json");
let prefs: Value = serde_json::from_reader(File::open(&default_prefs).unwrap()).unwrap();
let file = File::create(&dest.join("prefs.json")).unwrap();
let file = File::create(dest.join("prefs.json")).unwrap();
serde_json::to_writer(file, &prefs).unwrap();
}

View file

@ -84,11 +84,9 @@ impl App {
// Handle browser state.
let webviews = WebViewManager::new(window.clone());
let initial_url = get_default_url(
url.as_ref().map(String::as_str),
env::current_dir().unwrap(),
|path| fs::metadata(path).is_ok(),
);
let initial_url = get_default_url(url.as_deref(), env::current_dir().unwrap(), |path| {
fs::metadata(path).is_ok()
});
let mut app = App {
event_queue: RefCell::new(vec![]),
@ -270,7 +268,7 @@ impl App {
window.winit_window().unwrap().request_redraw();
},
winit::event::Event::WindowEvent { ref event, .. } => {
let response = minibrowser.on_event(&event);
let response = minibrowser.on_event(event);
if response.repaint {
// Request a winit redraw event, so we can recomposite, update and paint
// the minibrowser, and present the new frame.

View file

@ -28,17 +28,14 @@ pub fn get_default_url(
// If the url is not provided, we fallback to the homepage in prefs,
// or a blank page in case the homepage is not set either.
let mut new_url = None;
let cmdline_url = url_opt
.clone()
.map(|s| s.to_string())
.and_then(|url_string| {
parse_url_or_filename(cwd.as_ref(), &url_string)
.map_err(|error| {
warn!("URL parsing failed ({:?}).", error);
error
})
.ok()
});
let cmdline_url = url_opt.map(|s| s.to_string()).and_then(|url_string| {
parse_url_or_filename(cwd.as_ref(), &url_string)
.map_err(|error| {
warn!("URL parsing failed ({:?}).", error);
error
})
.ok()
});
if let Some(url) = cmdline_url.clone() {
// Check if the URL path corresponds to a file
@ -50,7 +47,7 @@ pub fn get_default_url(
}
}
if new_url.is_none() && !url_opt.is_none() {
if new_url.is_none() && url_opt.is_some() {
new_url = location_bar_input_to_url(url_opt.unwrap());
}

View file

@ -7,7 +7,7 @@ use std::path::Path;
use crate::parser::{get_default_url, location_bar_input_to_url, parse_url_or_filename};
#[cfg(not(target_os = "windows"))]
const FAKE_CWD: &'static str = "/fake/cwd";
const FAKE_CWD: &str = "/fake/cwd";
#[cfg(target_os = "windows")]
const FAKE_CWD: &'static str = "C:/fake/cwd";

View file

@ -127,7 +127,7 @@ fn incorrect_no_trace<'tcx, I: Into<MultiSpan> + Copy>(
let recur_into_subtree = match t.kind() {
ty::Adt(did, substs) => {
if let Some(pos) =
get_must_not_have_traceable(sym, &cx.tcx.get_attrs_unchecked(did.did()))
get_must_not_have_traceable(sym, cx.tcx.get_attrs_unchecked(did.did()))
{
let inner = substs.type_at(pos);
if inner.is_primitive_ty() {
@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for NotracePass {
return;
}*/
if let hir::ItemKind::Struct(def, ..) = &item.kind {
for ref field in def.fields() {
for field in def.fields() {
let field_type = cx.tcx.type_of(field.def_id);
incorrect_no_trace(&self.symbols, cx, field_type.skip_binder(), field.span);
}

View file

@ -86,7 +86,7 @@ fn is_unrooted_ty<'tcx>(
let recur_into_subtree = match t.kind() {
ty::Adt(did, substs) => {
let has_attr =
|did, name| has_lint_attr(sym, &cx.tcx.get_attrs_unchecked(did), name);
|did, name| has_lint_attr(sym, cx.tcx.get_attrs_unchecked(did), name);
if has_attr(did.did(), sym.must_root) {
ret = true;
false
@ -96,11 +96,7 @@ fn is_unrooted_ty<'tcx>(
// Rc<Promise> is okay
let inner = substs.type_at(0);
if let ty::Adt(did, _) = inner.kind() {
if has_attr(did.did(), sym.allow_unrooted_in_rc) {
false
} else {
true
}
!has_attr(did.did(), sym.allow_unrooted_in_rc)
} else {
true
}
@ -185,11 +181,11 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass {
/// must be #[crown::unrooted_must_root_lint::must_root] themselves
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item) {
let attrs = cx.tcx.hir().attrs(item.hir_id());
if has_lint_attr(&self.symbols, &attrs, self.symbols.must_root) {
if has_lint_attr(&self.symbols, attrs, self.symbols.must_root) {
return;
}
if let hir::ItemKind::Struct(def, ..) = &item.kind {
for ref field in def.fields() {
for field in def.fields() {
let field_type = cx.tcx.type_of(field.def_id);
if is_unrooted_ty(&self.symbols, cx, field_type.skip_binder(), false) {
cx.lint(
@ -206,10 +202,10 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass {
/// All enums containing #[crown::unrooted_must_root_lint::must_root] types
/// must be #[crown::unrooted_must_root_lint::must_root] themselves
fn check_variant(&mut self, cx: &LateContext, var: &hir::Variant) {
let ref map = cx.tcx.hir();
let map = &cx.tcx.hir();
let parent_item = map.expect_item(map.get_parent_item(var.hir_id).def_id);
let attrs = cx.tcx.hir().attrs(parent_item.hir_id());
if !has_lint_attr(&self.symbols, &attrs, self.symbols.must_root) {
if !has_lint_attr(&self.symbols, attrs, self.symbols.must_root) {
match var.data {
hir::VariantData::Tuple(fields, ..) => {
for field in fields {
@ -241,7 +237,7 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass {
) {
let in_new_function = match kind {
visit::FnKind::ItemFn(n, _, _) | visit::FnKind::Method(n, _) => {
&*n.as_str() == "new" || n.as_str().starts_with("new_")
n.as_str() == "new" || n.as_str().starts_with("new_")
},
visit::FnKind::Closure => return,
};
@ -271,7 +267,7 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass {
cx,
in_new_function,
};
visit::walk_expr(&mut visitor, &body.value);
visit::walk_expr(&mut visitor, body.value);
}
}
@ -288,8 +284,8 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'tcx> {
let cx = self.cx;
let require_rooted = |cx: &LateContext, in_new_function: bool, subexpr: &hir::Expr| {
let ty = cx.typeck_results().expr_ty(&subexpr);
if is_unrooted_ty(&self.symbols, cx, ty, in_new_function) {
let ty = cx.typeck_results().expr_ty(subexpr);
if is_unrooted_ty(self.symbols, cx, ty, in_new_function) {
cx.lint(
UNROOTED_MUST_ROOT,
format!("Expression of type {:?} must be rooted", ty),
@ -300,7 +296,7 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'tcx> {
match expr.kind {
// Trait casts from #[crown::unrooted_must_root_lint::must_root] types are not allowed
ExprKind::Cast(subexpr, _) => require_rooted(cx, self.in_new_function, &subexpr),
ExprKind::Cast(subexpr, _) => require_rooted(cx, self.in_new_function, subexpr),
// This catches assignments... the main point of this would be to catch mutable
// references to `JS<T>`.
// FIXME: Enable this? Triggers on certain kinds of uses of DomRefCell.

View file

@ -9,8 +9,8 @@ use style::stylesheets::{Namespaces, Origin};
use style_traits::ParseError;
use url::Url;
fn parse_selector<'i, 't>(
input: &mut Parser<'i, 't>,
fn parse_selector<'i>(
input: &mut Parser<'i, '_>,
) -> Result<SelectorList<SelectorImpl>, ParseError<'i>> {
let mut ns = Namespaces::default();
ns.prefixes

View file

@ -17,7 +17,7 @@ pub fn split_html_space_chars_whitespace() {
#[test]
pub fn test_str_join_empty() {
let slice: [&str; 0] = [];
let actual = str_join(&slice, "-");
let actual = str_join(slice, "-");
let expected = "";
assert_eq!(actual, expected);
}
@ -25,7 +25,7 @@ pub fn test_str_join_empty() {
#[test]
pub fn test_str_join_one() {
let slice = ["alpha"];
let actual = str_join(&slice, "-");
let actual = str_join(slice, "-");
let expected = "alpha";
assert_eq!(actual, expected);
}
@ -33,7 +33,7 @@ pub fn test_str_join_one() {
#[test]
pub fn test_str_join_many() {
let slice = ["", "alpha", "", "beta", "gamma", ""];
let actual = str_join(&slice, "-");
let actual = str_join(slice, "-");
let expected = "-alpha--beta-gamma-";
assert_eq!(actual, expected);
}

View file

@ -35,7 +35,7 @@ fn get_mock_rules(css_selectors: &[&str]) -> (Vec<Vec<Rule>>, SharedRwLock) {
.unwrap();
let locked = Arc::new(shared_lock.wrap(StyleRule {
selectors: selectors,
selectors,
block: Arc::new(shared_lock.wrap(PropertyDeclarationBlock::with_one(
PropertyDeclaration::Display(longhands::display::SpecifiedValue::Block),
Importance::Normal,
@ -75,7 +75,7 @@ fn parse_selectors(selectors: &[&str]) -> Vec<Selector<SelectorImpl>> {
.unwrap()
.0
.into_iter()
.nth(0)
.next()
.unwrap()
})
.collect()
@ -130,7 +130,7 @@ fn test_revalidation_selectors() {
"p:first-child span",
])
.into_iter()
.filter(|s| needs_revalidation_for_testing(&s))
.filter(needs_revalidation_for_testing)
.collect::<Vec<_>>();
let reference = parse_selectors(&[