about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdam Perry <adam.n.perry@gmail.com>2019-10-04 15:55:39 -0700
committerAdam Perry <adam.n.perry@gmail.com>2019-10-07 08:05:33 -0700
commit130be6d4b8015b32a3e68678dd75459b2a3de3ab (patch)
treef4891793d24e816a53ad94a3b3029aa00a829659
parentbdc4bd142b3a452d5e7456cf30e9fc67106ec01b (diff)
downloadrust-130be6d4b8015b32a3e68678dd75459b2a3de3ab.tar.gz
rust-130be6d4b8015b32a3e68678dd75459b2a3de3ab.zip
Expand E0738 to cover different cases.
-rw-r--r--src/librustc_typeck/check/wfcheck.rs2
-rw-r--r--src/librustc_typeck/error_codes.rs39
-rw-r--r--src/test/ui/rfc-2091-track-caller/error-with-trait-decl.rs (renamed from src/test/ui/rfc-2091-track-caller/error-with-trait-fns.rs)2
-rw-r--r--src/test/ui/rfc-2091-track-caller/error-with-trait-decl.stderr17
-rw-r--r--src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.rs9
-rw-r--r--src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.stderr17
-rw-r--r--src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.rs13
-rw-r--r--src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.stderr (renamed from src/test/ui/rfc-2091-track-caller/error-with-trait-fns.stderr)6
8 files changed, 93 insertions, 12 deletions
diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs
index b8d1da2bbed..4f9c686bd39 100644
--- a/src/librustc_typeck/check/wfcheck.rs
+++ b/src/librustc_typeck/check/wfcheck.rs
@@ -180,7 +180,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
                 tcx.sess,
                 attr.span,
                 E0738,
-                "`#[track_caller]` is not supported for trait items yet."
+                "`#[track_caller]` is not supported in trait declarations."
             ).emit();
         }
     }
diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs
index 1fb5b592616..026aff7a964 100644
--- a/src/librustc_typeck/error_codes.rs
+++ b/src/librustc_typeck/error_codes.rs
@@ -4926,12 +4926,11 @@ extern "C" fn foo() {}
 "##,
 
 E0738: r##"
-#[track_caller] cannot be applied to trait methods.
+#[track_caller] cannot be used in traits yet.  This is due to limitations in the
+compiler which are likely to be temporary. See [RFC 2091] for details on this
+and other restrictions.
 
-This is due to limitations in the compiler which are likely to be temporary.
-See [RFC 2091] for details on this and other restrictions.
-
-Erroneous code example:
+Erroneous example with a trait method implementation:
 
 ```compile_fail,E0738
 #![feature(track_caller)]
@@ -4940,14 +4939,40 @@ trait Foo {
     fn bar(&self);
 }
 
-struct Bar;
+impl Foo for u64 {
+    #[track_caller]
+    fn bar(&self) {}
+}
+```
 
