Skip to content

Commit e3cb9ea

Browse files
committed
Auto merge of #65178 - Centril:rollup-ep1zztj, r=Centril
Rollup of 4 pull requests Successful merges: - #63948 (Add feature gate for raw_dylib.) - #65137 (remove event that causes panics in measureme tools) - #65164 (Add long error explanation for E0566) - #65173 (Update reference) Failed merges: r? @ghost
2 parents f92f3c4 + 68a4cfc commit e3cb9ea

24 files changed

+246
-11
lines changed

src/doc/reference

src/librustc/error_codes.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,27 @@ To understand better how closures work in Rust, read:
17001700
https://doc.rust-lang.org/book/ch13-01-closures.html
17011701
"##,
17021702

1703+
E0566: r##"
1704+
Conflicting representation hints have been used on a same item.
1705+
1706+
Erroneous code example:
1707+
1708+
```
1709+
#[repr(u32, u64)] // warning!
1710+
enum Repr { A }
1711+
```
1712+
1713+
In most cases (if not all), using just one representation hint is more than
1714+
enough. If you want to have a representation hint depending on the current
1715+
architecture, use `cfg_attr`. Example:
1716+
1717+
```
1718+
#[cfg_attr(linux, repr(u32))]
1719+
#[cfg_attr(not(linux), repr(u64))]
1720+
enum Repr { A }
1721+
```
1722+
"##,
1723+
17031724
E0580: r##"
17041725
The `main` function was incorrectly declared.
17051726
@@ -2097,7 +2118,6 @@ rejected in your own crates.
20972118
E0490, // a value of type `..` is borrowed for too long
20982119
E0495, // cannot infer an appropriate lifetime due to conflicting
20992120
// requirements
2100-
E0566, // conflicting representation hints
21012121
E0623, // lifetime mismatch where both parameters are anonymous regions
21022122
E0628, // generators cannot have explicit parameters
21032123
E0631, // type mismatch in closure arguments

src/librustc/hir/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,11 @@ pub struct CodegenFnAttrs {
26692669
/// probably isn't set when this is set, this is for foreign items while
26702670
/// `#[export_name]` is for Rust-defined functions.
26712671
pub link_name: Option<Symbol>,
2672+
/// The `#[link_ordinal = "..."]` attribute, indicating an ordinal an
2673+
/// imported function has in the dynamic library. Note that this must not
2674+
/// be set when `link_name` is set. This is for foreign items with the
2675+
/// "raw-dylib" kind.
2676+
pub link_ordinal: Option<usize>,
26722677
/// The `#[target_feature(enable = "...")]` attribute and the enabled
26732678
/// features (only enabled features are supported right now).
26742679
pub target_features: Vec<Symbol>,
@@ -2728,6 +2733,7 @@ impl CodegenFnAttrs {
27282733
optimize: OptimizeAttr::None,
27292734
export_name: None,
27302735
link_name: None,
2736+
link_ordinal: None,
27312737
target_features: vec![],
27322738
linkage: None,
27332739
link_section: None,

src/librustc/middle/cstore.rs

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ pub enum NativeLibraryKind {
9696
NativeStaticNobundle,
9797
/// macOS-specific
9898
NativeFramework,
99+
/// Windows dynamic library without import library.
100+
NativeRawDylib,
99101
/// default way to specify a dynamic library
100102
NativeUnknown,
101103
}

src/librustc_codegen_ssa/back/link.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(sess: &'a Session,
323323
NativeLibraryKind::NativeStatic => {}
324324
NativeLibraryKind::NativeStaticNobundle |
325325
NativeLibraryKind::NativeFramework |
326+
NativeLibraryKind::NativeRawDylib |
326327
NativeLibraryKind::NativeUnknown => continue,
327328
}
328329
if let Some(name) = lib.name {
@@ -883,7 +884,8 @@ pub fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary
883884
Some(format!("-framework {}", name))
884885
},
885886
// These are included, no need to print them
886-
NativeLibraryKind::NativeStatic => None,
887+
NativeLibraryKind::NativeStatic |
888+
NativeLibraryKind::NativeRawDylib => None,
887889
}
888890
})
889891
.collect();
@@ -1293,7 +1295,11 @@ pub fn add_local_native_libraries(cmd: &mut dyn Linker,
12931295
NativeLibraryKind::NativeUnknown => cmd.link_dylib(name),
12941296
NativeLibraryKind::NativeFramework => cmd.link_framework(name),
12951297
NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(name),
1296-
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path)
1298+
NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path),
1299+
NativeLibraryKind::NativeRawDylib => {
1300+
// FIXME(#58713): Proper handling for raw dylibs.
1301+
bug!("raw_dylib feature not yet implemented");
1302+
},
12971303
}
12981304
}
12991305
}
@@ -1678,7 +1684,11 @@ pub fn add_upstream_native_libraries(
16781684
// ignore statically included native libraries here as we've
16791685
// already included them when we included the rust library
16801686
// previously
1681-
NativeLibraryKind::NativeStatic => {}
1687+
NativeLibraryKind::NativeStatic => {},
1688+
NativeLibraryKind::NativeRawDylib => {
1689+
// FIXME(#58713): Proper handling for raw dylibs.
1690+
bug!("raw_dylib feature not yet implemented");
1691+
},
16821692
}
16831693
}
16841694
}

