about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorantoyo <antoyo@users.noreply.github.com>2022-08-27 20:50:38 -0400
committerGitHub <noreply@github.com>2022-08-27 20:50:38 -0400
commit866f9c527a2c9e5c7cbde97fc515ffcebdcbee6d (patch)
tree427cd12364bc1cc8f056571571aa290477a4fd4d /src
parent06b6ec0ebe6ae9322f53b32c7c851899d7e99cd7 (diff)
parentfc56c544165d02e589369a97076ec64fe627a6b5 (diff)
downloadrust-866f9c527a2c9e5c7cbde97fc515ffcebdcbee6d.tar.gz
rust-866f9c527a2c9e5c7cbde97fc515ffcebdcbee6d.zip
Merge pull request #210 from rust-lang/fix/asm-newline
Remove extra newline in asm
Diffstat (limited to 'src')
-rw-r--r--src/asm.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/asm.rs b/src/asm.rs
index eb37488a6c5..9d9b6a23d07 100644
--- a/src/asm.rs
+++ b/src/asm.rs
@@ -695,17 +695,16 @@ impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
         for piece in template {
             match *piece {
                 InlineAsmTemplatePiece::String(ref string) => {
-                    for line in string.lines() {
+                    let mut index = 0;
+                    while index < string.len() {
                         // NOTE: gcc does not allow inline comment, so remove them.
-                        let line =
-                            if let Some(index) = line.rfind("//") {
-                                &line[..index]
-                            }
-                            else {
-                                line
-                            };
-                        template_str.push_str(line);
-                        template_str.push('\n');
+                        let comment_index = string[index..].find("//")
+                            .map(|comment_index| comment_index + index)
+                            .unwrap_or(string.len());
+                        template_str.push_str(&string[index..comment_index]);
+                        index = string[comment_index..].find('\n')
+                            .map(|index| index + comment_index)
+                            .unwrap_or(string.len());
                     }
                 },
                 InlineAsmTemplatePiece::Placeholder { operand_idx, modifier: _, span: _ } => {