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 9 pull requests #85452

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f429ab3
compiletest: "fix" FileCheck with --allow-unused-prefixes
durin42 May 3, 2021
c34e7c6
Fix v0 symbol mangling bug
camelid May 11, 2021
3fe1d7f
Only pass --[no-]gc-sections if linker is GNU ld.
luqmana May 13, 2021
15aad5f
bootstrap: build cargo only if requested in tools
infinity0 May 14, 2021
0daabbe
Change to just use first binders and add test
jackh726 May 15, 2021
45225d2
Windows mingw targets use gcc as the linker so the target spec should…
luqmana May 16, 2021
fbc01e5
Add abstract namespace support for Unix domain sockets
mdaverde May 11, 2021
1c08ebb
rustfmt
mdaverde May 16, 2021
253cbab
rustdoc: restore header sizes
jsha May 17, 2021
a4d0489
Update tracking issue in stability refs
mdaverde May 17, 2021
8345908
Remove legacy for trait object mangling test and replace crate hash
jackh726 May 16, 2021
3035816
runtest: correctly guard against LLVM version 13
durin42 May 17, 2021
a862b1f
Adjust linker_is_gnu branches for cases that don't work on windows.
luqmana May 17, 2021
18b0e7b
Fix must_use on `Option::is_none`
mbartlett21 May 18, 2021
e48b6b4
Stabilize extended_key_value_attributes
jyn514 Mar 22, 2021
e0d5872
Undo unnecessary changes.
luqmana May 18, 2021
ac5fd90
Don't pass -pie to linker on windows targets.
luqmana May 18, 2021
281dea4
Fix escape handling on search results
GuillaumeGomez May 18, 2021
d314b06
Add GUI tests for escape handling
GuillaumeGomez May 18, 2021
b0b0267
moves use ptr within from_abstract_namespace fn
mdaverde May 18, 2021
e4958da
Rollup merge of #83366 - jyn514:stabilize-key-value-attrs, r=petroche…
Dylan-DPC May 18, 2021
9d34ffc
Rollup merge of #83767 - camelid:mangle-v0-fix, r=nikomatsakis
Dylan-DPC May 18, 2021
cfda7f3
Rollup merge of #84883 - durin42:allow-unused-prefixes, r=nikic
Dylan-DPC May 18, 2021
9e20d98
Rollup merge of #85274 - luqmana:linker-is-gnu-gc-sections, r=petroch…
Dylan-DPC May 18, 2021
da0388d
Rollup merge of #85297 - infinity0:master, r=Mark-Simulacrum
Dylan-DPC May 18, 2021
edcaf88
Rollup merge of #85379 - mdaverde:uds-abstract, r=joshtriplett,Guilla…
Dylan-DPC May 18, 2021
8a9a7a6
Rollup merge of #85396 - jsha:top-doc-font-sizes, r=GuillaumeGomez
Dylan-DPC May 18, 2021
28d6677
Rollup merge of #85425 - mbartlett21:patch-1, r=scottmcm
Dylan-DPC May 18, 2021
c9c1068
Rollup merge of #85438 - GuillaumeGomez:fix-escape-handling, r=jsha
Dylan-DPC May 18, 2021
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
4 changes: 0 additions & 4 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(const_trait_impl, "const trait impls are experimental");
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
gate_all!(inline_const, "inline-const is experimental");
gate_all!(
extended_key_value_attributes,
"arbitrary expressions in key-value attributes are unstable"
);
gate_all!(
const_generics_defaults,
"default values for const generic parameters are experimental"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![feature(bool_to_option)]
#![feature(const_cstr_unchecked)]
#![feature(crate_visibility_modifier)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(extern_types)]
#![feature(in_band_lifetimes)]
#![feature(iter_zip)]
Expand Down
19 changes: 10 additions & 9 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ impl<'a> Linker for GccLinker<'a> {
}
}
LinkOutputKind::DynamicPicExe => {
// `-pie` works for both gcc wrapper and ld.
self.cmd.arg("-pie");
// noop on windows w/ gcc & ld, error w/ lld
if !self.sess.target.is_like_windows {
// `-pie` works for both gcc wrapper and ld.
self.cmd.arg("-pie");
}
}
LinkOutputKind::StaticNoPicExe => {
// `-static` works for both gcc wrapper and ld.
Expand Down Expand Up @@ -347,7 +350,7 @@ impl<'a> Linker for GccLinker<'a> {
// has -needed-l{} / -needed_library {}
// but we have no way to detect that here.
self.sess.warn("`as-needed` modifier not implemented yet for ld64");
} else if self.sess.target.linker_is_gnu {
} else if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
self.linker_arg("--no-as-needed");
} else {
self.sess.warn("`as-needed` modifier not supported for current linker");
Expand All @@ -358,7 +361,7 @@ impl<'a> Linker for GccLinker<'a> {
if !as_needed {
if self.sess.target.is_like_osx {
// See above FIXME comment
} else if self.sess.target.linker_is_gnu {
} else if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
self.linker_arg("--as-needed");
}
}
Expand Down Expand Up @@ -469,17 +472,15 @@ impl<'a> Linker for GccLinker<'a> {
// eliminate the metadata. If we're building an executable, however,
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
// reduction.
} else if !keep_metadata {
} else if self.sess.target.linker_is_gnu && !keep_metadata {
self.linker_arg("--gc-sections");
}
}