src/librustc_codegen_ssa/back/write.rs

-4
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
324324
let (coordinator_send, coordinator_receive) = channel();
325325
let sess = tcx.sess;
326326

327-
sess.prof.generic_activity_start("codegen_and_optimize_crate");
328-
329327
let crate_name = tcx.crate_name(LOCAL_CRATE);
330328
let crate_hash = tcx.crate_hash(LOCAL_CRATE);
331329
let no_builtins = attr::contains_name(&tcx.hir().krate().attrs, sym::no_builtins);
@@ -1777,8 +1775,6 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
17771775
self.backend.print_pass_timings()
17781776
}
17791777

1780-
sess.prof.generic_activity_end("codegen_and_optimize_crate");
1781-
17821778
(CodegenResults {
17831779
crate_name: self.crate_name,
17841780
crate_hash: self.crate_hash,

src/librustc_metadata/cstore_impl.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ pub fn provide(providers: &mut Providers<'_>) {
270270
// resolve! Does this work? Unsure! That's what the issue is about
271271
*providers = Providers {
272272
is_dllimport_foreign_item: |tcx, id| {
273-
tcx.native_library_kind(id) == Some(NativeLibraryKind::NativeUnknown)
273+
match tcx.native_library_kind(id) {
274+
Some(NativeLibraryKind::NativeUnknown) |
275+
Some(NativeLibraryKind::NativeRawDylib) => true,
276+
_ => false,
277+
}
274278
},
275279
is_statically_included_foreign_item: |tcx, id| {
276280
match tcx.native_library_kind(id) {

src/librustc_metadata/native_libs.rs

+9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
7373
"static-nobundle" => cstore::NativeStaticNobundle,
7474
"dylib" => cstore::NativeUnknown,
7575
"framework" => cstore::NativeFramework,
76+
"raw-dylib" => cstore::NativeRawDylib,
7677
k => {
7778
struct_span_err!(self.tcx.sess, item.span(), E0458,
7879
"unknown kind: `{}`", k)
@@ -169,6 +170,14 @@ impl Collector<'tcx> {
169170
GateIssue::Language,
170171
"kind=\"static-nobundle\" is unstable");
171172
}
173+
if lib.kind == cstore::NativeRawDylib &&
174+
!self.tcx.features().raw_dylib {
175+
feature_gate::emit_feature_err(&self.tcx.sess.parse_sess,
176+
sym::raw_dylib,
177+
span.unwrap_or_else(|| syntax_pos::DUMMY_SP),
178+
GateIssue::Language,
179+
"kind=\"raw-dylib\" is unstable");
180+
}
172181
self.libs.push(lib);
173182
}
174183

src/librustc_typeck/collect.rs

+53
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
25602560
let whitelist = tcx.target_features_whitelist(LOCAL_CRATE);
25612561

25622562
let mut inline_span = None;
2563+
let mut link_ordinal_span = None;
25632564
for attr in attrs.iter() {
25642565
if attr.check_name(sym::cold) {
25652566
codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD;
@@ -2641,6 +2642,11 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
26412642
}
26422643
} else if attr.check_name(sym::link_name) {
26432644
codegen_fn_attrs.link_name = attr.value_str();
2645+
} else if attr.check_name(sym::link_ordinal) {
2646+
link_ordinal_span = Some(attr.span);
2647+
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {
2648+
codegen_fn_attrs.link_ordinal = ordinal;
2649+
}
26442650
}
26452651
}
26462652

@@ -2718,6 +2724,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27182724
// purpose functions as they wouldn't have the right target features
27192725
// enabled. For that reason we also forbid #[inline(always)] as it can't be
27202726
// respected.
2727+
27212728
if codegen_fn_attrs.target_features.len() > 0 {
27222729
if codegen_fn_attrs.inline == InlineAttr::Always {
27232730
if let Some(span) = inline_span {
@@ -2742,6 +2749,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27422749
codegen_fn_attrs.export_name = Some(name);
27432750
codegen_fn_attrs.link_name = Some(name);
27442751
}
2752+
check_link_name_xor_ordinal(tcx, &codegen_fn_attrs, link_ordinal_span);
27452753

27462754
// Internal symbols to the standard library all have no_mangle semantics in
27472755
// that they have defined symbol names present in the function name. This
@@ -2752,3 +2760,48 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27522760

27532761
codegen_fn_attrs
27542762
}
2763+
2764+
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<usize> {
2765+
use syntax::ast::{Lit, LitIntType, LitKind};
2766+
let meta_item_list = attr.meta_item_list();
2767+
let meta_item_list: Option<&[ast::NestedMetaItem]> = meta_item_list.as_ref().map(Vec::as_ref);
2768+
let sole_meta_list = match meta_item_list {
2769+
Some([item]) => item.literal(),
2770+
_ => None,
2771+
};
2772+
if let Some(Lit { kind: LitKind::Int(ordinal, LitIntType::Unsuffixed), .. }) = sole_meta_list {
2773+
if *ordinal <= std::usize::MAX as u128 {
2774+
Some(*ordinal as usize)
2775+
} else {
2776+
let msg = format!(
2777+
"ordinal value in `link_ordinal` is too large: `{}`",
2778+
&ordinal
2779+
);
2780+
tcx.sess.struct_span_err(attr.span, &msg)
2781+
.note("the value may not exceed `std::usize::MAX`")
2782+
.emit();
2783+
None
2784+
}
2785+
} else {
2786+
tcx.sess.struct_span_err(attr.span, "illegal ordinal format in `link_ordinal`")
2787+
.note("an unsuffixed integer value, e.g., `1`, is expected")
2788+
.emit();
2789+
None
2790+
}
2791+
}
2792+
2793+
fn check_link_name_xor_ordinal(
2794+
tcx: TyCtxt<'_>,
2795+
codegen_fn_attrs: &CodegenFnAttrs,
2796+
inline_span: Option<Span>,
2797+
) {
2798+
if codegen_fn_attrs.link_name.is_none() || codegen_fn_attrs.link_ordinal.is_none() {
2799+
return;
2800+
}
2801+
let msg = "cannot use `#[link_name]` with `#[link_ordinal]`";
2802+
if let Some(span) = inline_span {
2803+
tcx.sess.span_err(span, msg);
2804+
} else {
2805+
tcx.sess.err(msg);
2806+
}
2807+
}

src/libsyntax/feature_gate/active.rs

+4
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ declare_features! (
522522
/// Allows the definition of `const extern fn` and `const unsafe extern fn`.
523523
(active, const_extern_fn, "1.40.0", Some(64926), None),
524524

525+
// Allows the use of raw-dylibs (RFC 2627).
526+
(active, raw_dylib, "1.40.0", Some(58713), None),
527+
525528
// -------------------------------------------------------------------------
526529
// feature-group-end: actual feature gates
527530
// -------------------------------------------------------------------------
@@ -536,4 +539,5 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
536539
sym::const_generics,
537540
sym::or_patterns,
538541
sym::let_chains,
542+
sym::raw_dylib,
539543
];

src/libsyntax/feature_gate/builtin_attrs.rs

+4
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
276276
"the `link_args` attribute is experimental and not portable across platforms, \
277277
it is recommended to use `#[link(name = \"foo\")] instead",
278278
),
279+
gated!(
280+
link_ordinal, Whitelisted, template!(List: "ordinal"), raw_dylib,
281+
experimental!(link_ordinal)
282+
),
279283

280284
// Plugins:
281285
(

src/libsyntax_pos/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ symbols! {
389389
link_cfg,
390390
link_llvm_intrinsics,
391391
link_name,
392+
link_ordinal,
392393
link_section,
393394
LintPass,
394395
lint_reasons,
@@ -531,6 +532,7 @@ symbols! {
531532
RangeInclusive,
532533
RangeTo,
533534
RangeToInclusive,
535+
raw_dylib,
534536
raw_identifiers,
535537
Ready,
536538
reason,

src/test/ui/conflicting-repr-hints.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ LL | | }
6666

6767
error: aborting due to 8 previous errors
6868

69+
For more information about this error, try `rustc --explain E0566`.

src/test/ui/feature-gates/feature-gate-repr-simd.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ LL | #[repr(simd)]
2626

2727
error: aborting due to 2 previous errors
2828

29-
For more information about this error, try `rustc --explain E0658`.
29+
Some errors have detailed explanations: E0566, E0658.
30+
For more information about an error, try `rustc --explain E0566`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[link(name="foo")]
2+
extern {
3+
#[link_ordinal(42)]
4+
//~^ ERROR: the `#[link_ordinal]` attribute is an experimental feature
5+
fn foo();
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: the `#[link_ordinal]` attribute is an experimental feature
2+
--> $DIR/feature-gate-raw-dylib-2.rs:3:5
3+
|
4+
LL | #[link_ordinal(42)]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/58713
8+
= help: add `#![feature(raw_dylib)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[link(name="foo", kind="raw-dylib")]
2+
//~^ ERROR: kind="raw-dylib" is unstable
3+
extern {}
4+
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: kind="raw-dylib" is unstable
2+
--> $DIR/feature-gate-raw-dylib.rs:1:1
3+
|
4+
LL | #[link(name="foo", kind="raw-dylib")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/58713
8+
= help: add `#![feature(raw_dylib)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(raw_dylib)]
2+
//~^ WARN the feature `raw_dylib` is incomplete and may cause the compiler to crash
3+
4+
#[link(name="foo")]
5+
extern {
6+
#[link_name="foo"]
7+
#[link_ordinal(42)]
8+
//~^ ERROR cannot use `#[link_name]` with `#[link_ordinal]`
9+
fn foo();
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: the feature `raw_dylib` is incomplete and may cause the compiler to crash
2+
--> $DIR/link-ordinal-and-name.rs:1:12
3+
|
4+
LL | #![feature(raw_dylib)]
5+
| ^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
error: cannot use `#[link_name]` with `#[link_ordinal]`
10+
--> $DIR/link-ordinal-and-name.rs:7:5
11+
|
12+
LL | #[link_ordinal(42)]
13+
| ^^^^^^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(raw_dylib)]
2+
//~^ WARN the feature `raw_dylib` is incomplete and may cause the compiler to crash
3+
4+
#[link(name="foo")]
5+
extern {
6+
#[link_ordinal("JustMonika")]
7+
//~^ ERROR illegal ordinal format in `link_ordinal`
8+
fn foo();
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)