make crate compatible with 1.56.0

This commit is contained in:
Connor Skees 2022-12-28 17:50:25 -05:00
parent 9b6623190d
commit 6cd208f41d
18 changed files with 112 additions and 56 deletions

View File

@ -81,7 +81,8 @@ impl ArgumentDeclaration {
} else { } else {
"arguments" "arguments"
}, },
if num_positional == 1 { "was" } else { "were" } if num_positional == 1 { "was" } else { "were" },
num_positional = num_positional,
), ),
span, span,
) )
@ -113,7 +114,7 @@ impl ArgumentDeclaration {
to_sentence( to_sentence(
unknown_names unknown_names
.into_iter() .into_iter()
.map(|name| format!("${name}")) .map(|name| format!("${name}", name = name))
.collect(), .collect(),
"or" "or"
) )
@ -234,7 +235,7 @@ impl ArgumentResult {
if len > max { if len > max {
let mut err = String::with_capacity(50); let mut err = String::with_capacity(50);
#[allow(clippy::format_push_string)] #[allow(clippy::format_push_string)]
err.push_str(&format!("Only {} argument", max)); err.push_str(&format!("Only {max} argument", max = max));
if max != 1 { if max != 1 {
err.push('s'); err.push('s');
} }

View File

@ -103,15 +103,15 @@ fn inner_hsl(
let saturation = args.get_err(1, "saturation")?; let saturation = args.get_err(1, "saturation")?;
if hue.is_var() || saturation.is_var() { if hue.is_var() || saturation.is_var() {
return Ok(Value::String( Ok(Value::String(
function_string(name, &[hue, saturation], visitor, span)?, function_string(name, &[hue, saturation], visitor, span)?,
QuoteKind::None, QuoteKind::None,
)); ))
} else { } else {
return Err(("Missing argument $lightness.", args.span()).into()); Err(("Missing argument $lightness.", args.span()).into())
} }
} else { } else {
return hsl_3_args(name, args, visitor); hsl_3_args(name, args, visitor)
} }
} }

View File

@ -162,7 +162,8 @@ pub(crate) fn percentage_or_unitless(
return Err(( return Err((
format!( format!(
"${name}: Expected {} to have no units or \"%\".", "${name}: Expected {} to have no units or \"%\".",
inspect_number(number, visitor.options, span)? inspect_number(number, visitor.options, span)?,
name = name,
), ),
span, span,
) )
@ -279,7 +280,11 @@ pub(crate) fn parse_channels(
return Ok(ParsedChannels::String(fn_string)); return Ok(ParsedChannels::String(fn_string));
} else { } else {
let argument = arg_names[list.len()]; let argument = arg_names[list.len()];
return Err((format!("Missing element ${argument}."), span).into()); return Err((
format!("Missing element ${argument}.", argument = argument),
span,
)
.into());
} }
} }

View File

@ -57,7 +57,7 @@ fn load_css(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult<()> {
if values.contains_key(&name) { if values.contains_key(&name) {
// todo: write test for this // todo: write test for this
return Err(( return Err((
format!("The variable {name} was configured twice."), format!("The variable {name} was configured twice.", name = name),
key.span, key.span,
) )
.into()); .into());

View File

@ -263,7 +263,7 @@ impl Environment {
for name in (*self.scopes.global_variables()).borrow().keys() { for name in (*self.scopes.global_variables()).borrow().keys() {
if (*module).borrow().var_exists(*name) { if (*module).borrow().var_exists(*name) {
return Err(( return Err((
format!("This module and the new module both define a variable named \"{name}\".") format!("This module and the new module both define a variable named \"{}\".", name = name)
, span).into()); , span).into());
} }
} }

View File

@ -474,7 +474,7 @@ impl<'a> Visitor<'a> {
let children = supports_rule.children; let children = supports_rule.children;
self.with_parent::<SassResult<()>>( self.with_parent(
css_supports_rule, css_supports_rule,
true, true,
|visitor| { |visitor| {
@ -496,7 +496,7 @@ impl<'a> Visitor<'a> {
is_group_end: false, is_group_end: false,
}; };
visitor.with_parent::<SassResult<()>>( visitor.with_parent(
ruleset, ruleset,
false, false,
|visitor| { |visitor| {
@ -529,7 +529,7 @@ impl<'a> Visitor<'a> {
let env = Environment::new(); let env = Environment::new();
let mut extension_store = ExtensionStore::new(self.span_before); let mut extension_store = ExtensionStore::new(self.span_before);
self.with_environment::<SassResult<()>>(env.new_closure(), |visitor| { self.with_environment::<SassResult<()>, _>(env.new_closure(), |visitor| {
let old_parent = visitor.parent; let old_parent = visitor.parent;
mem::swap(&mut visitor.extender, &mut extension_store); mem::swap(&mut visitor.extender, &mut extension_store);
let old_style_rule = visitor.style_rule_ignoring_at_root.take(); let old_style_rule = visitor.style_rule_ignoring_at_root.take();
@ -698,7 +698,10 @@ impl<'a> Visitor<'a> {
let Spanned { node: name, span } = config.first().unwrap(); let Spanned { node: name, span } = config.first().unwrap();
let msg = if name_in_error { let msg = if name_in_error {
format!("${name} was not declared with !default in the @used module.") format!(
"${name} was not declared with !default in the @used module.",
name = name
)
} else { } else {
"This variable was not declared with !default in the @used module.".to_owned() "This variable was not declared with !default in the @used module.".to_owned()
}; };
@ -907,6 +910,7 @@ impl<'a> Visitor<'a> {
fn visit_content_rule(&mut self, content_rule: AstContentRule) -> SassResult<Option<Value>> { fn visit_content_rule(&mut self, content_rule: AstContentRule) -> SassResult<Option<Value>> {
let span = content_rule.args.span; let span = content_rule.args.span;
if let Some(content) = &self.env.content { if let Some(content) = &self.env.content {
#[allow(mutable_borrow_reservation_conflict)]
self.run_user_defined_callable( self.run_user_defined_callable(
MaybeEvaledArguments::Invocation(content_rule.args), MaybeEvaledArguments::Invocation(content_rule.args),
Arc::clone(content), Arc::clone(content),
@ -1008,7 +1012,7 @@ impl<'a> Visitor<'a> {
// If we didn't exclude any rules, we don't need to use the copies we might // If we didn't exclude any rules, we don't need to use the copies we might
// have created. // have created.
if Some(root) == self.parent { if Some(root) == self.parent {
self.with_scope::<SassResult<()>>(false, true, |visitor| { self.with_scope::<SassResult<()>, _>(false, true, |visitor| {
for stmt in at_root_rule.children { for stmt in at_root_rule.children {
let result = visitor.visit_stmt(stmt)?; let result = visitor.visit_stmt(stmt)?;
debug_assert!(result.is_none()); debug_assert!(result.is_none());
@ -1053,7 +1057,7 @@ impl<'a> Visitor<'a> {
let body = mem::take(&mut at_root_rule.children); let body = mem::take(&mut at_root_rule.children);
self.with_scope_for_at_root::<SassResult<()>>(inner_copy, &query, |visitor| { self.with_scope_for_at_root::<SassResult<()>, _>(inner_copy, &query, |visitor| {
for stmt in body { for stmt in body {
let result = visitor.visit_stmt(stmt)?; let result = visitor.visit_stmt(stmt)?;
debug_assert!(result.is_none()); debug_assert!(result.is_none());
@ -1065,11 +1069,11 @@ impl<'a> Visitor<'a> {
Ok(None) Ok(None)
} }
fn with_scope_for_at_root<T>( fn with_scope_for_at_root<T, F: FnOnce(&mut Self) -> T>(
&mut self, &mut self,
new_parent_idx: Option<CssTreeIdx>, new_parent_idx: Option<CssTreeIdx>,
query: &AtRootQuery, query: &AtRootQuery,
callback: impl FnOnce(&mut Self) -> T, callback: F,
) -> T { ) -> T {
let old_parent = self.parent; let old_parent = self.parent;
self.parent = new_parent_idx; self.parent = new_parent_idx;
@ -1272,7 +1276,7 @@ impl<'a> Visitor<'a> {
false, false,
); );
self.with_parent::<SassResult<()>>( self.with_parent(
media_rule, media_rule,
true, true,
|visitor| { |visitor| {
@ -1298,7 +1302,7 @@ impl<'a> Visitor<'a> {
is_group_end: false, is_group_end: false,
}; };
visitor.with_parent::<SassResult<()>>( visitor.with_parent(
ruleset, ruleset,
false, false,
|visitor| { |visitor| {
@ -1390,7 +1394,7 @@ impl<'a> Visitor<'a> {
false, false,
); );
self.with_parent::<SassResult<()>>( self.with_parent(
stmt, stmt,
true, true,
|visitor| { |visitor| {
@ -1412,7 +1416,7 @@ impl<'a> Visitor<'a> {
is_group_end: false, is_group_end: false,
}; };
visitor.with_parent::<SassResult<()>>( visitor.with_parent(
style_rule, style_rule,
false, false,
|visitor| { |visitor| {
@ -1479,10 +1483,10 @@ impl<'a> Visitor<'a> {
result result
} }
fn with_environment<T>( fn with_environment<T, F: FnOnce(&mut Self) -> T>(
&mut self, &mut self,
env: Environment, env: Environment,
callback: impl FnOnce(&mut Self) -> T, callback: F,
) -> T { ) -> T {
let mut old_env = env; let mut old_env = env;
mem::swap(&mut self.env, &mut old_env); mem::swap(&mut self.env, &mut old_env);
@ -1491,10 +1495,10 @@ impl<'a> Visitor<'a> {
val val
} }
fn add_child( fn add_child<F: Fn(&CssStmt) -> bool>(
&mut self, &mut self,
node: CssStmt, node: CssStmt,
through: Option<impl Fn(&CssStmt) -> bool>, through: Option<F>,
) -> CssTreeIdx { ) -> CssTreeIdx {
if self.parent.is_none() || self.parent == Some(CssTree::ROOT) { if self.parent.is_none() || self.parent == Some(CssTree::ROOT) {
return self.css_tree.add_stmt(node, self.parent); return self.css_tree.add_stmt(node, self.parent);
@ -1530,15 +1534,15 @@ impl<'a> Visitor<'a> {
self.css_tree.add_child(node, parent) self.css_tree.add_child(node, parent)
} }
fn with_parent<T>( fn with_parent<F: FnOnce(&mut Self) -> SassResult<()>, FT: Fn(&CssStmt) -> bool>(
&mut self, &mut self,
parent: CssStmt, parent: CssStmt,
// default=true // default=true
scope_when: bool, scope_when: bool,
callback: impl FnOnce(&mut Self) -> T, callback: F,
// todo: optional // todo: optional
through: impl Fn(&CssStmt) -> bool, through: FT,
) -> T { ) -> SassResult<()> {
let parent_idx = self.add_child(parent, Some(through)); let parent_idx = self.add_child(parent, Some(through));
let old_parent = self.parent; let old_parent = self.parent;
self.parent = Some(parent_idx); self.parent = Some(parent_idx);
@ -1547,13 +1551,13 @@ impl<'a> Visitor<'a> {
result result
} }
fn with_scope<T>( fn with_scope<T, F: FnOnce(&mut Self) -> T>(
&mut self, &mut self,
// default=false // default=false
semi_global: bool, semi_global: bool,
// default=true // default=true
when: bool, when: bool,
callback: impl FnOnce(&mut Self) -> T, callback: F,
) -> T { ) -> T {
let semi_global = semi_global && self.flags.in_semi_global_scope(); let semi_global = semi_global && self.flags.in_semi_global_scope();
let was_in_semi_global_scope = self.flags.in_semi_global_scope(); let was_in_semi_global_scope = self.flags.in_semi_global_scope();
@ -1624,7 +1628,7 @@ impl<'a> Visitor<'a> {
}) })
}); });
self.run_user_defined_callable::<_, ()>( self.run_user_defined_callable::<_, (), _>(
MaybeEvaledArguments::Invocation(args), MaybeEvaledArguments::Invocation(args),
mixin, mixin,
&env, &env,
@ -1767,7 +1771,7 @@ impl<'a> Visitor<'a> {
} }
fn visit_while_stmt(&mut self, while_stmt: &AstWhile) -> SassResult<Option<Value>> { fn visit_while_stmt(&mut self, while_stmt: &AstWhile) -> SassResult<Option<Value>> {
self.with_scope::<SassResult<Option<Value>>>(true, true, |visitor| { self.with_scope(true, true, |visitor| {
let mut result = None; let mut result = None;
'outer: while visitor.visit_expr(while_stmt.condition.clone())?.is_true() { 'outer: while visitor.visit_expr(while_stmt.condition.clone())?.is_true() {
@ -2094,13 +2098,17 @@ impl<'a> Visitor<'a> {
Ok(()) Ok(())
} }
fn run_user_defined_callable<F: UserDefinedCallable, V: fmt::Debug>( fn run_user_defined_callable<
F: UserDefinedCallable,
V: fmt::Debug,
R: FnOnce(F, &mut Self) -> SassResult<V>,
>(
&mut self, &mut self,
arguments: MaybeEvaledArguments, arguments: MaybeEvaledArguments,
func: F, func: F,
env: &Environment, env: &Environment,
span: Span, span: Span,
run: impl FnOnce(F, &mut Self) -> SassResult<V>, run: R,
) -> SassResult<V> { ) -> SassResult<V> {
let mut evaluated = self.eval_maybe_args(arguments, span)?; let mut evaluated = self.eval_maybe_args(arguments, span)?;
@ -2110,7 +2118,7 @@ impl<'a> Visitor<'a> {
name.push_str("()"); name.push_str("()");
} }
self.with_environment::<SassResult<V>>(env.new_closure(), |visitor| { self.with_environment(env.new_closure(), |visitor| {
visitor.with_scope(false, true, move |visitor| { visitor.with_scope(false, true, move |visitor| {
func.arguments().verify( func.arguments().verify(
evaluated.positional.len(), evaluated.positional.len(),
@ -2204,12 +2212,20 @@ impl<'a> Visitor<'a> {
evaluated evaluated
.named .named
.keys() .keys()
.map(|key| format!("${key}")) .map(|key| format!("${key}", key = key))
.collect(), .collect(),
"or", "or",
); );
Err((format!("No {argument_word} named {argument_names}."), span).into()) Err((
format!(
"No {argument_word} named {argument_names}.",
argument_word = argument_word,
argument_names = argument_names
),
span,
)
.into())
}) })
}) })
} }
@ -2762,7 +2778,7 @@ impl<'a> Visitor<'a> {
body: Vec::new(), body: Vec::new(),
}); });
self.with_parent::<SassResult<()>>( self.with_parent(
keyframes_ruleset, keyframes_ruleset,
true, true,
|visitor| { |visitor| {
@ -2813,7 +2829,7 @@ impl<'a> Visitor<'a> {
let old_style_rule_ignoring_at_root = self.style_rule_ignoring_at_root.take(); let old_style_rule_ignoring_at_root = self.style_rule_ignoring_at_root.take();
self.style_rule_ignoring_at_root = Some(selector); self.style_rule_ignoring_at_root = Some(selector);
self.with_parent::<SassResult<()>>( self.with_parent(
rule, rule,
true, true,
|visitor| { |visitor| {
@ -2910,7 +2926,7 @@ impl<'a> Visitor<'a> {
if !children.is_empty() { if !children.is_empty() {
let old_declaration_name = self.declaration_name.take(); let old_declaration_name = self.declaration_name.take();
self.declaration_name = Some(name); self.declaration_name = Some(name);
self.with_scope::<SassResult<()>>(false, true, |visitor| { self.with_scope::<SassResult<()>, _>(false, true, |visitor| {
for stmt in children { for stmt in children {
let result = visitor.visit_stmt(stmt)?; let result = visitor.visit_stmt(stmt)?;
debug_assert!(result.is_none()); debug_assert!(result.is_none());

View File

@ -64,6 +64,8 @@ grass input.scss
clippy::wildcard_imports, clippy::wildcard_imports,
clippy::comparison_chain, clippy::comparison_chain,
clippy::bool_to_int_with_if, clippy::bool_to_int_with_if,
unknown_lints,
)] )]
use std::path::Path; use std::path::Path;

View File

@ -205,7 +205,7 @@ fn main() -> std::io::Result<()> {
.open(path)?; .open(path)?;
&mut file_write &mut file_write
} else { } else {
stdout_write = stdout().lock(); stdout_write = stdout();
&mut stdout_write &mut stdout_write
}; };

View File

@ -330,7 +330,11 @@ pub(crate) trait BaseParser<'a> {
} }
if !found_matching_quote { if !found_matching_quote {
return Err((format!("Expected {quote}."), self.toks().current_span()).into()); return Err((
format!("Expected {quote}.", quote = quote),
self.toks().current_span(),
)
.into());
} }
Ok(buffer) Ok(buffer)

View File

@ -20,6 +20,7 @@ mod stylesheet;
mod value; mod value;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum DeclarationOrBuffer { pub(crate) enum DeclarationOrBuffer {
Stmt(AstStmt), Stmt(AstStmt),
Buffer(Interpolation), Buffer(Interpolation),

View File

@ -511,7 +511,10 @@ impl<'a> SassParser<'a> {
if child_indent != indentation { if child_indent != indentation {
return Err(( return Err((
format!("Inconsistent indentation, expected {child_indent} spaces."), format!(
"Inconsistent indentation, expected {child_indent} spaces.",
child_indent = child_indent
),
self.toks.current_span(), self.toks.current_span(),
) )
.into()); .into());

View File

@ -1044,7 +1044,11 @@ pub(crate) trait StylesheetParser<'a>: BaseParser<'a> + Sized {
} }
if !found_match { if !found_match {
return Err((format!("Expected {quote}."), self.toks().current_span()).into()); return Err((
format!("Expected {quote}.", quote = quote),
self.toks().current_span(),
)
.into());
} }
Ok(Spanned { Ok(Spanned {
@ -1547,7 +1551,10 @@ pub(crate) trait StylesheetParser<'a>: BaseParser<'a> + Sized {
(Ok(i), true) => Ok(Some(i)), (Ok(i), true) => Ok(Some(i)),
_ => { _ => {
Err(( Err((
format!("The default namespace \"{namespace}\" is not a valid Sass identifier.\n\nRecommendation: add an \"as\" clause to define an explicit namespace."), format!(
"The default namespace \"{namespace}\" is not a valid Sass identifier.\n\nRecommendation: add an \"as\" clause to define an explicit namespace.",
namespace = namespace
),
self.toks_mut().span_from(start) self.toks_mut().span_from(start)
).into()) ).into())
} }

View File

@ -92,6 +92,7 @@ pub(crate) fn to_sentence<T: Into<String>>(mut elems: Vec<T>, conjunction: &'sta
.map(Into::into) .map(Into::into)
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
last.into() last.into(),
conjunction = conjunction,
) )
} }

View File

@ -245,7 +245,9 @@ impl SassCalculation {
Err(( Err((
format!( format!(
"{len} arguments required, but only {} {was_or_were} passed.", "{len} arguments required, but only {} {was_or_were} passed.",
args.len() args.len(),
len = len,
was_or_were = was_or_were,
), ),
span, span,
) )

View File

@ -228,7 +228,11 @@ impl Value {
match self { match self {
Value::Dimension(n) => Ok(n), Value::Dimension(n) => Ok(n),
_ => Err(( _ => Err((
format!("${name}: {} is not a number.", self.inspect(span)?), format!(
"${name}: {} is not a number.",
self.inspect(span)?,
name = name,
),
span, span,
) )
.into()), .into()),
@ -239,7 +243,11 @@ impl Value {
match self { match self {
Value::Color(c) => Ok(*c), Value::Color(c) => Ok(*c),
_ => Err(( _ => Err((
format!("${name}: {} is not a color.", self.inspect(span)?), format!(
"${name}: {} is not a color.",
self.inspect(span)?,
name = name,
),
span, span,
) )
.into()), .into()),

View File

@ -121,7 +121,11 @@ impl Number {
match fuzzy_as_int(self.0) { match fuzzy_as_int(self.0) {
Some(i) => Ok(i), Some(i) => Ok(i),
None => Err(( None => Err((
format!("${name}: {} is not an int.", self.to_string(false)), format!(
"${name}: {} is not an int.",
self.to_string(false),
name = name,
),
span, span,
) )
.into()), .into()),

View File

@ -136,7 +136,8 @@ impl SassNumber {
Err(( Err((
format!( format!(
"${name}: Expected {} to have no units.", "${name}: Expected {} to have no units.",
inspect_number(self, &Options::default(), span)? inspect_number(self, &Options::default(), span)?,
name = name,
), ),
span, span,
) )
@ -151,7 +152,9 @@ impl SassNumber {
Err(( Err((
format!( format!(
"${name}: Expected {} to have unit \"{unit}\".", "${name}: Expected {} to have unit \"{unit}\".",
inspect_number(self, &Options::default(), span)? inspect_number(self, &Options::default(), span)?,
name = name,
unit = unit,
), ),
span, span,
) )

View File

@ -448,7 +448,6 @@ fn chained_imports_in_directory() {
&grass::from_string(input.to_string(), &grass::Options::default()).expect(input) &grass::from_string(input.to_string(), &grass::Options::default()).expect(input)
); );
} }
error!( error!(
// note: dart-sass error is "expected more input." // note: dart-sass error is "expected more input."
missing_input_after_import, missing_input_after_import,