-impl Foo for Bar {
+Erroneous example with a blanket trait method implementation:
+
+```compile_fail,E0738
+#![feature(track_caller)]
+
+trait Foo {
     #[track_caller]
     fn bar(&self) {}
+    fn baz(&self);
+}
+```
+
+Erroneous example with a trait method declaration:
+
+```compile_fail,E0738
+#[!feature(track_caller)]
+
+trait Foo {
+    fn bar(&self) {}
+
+    #[track_caller]
+    fn baz(&self);
 }
 ```
 
+Note that while the compiler may be able to support the attribute in traits in
+the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
+
 [RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md
 "##,
 
diff --git a/src/test/ui/rfc-2091-track-caller/error-with-trait-fns.rs b/src/test/ui/rfc-2091-track-caller/error-with-trait-decl.rs
index e42568076b9..72f690777da 100644
--- a/src/test/ui/rfc-2091-track-caller/error-with-trait-fns.rs
+++ b/src/test/ui/rfc-2091-track-caller/error-with-trait-decl.rs
@@ -3,7 +3,7 @@
 trait Trait {
     #[track_caller]
     fn unwrap(&self);
-    //~^^ ERROR: `#[track_caller]` is not supported for trait items yet.
+    //~^^ ERROR: `#[track_caller]` is not supported in traits yet.
 }
 
 impl Trait for u64 {
diff --git a/src/test/ui/rfc-2091-track-caller/error-with-trait-decl.stderr b/src/test/ui/rfc-2091-track-caller/error-with-trait-decl.stderr
new file mode 100644
index 00000000000..fb3732b5970
--- /dev/null
+++ b/src/test/ui/rfc-2091-track-caller/error-with-trait-decl.stderr
@@ -0,0 +1,17 @@
+warning: the feature `track_caller` is incomplete and may cause the compiler to crash
+  --> $DIR/error-with-trait-decl.rs:1:12
+   |
+LL | #![feature(track_caller)]
+   |            ^^^^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+
+error[E0738]: `#[track_caller]` is not supported in trait declarations.
+  --> $DIR/error-with-trait-decl.rs:4:5
+   |
+LL |     #[track_caller]
+   |     ^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0738`.
diff --git a/src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.rs b/src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.rs
new file mode 100644
index 00000000000..0f2020d6fb2
--- /dev/null
+++ b/src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.rs
@@ -0,0 +1,9 @@
+#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete
+
+trait Trait {
+    #[track_caller]
+    fn unwrap(&self) {}
+    //~^^ ERROR: `#[track_caller]` is not supported in trait declarations.
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.stderr b/src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.stderr
new file mode 100644
index 00000000000..f7faeba189b
--- /dev/null
+++ b/src/test/ui/rfc-2091-track-caller/error-with-trait-default-impl.stderr
@@ -0,0 +1,17 @@
+warning: the feature `track_caller` is incomplete and may cause the compiler to crash
+  --> $DIR/error-with-trait-default-impl.rs:1:12
+   |
+LL | #![feature(track_caller)]
+   |            ^^^^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+
+error[E0738]: `#[track_caller]` is not supported in traits yet.
+  --> $DIR/error-with-trait-default-impl.rs:4:5
+   |
+LL |     #[track_caller]
+   |     ^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0738`.
diff --git a/src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.rs b/src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.rs
new file mode 100644
index 00000000000..1378ebaa03f
--- /dev/null
+++ b/src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.rs
@@ -0,0 +1,13 @@
+#![feature(track_caller)] //~ WARN the feature `track_caller` is incomplete
+
+trait Trait {
+    fn unwrap(&self);
+}
+
+impl Trait for u64 {
+    #[track_caller]
+    fn unwrap(&self) {}
+    //~^^ ERROR: `#[track_caller]` is not supported in traits yet.
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2091-track-caller/error-with-trait-fns.stderr b/src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.stderr
index c5c2f136a3a..1e6c2eeca47 100644
--- a/src/test/ui/rfc-2091-track-caller/error-with-trait-fns.stderr
+++ b/src/test/ui/rfc-2091-track-caller/error-with-trait-fn-impl.stderr
@@ -1,13 +1,13 @@
 warning: the feature `track_caller` is incomplete and may cause the compiler to crash
-  --> $DIR/error-with-trait-fns.rs:1:12
+  --> $DIR/error-with-trait-fn-impl.rs:1:12
    |
 LL | #![feature(track_caller)]
    |            ^^^^^^^^^^^^
    |
    = note: `#[warn(incomplete_features)]` on by default
 
-error[E0738]: `#[track_caller]` is not supported for trait items yet.
-  --> $DIR/error-with-trait-fns.rs:4:5
+error[E0738]: `#[track_caller]` is not supported in traits yet.
+  --> $DIR/error-with-trait-fn-impl.rs:4:5
    |
 LL |     #[track_caller]
    |     ^^^^^^^^^^^^^^^