mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
Add more tests, fix span issue, improve diagnostics.
This commit is contained in:
parent
eb492455f2
commit
dda10f2a2a
@ -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
|
||||
}
|
||||
}
|
||||
|
12
src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.rs
Normal file
12
src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.rs
Normal file
@ -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() {}
|
16
src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.stderr
Normal file
16
src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.stderr
Normal file
@ -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
|
||||
|
@ -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() {}
|
@ -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
|
||||
|
11
src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs
Normal file
11
src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.rs
Normal file
@ -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() {}
|
18
src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr
Normal file
18
src/test/ui/rfc-2627-raw-dylib/link-ordinal-too-large.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user