From cf3d702720f1792019efa84fd35f18094c66af53 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 15 Jun 2017 13:18:17 +0200 Subject: [PATCH] Fix deprecations (#458) * Properly import core.exception in analysis/helpers * Remove the old std.string.removechars from useless_assert --- src/analysis/helpers.d | 7 ++++--- src/analysis/useless_assert.d | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/analysis/helpers.d b/src/analysis/helpers.d index f609d66..5312ff9 100644 --- a/src/analysis/helpers.d +++ b/src/analysis/helpers.d @@ -5,6 +5,7 @@ module analysis.helpers; +import core.exception : AssertError; import std.string; import std.traits; import std.stdio; @@ -107,14 +108,14 @@ void assertAnalyzerWarnings(string code, const StaticAnalysisConfig config, { immutable string errors = "Expected warning:\n%s\nFrom source code at (%s:?):\n%s".format(messages[lineNo], lineNo, codeLines[lineNo - line]); - throw new core.exception.AssertError(errors, file, lineNo); + throw new AssertError(errors, file, lineNo); } // Different warning else if (warnings[lineNo] != messages[lineNo]) { immutable string errors = "Expected warning:\n%s\nBut was:\n%s\nFrom source code at (%s:?):\n%s".format( messages[lineNo], warnings[lineNo], lineNo, codeLines[lineNo - line]); - throw new core.exception.AssertError(errors, file, lineNo); + throw new AssertError(errors, file, lineNo); } } @@ -132,6 +133,6 @@ void assertAnalyzerWarnings(string code, const StaticAnalysisConfig config, if (unexpectedWarnings.length) { immutable string message = "Unexpected warnings:\n" ~ unexpectedWarnings.join("\n"); - throw new core.exception.AssertError(message, file, line); + throw new AssertError(message, file, line); } } diff --git a/src/analysis/useless_assert.d b/src/analysis/useless_assert.d index 6ea1323..ad61ada 100644 --- a/src/analysis/useless_assert.d +++ b/src/analysis/useless_assert.d @@ -12,6 +12,14 @@ import dparse.lexer; import std.stdio; +auto filterChars(string chars, S)(S str) +{ + import std.algorithm.comparison : among; + import std.algorithm.iteration : filter; + import std.meta : aliasSeqOf; + return str.filter!(c => !c.among(aliasSeqOf!chars)); +} + /** * Checks for asserts that always succeed */ @@ -28,7 +36,6 @@ class UselessAssertCheck : BaseAnalyzer override void visit(const AssertExpression ae) { import std.conv : to; - import std.string : removechars; UnaryExpression unary = cast(UnaryExpression) ae.assertion; if (unary is null) @@ -42,11 +49,11 @@ class UselessAssertCheck : BaseAnalyzer if (!skipSwitch) switch (token.type) { case tok!"doubleLiteral": - if (!token.text.removechars("Ll").to!double) + if (!token.text.filterChars!"Ll".to!double) return; break; case tok!"floatLiteral": - if (!token.text.removechars("Ff").to!float) + if (!token.text.filterChars!"Ff".to!float) return; break; case tok!"idoubleLiteral": @@ -58,7 +65,7 @@ class UselessAssertCheck : BaseAnalyzer return; break; case tok!"longLiteral": - if (!token.text.removechars("Ll").to!long) + if (!token.text.filterChars!"Ll".to!long) return; break; case tok!"realLiteral": @@ -66,11 +73,11 @@ class UselessAssertCheck : BaseAnalyzer return; break; case tok!"uintLiteral": - if (!token.text.removechars("Uu").to!uint) + if (!token.text.filterChars!"Uu".to!uint) return; break; case tok!"ulongLiteral": - if (!token.text.removechars("UuLl").to!ulong) + if (!token.text.filterChars!"UuLl".to!ulong) return; break; case tok!"characterLiteral":