Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Apr 14, 2024
1 parent 002b8f7 commit fbde1ee
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@1.74
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
Expand Down
2 changes: 1 addition & 1 deletion crates/rune-alloc/src/hashbrown/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7057,7 +7057,7 @@ mod test_map {
use crate::iter::TryExtend;
use crate::testing::*;

std::thread_local!(static DROP_VECTOR: RefCell<Vec<i32>> = RefCell::new(Vec::new()));
std::thread_local!(static DROP_VECTOR: RefCell<Vec<i32>> = const { RefCell::new(Vec::new()) });

#[test]
fn test_zero_capacities() {
Expand Down
2 changes: 1 addition & 1 deletion crates/rune-alloc/src/limit/std.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::cell::Cell;

std::thread_local!(static MEMORY: Cell<usize> = Cell::new(usize::MAX));
std::thread_local!(static MEMORY: Cell<usize> = const { Cell::new(usize::MAX) });

pub(super) fn rune_memory_take(amount: usize) -> bool {
MEMORY.with(|tls| {
Expand Down
2 changes: 1 addition & 1 deletion crates/rune/src/ast/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Parse for AttrStyle {
}

/// Helper struct to only parse inner attributes.
pub(crate) struct InnerAttribute(pub(crate) Attribute);
pub(crate) struct InnerAttribute(#[allow(unused)] pub(crate) Attribute);

impl Parse for InnerAttribute {
fn parse(p: &mut Parser) -> Result<Self> {
Expand Down
4 changes: 2 additions & 2 deletions crates/rune/src/doc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) enum MetaSource<'a> {
/// Meta came from context.
Context,
/// Meta came from source.
Source(&'a Item),
Source(#[allow(unused)] &'a Item),
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -94,7 +94,7 @@ pub(crate) enum Kind<'a> {
Enum,
Macro,
Function(Function<'a>),
Const(&'a ConstValue),
Const(#[allow(unused)] &'a ConstValue),
Module,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rune/src/runtime/budget/std.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::cell::Cell;

std::thread_local!(static BUDGET: Cell<usize> = Cell::new(usize::MAX));
std::thread_local!(static BUDGET: Cell<usize> = const { Cell::new(usize::MAX) });

pub(super) fn rune_budget_take() -> bool {
BUDGET.with(|tls| {
Expand Down
2 changes: 1 addition & 1 deletion crates/rune/src/runtime/env/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::cell::Cell;

use super::Env;

std::thread_local!(static ENV: Cell<Env> = Cell::new(Env::null()));
std::thread_local!(static ENV: Cell<Env> = const { Cell::new(Env::null()) });

pub(super) fn rune_env_get() -> Env {
ENV.with(|env| env.get())
Expand Down
1 change: 1 addition & 0 deletions crates/rune/src/tests/vm_test_from_value_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fn test_missing_dynamic_field() {
);

#[derive(Debug, FromValue)]
#[allow(unused)]
struct ProxyTuple(u32, u32);

assert_vm_error!(
Expand Down
10 changes: 4 additions & 6 deletions examples/examples/hot_reloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ async fn main() -> Result<()> {
}

for event in events.drain(..) {
match event {
path_reloader::PathEvent::Added(path, unit) => {
let mut vm = Vm::new(context.clone(), unit);
let mut vm = Vm::new(context.clone(), event.unit);

match event.kind {
path_reloader::EventKind::Added => {
if let Err(error) = vm.call(["hello"], ()) {
println!("Error: {}", error);
}
}
path_reloader::PathEvent::Removed(path, unit) => {
let mut vm = Vm::new(context.clone(), unit);

path_reloader::EventKind::Removed => {
if let Err(error) = vm.call(["goodbye"], ()) {
println!("Error: {}", error);
}
Expand Down
55 changes: 39 additions & 16 deletions examples/examples/hot_reloading/path_reloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,45 @@ use std::sync::{Arc, Mutex};
use anyhow::{anyhow, Result};
use notify::Watcher;
use pin_project::pin_project;
use rune::runtime::RuntimeContext;
use rune::termcolor::{ColorChoice, StandardStream};
use rune::{Context, Diagnostics, Source, Sources, Unit};
use tokio::sync::mpsc;
use tokio::time::{Duration, Instant, Sleep};

/// A path update event.
pub enum PathEvent {
/// The kind of path event emitted.
pub enum EventKind {
/// The specified unit has been added.
Added(PathBuf, Arc<Unit>),
Added,
/// The specified unit has been removed.
Removed(PathBuf, Arc<Unit>),
Removed,
}

/// A path update event.
pub struct Event {
/// The path that was modified.
pub path: PathBuf,
/// The unit that was constructed from the path.
pub unit: Arc<Unit>,
/// The kind of event emitted.
pub kind: EventKind,
}

impl Event {
fn removed(path: PathBuf, unit: Arc<Unit>) -> Self {
Self {
path,
unit,
kind: EventKind::Removed,
}
}

fn added(path: PathBuf, unit: Arc<Unit>) -> Self {
Self {
path,
unit,
kind: EventKind::Added,
}
}
}

enum Update {
Expand All @@ -55,8 +82,6 @@ impl<'a> PathReloader<'a> {
where
P: AsRef<Path>,
{
let runtime_context = Arc::new(context.runtime()?);

let (tx, rx) = mpsc::unbounded_channel();

let mut watcher = notify::recommended_watcher(move |res| {
Expand All @@ -69,7 +94,6 @@ impl<'a> PathReloader<'a> {
inner: Inner {
context,
path: path.as_ref().into(),
runtime_context,
scripts: Mutex::new(HashMap::new()),
updates: HashMap::new(),
},
Expand Down Expand Up @@ -98,7 +122,7 @@ impl<'a> PathReloader<'a> {
}

/// Watch the current path for changes.
pub async fn watch(self: Pin<&mut Self>, events: &mut Vec<PathEvent>) -> Result<()> {
pub async fn watch(self: Pin<&mut Self>, events: &mut Vec<Event>) -> Result<()> {
let mut this = self.project();

tokio::select! {
Expand Down Expand Up @@ -134,13 +158,12 @@ impl<'a> PathReloader<'a> {
struct Inner<'a> {
context: &'a Context,
path: Box<Path>,
runtime_context: Arc<RuntimeContext>,
scripts: Mutex<HashMap<PathBuf, Arc<Unit>>>,
updates: HashMap<PathBuf, Update>,
}

impl<'a> Inner<'a> {
fn reload(&mut self, events: &mut Vec<PathEvent>) -> Result<()> {
fn reload(&mut self, events: &mut Vec<Event>) -> Result<()> {
fn compile(context: &Context, path: &Path) -> Result<Unit> {
let mut sources = Sources::new();
sources.insert(Source::from_path(path)?)?;
Expand All @@ -154,7 +177,7 @@ impl<'a> Inner<'a> {

if !diagnostics.is_empty() {
let mut writer = StandardStream::stderr(ColorChoice::Always);
diagnostics.emit(&mut writer, &mut sources)?;
diagnostics.emit(&mut writer, &sources)?;
}

Ok(unit?)
Expand All @@ -169,7 +192,7 @@ impl<'a> Inner<'a> {
println!("{}: Failed to compile: {error}", path.display());

if let Some(old) = self.scripts.lock().unwrap().remove(&path) {
events.push(PathEvent::Removed(path.clone(), old));
events.push(Event::removed(path.clone(), old));
}

continue;
Expand All @@ -184,14 +207,14 @@ impl<'a> Inner<'a> {
.unwrap()
.insert(path.clone(), new.clone())
{
events.push(PathEvent::Removed(path.clone(), old));
events.push(Event::removed(path.clone(), old));
}

events.push(PathEvent::Added(path, new));
events.push(Event::added(path, new));
}
Update::Removed => {
if let Some(unit) = self.scripts.lock().unwrap().remove(&path) {
events.push(PathEvent::Removed(path, unit));
events.push(Event::removed(path, unit));
}
}
}
Expand Down

0 comments on commit fbde1ee

Please sign in to comment.