fn no_gc_sections(&mut self) {
if self.sess.target.is_like_osx {
self.linker_arg("-no_dead_strip");
} else if self.sess.target.is_like_solaris {
self.linker_arg("-zrecord");
} else {
} else if self.sess.target.linker_is_gnu {
self.linker_arg("--no-gc-sections");
}
}
Expand Down Expand Up @@ -692,7 +693,7 @@ impl<'a> Linker for GccLinker<'a> {
}

fn add_as_needed(&mut self) {
if self.sess.target.linker_is_gnu {
if self.sess.target.linker_is_gnu && !self.sess.target.is_like_windows {
self.linker_arg("--as-needed");
} else if self.sess.target.is_like_solaris {
// -z ignore is the Solaris equivalent to the GNU ld --as-needed option
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(crate_visibility_modifier)]
#![feature(backtrace)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(format_args_capture)]
#![feature(iter_zip)]
#![feature(nll)]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ declare_features! (
(accepted, or_patterns, "1.53.0", Some(54883), None),
/// Allows defining identifiers beyond ASCII.
(accepted, non_ascii_idents, "1.53.0", Some(55467), None),
/// Allows arbitrary expressions in key-value attributes at parse time.
(accepted, extended_key_value_attributes, "1.54.0", Some(78835), None),

// -------------------------------------------------------------------------
// feature-group-end: accepted features
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,6 @@ declare_features! (
/// Allows capturing disjoint fields in a closure/generator (RFC 2229).
(active, capture_disjoint_fields, "1.49.0", Some(53488), None),

/// Allows arbitrary expressions in key-value attributes at parse time.
(active, extended_key_value_attributes, "1.50.0", Some(78835), None),

/// Allows const generics to have default values (e.g. `struct Foo<const N: usize = 3>(...);`).
(active, const_generics_defaults, "1.51.0", Some(44580), None),

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![feature(crate_visibility_modifier)]
#![feature(const_panic)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(in_band_lifetimes)]
#![feature(once_cell)]
#![cfg_attr(bootstrap, feature(or_patterns))]
Expand Down
13 changes: 0 additions & 13 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,24 +1065,11 @@ impl<'a> Parser<'a> {
} else if !delimited_only {
if self.eat(&token::Eq) {
let eq_span = self.prev_token.span;
let mut is_interpolated_expr = false;
if let token::Interpolated(nt) = &self.token.kind {
if let token::NtExpr(..) = **nt {
is_interpolated_expr = true;
}
}

// Collect tokens because they are used during lowering to HIR.
let expr = self.parse_expr_force_collect()?;
let span = expr.span;

match &expr.kind {
// Not gated to support things like `doc = $expr` that work on stable.
_ if is_interpolated_expr => {}
ExprKind::Lit(lit) if lit.kind.is_unsuffixed() => {}
_ => self.sess.gated_spans.gate(sym::extended_key_value_attributes, span),
}

let token_kind = token::Interpolated(Lrc::new(token::NtExpr(expr)));
MacArgs::Eq(eq_span, Token::new(token_kind, span))
} else {
Expand Down
43 changes: 37 additions & 6 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,39 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
mut self,
predicates: &'tcx ty::List<ty::Binder<'tcx, ty::ExistentialPredicate<'tcx>>>,
) -> Result<Self::DynExistential, Self::Error> {
for predicate in predicates {
self = self.in_binder(&predicate, |mut cx, predicate| {
match predicate {
// Okay, so this is a bit tricky. Imagine we have a trait object like
// `dyn for<'a> Foo<'a, Bar = &'a ()>`. When we mangle this, the
// output looks really close to the syntax, where the `Bar = &'a ()` bit
// is under the same binders (`['a]`) as the `Foo<'a>` bit. However, we
// actually desugar these into two separate `ExistentialPredicate`s. We
// can't enter/exit the "binder scope" twice though, because then we
// would mangle the binders twice. (Also, side note, we merging these
// two is kind of difficult, because of potential HRTBs in the Projection
// predicate.)
//
// Also worth mentioning: imagine that we instead had
// `dyn for<'a> Foo<'a, Bar = &'a ()> + Send`. In this case, `Send` is
// under the same binders as `Foo`. Currently, this doesn't matter,
// because only *auto traits* are allowed other than the principal trait
// and all auto traits don't have any generics. Two things could
// make this not an "okay" mangling:
// 1) Instead of mangling only *used*
// bound vars, we want to mangle *all* bound vars (`for<'b> Send` is a
// valid trait predicate);
// 2) We allow multiple "principal" traits in the future, or at least
// allow in any form another trait predicate that can take generics.
//
// Here we assume that predicates have the following structure:
// [<Trait> [{<Projection>}]] [{<Auto>}]
// Since any predicates after the first one shouldn't change the binders,
// just put them all in the binders of the first.
self = self.in_binder(&predicates[0], |mut cx, _| {
for predicate in predicates.iter() {
// It would be nice to be able to validate bound vars here, but
// projections can actually include bound vars from super traits
// because of HRTBs (only in the `Self` type). Also, auto traits
// could have different bound vars *anyways*.
match predicate.as_ref().skip_binder() {
ty::ExistentialPredicate::Trait(trait_ref) => {
// Use a type that can't appear in defaults of type parameters.
let dummy_self = cx.tcx.mk_ty_infer(ty::FreshTy(0));
Expand All @@ -504,9 +534,10 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
cx = cx.print_def_path(*def_id, &[])?;
}
}
Ok(cx)
})?;
}
}
Ok(cx)
})?;

self.push("E");
Ok(self)
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/windows_gnu_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub fn opts() -> TargetOptions {
// FIXME(#13846) this should be enabled for windows
function_sections: false,
linker: Some("gcc".to_string()),
linker_is_gnu: true,
dynamic_linking: true,
executables: true,
dll_prefix: String::new(),
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,11 +1394,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let auto_trait_predicates = auto_traits.into_iter().map(|trait_ref| {
ty::Binder::dummy(ty::ExistentialPredicate::AutoTrait(trait_ref.trait_ref().def_id()))
});
// N.b. principal, projections, auto traits
// FIXME: This is actually wrong with multiple principals in regards to symbol mangling
let mut v = regular_trait_predicates
.chain(auto_trait_predicates)
.chain(
existential_projections.map(|x| x.map_bound(ty::ExistentialPredicate::Projection)),
)
.chain(auto_trait_predicates)
.collect::<SmallVec<[_; 8]>>();
v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder()));
v.dedup();
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
#![cfg_attr(bootstrap, feature(doc_spotlight))]
#![cfg_attr(not(bootstrap), feature(doc_notable_trait))]
#![feature(duration_consts_2)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(extern_types)]
#![feature(fundamental)]
#![feature(intra_doc_pointers)]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<T> Option<T> {
/// assert_eq!(x.is_none(), true);
/// ```
#[must_use = "if you intended to assert that this doesn't have a value, consider \
`.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"]
`.and_then(|_| panic!(\"`Option` had a value when expected `None`\"))` instead"]
#[inline]
#[rustc_const_stable(feature = "const_option", since = "1.48.0")]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
#![feature(exact_size_is_empty)]
#![feature(exhaustive_patterns)]
#![feature(extend_one)]
#![feature(extended_key_value_attributes)]
#![cfg_attr(bootstrap, feature(extended_key_value_attributes))]
#![feature(fn_traits)]
#![feature(format_args_nl)]
#![feature(gen_future)]
Expand Down
86 changes: 84 additions & 2 deletions library/std/src/os/unix/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ impl<'a> fmt::Display for AsciiEscaped<'a> {
#[derive(Clone)]
#[stable(feature = "unix_socket", since = "1.10.0")]
pub struct SocketAddr {
addr: libc::sockaddr_un,
len: libc::socklen_t,
pub(super) addr: libc::sockaddr_un,
pub(super) len: libc::socklen_t,
}

impl SocketAddr {
Expand Down Expand Up @@ -196,6 +196,30 @@ impl SocketAddr {
if let AddressKind::Pathname(path) = self.address() { Some(path) } else { None }
}

/// Returns the contents of this address if it is an abstract namespace
/// without the leading null byte.
///
/// # Examples
///
/// ```no_run
/// #![feature(unix_socket_abstract)]
/// use std::os::unix::net::{UnixListener, SocketAddr};
///
/// fn main() -> std::io::Result<()> {
/// let namespace = b"hidden";
/// let namespace_addr = SocketAddr::from_abstract_namespace(&namespace[..])?;
/// let socket = UnixListener::bind_addr(&namespace_addr)?;
/// let local_addr = socket.local_addr().expect("Couldn't get local address");
/// assert_eq!(local_addr.as_abstract_namespace(), Some(&namespace[..]));
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
#[unstable(feature = "unix_socket_abstract", issue = "85410")]
pub fn as_abstract_namespace(&self) -> Option<&[u8]> {
if let AddressKind::Abstract(name) = self.address() { Some(name) } else { None }
}

fn address(&self) -> AddressKind<'_> {
let len = self.len as usize - sun_path_offset(&self.addr);
let path = unsafe { mem::transmute::<&[libc::c_char], &[u8]>(&self.addr.sun_path) };
Expand All @@ -212,6 +236,64 @@ impl SocketAddr {
AddressKind::Pathname(OsStr::from_bytes(&path[..len - 1]).as_ref())
}
}

/// Creates an abstract domain socket address from a namespace
///
/// An abstract address does not create a file unlike traditional path-based
/// Unix sockets. The advantage of this is that the address will disappear when
/// the socket bound to it is closed, so no filesystem clean up is required.
///
/// The leading null byte for the abstract namespace is automatically added.
///
/// This is a Linux-specific extension. See more at [`unix(7)`].
///
/// [`unix(7)`]: https://man7.org/linux/man-pages/man7/unix.7.html
///
/// # Errors
///
/// This will return an error if the given namespace is too long
///
/// # Examples
///
/// ```no_run
/// #![feature(unix_socket_abstract)]
/// use std::os::unix::net::{UnixListener, SocketAddr};
///
/// fn main() -> std::io::Result<()> {
/// let addr = SocketAddr::from_abstract_namespace(b"hidden")?;
/// let listener = match UnixListener::bind_addr(&addr) {
/// Ok(sock) => sock,
/// Err(err) => {
/// println!("Couldn't bind: {:?}", err);
/// return Err(err);
/// }
/// };
/// Ok(())
/// }
/// ```
#[cfg(any(doc, target_os = "android", target_os = "linux",))]
#[unstable(feature = "unix_socket_abstract", issue = "85410")]
pub fn from_abstract_namespace(namespace: &[u8]) -> io::Result<SocketAddr> {
unsafe {
let mut addr: libc::sockaddr_un = mem::zeroed();
addr.sun_family = libc::AF_UNIX as libc::sa_family_t;

if namespace.len() + 1 > addr.sun_path.len() {
return Err(io::Error::new_const(
io::ErrorKind::InvalidInput,
&"namespace must be shorter than SUN_LEN",
));
}

crate::ptr::copy_nonoverlapping(
namespace.as_ptr(),
addr.sun_path.as_mut_ptr().offset(1) as *mut u8,
namespace.len(),
);
let len = (sun_path_offset(&addr) + 1 + namespace.len()) as libc::socklen_t;
SocketAddr::from_parts(addr, len)
}
}
}

#[stable(feature = "unix_socket", since = "1.10.0")]
Expand Down
Loading