Skip to content

Commit 59f551a

Browse files
committed
Auto merge of #84840 - Dylan-DPC:rollup-uzk7w0h, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #84072 (Allow setting `target_family` to multiple values, and implement `target_family="wasm"`) - #84744 (Add ErrorKind::OutOfMemory) - #84784 (Add help message to suggest const for unused type param) - #84811 (RustDoc: Fix bounds linking trait.Foo instead of traitalias.Foo) - #84818 (suggestion for unit enum variant when matched with a patern) - #84832 (Do not print visibility in external traits) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8a8ed07 + 83c49d0 commit 59f551a

File tree

67 files changed

+383
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+383
-94
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+31-12
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,19 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
819819
_ => false,
820820
};
821821

822+
let find_span = |source: &PathSource<'_>, err: &mut DiagnosticBuilder<'_>| {
823+
match source {
824+
PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. }))
825+
| PathSource::TupleStruct(span, _) => {
826+
// We want the main underline to cover the suggested code as well for
827+
// cleaner output.
828+
err.set_span(*span);
829+
*span
830+
}
831+
_ => span,
832+
}
833+
};
834+
822835
let mut bad_struct_syntax_suggestion = |def_id: DefId| {
823836
let (followed_by_brace, closing_brace) = self.followed_by_brace(span);
824837

@@ -862,18 +875,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
862875
}
863876
}
864877
PathSource::Expr(_) | PathSource::TupleStruct(..) | PathSource::Pat => {
865-
let span = match &source {
866-
PathSource::Expr(Some(Expr {
867-
span, kind: ExprKind::Call(_, _), ..
868-
}))
869-
| PathSource::TupleStruct(span, _) => {
870-
// We want the main underline to cover the suggested code as well for
871-
// cleaner output.
872-
err.set_span(*span);
873-
*span
874-
}
875-
_ => span,
876-
};
878+
let span = find_span(&source, err);
877879
if let Some(span) = self.def_span(def_id) {
878880
err.span_label(span, &format!("`{}` defined here", path_str));
879881
}
@@ -1047,6 +1049,23 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
10471049
) if ns == ValueNS => {
10481050
bad_struct_syntax_suggestion(def_id);
10491051
}
1052+
(Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id), _) if ns == ValueNS => {
1053+
match source {
1054+
PathSource::Expr(_) | PathSource::TupleStruct(..) | PathSource::Pat => {
1055+
let span = find_span(&source, err);
1056+
if let Some(span) = self.def_span(def_id) {
1057+
err.span_label(span, &format!("`{}` defined here", path_str));
1058+
}
1059+
err.span_suggestion(
1060+
span,
1061+
&format!("use this syntax instead"),
1062+
format!("{path_str}"),
1063+
Applicability::MaybeIncorrect,
1064+
);
1065+
}
1066+
_ => return false,
1067+
}
1068+
}
10501069
(Res::Def(DefKind::Ctor(_, CtorKind::Fn), def_id), _) if ns == ValueNS => {
10511070
if let Some(span) = self.def_span(def_id) {
10521071
err.span_label(span, &format!("`{}` defined here", path_str));

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
816816
ret.reserve(6); // the minimum number of insertions
817817
// Target bindings.
818818
ret.insert((sym::target_os, Some(Symbol::intern(os))));
819-
if let Some(ref fam) = sess.target.os_family {
819+
for fam in &sess.target.families {
820820
ret.insert((sym::target_family, Some(Symbol::intern(fam))));
821821
if fam == "windows" {
822822
ret.insert((sym::windows, None));

compiler/rustc_target/src/spec/apple_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn opts(os: &str) -> TargetOptions {
2323
function_sections: false,
2424
dynamic_linking: true,
2525
executables: true,
26-
os_family: Some("unix".to_string()),
26+
families: vec!["unix".to_string()],
2727
is_like_osx: true,
2828
dwarf_version: Some(2),
2929
has_rpath: true,

compiler/rustc_target/src/spec/dragonfly_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "dragonfly".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
has_rpath: true,
1111
position_independent_executables: true,

compiler/rustc_target/src/spec/freebsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "freebsd".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
has_rpath: true,
1111
position_independent_executables: true,

compiler/rustc_target/src/spec/fuchsia_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn opts() -> TargetOptions {
2525
linker: Some("rust-lld".to_owned()),
2626
dynamic_linking: true,
2727
executables: true,
28-
os_family: Some("unix".to_string()),
28+
families: vec!["unix".to_string()],
2929
is_like_fuchsia: true,
3030
linker_is_gnu: true,
3131
pre_link_args,

compiler/rustc_target/src/spec/haiku_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "haiku".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
relro_level: RelroLevel::Full,
1010
linker_is_gnu: true,
1111
..Default::default()

compiler/rustc_target/src/spec/illumos_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn opts() -> TargetOptions {
2020
dynamic_linking: true,
2121
executables: true,
2222
has_rpath: true,
23-
os_family: Some("unix".to_string()),
23+
families: vec!["unix".to_string()],
2424
is_like_solaris: true,
2525
limit_rdylib_exports: false, // Linker doesn't support this
2626
eliminate_frame_pointer: false,

compiler/rustc_target/src/spec/l4re_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn opts() -> TargetOptions {
2020
executables: true,
2121
panic_strategy: PanicStrategy::Abort,
2222
linker: Some("ld".to_string()),
23-
os_family: Some("unix".to_string()),
23+
families: vec!["unix".to_string()],
2424
..Default::default()
2525
}
2626
}

compiler/rustc_target/src/spec/linux_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "linux".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
has_rpath: true,
1111
position_independent_executables: true,

compiler/rustc_target/src/spec/mod.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,12 @@ pub struct TargetOptions {
10421042
pub staticlib_prefix: String,
10431043
/// String to append to the name of every static library. Defaults to ".a".
10441044
pub staticlib_suffix: String,
1045-
/// OS family to use for conditional compilation. Valid options: "unix", "windows".
1046-
pub os_family: Option<String>,
1045+
/// Values of the `target_family` cfg set for this target.
1046+
///
1047+
/// Common options are: "unix", "windows". Defaults to no families.
1048+
///
1049+
/// See <https://doc.rust-lang.org/reference/conditional-compilation.html#target_family>.
1050+
pub families: Vec<String>,
10471051
/// Whether the target toolchain's ABI supports returning small structs as an integer.
10481052
pub abi_return_struct_as_int: bool,
10491053
/// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS,
@@ -1293,7 +1297,7 @@ impl Default for TargetOptions {
12931297
exe_suffix: String::new(),
12941298
staticlib_prefix: "lib".to_string(),
12951299
staticlib_suffix: ".a".to_string(),
1296-
os_family: None,
1300+
families: Vec::new(),
12971301
abi_return_struct_as_int: false,
12981302
is_like_osx: false,
12991303
is_like_solaris: false,
@@ -1605,14 +1609,6 @@ impl Target {
16051609
.map(|s| s.to_string() );
16061610
}
16071611
} );
1608-
($key_name:ident = $json_name:expr, optional) => ( {
1609-
let name = $json_name;
1610-
if let Some(o) = obj.find(name) {
1611-
base.$key_name = o
1612-
.as_string()
1613-
.map(|s| s.to_string() );
1614-
}
1615-
} );
16161612
($key_name:ident, LldFlavor) => ( {
16171613
let name = (stringify!($key_name)).replace("_", "-");
16181614
obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| {
@@ -1759,6 +1755,16 @@ impl Target {
17591755
Some(Ok(()))
17601756
})).unwrap_or(Ok(()))
17611757
} );
1758+
($key_name:ident, TargetFamilies) => ( {
1759+
let value = obj.find("target-family");
1760+
if let Some(v) = value.and_then(Json::as_array) {
1761+
base.$key_name = v.iter()
1762+
.map(|a| a.as_string().unwrap().to_string())
1763+
.collect();
1764+
} else if let Some(v) = value.and_then(Json::as_string) {
1765+
base.$key_name = vec![v.to_string()];
1766+
}
1767+
} );
17621768
}
17631769

17641770
if let Some(s) = obj.find("target-endian").and_then(Json::as_string) {
@@ -1802,7 +1808,7 @@ impl Target {
18021808
key!(exe_suffix);
18031809
key!(staticlib_prefix);
18041810
key!(staticlib_suffix);
1805-
key!(os_family = "target-family", optional);
1811+
key!(families, TargetFamilies);
18061812
key!(abi_return_struct_as_int, bool);
18071813
key!(is_like_osx, bool);
18081814
key!(is_like_solaris, bool);
@@ -2042,7 +2048,7 @@ impl ToJson for Target {
20422048
target_option_val!(exe_suffix);
20432049
target_option_val!(staticlib_prefix);
20442050
target_option_val!(staticlib_suffix);
2045-
target_option_val!(os_family, "target-family");
2051+
target_option_val!(families, "target-family");
20462052
target_option_val!(abi_return_struct_as_int);
20472053
target_option_val!(is_like_osx);
20482054
target_option_val!(is_like_solaris);

compiler/rustc_target/src/spec/netbsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "netbsd".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
no_default_libraries: false,
1111
has_rpath: true,

compiler/rustc_target/src/spec/openbsd_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions {
55
os: "openbsd".to_string(),
66
dynamic_linking: true,
77
executables: true,
8-
os_family: Some("unix".to_string()),
8+
families: vec!["unix".to_string()],
99
linker_is_gnu: true,
1010
has_rpath: true,
1111
abi_return_struct_as_int: true,

compiler/rustc_target/src/spec/redox_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn opts() -> TargetOptions {
66
env: "relibc".to_string(),
77
dynamic_linking: true,
88
executables: true,
9-
os_family: Some("unix".to_string()),
9+
families: vec!["unix".to_string()],
1010
linker_is_gnu: true,
1111
has_rpath: true,
1212
position_independent_executables: true,

compiler/rustc_target/src/spec/solaris_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn opts() -> TargetOptions {
66
dynamic_linking: true,
77
executables: true,
88
has_rpath: true,
9-
os_family: Some("unix".to_string()),
9+
families: vec!["unix".to_string()],
1010
is_like_solaris: true,
1111
limit_rdylib_exports: false, // Linker doesn't support this
1212
eh_frame_header: false,

compiler/rustc_target/src/spec/vxworks_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn opts() -> TargetOptions {
99
exe_suffix: ".vxe".to_string(),
1010
dynamic_linking: true,
1111
executables: true,
12-
os_family: Some("unix".to_string()),
12+
families: vec!["unix".to_string()],
1313
linker_is_gnu: true,
1414
has_rpath: true,
1515
has_elf_tls: true,

compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn target() -> Target {
3838
is_like_emscripten: true,
3939
panic_strategy: PanicStrategy::Unwind,
4040
post_link_args,
41-
os_family: Some("unix".to_string()),
41+
families: vec!["unix".to_string()],
4242
..options
4343
};
4444
Target {

compiler/rustc_target/src/spec/wasm_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub fn options() -> TargetOptions {
6161

6262
TargetOptions {
6363
is_like_wasm: true,
64+
families: vec!["wasm".to_string()],
6465

6566
// we allow dynamic linking, but only cdylibs. Basically we allow a
6667
// final library artifact that exports some symbols (a wasm module) but

compiler/rustc_target/src/spec/windows_gnu_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn opts() -> TargetOptions {
7171
dll_prefix: String::new(),
7272
dll_suffix: ".dll".to_string(),
7373
exe_suffix: ".exe".to_string(),
74-
os_family: Some("windows".to_string()),
74+
families: vec!["windows".to_string()],
7575
is_like_windows: true,
7676
allows_weak_linkage: false,
7777
pre_link_args,

compiler/rustc_target/src/spec/windows_msvc_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn opts() -> TargetOptions {
1313
exe_suffix: ".exe".to_string(),
1414
staticlib_prefix: String::new(),
1515
staticlib_suffix: ".lib".to_string(),
16-
os_family: Some("windows".to_string()),
16+
families: vec!["windows".to_string()],
1717
crt_static_allows_dylibs: true,
1818
crt_static_respected: true,
1919
requires_uwtable: true,

compiler/rustc_typeck/src/check/wfcheck.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1298,12 +1298,14 @@ fn check_variances_for_type_defn<'tcx>(
12981298

12991299
match param.name {
13001300
hir::ParamName::Error => {}
1301-
_ => report_bivariance(tcx, param.span, param.name.ident().name),
1301+
_ => report_bivariance(tcx, param),
13021302
}
13031303
}
13041304
}
13051305

1306-
fn report_bivariance(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) {
1306+
fn report_bivariance(tcx: TyCtxt<'_>, param: &rustc_hir::GenericParam<'_>) {
1307+
let span = param.span;
1308+
let param_name = param.name.ident().name;
13071309
let mut err = error_392(tcx, span, param_name);
13081310

13091311
let suggested_marker_id = tcx.lang_items().phantom_data();
@@ -1318,7 +1320,14 @@ fn report_bivariance(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) {
13181320
format!("consider removing `{}` or referring to it in a field", param_name)
13191321
};
13201322
err.help(&msg);
1321-
err.emit();
1323+
1324+
if matches!(param.kind, rustc_hir::GenericParamKind::Type { .. }) {
1325+
err.help(&format!(
1326+
"if you intended `{0}` to be a const parameter, use `const {0}: usize` instead",
1327+
param_name
1328+
));
1329+
}
1330+
err.emit()
13221331
}
13231332

13241333
/// Feature gates RFC 2056 -- trivial bounds, checking for global bounds that

library/std/src/io/error.rs

+6
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ pub enum ErrorKind {
186186
/// This means that the operation can never succeed.
187187
#[stable(feature = "unsupported_error", since = "1.53.0")]
188188
Unsupported,
189+
190+
/// An operation could not be completed, because it failed
191+
/// to allocate enough memory.
192+
#[stable(feature = "out_of_memory_error", since = "1.53.0")]
193+
OutOfMemory,
189194
}
190195

191196
impl ErrorKind {
@@ -210,6 +215,7 @@ impl ErrorKind {
210215
ErrorKind::Other => "other os error",
211216
ErrorKind::UnexpectedEof => "unexpected end of file",
212217
ErrorKind::Unsupported => "unsupported",
218+
ErrorKind::OutOfMemory => "out of memory",
213219
}
214220
}
215221
}

library/std/src/sys/unix/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
149149
libc::ETIMEDOUT => ErrorKind::TimedOut,
150150
libc::EEXIST => ErrorKind::AlreadyExists,
151151
libc::ENOSYS => ErrorKind::Unsupported,
152+
libc::ENOMEM => ErrorKind::OutOfMemory,
152153

153154
// These two constants can have the same value on some systems,
154155
// but different values on others, so we can't use a match

library/std/src/sys/wasi/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
7777
wasi::ERRNO_EXIST => AlreadyExists,
7878
wasi::ERRNO_AGAIN => WouldBlock,
7979
wasi::ERRNO_NOSYS => Unsupported,
80+
wasi::ERRNO_NOMEM => OutOfMemory,
8081
_ => Other,
8182
}
8283
}

library/std/src/sys/windows/c.rs

+2
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ pub const ERROR_FILE_NOT_FOUND: DWORD = 2;
168168
pub const ERROR_PATH_NOT_FOUND: DWORD = 3;
169169
pub const ERROR_ACCESS_DENIED: DWORD = 5;
170170
pub const ERROR_INVALID_HANDLE: DWORD = 6;
171+
pub const ERROR_NOT_ENOUGH_MEMORY: DWORD = 8;
172+
pub const ERROR_OUTOFMEMORY: DWORD = 14;
171173
pub const ERROR_NO_MORE_FILES: DWORD = 18;
172174
pub const ERROR_HANDLE_EOF: DWORD = 38;
173175
pub const ERROR_FILE_EXISTS: DWORD = 80;

library/std/src/sys/windows/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind {
7171
c::ERROR_PATH_NOT_FOUND => return ErrorKind::NotFound,
7272
c::ERROR_NO_DATA => return ErrorKind::BrokenPipe,
7373
c::ERROR_INVALID_PARAMETER => return ErrorKind::InvalidInput,
74+
c::ERROR_NOT_ENOUGH_MEMORY | c::ERROR_OUTOFMEMORY => return ErrorKind::OutOfMemory,
7475
c::ERROR_SEM_TIMEOUT
7576
| c::WAIT_TIMEOUT
7677
| c::ERROR_DRIVER_CANCEL_TIMEOUT

0 commit comments

Comments
 (0)