From cc319f88a7481e951064f87114584d7daebb0d5f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 11 Aug 2021 20:14:26 +0200 Subject: Fix rustdoc-js tool string "parsing" Improve tool: add support for multiline comments --- src/tools/rustdoc-js/tester.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/tools') diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js index 86b16f8b0e6..bb9cd00f3f5 100644 --- a/src/tools/rustdoc-js/tester.js +++ b/src/tools/rustdoc-js/tester.js @@ -20,15 +20,17 @@ function getNextStep(content, pos, stop) { // will blow up. Template strings are not tested and might also be // broken. function extractFunction(content, functionName) { - var indent = 0; + var level = 0; var splitter = "function " + functionName + "("; + var stop; + var pos, start; while (true) { - var start = content.indexOf(splitter); + start = content.indexOf(splitter); if (start === -1) { break; } - var pos = start; + pos = start; while (pos < content.length && content[pos] !== ')') { pos += 1; } @@ -44,30 +46,33 @@ function extractFunction(content, functionName) { } while (pos < content.length) { // Eat single-line comments - if (content[pos] === '/' && pos > 0 && content[pos-1] === '/') { + if (content[pos] === '/' && pos > 0 && content[pos - 1] === '/') { do { pos += 1; } while (pos < content.length && content[pos] !== '\n'); + // Eat multiline comment. + } else if (content[pos] === '*' && pos > 0 && content[pos - 1] === '/') { + do { + pos += 1; + } while (pos < content.length && content[pos] !== '/' && content[pos - 1] !== '*'); + // Eat quoted strings } else if (content[pos] === '"' || content[pos] === "'" || content[pos] === "`") { - var stop = content[pos]; - var is_escaped = false; + stop = content[pos]; do { if (content[pos] === '\\') { - pos += 2; - } else { pos += 1; } - } while (pos < content.length && - (content[pos] !== stop || content[pos - 1] === '\\')); + pos += 1; + } while (pos < content.length && content[pos] !== stop); - // Otherwise, check for indent + // Otherwise, check for block level. } else if (content[pos] === '{') { - indent += 1; + level += 1; } else if (content[pos] === '}') { - indent -= 1; - if (indent === 0) { + level -= 1; + if (level === 0) { return content.slice(start, pos + 1); } } -- cgit 1.4.1-3-g733a5 From a851b56a105ae52f71bf040f80f9800db547d93d Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 12 Aug 2021 10:48:16 +0200 Subject: Bless clippy tests. --- src/tools/clippy/tests/ui/crashes/ice-3969.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/tools') diff --git a/src/tools/clippy/tests/ui/crashes/ice-3969.stderr b/src/tools/clippy/tests/ui/crashes/ice-3969.stderr index 8b2c318acf8..9a89047f072 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-3969.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-3969.stderr @@ -6,7 +6,7 @@ LL | for<'a> Dst: Sized, | = note: `-D bare-trait-objects` implied by `-D warnings` = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see issue #80165 + = note: for more information, see error: trait objects without an explicit `dyn` are deprecated --> $DIR/ice-3969.rs:27:16 @@ -15,7 +15,7 @@ LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); | ^ help: use `dyn`: `dyn A` | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see issue #80165 + = note: for more information, see error: trait objects without an explicit `dyn` are deprecated --> $DIR/ice-3969.rs:27:57 @@ -24,7 +24,7 @@ LL | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); | ^ help: use `dyn`: `dyn A` | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! - = note: for more information, see issue #80165 + = note: for more information, see error: aborting due to 3 previous errors -- cgit 1.4.1-3-g733a5