Skip to content

Commit

Permalink
rune: Rework context spans
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Oct 26, 2024
1 parent 9e5f3c3 commit 7ee83c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions crates/rune/src/compile/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'arena> CompileBuildEntry<'_, 'arena> {
fn compiler1<'a, 'hir>(
&'a mut self,
location: Location,
span: &dyn Spanned,
span: &'hir dyn Spanned,
asm: &'a mut Assembly,
scopes: &'a mut v1::Scopes<'hir>,
) -> alloc::Result<v1::Ctxt<'a, 'hir, 'arena>> {
Expand All @@ -134,7 +134,7 @@ impl<'arena> CompileBuildEntry<'_, 'arena> {
q: self.q.borrow(),
asm,
scopes,
contexts: try_vec![span.span()],
contexts: try_vec![span],
breaks: self::v1::Breaks::new(),
options: self.options,
select_branches: Vec::new(),
Expand Down
10 changes: 5 additions & 5 deletions crates/rune/src/compile/v1/assemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tracing::instrument_ast;

use crate::alloc::prelude::*;
use crate::alloc::BTreeMap;
use crate::ast::{self, Span, Spanned};
use crate::ast::{self, Spanned};
use crate::compile::ir;
use crate::compile::{self, Assembly, ErrorKind, ItemId, ModId, Options, WithSpan};
use crate::hir;
Expand Down Expand Up @@ -58,7 +58,7 @@ pub(crate) struct Ctxt<'a, 'hir, 'arena> {
/// Scopes defined in the compiler.
pub(crate) scopes: &'a Scopes<'hir>,
/// Context for which to emit warnings.
pub(crate) contexts: Vec<Span>,
pub(crate) contexts: Vec<&'hir dyn Spanned>,
/// The nesting of loop we are currently in.
pub(crate) breaks: Breaks<'hir>,
/// Enabled optimizations.
Expand All @@ -83,7 +83,7 @@ impl<'a, 'hir, 'arena> Ctxt<'a, 'hir, 'arena> {
}

/// Get the latest relevant warning context.
pub(crate) fn context(&self) -> Option<Span> {
pub(crate) fn context(&self) -> Option<&'hir dyn Spanned> {
self.contexts.last().copied()
}

Expand Down Expand Up @@ -940,7 +940,7 @@ fn block_without_scope<'a, 'hir>(
needs: &mut dyn Needs<'a, 'hir>,
) -> compile::Result<Asm<'hir>> {
let mut diverge = None;
cx.contexts.try_push(hir.span())?;
cx.contexts.try_push(hir)?;

for stmt in hir.statements {
let mut needs = Any::ignore(hir).with_name("statement ignore");
Expand Down Expand Up @@ -2817,7 +2817,7 @@ fn expr_select<'a, 'hir>(
span: &'hir dyn Spanned,
needs: &mut dyn Needs<'a, 'hir>,
) -> compile::Result<Asm<'hir>> {
cx.contexts.try_push(span.span())?;
cx.contexts.try_push(span)?;
cx.select_branches.clear();

let asm = expr_select_inner(cx, hir, span, needs)?;
Expand Down
22 changes: 11 additions & 11 deletions crates/rune/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use ::rust_alloc::boxed::Box;
use rune_alloc::String;

use crate::alloc::{self, Vec};
use crate::ast::{Span, Spanned};
use crate::ast::Spanned;
use crate::{Hash, SourceId};

#[cfg(feature = "emit")]
Expand Down Expand Up @@ -207,13 +207,13 @@ impl Diagnostics {
&mut self,
source_id: SourceId,
span: &dyn Spanned,
context: Option<Span>,
context: Option<&dyn Spanned>,
) -> alloc::Result<()> {
self.warning(
source_id,
WarningDiagnosticKind::NotUsed {
span: span.span(),
context,
context: context.map(Spanned::span),
},
)
}
Expand Down Expand Up @@ -241,13 +241,13 @@ impl Diagnostics {
&mut self,
source_id: SourceId,
span: &dyn Spanned,
context: Option<Span>,
context: Option<&dyn Spanned>,
) -> alloc::Result<()> {
self.warning(
source_id,
WarningDiagnosticKind::LetPatternMightPanic {
span: span.span(),
context,
context: context.map(Spanned::span),
},
)
}
Expand All @@ -260,13 +260,13 @@ impl Diagnostics {
&mut self,
source_id: SourceId,
span: &dyn Spanned,
context: Option<Span>,
context: Option<&dyn Spanned>,
) -> alloc::Result<()> {
self.warning(
source_id,
WarningDiagnosticKind::TemplateWithoutExpansions {
span: span.span(),
context,
context: context.map(Spanned::span),
},
)
}
Expand All @@ -280,14 +280,14 @@ impl Diagnostics {
source_id: SourceId,
span: &dyn Spanned,
variant: &dyn Spanned,
context: Option<Span>,
context: Option<&dyn Spanned>,
) -> alloc::Result<()> {
self.warning(
source_id,
WarningDiagnosticKind::RemoveTupleCallParams {
span: span.span(),
variant: variant.span(),
context,
context: context.map(Spanned::span),
},
)
}
Expand All @@ -309,14 +309,14 @@ impl Diagnostics {
&mut self,
source_id: SourceId,
span: &dyn Spanned,
context: Option<Span>,
context: Option<&dyn Spanned>,
message: String,
) -> alloc::Result<()> {
self.warning(
source_id,
WarningDiagnosticKind::UsedDeprecated {
span: span.span(),
context,
context: context.map(Spanned::span),
message,
},
)
Expand Down

0 comments on commit 7ee83c2

Please sign in to comment.