From 4afea69090b5501c17b16957d090658a1b3c2216 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 10 Apr 2021 23:22:58 +0300 Subject: [PATCH 1/9] Allow setting `target_family` to multiple values This enables us to set more generic labels shared between targets. For example `target_family="wasm"` across all targets that are conceptually "wasm". See https://github.com/rust-lang/reference/pull/1006 --- compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_target/src/spec/apple_base.rs | 2 +- .../rustc_target/src/spec/dragonfly_base.rs | 2 +- .../rustc_target/src/spec/freebsd_base.rs | 2 +- .../rustc_target/src/spec/fuchsia_base.rs | 2 +- compiler/rustc_target/src/spec/haiku_base.rs | 2 +- .../rustc_target/src/spec/illumos_base.rs | 2 +- compiler/rustc_target/src/spec/l4re_base.rs | 2 +- compiler/rustc_target/src/spec/linux_base.rs | 2 +- compiler/rustc_target/src/spec/mod.rs | 32 +++++++++++-------- compiler/rustc_target/src/spec/netbsd_base.rs | 2 +- .../rustc_target/src/spec/openbsd_base.rs | 2 +- compiler/rustc_target/src/spec/redox_base.rs | 2 +- .../rustc_target/src/spec/solaris_base.rs | 2 +- .../rustc_target/src/spec/vxworks_base.rs | 2 +- .../src/spec/wasm32_unknown_emscripten.rs | 2 +- .../rustc_target/src/spec/windows_gnu_base.rs | 2 +- .../src/spec/windows_msvc_base.rs | 2 +- 18 files changed, 36 insertions(+), 30 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b6b349e4a803d..ad26c73162c90 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -813,7 +813,7 @@ pub fn default_configuration(sess: &Session) -> CrateConfig { ret.reserve(6); // the minimum number of insertions // Target bindings. ret.insert((sym::target_os, Some(Symbol::intern(os)))); - if let Some(ref fam) = sess.target.os_family { + for fam in &sess.target.families { ret.insert((sym::target_family, Some(Symbol::intern(fam)))); if fam == "windows" { ret.insert((sym::windows, None)); diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs index 6fa0b34545097..bc2ec6709011a 100644 --- a/compiler/rustc_target/src/spec/apple_base.rs +++ b/compiler/rustc_target/src/spec/apple_base.rs @@ -23,7 +23,7 @@ pub fn opts(os: &str) -> TargetOptions { function_sections: false, dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], is_like_osx: true, dwarf_version: Some(2), has_rpath: true, diff --git a/compiler/rustc_target/src/spec/dragonfly_base.rs b/compiler/rustc_target/src/spec/dragonfly_base.rs index dd0170987824a..fb94498c131fd 100644 --- a/compiler/rustc_target/src/spec/dragonfly_base.rs +++ b/compiler/rustc_target/src/spec/dragonfly_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "dragonfly".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/freebsd_base.rs b/compiler/rustc_target/src/spec/freebsd_base.rs index ad3383cc5f261..5d3c28e5f29c9 100644 --- a/compiler/rustc_target/src/spec/freebsd_base.rs +++ b/compiler/rustc_target/src/spec/freebsd_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "freebsd".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/fuchsia_base.rs b/compiler/rustc_target/src/spec/fuchsia_base.rs index 2b925f8b946c4..13264dffeb4ed 100644 --- a/compiler/rustc_target/src/spec/fuchsia_base.rs +++ b/compiler/rustc_target/src/spec/fuchsia_base.rs @@ -25,7 +25,7 @@ pub fn opts() -> TargetOptions { linker: Some("rust-lld".to_owned()), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], is_like_fuchsia: true, linker_is_gnu: true, pre_link_args, diff --git a/compiler/rustc_target/src/spec/haiku_base.rs b/compiler/rustc_target/src/spec/haiku_base.rs index 956e4ed4bf9c8..fae56f6a82dc8 100644 --- a/compiler/rustc_target/src/spec/haiku_base.rs +++ b/compiler/rustc_target/src/spec/haiku_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "haiku".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], relro_level: RelroLevel::Full, linker_is_gnu: true, ..Default::default() diff --git a/compiler/rustc_target/src/spec/illumos_base.rs b/compiler/rustc_target/src/spec/illumos_base.rs index d9b5716c04185..2e365d210f3f6 100644 --- a/compiler/rustc_target/src/spec/illumos_base.rs +++ b/compiler/rustc_target/src/spec/illumos_base.rs @@ -20,7 +20,7 @@ pub fn opts() -> TargetOptions { dynamic_linking: true, executables: true, has_rpath: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], is_like_solaris: true, limit_rdylib_exports: false, // Linker doesn't support this eliminate_frame_pointer: false, diff --git a/compiler/rustc_target/src/spec/l4re_base.rs b/compiler/rustc_target/src/spec/l4re_base.rs index db6b74eff6dbd..65c343a5f2169 100644 --- a/compiler/rustc_target/src/spec/l4re_base.rs +++ b/compiler/rustc_target/src/spec/l4re_base.rs @@ -20,7 +20,7 @@ pub fn opts() -> TargetOptions { executables: true, panic_strategy: PanicStrategy::Abort, linker: Some("ld".to_string()), - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], ..Default::default() } } diff --git a/compiler/rustc_target/src/spec/linux_base.rs b/compiler/rustc_target/src/spec/linux_base.rs index eeefd056e4b74..184659e22d986 100644 --- a/compiler/rustc_target/src/spec/linux_base.rs +++ b/compiler/rustc_target/src/spec/linux_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "linux".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 57b0a36e009ef..2223237143b8f 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1042,8 +1042,12 @@ pub struct TargetOptions { pub staticlib_prefix: String, /// String to append to the name of every static library. Defaults to ".a". pub staticlib_suffix: String, - /// OS family to use for conditional compilation. Valid options: "unix", "windows". - pub os_family: Option, + /// Values of the `target_family` cfg set for this target. + /// + /// Common options are: "unix", "windows". Defaults to no families. + /// + /// See https://doc.rust-lang.org/reference/conditional-compilation.html#target_family + pub families: Vec, /// Whether the target toolchain's ABI supports returning small structs as an integer. pub abi_return_struct_as_int: bool, /// Whether the target toolchain is like macOS's. Only useful for compiling against iOS/macOS, @@ -1293,7 +1297,7 @@ impl Default for TargetOptions { exe_suffix: String::new(), staticlib_prefix: "lib".to_string(), staticlib_suffix: ".a".to_string(), - os_family: None, + families: Vec::new(), abi_return_struct_as_int: false, is_like_osx: false, is_like_solaris: false, @@ -1605,14 +1609,6 @@ impl Target { .map(|s| s.to_string() ); } } ); - ($key_name:ident = $json_name:expr, optional) => ( { - let name = $json_name; - if let Some(o) = obj.find(name) { - base.$key_name = o - .as_string() - .map(|s| s.to_string() ); - } - } ); ($key_name:ident, LldFlavor) => ( { let name = (stringify!($key_name)).replace("_", "-"); obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| { @@ -1759,6 +1755,16 @@ impl Target { Some(Ok(())) })).unwrap_or(Ok(())) } ); + ($key_name:ident, TargetFamilies) => ( { + let value = obj.find("target-family"); + if let Some(v) = value.and_then(Json::as_array) { + base.$key_name = v.iter() + .map(|a| a.as_string().unwrap().to_string()) + .collect(); + } else if let Some(v) = value.and_then(Json::as_string) { + base.$key_name = vec![v.to_string()]; + } + } ); } if let Some(s) = obj.find("target-endian").and_then(Json::as_string) { @@ -1802,7 +1808,7 @@ impl Target { key!(exe_suffix); key!(staticlib_prefix); key!(staticlib_suffix); - key!(os_family = "target-family", optional); + key!(families, TargetFamilies); key!(abi_return_struct_as_int, bool); key!(is_like_osx, bool); key!(is_like_solaris, bool); @@ -2042,7 +2048,7 @@ impl ToJson for Target { target_option_val!(exe_suffix); target_option_val!(staticlib_prefix); target_option_val!(staticlib_suffix); - target_option_val!(os_family, "target-family"); + target_option_val!(families, "target-family"); target_option_val!(abi_return_struct_as_int); target_option_val!(is_like_osx); target_option_val!(is_like_solaris); diff --git a/compiler/rustc_target/src/spec/netbsd_base.rs b/compiler/rustc_target/src/spec/netbsd_base.rs index 680cd60788bde..602fb6eb6413b 100644 --- a/compiler/rustc_target/src/spec/netbsd_base.rs +++ b/compiler/rustc_target/src/spec/netbsd_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "netbsd".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, no_default_libraries: false, has_rpath: true, diff --git a/compiler/rustc_target/src/spec/openbsd_base.rs b/compiler/rustc_target/src/spec/openbsd_base.rs index a6fd01ab110df..8f33bacd9228e 100644 --- a/compiler/rustc_target/src/spec/openbsd_base.rs +++ b/compiler/rustc_target/src/spec/openbsd_base.rs @@ -5,7 +5,7 @@ pub fn opts() -> TargetOptions { os: "openbsd".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, abi_return_struct_as_int: true, diff --git a/compiler/rustc_target/src/spec/redox_base.rs b/compiler/rustc_target/src/spec/redox_base.rs index 0afb4a72ac14f..72052b9e2e2e3 100644 --- a/compiler/rustc_target/src/spec/redox_base.rs +++ b/compiler/rustc_target/src/spec/redox_base.rs @@ -6,7 +6,7 @@ pub fn opts() -> TargetOptions { env: "relibc".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/compiler/rustc_target/src/spec/solaris_base.rs b/compiler/rustc_target/src/spec/solaris_base.rs index 59731f25821ff..4c922eb5cea55 100644 --- a/compiler/rustc_target/src/spec/solaris_base.rs +++ b/compiler/rustc_target/src/spec/solaris_base.rs @@ -6,7 +6,7 @@ pub fn opts() -> TargetOptions { dynamic_linking: true, executables: true, has_rpath: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], is_like_solaris: true, limit_rdylib_exports: false, // Linker doesn't support this eh_frame_header: false, diff --git a/compiler/rustc_target/src/spec/vxworks_base.rs b/compiler/rustc_target/src/spec/vxworks_base.rs index 41c4d7625af2a..0e8e87f2dff5c 100644 --- a/compiler/rustc_target/src/spec/vxworks_base.rs +++ b/compiler/rustc_target/src/spec/vxworks_base.rs @@ -9,7 +9,7 @@ pub fn opts() -> TargetOptions { exe_suffix: ".vxe".to_string(), dynamic_linking: true, executables: true, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], linker_is_gnu: true, has_rpath: true, has_elf_tls: true, diff --git a/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs b/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs index e028dbaa32520..ddf28b423f0d2 100644 --- a/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs +++ b/compiler/rustc_target/src/spec/wasm32_unknown_emscripten.rs @@ -38,7 +38,7 @@ pub fn target() -> Target { is_like_emscripten: true, panic_strategy: PanicStrategy::Unwind, post_link_args, - os_family: Some("unix".to_string()), + families: vec!["unix".to_string()], ..options }; Target { diff --git a/compiler/rustc_target/src/spec/windows_gnu_base.rs b/compiler/rustc_target/src/spec/windows_gnu_base.rs index 478c567a93b25..35a52896f6fa6 100644 --- a/compiler/rustc_target/src/spec/windows_gnu_base.rs +++ b/compiler/rustc_target/src/spec/windows_gnu_base.rs @@ -71,7 +71,7 @@ pub fn opts() -> TargetOptions { dll_prefix: String::new(), dll_suffix: ".dll".to_string(), exe_suffix: ".exe".to_string(), - os_family: Some("windows".to_string()), + families: vec!["windows".to_string()], is_like_windows: true, allows_weak_linkage: false, pre_link_args, diff --git a/compiler/rustc_target/src/spec/windows_msvc_base.rs b/compiler/rustc_target/src/spec/windows_msvc_base.rs index c041245e32862..0d58618a449a9 100644 --- a/compiler/rustc_target/src/spec/windows_msvc_base.rs +++ b/compiler/rustc_target/src/spec/windows_msvc_base.rs @@ -13,7 +13,7 @@ pub fn opts() -> TargetOptions { exe_suffix: ".exe".to_string(), staticlib_prefix: String::new(), staticlib_suffix: ".lib".to_string(), - os_family: Some("windows".to_string()), + families: vec!["windows".to_string()], crt_static_allows_dylibs: true, crt_static_respected: true, requires_uwtable: true, From 50c86db4facf516d2248b81d56f7ee4e8381b6da Mon Sep 17 00:00:00 2001 From: kadmin Date: Sat, 1 May 2021 04:39:50 +0000 Subject: [PATCH 2/9] Add help message for unused type param --- compiler/rustc_typeck/src/check/wfcheck.rs | 15 ++++++++++++--- ...t-param-type-depends-on-type-param.full.stderr | 1 + ...st-param-type-depends-on-type-param.min.stderr | 1 + .../ui/const-generics/issue-67375.full.stderr | 1 + src/test/ui/const-generics/issue-67375.min.stderr | 1 + .../ui/const-generics/issue-67945-1.full.stderr | 1 + .../ui/const-generics/issue-67945-1.min.stderr | 1 + .../ui/const-generics/issue-67945-2.full.stderr | 1 + .../ui/const-generics/issue-67945-2.min.stderr | 1 + .../unused-type-param-suggestion.rs | 4 ++++ .../unused-type-param-suggestion.stderr | 12 ++++++++++++ .../issue-70453-generics-in-discr-ice.stderr | 1 + src/test/ui/enum/issue-67945-1.stderr | 1 + src/test/ui/enum/issue-67945-2.stderr | 1 + src/test/ui/error-codes/E0392.stderr | 1 + src/test/ui/inner-static-type-parameter.stderr | 1 + src/test/ui/issues/issue-17904-2.stderr | 1 + src/test/ui/issues/issue-20413.stderr | 1 + src/test/ui/issues/issue-36299.stderr | 1 + src/test/ui/issues/issue-36638.stderr | 1 + src/test/ui/issues/issue-37534.stderr | 1 + .../ui/variance/variance-unused-type-param.stderr | 3 +++ 22 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/const-generics/unused-type-param-suggestion.rs create mode 100644 src/test/ui/const-generics/unused-type-param-suggestion.stderr diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index d25dd9a6e8302..4914f196afbb5 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -1298,12 +1298,14 @@ fn check_variances_for_type_defn<'tcx>( match param.name { hir::ParamName::Error => {} - _ => report_bivariance(tcx, param.span, param.name.ident().name), + _ => report_bivariance(tcx, param), } } } -fn report_bivariance(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) { +fn report_bivariance(tcx: TyCtxt<'_>, param: &rustc_hir::GenericParam<'_>) { + let span = param.span; + let param_name = param.name.ident().name; let mut err = error_392(tcx, span, param_name); let suggested_marker_id = tcx.lang_items().phantom_data(); @@ -1318,7 +1320,14 @@ fn report_bivariance(tcx: TyCtxt<'_>, span: Span, param_name: Symbol) { format!("consider removing `{}` or referring to it in a field", param_name) }; err.help(&msg); - err.emit(); + + if matches!(param.kind, rustc_hir::GenericParamKind::Type { .. }) { + err.help(&format!( + "if you intended `{0}` to be a const parameter, use `const {0}: usize` instead", + param_name + )); + } + err.emit() } /// Feature gates RFC 2056 -- trivial bounds, checking for global bounds that diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param.full.stderr b/src/test/ui/const-generics/const-param-type-depends-on-type-param.full.stderr index a83ee627187b5..32f7dea82639b 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param.full.stderr +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param.full.stderr @@ -11,6 +11,7 @@ LL | pub struct Dependent([(); X]); | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param.min.stderr b/src/test/ui/const-generics/const-param-type-depends-on-type-param.min.stderr index a83ee627187b5..32f7dea82639b 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param.min.stderr +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param.min.stderr @@ -11,6 +11,7 @@ LL | pub struct Dependent([(); X]); | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issue-67375.full.stderr b/src/test/ui/const-generics/issue-67375.full.stderr index 2f004f75de56c..0fe65272f1b78 100644 --- a/src/test/ui/const-generics/issue-67375.full.stderr +++ b/src/test/ui/const-generics/issue-67375.full.stderr @@ -15,6 +15,7 @@ LL | struct Bug { | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/const-generics/issue-67375.min.stderr b/src/test/ui/const-generics/issue-67375.min.stderr index 337e7bc14099d..be81fa921297b 100644 --- a/src/test/ui/const-generics/issue-67375.min.stderr +++ b/src/test/ui/const-generics/issue-67375.min.stderr @@ -14,6 +14,7 @@ LL | struct Bug { | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issue-67945-1.full.stderr b/src/test/ui/const-generics/issue-67945-1.full.stderr index 5cdcefe35015f..63c50b5ca5423 100644 --- a/src/test/ui/const-generics/issue-67945-1.full.stderr +++ b/src/test/ui/const-generics/issue-67945-1.full.stderr @@ -19,6 +19,7 @@ LL | struct Bug { | ^ unused parameter | = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `S` to be a const parameter, use `const S: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issue-67945-1.min.stderr b/src/test/ui/const-generics/issue-67945-1.min.stderr index a3e086ea95486..074d36c8ef3ed 100644 --- a/src/test/ui/const-generics/issue-67945-1.min.stderr +++ b/src/test/ui/const-generics/issue-67945-1.min.stderr @@ -23,6 +23,7 @@ LL | struct Bug { | ^ unused parameter | = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `S` to be a const parameter, use `const S: usize` instead error: aborting due to 3 previous errors diff --git a/src/test/ui/const-generics/issue-67945-2.full.stderr b/src/test/ui/const-generics/issue-67945-2.full.stderr index 4d96058b395b2..b900406023117 100644 --- a/src/test/ui/const-generics/issue-67945-2.full.stderr +++ b/src/test/ui/const-generics/issue-67945-2.full.stderr @@ -19,6 +19,7 @@ LL | struct Bug { | ^ unused parameter | = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `S` to be a const parameter, use `const S: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issue-67945-2.min.stderr b/src/test/ui/const-generics/issue-67945-2.min.stderr index 860be4a9b6ac9..c06df79f8428c 100644 --- a/src/test/ui/const-generics/issue-67945-2.min.stderr +++ b/src/test/ui/const-generics/issue-67945-2.min.stderr @@ -23,6 +23,7 @@ LL | struct Bug { | ^ unused parameter | = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `S` to be a const parameter, use `const S: usize` instead error: aborting due to 3 previous errors diff --git a/src/test/ui/const-generics/unused-type-param-suggestion.rs b/src/test/ui/const-generics/unused-type-param-suggestion.rs new file mode 100644 index 0000000000000..2251512c4596e --- /dev/null +++ b/src/test/ui/const-generics/unused-type-param-suggestion.rs @@ -0,0 +1,4 @@ +#![crate_type="lib"] + +struct Example; +//~^ ERROR parameter diff --git a/src/test/ui/const-generics/unused-type-param-suggestion.stderr b/src/test/ui/const-generics/unused-type-param-suggestion.stderr new file mode 100644 index 0000000000000..807065ca109e5 --- /dev/null +++ b/src/test/ui/const-generics/unused-type-param-suggestion.stderr @@ -0,0 +1,12 @@ +error[E0392]: parameter `N` is never used + --> $DIR/unused-type-param-suggestion.rs:3:16 + | +LL | struct Example; + | ^ unused parameter + | + = help: consider removing `N`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `N` to be a const parameter, use `const N: usize` instead + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0392`. diff --git a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr index 1d43903928bef..f89be630eeb30 100644 --- a/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr +++ b/src/test/ui/enum-discriminant/issue-70453-generics-in-discr-ice.stderr @@ -14,6 +14,7 @@ LL | enum MyWeirdOption { | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/enum/issue-67945-1.stderr b/src/test/ui/enum/issue-67945-1.stderr index 32ca94203e630..227899e75350f 100644 --- a/src/test/ui/enum/issue-67945-1.stderr +++ b/src/test/ui/enum/issue-67945-1.stderr @@ -14,6 +14,7 @@ LL | enum Bug { | ^ unused parameter | = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `S` to be a const parameter, use `const S: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/enum/issue-67945-2.stderr b/src/test/ui/enum/issue-67945-2.stderr index a738d3b15a557..5a90f00c346d0 100644 --- a/src/test/ui/enum/issue-67945-2.stderr +++ b/src/test/ui/enum/issue-67945-2.stderr @@ -14,6 +14,7 @@ LL | enum Bug { | ^ unused parameter | = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `S` to be a const parameter, use `const S: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/error-codes/E0392.stderr b/src/test/ui/error-codes/E0392.stderr index 860bf68f0189b..622402999c348 100644 --- a/src/test/ui/error-codes/E0392.stderr +++ b/src/test/ui/error-codes/E0392.stderr @@ -5,6 +5,7 @@ LL | enum Foo { Bar } | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to previous error diff --git a/src/test/ui/inner-static-type-parameter.stderr b/src/test/ui/inner-static-type-parameter.stderr index 990e4649a5817..e4e449e4159b6 100644 --- a/src/test/ui/inner-static-type-parameter.stderr +++ b/src/test/ui/inner-static-type-parameter.stderr @@ -13,6 +13,7 @@ LL | enum Bar { What } | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-17904-2.stderr b/src/test/ui/issues/issue-17904-2.stderr index 62b7b79538c61..259e029113d50 100644 --- a/src/test/ui/issues/issue-17904-2.stderr +++ b/src/test/ui/issues/issue-17904-2.stderr @@ -5,6 +5,7 @@ LL | struct Foo where T: Copy; | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to previous error diff --git a/src/test/ui/issues/issue-20413.stderr b/src/test/ui/issues/issue-20413.stderr index 7fb1e3f2bba4f..6bcff7aff2dc4 100644 --- a/src/test/ui/issues/issue-20413.stderr +++ b/src/test/ui/issues/issue-20413.stderr @@ -5,6 +5,7 @@ LL | struct NoData; | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error[E0275]: overflow evaluating the requirement `NoData>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo` --> $DIR/issue-20413.rs:8:36 diff --git a/src/test/ui/issues/issue-36299.stderr b/src/test/ui/issues/issue-36299.stderr index 8e29a925d8044..dc24fb353f408 100644 --- a/src/test/ui/issues/issue-36299.stderr +++ b/src/test/ui/issues/issue-36299.stderr @@ -13,6 +13,7 @@ LL | struct Foo<'a, A> {} | ^ unused parameter | = help: consider removing `A`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `A` to be a const parameter, use `const A: usize` instead error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-36638.stderr b/src/test/ui/issues/issue-36638.stderr index e5d6f8ec7adeb..733fc4af534f7 100644 --- a/src/test/ui/issues/issue-36638.stderr +++ b/src/test/ui/issues/issue-36638.stderr @@ -17,6 +17,7 @@ LL | struct Foo(Self); | ^^^^ unused parameter | = help: consider removing `Self`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `Self` to be a const parameter, use `const Self: usize` instead error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-37534.stderr b/src/test/ui/issues/issue-37534.stderr index 895479986f1d1..82bb51028c977 100644 --- a/src/test/ui/issues/issue-37534.stderr +++ b/src/test/ui/issues/issue-37534.stderr @@ -22,6 +22,7 @@ LL | struct Foo { } | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to 2 previous errors; 1 warning emitted diff --git a/src/test/ui/variance/variance-unused-type-param.stderr b/src/test/ui/variance/variance-unused-type-param.stderr index a4d636bc03c76..270233c0c9772 100644 --- a/src/test/ui/variance/variance-unused-type-param.stderr +++ b/src/test/ui/variance/variance-unused-type-param.stderr @@ -5,6 +5,7 @@ LL | struct SomeStruct { x: u32 } | ^ unused parameter | = help: consider removing `A`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `A` to be a const parameter, use `const A: usize` instead error[E0392]: parameter `A` is never used --> $DIR/variance-unused-type-param.rs:9:15 @@ -13,6 +14,7 @@ LL | enum SomeEnum { Nothing } | ^ unused parameter | = help: consider removing `A`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `A` to be a const parameter, use `const A: usize` instead error[E0392]: parameter `T` is never used --> $DIR/variance-unused-type-param.rs:13:15 @@ -21,6 +23,7 @@ LL | enum ListCell { | ^ unused parameter | = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: usize` instead error: aborting due to 3 previous errors From fe540ae1bb13d3838d1d5c78b546d96b4d44797e Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 1 May 2021 21:39:59 -0700 Subject: [PATCH 3/9] RustDoc: Fix bounds linking trait.Foo instead of traitalias.Foo --- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 7 +++- src/librustdoc/formats/cache.rs | 46 +++++++++++++++++-------- src/test/rustdoc/trait-alias-mention.rs | 9 +++++ src/test/rustdoc/trait_alias.rs | 2 ++ 5 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 src/test/rustdoc/trait-alias-mention.rs diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 3e89c1ac4c514..4660ac17b279f 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -188,7 +188,7 @@ crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) if did.is_local() { cx.cache.exact_paths.insert(did, fqn); } else { - cx.cache.external_paths.insert(did, (fqn, ItemType::from(kind))); + cx.cache.external_paths.insert(did, (fqn, kind)); } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6563f398edb6f..2c6bade11fb95 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -157,7 +157,12 @@ impl Clean for hir::GenericBound<'_> { impl Clean for (ty::TraitRef<'_>, &[TypeBinding]) { fn clean(&self, cx: &mut DocContext<'_>) -> Type { let (trait_ref, bounds) = *self; - inline::record_extern_fqn(cx, trait_ref.def_id, ItemType::Trait); + let kind = match cx.tcx.def_kind(trait_ref.def_id) { + DefKind::Trait => ItemType::Trait, + DefKind::TraitAlias => ItemType::TraitAlias, + other => bug!("`TraitRef` had unexpected kind {:?}", other), + }; + inline::record_extern_fqn(cx, trait_ref.def_id, kind); let path = external_path( cx, cx.tcx.item_name(trait_ref.def_id), diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 8f8bca64e1497..a023400a436fd 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -340,6 +340,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { | clean::EnumItem(..) | clean::TypedefItem(..) | clean::TraitItem(..) + | clean::TraitAliasItem(..) | clean::FunctionItem(..) | clean::ModuleItem(..) | clean::ForeignFunctionItem(..) @@ -350,26 +351,43 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { | clean::ForeignTypeItem | clean::MacroItem(..) | clean::ProcMacroItem(..) - | clean::VariantItem(..) - if !self.cache.stripped_mod => - { - // Re-exported items mean that the same id can show up twice - // in the rustdoc ast that we're looking at. We know, - // however, that a re-exported item doesn't show up in the - // `public_items` map, so we can skip inserting into the - // paths map if there was already an entry present and we're - // not a public item. - if !self.cache.paths.contains_key(&item.def_id) - || self.cache.access_levels.is_public(item.def_id) - { - self.cache.paths.insert(item.def_id, (self.cache.stack.clone(), item.type_())); + | clean::VariantItem(..) => { + if !self.cache.stripped_mod { + // Re-exported items mean that the same id can show up twice + // in the rustdoc ast that we're looking at. We know, + // however, that a re-exported item doesn't show up in the + // `public_items` map, so we can skip inserting into the + // paths map if there was already an entry present and we're + // not a public item. + if !self.cache.paths.contains_key(&item.def_id) + || self.cache.access_levels.is_public(item.def_id) + { + self.cache + .paths + .insert(item.def_id, (self.cache.stack.clone(), item.type_())); + } } } clean::PrimitiveItem(..) => { self.cache.paths.insert(item.def_id, (self.cache.stack.clone(), item.type_())); } - _ => {} + clean::ExternCrateItem { .. } + | clean::ImportItem(..) + | clean::OpaqueTyItem(..) + | clean::ImplItem(..) + | clean::TyMethodItem(..) + | clean::MethodItem(..) + | clean::StructFieldItem(..) + | clean::AssocConstItem(..) + | clean::AssocTypeItem(..) + | clean::StrippedItem(..) + | clean::KeywordItem(..) => { + // FIXME: Do these need handling? + // The person writing this comment doesn't know. + // So would rather leave them to an expert, + // as at least the list is better than `_ => {}`. + } } // Maintain the parent stack diff --git a/src/test/rustdoc/trait-alias-mention.rs b/src/test/rustdoc/trait-alias-mention.rs new file mode 100644 index 0000000000000..dea72cdb5fbbd --- /dev/null +++ b/src/test/rustdoc/trait-alias-mention.rs @@ -0,0 +1,9 @@ +#![feature(trait_alias)] +#![feature(ptr_metadata)] + +#![crate_name = "foo"] + +// @has foo/fn.this_never_panics.html '//a[@title="traitalias core::ptr::metadata::Thin"]' 'Thin' +pub fn this_never_panics() { + assert_eq!(std::mem::size_of::<&T>(), std::mem::size_of::()) +} diff --git a/src/test/rustdoc/trait_alias.rs b/src/test/rustdoc/trait_alias.rs index 98b8d879ac078..6cd4a1a0afa08 100644 --- a/src/test/rustdoc/trait_alias.rs +++ b/src/test/rustdoc/trait_alias.rs @@ -19,3 +19,5 @@ pub trait CopyAlias = Copy; pub trait Alias2 = Copy + Debug; // @has foo/traitalias.Foo.html '//section[@id="main"]/pre' 'trait Foo = Into + Debug;' pub trait Foo = Into + Debug; +// @has foo/fn.bar.html '//a[@href="traitalias.Alias2.html"]' 'Alias2' +pub fn bar() where T: Alias2 {} From 541c8d898ea96f2475fa752e29d2e2fbe5593643 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 30 Apr 2021 12:15:38 +0100 Subject: [PATCH 4/9] Add ErrorKind::OutOfMemory --- library/std/src/io/error.rs | 6 ++++++ src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed | 3 ++- src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs | 1 + src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 9bed12bf2ae2b..ae896d1240ea5 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -186,6 +186,11 @@ pub enum ErrorKind { /// This means that the operation can never succeed. #[stable(feature = "unsupported_error", since = "1.53.0")] Unsupported, + + /// An operation could not be completed, because it failed + /// to allocate enough memory. + #[stable(feature = "out_of_memory_error", since = "1.53.0")] + OutOfMemory, } impl ErrorKind { @@ -210,6 +215,7 @@ impl ErrorKind { ErrorKind::Other => "other os error", ErrorKind::UnexpectedEof => "unexpected end of file", ErrorKind::Unsupported => "unsupported", + ErrorKind::OutOfMemory => "out of memory", } } } diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed index 129d82652d759..5ad27bb14501f 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed @@ -77,7 +77,7 @@ fn main() { let error_kind = ErrorKind::NotFound; match error_kind { ErrorKind::NotFound => {}, - ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | _ => {}, + ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | ErrorKind::OutOfMemory | _ => {}, } match error_kind { ErrorKind::NotFound => {}, @@ -99,6 +99,7 @@ fn main() { ErrorKind::Other => {}, ErrorKind::UnexpectedEof => {}, ErrorKind::Unsupported => {}, + ErrorKind::OutOfMemory => {}, _ => {}, } } diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs index 028ecb63e7e6d..adca0738bba5b 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.rs @@ -99,6 +99,7 @@ fn main() { ErrorKind::Other => {}, ErrorKind::UnexpectedEof => {}, ErrorKind::Unsupported => {}, + ErrorKind::OutOfMemory => {}, _ => {}, } } diff --git a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr index fd45cad00d6b5..73f6a4a80c960 100644 --- a/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr +++ b/src/tools/clippy/tests/ui/wildcard_enum_match_arm.stderr @@ -32,7 +32,7 @@ error: wildcard matches known variants and will also match future added variants --> $DIR/wildcard_enum_match_arm.rs:80:9 | LL | _ => {}, - | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | _` + | ^ help: try this: `ErrorKind::PermissionDenied | ErrorKind::ConnectionRefused | ErrorKind::ConnectionReset | ErrorKind::ConnectionAborted | ErrorKind::NotConnected | ErrorKind::AddrInUse | ErrorKind::AddrNotAvailable | ErrorKind::BrokenPipe | ErrorKind::AlreadyExists | ErrorKind::WouldBlock | ErrorKind::InvalidInput | ErrorKind::InvalidData | ErrorKind::TimedOut | ErrorKind::WriteZero | ErrorKind::Interrupted | ErrorKind::Other | ErrorKind::UnexpectedEof | ErrorKind::Unsupported | ErrorKind::OutOfMemory | _` error: aborting due to 5 previous errors From 19568f9a8368c9f433d8f73d9eed59eb6ad24651 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 30 Apr 2021 12:34:32 +0100 Subject: [PATCH 5/9] Use ErrorKind::OutOfMemory in unix, windows, and wasi --- library/std/src/sys/unix/mod.rs | 1 + library/std/src/sys/wasi/mod.rs | 1 + library/std/src/sys/windows/c.rs | 2 ++ library/std/src/sys/windows/mod.rs | 1 + 4 files changed, 5 insertions(+) diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs index 6c4fbaf27344b..562d9d92637a6 100644 --- a/library/std/src/sys/unix/mod.rs +++ b/library/std/src/sys/unix/mod.rs @@ -149,6 +149,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { libc::ETIMEDOUT => ErrorKind::TimedOut, libc::EEXIST => ErrorKind::AlreadyExists, libc::ENOSYS => ErrorKind::Unsupported, + libc::ENOMEM => ErrorKind::OutOfMemory, // These two constants can have the same value on some systems, // but different values on others, so we can't use a match diff --git a/library/std/src/sys/wasi/mod.rs b/library/std/src/sys/wasi/mod.rs index 37f74fcc052e3..88b81d455d241 100644 --- a/library/std/src/sys/wasi/mod.rs +++ b/library/std/src/sys/wasi/mod.rs @@ -77,6 +77,7 @@ pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { wasi::ERRNO_EXIST => AlreadyExists, wasi::ERRNO_AGAIN => WouldBlock, wasi::ERRNO_NOSYS => Unsupported, + wasi::ERRNO_NOMEM => OutOfMemory, _ => Other, } } diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 3e4176ef7f8fe..7ea6048e94a88 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -168,6 +168,8 @@ pub const ERROR_FILE_NOT_FOUND: DWORD = 2; pub const ERROR_PATH_NOT_FOUND: DWORD = 3; pub const ERROR_ACCESS_DENIED: DWORD = 5; pub const ERROR_INVALID_HANDLE: DWORD = 6; +pub const ERROR_NOT_ENOUGH_MEMORY: DWORD = 8; +pub const ERROR_OUTOFMEMORY: DWORD = 14; pub const ERROR_NO_MORE_FILES: DWORD = 18; pub const ERROR_HANDLE_EOF: DWORD = 38; pub const ERROR_FILE_EXISTS: DWORD = 80; diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index ddb6ac5f55c0d..2208ff025c0f7 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -71,6 +71,7 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { c::ERROR_PATH_NOT_FOUND => return ErrorKind::NotFound, c::ERROR_NO_DATA => return ErrorKind::BrokenPipe, c::ERROR_INVALID_PARAMETER => return ErrorKind::InvalidInput, + c::ERROR_NOT_ENOUGH_MEMORY | c::ERROR_OUTOFMEMORY => return ErrorKind::OutOfMemory, c::ERROR_SEM_TIMEOUT | c::WAIT_TIMEOUT | c::ERROR_DRIVER_CANCEL_TIMEOUT From 5cc21d9051e421cab8ca271115b9a6d5ea927679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Sun, 2 May 2021 11:46:29 +0200 Subject: [PATCH 6/9] add suggestion for unit enum variant when matched with a patern --- .../rustc_resolve/src/late/diagnostics.rs | 43 +++++--- .../ui/empty/empty-struct-unit-pat.stderr | 102 +++++++++++++++--- src/test/ui/issues/issue-32004.stderr | 5 +- src/test/ui/issues/issue-pr29383.stderr | 10 +- .../match-pattern-field-mismatch-2.stderr | 5 +- .../ui/pattern/pattern-error-continue.stderr | 16 ++- src/test/ui/suggestions/issue-84700.rs | 26 +++++ src/test/ui/suggestions/issue-84700.stderr | 21 ++++ 8 files changed, 193 insertions(+), 35 deletions(-) create mode 100644 src/test/ui/suggestions/issue-84700.rs create mode 100644 src/test/ui/suggestions/issue-84700.stderr diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index e33c374f562e2..7561b3df3af70 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -819,6 +819,19 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { _ => false, }; + let find_span = |source: &PathSource<'_>, err: &mut DiagnosticBuilder<'_>| { + match source { + PathSource::Expr(Some(Expr { span, kind: ExprKind::Call(_, _), .. })) + | PathSource::TupleStruct(span, _) => { + // We want the main underline to cover the suggested code as well for + // cleaner output. + err.set_span(*span); + *span + } + _ => span, + } + }; + let mut bad_struct_syntax_suggestion = |def_id: DefId| { let (followed_by_brace, closing_brace) = self.followed_by_brace(span); @@ -862,18 +875,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { } } PathSource::Expr(_) | PathSource::TupleStruct(..) | PathSource::Pat => { - let span = match &source { - PathSource::Expr(Some(Expr { - span, kind: ExprKind::Call(_, _), .. - })) - | PathSource::TupleStruct(span, _) => { - // We want the main underline to cover the suggested code as well for - // cleaner output. - err.set_span(*span); - *span - } - _ => span, - }; + let span = find_span(&source, err); if let Some(span) = self.def_span(def_id) { err.span_label(span, &format!("`{}` defined here", path_str)); } @@ -1047,6 +1049,23 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { ) if ns == ValueNS => { bad_struct_syntax_suggestion(def_id); } + (Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id), _) if ns == ValueNS => { + match source { + PathSource::Expr(_) | PathSource::TupleStruct(..) | PathSource::Pat => { + let span = find_span(&source, err); + if let Some(span) = self.def_span(def_id) { + err.span_label(span, &format!("`{}` defined here", path_str)); + } + err.span_suggestion( + span, + &format!("use this syntax instead"), + format!("{path_str}"), + Applicability::MaybeIncorrect, + ); + } + _ => return false, + } + } (Res::Def(DefKind::Ctor(_, CtorKind::Fn), def_id), _) if ns == ValueNS => { if let Some(span) = self.def_span(def_id) { err.span_label(span, &format!("`{}` defined here", path_str)); diff --git a/src/test/ui/empty/empty-struct-unit-pat.stderr b/src/test/ui/empty/empty-struct-unit-pat.stderr index 8ee14a3d01d89..a704e1fae497c 100644 --- a/src/test/ui/empty/empty-struct-unit-pat.stderr +++ b/src/test/ui/empty/empty-struct-unit-pat.stderr @@ -1,84 +1,154 @@ error[E0532]: expected tuple struct or tuple variant, found unit struct `Empty2` --> $DIR/empty-struct-unit-pat.rs:21:9 | +LL | struct Empty2; + | -------------- `Empty2` defined here +... LL | Empty2() => () - | ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6` + | ^^^^^^^^ | ::: $DIR/auxiliary/empty-struct.rs:3:1 | LL | pub struct XEmpty6(); | --------------------- similarly named tuple struct `XEmpty6` defined here + | +help: use this syntax instead + | +LL | Empty2 => () + | ^^^^^^ +help: a tuple struct with a similar name exists + | +LL | XEmpty6() => () + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found unit struct `XEmpty2` --> $DIR/empty-struct-unit-pat.rs:24:9 | LL | XEmpty2() => () - | ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6` + | ^^^^^^^^^ | - ::: $DIR/auxiliary/empty-struct.rs:3:1 + ::: $DIR/auxiliary/empty-struct.rs:2:1 | +LL | pub struct XEmpty2; + | ------------------- `XEmpty2` defined here LL | pub struct XEmpty6(); | --------------------- similarly named tuple struct `XEmpty6` defined here + | +help: use this syntax instead + | +LL | XEmpty2 => () + | ^^^^^^^ +help: a tuple struct with a similar name exists + | +LL | XEmpty6() => () + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found unit struct `Empty2` --> $DIR/empty-struct-unit-pat.rs:28:9 | +LL | struct Empty2; + | -------------- `Empty2` defined here +... LL | Empty2(..) => () - | ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6` + | ^^^^^^^^^^ | ::: $DIR/auxiliary/empty-struct.rs:3:1 | LL | pub struct XEmpty6(); | --------------------- similarly named tuple struct `XEmpty6` defined here + | +help: use this syntax instead + | +LL | Empty2 => () + | ^^^^^^ +help: a tuple struct with a similar name exists + | +LL | XEmpty6(..) => () + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found unit struct `XEmpty2` --> $DIR/empty-struct-unit-pat.rs:32:9 | LL | XEmpty2(..) => () - | ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6` + | ^^^^^^^^^^^ | - ::: $DIR/auxiliary/empty-struct.rs:3:1 + ::: $DIR/auxiliary/empty-struct.rs:2:1 | +LL | pub struct XEmpty2; + | ------------------- `XEmpty2` defined here LL | pub struct XEmpty6(); | --------------------- similarly named tuple struct `XEmpty6` defined here + | +help: use this syntax instead + | +LL | XEmpty2 => () + | ^^^^^^^ +help: a tuple struct with a similar name exists + | +LL | XEmpty6(..) => () + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found unit variant `E::Empty4` --> $DIR/empty-struct-unit-pat.rs:37:9 | +LL | Empty4 + | ------ `E::Empty4` defined here +... LL | E::Empty4() => () - | ^^^^^^^^^ not a tuple struct or tuple variant + | ^^^^^^^^^^^ help: use this syntax instead: `E::Empty4` error[E0532]: expected tuple struct or tuple variant, found unit variant `XE::XEmpty4` --> $DIR/empty-struct-unit-pat.rs:41:9 | LL | XE::XEmpty4() => (), - | ^^^^------- - | | - | help: a tuple variant with a similar name exists: `XEmpty5` + | ^^^^^^^^^^^^^ | - ::: $DIR/auxiliary/empty-struct.rs:8:5 + ::: $DIR/auxiliary/empty-struct.rs:7:5 | +LL | XEmpty4, + | ------- `XE::XEmpty4` defined here LL | XEmpty5(), | --------- similarly named tuple variant `XEmpty5` defined here + | +help: use this syntax instead + | +LL | XE::XEmpty4 => (), + | ^^^^^^^^^^^ +help: a tuple variant with a similar name exists + | +LL | XE::XEmpty5() => (), + | ^^^^^^^ error[E0532]: expected tuple struct or tuple variant, found unit variant `E::Empty4` --> $DIR/empty-struct-unit-pat.rs:46:9 | +LL | Empty4 + | ------ `E::Empty4` defined here +... LL | E::Empty4(..) => () - | ^^^^^^^^^ not a tuple struct or tuple variant + | ^^^^^^^^^^^^^ help: use this syntax instead: `E::Empty4` error[E0532]: expected tuple struct or tuple variant, found unit variant `XE::XEmpty4` --> $DIR/empty-struct-unit-pat.rs:50:9 | LL | XE::XEmpty4(..) => (), - | ^^^^------- - | | - | help: a tuple variant with a similar name exists: `XEmpty5` + | ^^^^^^^^^^^^^^^ | - ::: $DIR/auxiliary/empty-struct.rs:8:5 + ::: $DIR/auxiliary/empty-struct.rs:7:5 | +LL | XEmpty4, + | ------- `XE::XEmpty4` defined here LL | XEmpty5(), | --------- similarly named tuple variant `XEmpty5` defined here + | +help: use this syntax instead + | +LL | XE::XEmpty4 => (), + | ^^^^^^^^^^^ +help: a tuple variant with a similar name exists + | +LL | XE::XEmpty5(..) => (), + | ^^^^^^^ error: aborting due to 8 previous errors diff --git a/src/test/ui/issues/issue-32004.stderr b/src/test/ui/issues/issue-32004.stderr index f95afb9c1fdc7..bf125a8942edf 100644 --- a/src/test/ui/issues/issue-32004.stderr +++ b/src/test/ui/issues/issue-32004.stderr @@ -21,8 +21,11 @@ LL | Foo::Baz => {} error[E0532]: expected tuple struct or tuple variant, found unit struct `S` --> $DIR/issue-32004.rs:16:9 | +LL | struct S; + | --------- `S` defined here +... LL | S(()) => {} - | ^ not a tuple struct or tuple variant + | ^^^^^ help: use this syntax instead: `S` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-pr29383.stderr b/src/test/ui/issues/issue-pr29383.stderr index e92fd6c2fdc5a..57783d75ba182 100644 --- a/src/test/ui/issues/issue-pr29383.stderr +++ b/src/test/ui/issues/issue-pr29383.stderr @@ -1,14 +1,20 @@ error[E0532]: expected tuple struct or tuple variant, found unit variant `E::A` --> $DIR/issue-pr29383.rs:9:14 | +LL | A, + | - `E::A` defined here +... LL | Some(E::A(..)) => {} - | ^^^^ not a tuple struct or tuple variant + | ^^^^^^^^ help: use this syntax instead: `E::A` error[E0532]: expected tuple struct or tuple variant, found unit variant `E::B` --> $DIR/issue-pr29383.rs:11:14 | +LL | B, + | - `E::B` defined here +... LL | Some(E::B(..)) => {} - | ^^^^ not a tuple struct or tuple variant + | ^^^^^^^^ help: use this syntax instead: `E::B` error: aborting due to 2 previous errors diff --git a/src/test/ui/match/match-pattern-field-mismatch-2.stderr b/src/test/ui/match/match-pattern-field-mismatch-2.stderr index cfffcd13851b8..ba32d0e99a471 100644 --- a/src/test/ui/match/match-pattern-field-mismatch-2.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch-2.stderr @@ -1,8 +1,11 @@ error[E0532]: expected tuple struct or tuple variant, found unit variant `Color::NoColor` --> $DIR/match-pattern-field-mismatch-2.rs:12:11 | +LL | NoColor, + | ------- `Color::NoColor` defined here +... LL | Color::NoColor(_) => { } - | ^^^^^^^^^^^^^^ not a tuple struct or tuple variant + | ^^^^^^^^^^^^^^^^^ help: use this syntax instead: `Color::NoColor` error: aborting due to previous error diff --git a/src/test/ui/pattern/pattern-error-continue.stderr b/src/test/ui/pattern/pattern-error-continue.stderr index 497c93b29497c..44d6a854b3db6 100644 --- a/src/test/ui/pattern/pattern-error-continue.stderr +++ b/src/test/ui/pattern/pattern-error-continue.stderr @@ -9,11 +9,21 @@ error[E0532]: expected tuple struct or tuple variant, found unit variant `A::D` | LL | B(isize, isize), | --------------- similarly named tuple variant `B` defined here +LL | C(isize, isize, isize), +LL | D + | - `A::D` defined here ... LL | A::D(_) => (), - | ^^^- - | | - | help: a tuple variant with a similar name exists: `B` + | ^^^^^^^ + | +help: use this syntax instead + | +LL | A::D => (), + | ^^^^ +help: a tuple variant with a similar name exists + | +LL | A::B(_) => (), + | ^ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields --> $DIR/pattern-error-continue.rs:17:9 diff --git a/src/test/ui/suggestions/issue-84700.rs b/src/test/ui/suggestions/issue-84700.rs new file mode 100644 index 0000000000000..a27169fdbb2d5 --- /dev/null +++ b/src/test/ui/suggestions/issue-84700.rs @@ -0,0 +1,26 @@ +// test for suggestion on fieldless enum variant + +#[derive(PartialEq, Debug)] +enum FarmAnimal { + Worm, + Cow, + Bull, + Chicken { num_eggs: usize }, + Dog (String), +} + +fn what_does_the_animal_say(animal: &FarmAnimal) { + + let noise = match animal { + FarmAnimal::Cow(_) => "moo".to_string(), + //~^ ERROR expected tuple struct or tuple variant, found unit variant `FarmAnimal::Cow` + FarmAnimal::Chicken(_) => "cluck, cluck!".to_string(), + //~^ ERROR expected tuple struct or tuple variant, found struct variant `FarmAnimal::Chicken` + FarmAnimal::Dog{..} => "woof!".to_string(), + _ => todo!() + }; + + println!("{:?} says: {:?}", animal, noise); +} + +fn main() {} diff --git a/src/test/ui/suggestions/issue-84700.stderr b/src/test/ui/suggestions/issue-84700.stderr new file mode 100644 index 0000000000000..b36d8aba36d30 --- /dev/null +++ b/src/test/ui/suggestions/issue-84700.stderr @@ -0,0 +1,21 @@ +error[E0532]: expected tuple struct or tuple variant, found unit variant `FarmAnimal::Cow` + --> $DIR/issue-84700.rs:15:9 + | +LL | Cow, + | --- `FarmAnimal::Cow` defined here +... +LL | FarmAnimal::Cow(_) => "moo".to_string(), + | ^^^^^^^^^^^^^^^^^^ help: use this syntax instead: `FarmAnimal::Cow` + +error[E0532]: expected tuple struct or tuple variant, found struct variant `FarmAnimal::Chicken` + --> $DIR/issue-84700.rs:17:9 + | +LL | Chicken { num_eggs: usize }, + | --------------------------- `FarmAnimal::Chicken` defined here +... +LL | FarmAnimal::Chicken(_) => "cluck, cluck!".to_string(), + | ^^^^^^^^^^^^^^^^^^^^^^ help: use struct pattern syntax instead: `FarmAnimal::Chicken { num_eggs }` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0532`. From 9ca6d5863be4ca847458a8b42e995b98406ad015 Mon Sep 17 00:00:00 2001 From: Justus K Date: Sun, 2 May 2021 19:39:33 +0200 Subject: [PATCH 7/9] Do not print visibility in external traits --- src/librustdoc/clean/inline.rs | 16 +++++++++++++--- src/test/rustdoc/auxiliary/trait-visibility.rs | 3 +++ src/test/rustdoc/trait-visibility.rs | 8 ++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/test/rustdoc/auxiliary/trait-visibility.rs create mode 100644 src/test/rustdoc/trait-visibility.rs diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 5dd9f3f1ebd34..0ff7e8c4d8319 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -19,7 +19,7 @@ use crate::clean::{self, Attributes, AttributesExt, GetDefId, ToSource}; use crate::core::DocContext; use crate::formats::item_type::ItemType; -use super::Clean; +use super::{Clean, Visibility}; type Attrs<'hir> = rustc_middle::ty::Attributes<'hir>; @@ -193,8 +193,18 @@ crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) } crate fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait { - let trait_items = - cx.tcx.associated_items(did).in_definition_order().map(|item| item.clean(cx)).collect(); + let trait_items = cx + .tcx + .associated_items(did) + .in_definition_order() + .map(|item| { + // When building an external trait, the cleaned trait will have all items public, + // which causes methods to have a `pub` prefix, which is invalid since items in traits + // can not have a visibility prefix. Thus we override the visibility here manually. + // See https://github.com/rust-lang/rust/issues/81274 + clean::Item { visibility: Visibility::Inherited, ..item.clean(cx) } + }) + .collect(); let predicates = cx.tcx.predicates_of(did); let generics = (cx.tcx.generics_of(did), predicates).clean(cx); diff --git a/src/test/rustdoc/auxiliary/trait-visibility.rs b/src/test/rustdoc/auxiliary/trait-visibility.rs new file mode 100644 index 0000000000000..1e8d0b8e02a93 --- /dev/null +++ b/src/test/rustdoc/auxiliary/trait-visibility.rs @@ -0,0 +1,3 @@ +pub trait Bar { + fn foo(); +} diff --git a/src/test/rustdoc/trait-visibility.rs b/src/test/rustdoc/trait-visibility.rs new file mode 100644 index 0000000000000..8ba3ee03a74f3 --- /dev/null +++ b/src/test/rustdoc/trait-visibility.rs @@ -0,0 +1,8 @@ +// aux-build:trait-visibility.rs + +#![crate_name = "foo"] + +extern crate trait_visibility; + +// @has foo/trait.Bar.html '//a[@href="#tymethod.foo"]/..' "fn foo()" +pub use trait_visibility::Bar; From 40ffa942444b84336b0d03f3004d7eb9ca36f8ad Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 2 May 2021 12:11:13 -0700 Subject: [PATCH 8/9] PR feedback --- src/librustdoc/clean/mod.rs | 15 +++++++++------ src/test/rustdoc/auxiliary/trait-alias-mention.rs | 3 +++ src/test/rustdoc/trait-alias-mention.rs | 11 ++++++----- 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 src/test/rustdoc/auxiliary/trait-alias-mention.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2c6bade11fb95..f71489f32311f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -17,11 +17,11 @@ use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_index::vec::{Idx, IndexVec}; use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData}; -use rustc_middle::bug; use rustc_middle::middle::resolve_lifetime as rl; use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::{self, AdtKind, Lift, Ty, TyCtxt}; +use rustc_middle::{bug, span_bug}; use rustc_mir::const_eval::{is_const_fn, is_unstable_const_fn}; use rustc_span::hygiene::{AstPass, MacroKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; @@ -157,11 +157,14 @@ impl Clean for hir::GenericBound<'_> { impl Clean for (ty::TraitRef<'_>, &[TypeBinding]) { fn clean(&self, cx: &mut DocContext<'_>) -> Type { let (trait_ref, bounds) = *self; - let kind = match cx.tcx.def_kind(trait_ref.def_id) { - DefKind::Trait => ItemType::Trait, - DefKind::TraitAlias => ItemType::TraitAlias, - other => bug!("`TraitRef` had unexpected kind {:?}", other), - }; + let kind = cx.tcx.def_kind(trait_ref.def_id).into(); + if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) { + span_bug!( + cx.tcx.def_span(trait_ref.def_id), + "`TraitRef` had unexpected kind {:?}", + kind + ); + } inline::record_extern_fqn(cx, trait_ref.def_id, kind); let path = external_path( cx, diff --git a/src/test/rustdoc/auxiliary/trait-alias-mention.rs b/src/test/rustdoc/auxiliary/trait-alias-mention.rs new file mode 100644 index 0000000000000..6df06c87a09d5 --- /dev/null +++ b/src/test/rustdoc/auxiliary/trait-alias-mention.rs @@ -0,0 +1,3 @@ +#![feature(trait_alias)] + +pub trait SomeAlias = std::fmt::Debug + std::marker::Copy; diff --git a/src/test/rustdoc/trait-alias-mention.rs b/src/test/rustdoc/trait-alias-mention.rs index dea72cdb5fbbd..6da0dc68785c5 100644 --- a/src/test/rustdoc/trait-alias-mention.rs +++ b/src/test/rustdoc/trait-alias-mention.rs @@ -1,9 +1,10 @@ -#![feature(trait_alias)] -#![feature(ptr_metadata)] +// aux-build:trait-alias-mention.rs +// build-aux-docs #![crate_name = "foo"] -// @has foo/fn.this_never_panics.html '//a[@title="traitalias core::ptr::metadata::Thin"]' 'Thin' -pub fn this_never_panics() { - assert_eq!(std::mem::size_of::<&T>(), std::mem::size_of::()) +extern crate trait_alias_mention; + +// @has foo/fn.mention_alias_in_bounds.html '//a[@href="../trait_alias_mention/traitalias.SomeAlias.html"]' 'SomeAlias' +pub fn mention_alias_in_bounds() { } From 1a491e2304387c2a50c5a0ae219e8d5a0ce1bc89 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 10 Apr 2021 23:28:58 +0300 Subject: [PATCH 9/9] Set target_family="wasm" for wasm targets --- compiler/rustc_target/src/spec/mod.rs | 2 +- compiler/rustc_target/src/spec/wasm_base.rs | 1 + src/test/ui/cfg/cfg-family.rs | 4 ++-- src/test/ui/cfg/cfg-target-family.rs | 7 +++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 2223237143b8f..3ac9b5b3d3b7f 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1046,7 +1046,7 @@ pub struct TargetOptions { /// /// Common options are: "unix", "windows". Defaults to no families. /// - /// See https://doc.rust-lang.org/reference/conditional-compilation.html#target_family + /// See . pub families: Vec, /// Whether the target toolchain's ABI supports returning small structs as an integer. pub abi_return_struct_as_int: bool, diff --git a/compiler/rustc_target/src/spec/wasm_base.rs b/compiler/rustc_target/src/spec/wasm_base.rs index b208eb92f8ff9..87e740de08e91 100644 --- a/compiler/rustc_target/src/spec/wasm_base.rs +++ b/compiler/rustc_target/src/spec/wasm_base.rs @@ -61,6 +61,7 @@ pub fn options() -> TargetOptions { TargetOptions { is_like_wasm: true, + families: vec!["wasm".to_string()], // we allow dynamic linking, but only cdylibs. Basically we allow a // final library artifact that exports some symbols (a wasm module) but diff --git a/src/test/ui/cfg/cfg-family.rs b/src/test/ui/cfg/cfg-family.rs index 912bda4b5e500..c7d196a2aa6eb 100644 --- a/src/test/ui/cfg/cfg-family.rs +++ b/src/test/ui/cfg/cfg-family.rs @@ -1,6 +1,6 @@ -// run-pass +// build-pass // pretty-expanded FIXME #23616 -// ignore-wasm32-bare no target_family +// ignore-wasm32-bare no bare family // ignore-sgx #[cfg(windows)] diff --git a/src/test/ui/cfg/cfg-target-family.rs b/src/test/ui/cfg/cfg-target-family.rs index b4dc1b738638c..90a59fab8e250 100644 --- a/src/test/ui/cfg/cfg-target-family.rs +++ b/src/test/ui/cfg/cfg-target-family.rs @@ -1,5 +1,4 @@ -// run-pass -// ignore-wasm32-bare no target_family +// build-pass // ignore-sgx // pretty-expanded FIXME #23616 @@ -11,3 +10,7 @@ pub fn main() { #[cfg(target_family = "unix")] pub fn main() { } + +#[cfg(target_family="wasm")] +pub fn main() { +}