Skip to content

Commit

Permalink
Unbreak feature combination builds
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Aug 25, 2023
1 parent 9a36b2d commit bb58c97
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 32 deletions.
5 changes: 4 additions & 1 deletion crates/rune/src/compile/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use crate::no_std::sync::Arc;
use crate::compile::meta;
#[cfg(feature = "doc")]
use crate::compile::Docs;
use crate::compile::{ComponentRef, ContextError, IntoComponent, Item, ItemBuf, MetaInfo, Names};
#[cfg(feature = "emit")]
use crate::compile::MetaInfo;
use crate::compile::{ComponentRef, ContextError, IntoComponent, Item, ItemBuf, Names};
use crate::hash;
use crate::module::{
Fields, InternalEnum, Module, ModuleAssociated, ModuleAttributeMacro, ModuleConstant,
Expand Down Expand Up @@ -35,6 +37,7 @@ pub(crate) struct ContextMeta {
}

impl ContextMeta {
#[cfg(feature = "emit")]
pub(crate) fn info(&self) -> MetaInfo {
MetaInfo::new(&self.kind, self.hash, self.item.as_deref())
}
Expand Down
15 changes: 15 additions & 0 deletions crates/rune/src/compile/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub(crate) enum ErrorKind {
},
ModAlreadyLoaded {
item: ItemBuf,
#[cfg(feature = "emit")]
existing: (SourceId, Span),
},
MissingMacro {
Expand Down Expand Up @@ -268,7 +269,9 @@ pub(crate) enum ErrorKind {
UnsupportedPatternExpr,
UnsupportedBinding,
DuplicateObjectKey {
#[cfg(feature = "emit")]
existing: Span,
#[cfg(feature = "emit")]
object: Span,
},
InstanceFunctionOutsideImpl,
Expand All @@ -279,6 +282,7 @@ pub(crate) enum ErrorKind {
ContinueOutsideOfLoop,
SelectMultipleDefaults,
ExpectedBlockSemiColon {
#[cfg(feature = "emit")]
followed_span: Span,
},
FnConstAsyncConflict,
Expand Down Expand Up @@ -339,13 +343,16 @@ pub(crate) enum ErrorKind {
name: Box<str>,
},
VariableMoved {
#[cfg(feature = "emit")]
moved_at: Span,
},
UnsupportedGenerics,
NestedTest {
#[cfg(feature = "emit")]
nested_span: Span,
},
NestedBench {
#[cfg(feature = "emit")]
nested_span: Span,
},
MissingFunctionHash {
Expand All @@ -356,6 +363,7 @@ pub(crate) enum ErrorKind {
},
PatternMissingFields {
item: ItemBuf,
#[cfg(feature = "emit")]
fields: Box<[Box<str>]>,
},
MissingLabelLocation {
Expand Down Expand Up @@ -412,21 +420,27 @@ pub(crate) enum ErrorKind {
BadNumberLiteral,
AmbiguousItem {
item: ItemBuf,
#[cfg(feature = "emit")]
locations: Vec<(Location, ItemBuf)>,
},
AmbiguousContextItem {
item: ItemBuf,
#[cfg(feature = "emit")]
infos: Box<[MetaInfo]>,
},
NotVisible {
#[cfg(feature = "emit")]
chain: Vec<Location>,
#[cfg(feature = "emit")]
location: Location,
visibility: Visibility,
item: ItemBuf,
from: ItemBuf,
},
NotVisibleMod {
#[cfg(feature = "emit")]
chain: Vec<Location>,
#[cfg(feature = "emit")]
location: Location,
visibility: Visibility,
item: ItemBuf,
Expand All @@ -436,6 +450,7 @@ pub(crate) enum ErrorKind {
item: ItemBuf,
},
ImportCycle {
#[cfg(feature = "emit")]
path: Vec<ImportStep>,
},
ImportRecursionLimit {
Expand Down
5 changes: 4 additions & 1 deletion crates/rune/src/compile/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use core::fmt;

use crate::no_std::collections::HashMap;

use crate::compile::{Item, ItemBuf, Location, Visibility};
#[cfg(feature = "emit")]
use crate::compile::Location;
use crate::compile::{Item, ItemBuf, Visibility};
use crate::hash::Hash;

/// The identifier of a module.
Expand Down Expand Up @@ -34,6 +36,7 @@ impl fmt::Display for ItemId {
#[non_exhaustive]
pub(crate) struct ModMeta {
/// The location of the module.
#[cfg(feature = "emit")]
pub(crate) location: Location,
/// The item of the module.
pub(crate) item: ItemId,
Expand Down
10 changes: 6 additions & 4 deletions crates/rune/src/compile/v1/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ impl<'hir> Scopes<'hir> {
tracing::trace!(?var, "getting var");
q.visitor.visit_variable_use(self.source_id, var.span, span);

if let Some(moved_at) = var.moved_at {
if let Some(_moved_at) = var.moved_at {
return Err(compile::Error::new(
span,
ErrorKind::VariableMoved {
moved_at: moved_at.span(),
#[cfg(feature = "emit")]
moved_at: _moved_at.span(),
},
));
}
Expand Down Expand Up @@ -177,11 +178,12 @@ impl<'hir> Scopes<'hir> {
tracing::trace!(?var, "taking var");
q.visitor.visit_variable_use(self.source_id, var.span, span);

if let Some(moved_at) = var.moved_at {
if let Some(_moved_at) = var.moved_at {
return Err(compile::Error::new(
span,
ErrorKind::VariableMoved {
moved_at: moved_at.span(),
#[cfg(feature = "emit")]
moved_at: _moved_at.span(),
},
));
}
Expand Down
13 changes: 9 additions & 4 deletions crates/rune/src/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,13 @@ pub(crate) fn expr_object<'hir>(
let assignments = &mut *iter!(&ast.assignments, |(ast, _)| {
let key = object_key(cx, &ast.key)?;

if let Some(existing) = keys_dup.insert(key.1, key.0) {
if let Some(_existing) = keys_dup.insert(key.1, key.0) {
return Err(compile::Error::new(
key.0,
ErrorKind::DuplicateObjectKey {
existing: existing.span(),
#[cfg(feature = "emit")]
existing: _existing.span(),
#[cfg(feature = "emit")]
object: key.0.span(),
},
));
Expand Down Expand Up @@ -1206,11 +1208,13 @@ fn pat<'hir>(cx: &mut Ctxt<'hir, '_, '_>, ast: &ast::Pat) -> compile::Result<hir
}
};

if let Some(existing) = keys_dup.insert(key, pat) {
if let Some(_existing) = keys_dup.insert(key, pat) {
return Err(compile::Error::new(
pat,
ErrorKind::DuplicateObjectKey {
existing: existing.span(),
#[cfg(feature = "emit")]
existing: _existing.span(),
#[cfg(feature = "emit")]
object: pat.span(),
},
));
Expand Down Expand Up @@ -1259,6 +1263,7 @@ fn pat<'hir>(cx: &mut Ctxt<'hir, '_, '_>, ast: &ast::Pat) -> compile::Result<hir
ast,
ErrorKind::PatternMissingFields {
item: cx.q.pool.item(meta.item_meta.item).to_owned(),
#[cfg(feature = "emit")]
fields,
},
));
Expand Down
20 changes: 14 additions & 6 deletions crates/rune/src/indexing/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,13 @@ impl<'a, 'arena> Indexer<'a, 'arena> {
.load(root, self.q.pool.module_item(mod_item), &*item_mod)?;

if let Some(loaded) = self.loaded.as_mut() {
if let Some(existing) = loaded.insert(mod_item, (self.source_id, item_mod.span())) {
if let Some(_existing) = loaded.insert(mod_item, (self.source_id, item_mod.span())) {
return Err(compile::Error::new(
&*item_mod,
ErrorKind::ModAlreadyLoaded {
item: self.q.pool.module_item(mod_item).to_owned(),
existing,
#[cfg(feature = "emit")]
existing: _existing,
},
));
}
Expand Down Expand Up @@ -756,10 +757,13 @@ fn item_fn(idx: &mut Indexer<'_, '_>, mut ast: ast::ItemFn) -> compile::Result<(

let is_test = match p.try_parse::<attrs::Test>(resolve_context!(idx.q), &ast.attributes)? {
Some((attr, _)) => {
if let Some(nested_span) = idx.nested_item {
if let Some(_nested_span) = idx.nested_item {
return Err(compile::Error::new(
attr,
ErrorKind::NestedTest { nested_span },
ErrorKind::NestedTest {
#[cfg(feature = "emit")]
nested_span: _nested_span,
},
));
}

Expand All @@ -770,12 +774,15 @@ fn item_fn(idx: &mut Indexer<'_, '_>, mut ast: ast::ItemFn) -> compile::Result<(

let is_bench = match p.try_parse::<attrs::Bench>(resolve_context!(idx.q), &ast.attributes)? {
Some((attr, _)) => {
if let Some(nested_span) = idx.nested_item {
if let Some(_nested_span) = idx.nested_item {
let span = attr.span().join(ast.descriptive_span());

return Err(compile::Error::new(
span,
ErrorKind::NestedBench { nested_span },
ErrorKind::NestedBench {
#[cfg(feature = "emit")]
nested_span: _nested_span,
},
));
}

Expand Down Expand Up @@ -940,6 +947,7 @@ fn statements(idx: &mut Indexer<'_, '_>, ast: &mut Vec<ast::Stmt>) -> compile::R
return Err(compile::Error::new(
span,
ErrorKind::ExpectedBlockSemiColon {
#[cfg(feature = "emit")]
followed_span: stmt.span(),
},
));
Expand Down
4 changes: 2 additions & 2 deletions crates/rune/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ mod exported_macros;
#[macro_use]
pub mod ast;

#[cfg(feature = "fmt")]
pub mod fmt;
#[cfg(all(feature = "fmt", feature = "cli"))]
pub(crate) mod fmt;

cfg_emit! {
pub use ::codespan_reporting::term::termcolor;
Expand Down
4 changes: 4 additions & 0 deletions crates/rune/src/modules/collections.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
//! `std::collections` module.
#[cfg(feature = "std")]
mod hash_map;
#[cfg(feature = "std")]
mod hash_set;
mod vec_deque;

use crate::{ContextError, Module};

#[cfg(feature = "std")]
pub(crate) use self::hash_map::HashMap;
#[cfg(feature = "std")]
pub(crate) use self::hash_set::HashSet;
pub(crate) use self::vec_deque::VecDeque;
use crate as rune;
Expand Down
13 changes: 10 additions & 3 deletions crates/rune/src/modules/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
use crate::no_std::prelude::*;

use crate as rune;
use crate::modules::collections::{HashMap, HashSet, VecDeque};
use crate::modules::collections::VecDeque;
#[cfg(feature = "std")]
use crate::modules::collections::{HashMap, HashSet};
#[cfg(feature = "std")]
use crate::runtime::EnvProtocolCaller;
use crate::runtime::{
EnvProtocolCaller, FromValue, Function, Iterator, Object, OwnedTuple, Protocol, Value, Vec,
VmResult,
FromValue, Function, Iterator, Object, OwnedTuple, Protocol, Value, Vec, VmResult,
};
use crate::{ContextError, Module};

Expand Down Expand Up @@ -49,7 +52,9 @@ pub fn module() -> Result<Module, ContextError> {

module.function_meta(collect_vec)?;
module.function_meta(collect_vec_deque)?;
#[cfg(feature = "std")]
module.function_meta(collect_hash_set)?;
#[cfg(feature = "std")]
module.function_meta(collect_hash_map)?;
module.function_meta(collect_tuple)?;
module.function_meta(collect_object)?;
Expand Down Expand Up @@ -1070,6 +1075,7 @@ fn collect_vec_deque(it: Iterator) -> VmResult<VecDeque> {
/// assert_eq!((0..3).iter().collect::<HashSet>(), HashSet::from([0, 1, 2]));
/// ```
#[rune::function(instance, path = collect::<HashSet>)]
#[cfg(feature = "std")]
fn collect_hash_set(it: Iterator) -> VmResult<HashSet> {
let mut caller = EnvProtocolCaller;
HashSet::from_iter(it, &mut caller)
Expand All @@ -1087,6 +1093,7 @@ fn collect_hash_set(it: Iterator) -> VmResult<HashSet> {
/// assert_eq!(actual, expected);
/// ```
#[rune::function(instance, path = collect::<HashMap>)]
#[cfg(feature = "std")]
fn collect_hash_map(it: Iterator) -> VmResult<HashMap> {
let mut caller = EnvProtocolCaller;
HashMap::from_iter(it, &mut caller)
Expand Down
Loading

0 comments on commit bb58c97

Please sign in to comment.