Repository: intellij-rust/intellij-rust
Issue: Postfix completion doesn't work well to print variables of type string

<!--
Hello and thank you for the issue!
If you would like to report a bug, we have added some points below that you can fill out.
Feel free to remove all the irrelevant text to request a new feature.
-->

## Environment

* **IntelliJ Rust plugin version**: 0.2.118.2171-193
* **Rust toolchain version**: 1.42.0
* **IDE name and version**: IntelliJ IDEA 2019.3.4
* **Operating system**: Linux

# Problem and explanation
Postfix completion works well for strings when doing the following:
```rust
"Some string".println
```

In such case, the result ends up being
```rust
println!("Some string")
```
However, in cases where we have a variable, such as

```rust
let s = "Some string";
s.println
```
the result ends up being
```rust
println!(s)
```
when it should be 
```rust
println!("{}, s)
```

<!--
Please include as much of your codebase as needed to reproduce the error.
If the relevant files are large, please provide a link to a public repository or a [Gist](https://gist.github.com/).
-->


Changed files:
src/test/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplateTest.kt, src/main/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplate.kt

diff --git a/src/main/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplate.kt b/src/main/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplate.kt
index 3cb40c01e..c96536df6 100644
--- a/src/main/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplate.kt
+++ b/src/main/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplate.kt
@@ -33,10 +33,13 @@ class PrintlnPostfixTemplate(provider: RsPostfixTemplateProvider, private val ma
         Debug("{:?}");
 
         companion object {
-            fun fromExpr(expr: RsExpr): Fmt = when {
-                (expr.type as? TyReference)?.referenced is TyStr -> Fmt.None
-                expr.isDebug -> Fmt.Debug
-                else -> Fmt.Display
+            fun fromExpr(expr: RsExpr): Fmt {
+                val kind = (expr as? RsLitExpr)?.kind
+                return when {
+                    kind is RsLiteralKind.String && !kind.isByte -> None
+                    expr.isDebug -> Debug
+                    else -> Display
+                }
             }
         }
     }
diff --git a/src/test/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplateTest.kt b/src/test/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplateTest.kt
index 330e32c28..c183d1bc0 100644
--- a/src/test/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplateTest.kt
+++ b/src/test/kotlin/org/rust/ide/template/postfix/PrintlnPostfixTemplateTest.kt
@@ -20,6 +20,84 @@ class PrintlnPostfixTemplateTests : RsPostfixTemplateTest(PrintlnPostfixTemplate
        }
     """)
 
+    fun `test byte string`() = doTest("""
+       fn main() {
+           b"Arbitrary string".println/*caret*/
+       }
+    """, """
+       fn main() {
+           println!("{:?}", b"Arbitrary string");/*caret*/
+       }
+    """)
+
+    fun `test raw string`() = doTest("""
+       fn main() {
+           r#"Arbitrary string"#.println/*caret*/
+       }
+    """, """
+       fn main() {
+           println!(r#"Arbitrary string"#);/*caret*/
+       }
+    """)
+
+    fun `test raw byte string`() = doTest("""
+       fn main() {
+           br#"Arbitrary string"#.println/*caret*/
+       }
+    """, """
+       fn main() {
+           println!("{:?}", br#"Arbitrary string"#);/*caret*/
+       }
+    """)
+
+    fun `test string variable`() = doTest("""
+       fn main() {
+           let s = "Arbitrary string";
+           s.println/*caret*/
+       }
+    """, """
+       fn main() {
+           let s = "Arbitrary string";
+           println!("{:?}", s);/*caret*/
+       }
+    """)
+
+    fun `test byte string variable`() = doTest("""
+       fn main() {
+           let s = b"Arbitrary string";
+           s.println/*caret*/
+       }
+    """, """
+       fn main() {
+           let s = b"Arbitrary string";
+           println!("{:?}", s);/*caret*/
+       }
+    """)
+
+    fun `test raw string variable`() = doTest("""
+       fn main() {
+           let s = r#"Arbitrary string"#;
+           s.println/*caret*/
+       }
+    """, """
+       fn main() {
+           let s = r#"Arbitrary string"#;
+           println!("{:?}", s);/*caret*/
+       }
+    """)
+
+    fun `test raw byte string variable`() = doTest("""
+       fn main() {
+           let s = br#"Arbitrary string"#;
+           s.println/*caret*/
+       }
+    """, """
+       fn main() {
+           let s = br#"Arbitrary string"#;
+           println!("{:?}", s);/*caret*/
+       }
+    """)
+
     fun `test method returning Debug`() = doTest("""
         #[derive(Debug)]
         enum E { A }