about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCharles Lew <crlf0710@gmail.com>2019-09-20 01:48:30 +0800
committerCharles Lew <crlf0710@gmail.com>2019-10-07 12:01:57 +0800
commitdda10f2a2afcdde60bb408d119609dfa00465f02 (patch)
treeca15276433938ccec2430f4836eec631297179ba /src
parenteb492455f2b840d28a10a68702727a5227343634 (diff)
downloadrust-dda10f2a2afcdde60bb408d119609dfa00465f02.tar.gz
rust-dda10f2a2afcdde60bb408d119609dfa00465f02.zip
Add more tests, fix span issue, improve diagnostics.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/collect.rs14
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.rs12
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.stderr16
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.rs11
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.stderr18
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs11
-rw-r--r--src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr18
7 files changed, 96 insertions, 4 deletions
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 9aeeffa70a1..30b8af99619 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -2560,6 +2560,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
     let whitelist = tcx.target_features_whitelist(LOCAL_CRATE);
 
     let mut inline_span = None;
+    let mut link_ordinal_span = None;
     for attr in attrs.iter() {
         if attr.check_name(sym::cold) {
             codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD;
@@ -2642,6 +2643,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
         } else if attr.check_name(sym::link_name) {
             codegen_fn_attrs.link_name = attr.value_str();
         } else if attr.check_name(sym::link_ordinal) {
+            link_ordinal_span = Some(attr.span);
             if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {
                 codegen_fn_attrs.link_ordinal = ordinal;
             }
@@ -2747,7 +2749,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
         codegen_fn_attrs.export_name = Some(name);
         codegen_fn_attrs.link_name = Some(name);
     }
-    check_link_name_xor_ordinal(tcx, &codegen_fn_attrs, inline_span);
+    check_link_name_xor_ordinal(tcx, &codegen_fn_attrs, link_ordinal_span);
 
     // Internal symbols to the standard library all have no_mangle semantics in
     // that they have defined symbol names present in the function name. This
@@ -2772,14 +2774,18 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<usize> {
             Some(*ordinal as usize)
         } else {
             let msg = format!(
-                "too large ordinal value in link_ordinal value: `{}`",
+                "ordinal value in `link_ordinal` is too large: `{}`",
                 &ordinal
             );
-            tcx.sess.span_err(attr.span, &msg);
+            tcx.sess.struct_span_err(attr.span, &msg)
+                .note("the value may not exceed `std::usize::MAX`")
+                .emit();
             None
         }
     } else {
-        tcx.sess.span_err(attr.span, "illegal ordinal format in link_ordinal");
+        tcx.sess.struct_span_err(attr.span, "illegal ordinal format in `link_ordinal`")
+            .note("an unsuffixed integer value, e.g., `1`, is expected")
+            .emit();
         None
     }
 }
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.rs
new file mode 100644
index 00000000000..5769366fb45
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.rs
@@ -0,0 +1,12 @@
+#![feature(raw_dylib)]
+//~^ WARN the feature `raw_dylib` is incomplete and may cause the compiler to crash
+
+#[link(name="foo")]
+extern {
+    #[link_name="foo"]
+    #[link_ordinal(42)]
+    //~^ ERROR cannot use `#[link_name]` with `#[link_ordinal]`
+    fn foo();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.stderr
new file mode 100644
index 00000000000..303a1c02eb8
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.stderr
@@ -0,0 +1,16 @@
+warning: the feature `raw_dylib` is incomplete and may cause the compiler to crash
+  --> $DIR/link-ordinal-and-name.rs:1:12
+   |
+LL | #![feature(raw_dylib)]
+   |            ^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+
+error: cannot use `#[link_name]` with `#[link_ordinal]`
+  --> $DIR/link-ordinal-and-name.rs:7:5
+   |
+LL |     #[link_ordinal(42)]
+   |     ^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.rs
new file mode 100644
index 00000000000..82fb1151c23
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.rs
@@ -0,0 +1,11 @@
+#![feature(raw_dylib)]
+//~^ WARN the feature `raw_dylib` is incomplete and may cause the compiler to crash
+
+#[link(name="foo")]
+extern {
+    #[link_ordinal("JustMonika")]
+    //~^ ERROR illegal ordinal format in `link_ordinal`
+    fn foo();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.stderr
new file mode 100644
index 00000000000..14556a7262b
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.stderr
@@ -0,0 +1,18 @@
+warning: the feature `raw_dylib` is incomplete and may cause the compiler to crash
+  --> $DIR/link-ordinal-invalid-format.rs:1:12
+   |
+LL | #![feature(raw_dylib)]
+   |            ^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+
+error: illegal ordinal format in `link_ordinal`
+  --> $DIR/link-ordinal-invalid-format.rs:6:5
+   |
+LL |     #[link_ordinal("JustMonika")]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: an unsuffixed integer value, e.g., `1`, is expected
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs
new file mode 100644
index 00000000000..69596ad04ff
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs
@@ -0,0 +1,11 @@
+#![feature(raw_dylib)]
+//~^ WARN the feature `raw_dylib` is incomplete and may cause the compiler to crash
+
+#[link(name="foo")]
+extern {
+    #[link_ordinal(18446744073709551616)]
+    //~^ ERROR ordinal value in `link_ordinal` is too large: `18446744073709551616`
+    fn foo();
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr
new file mode 100644
index 00000000000..b3b22f9776d
--- /dev/null
+++ b/src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr
@@ -0,0 +1,18 @@
+warning: the feature `raw_dylib` is incomplete and may cause the compiler to crash
+  --> $DIR/link-ordinal-too-large.rs:1:12
+   |
+LL | #![feature(raw_dylib)]
+   |            ^^^^^^^^^
+   |
+   = note: `#[warn(incomplete_features)]` on by default
+
+error: ordinal value in `link_ordinal` is too large: `18446744073709551616`
+  --> $DIR/link-ordinal-too-large.rs:6:5
+   |
+LL |     #[link_ordinal(18446744073709551616)]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the value may not exceed `std::usize::MAX`
+
+error: aborting due to previous error
+