Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #84840

Merged
merged 15 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ 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));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/dragonfly_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/freebsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/fuchsia_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/haiku_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/illumos_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/l4re_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/linux_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 19 additions & 13 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// 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<String>,
/// 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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/netbsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/openbsd_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/redox_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/solaris_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/vxworks_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/wasm_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/windows_gnu_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/spec/windows_msvc_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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",
}
}
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/sys/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading