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 7 pull requests #100481

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
ca3d101
Add `Iterator::array_chunks()`
rossmacarthur Jan 2, 2022
f548518
Use `array::IntoIter` for the `ArrayChunks` remainder
rossmacarthur Feb 4, 2022
ef72349
Remove `array::IntoIter::with_partial` -- an artifact of the past, on…
WaffleLapkin Aug 1, 2022
b8b1486
Forward `ArrayChunks::next{,_back}` to `try_{for_each,rfold}`
WaffleLapkin Aug 1, 2022
4db628a
Remove incorrect impl `TrustedLen` for `ArrayChunks`
WaffleLapkin Aug 1, 2022
3102b39
Use `#[track_caller]` to make panic in `Iterator::array_chunks` nicer
WaffleLapkin Aug 1, 2022
37dfb04
Remove `Fuse` from `ArrayChunks` implementation
WaffleLapkin Aug 1, 2022
4c0292c
Simplify `ArrayChunks::is_empty`
WaffleLapkin Aug 1, 2022
475e4ba
Simplify `ArrayChunks::{,r}fold` impls
WaffleLapkin Aug 1, 2022
756bd6e
Use `next_chunk` in `ArrayChunks` impl
WaffleLapkin Aug 2, 2022
86bdb3e
Rustdoc-Json: Add `Path` type for traits.
aDotInTheVoid Aug 9, 2022
0fb4ef6
Suggest path separator when a dot is used on a trait
fmease Aug 10, 2022
e182d12
Fix HIR pretty printing of let else
compiler-errors Aug 12, 2022
a65647a
remove Clean trait implementation for hir::PathSegment
GuillaumeGomez Aug 12, 2022
001cc12
remove Clean trait implementation for hir::BareFnTy
GuillaumeGomez Aug 12, 2022
eb6b729
address review comments
WaffleLapkin Aug 12, 2022
5fbcde1
fill-in tracking issue for `feature(iter_array_chunks)`
WaffleLapkin Aug 12, 2022
20121fa
Point out a single arg if we have a single arg incompatibility
compiler-errors Jul 23, 2022
262644d
And for closures
compiler-errors Jul 23, 2022
237cbe9
Adjust span of closure param
compiler-errors Jul 23, 2022
c608918
Address nit
compiler-errors Aug 12, 2022
8fa707a
rustc_target: Update some old naming around self contained linking
petrochenkov Aug 3, 2022
6189cba
Rollup merge of #99646 - compiler-errors:arg-mismatch-single-arg-labe…
Dylan-DPC Aug 13, 2022
2dac0f1
Rollup merge of #100026 - WaffleLapkin:array-chunks, r=scottmcm
Dylan-DPC Aug 13, 2022
de80bb8
Rollup merge of #100126 - petrochenkov:screname, r=davidtwco
Dylan-DPC Aug 13, 2022
b7a020f
Rollup merge of #100335 - aDotInTheVoid:rdj-resolved-path, r=Guillaum…
Dylan-DPC Aug 13, 2022
f8d1dcc
Rollup merge of #100367 - fmease:fix-100365, r=compiler-errors
Dylan-DPC Aug 13, 2022
60fa217
Rollup merge of #100434 - compiler-errors:issue-100373, r=cjgillot
Dylan-DPC Aug 13, 2022
5cdb1e3
Rollup merge of #100447 - GuillaumeGomez:rm-clean-impl, r=Dylan-DPC
Dylan-DPC Aug 13, 2022
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
50 changes: 26 additions & 24 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_session::utils::NativeLibKind;
use rustc_session::{filesearch, Session};
use rustc_span::symbol::Symbol;
use rustc_span::DebuggerVisualizerFile;
use rustc_target::spec::crt_objects::{CrtObjects, CrtObjectsFallback};
use rustc_target::spec::crt_objects::{CrtObjects, LinkSelfContainedDefault};
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor, SplitDebuginfo};
use rustc_target::spec::{PanicStrategy, RelocModel, RelroLevel, SanitizerSet, Target};

Expand Down Expand Up @@ -764,15 +764,15 @@ fn link_natively<'a>(
"Linker does not support -static-pie command line option. Retrying with -static instead."
);
// Mirror `add_(pre,post)_link_objects` to replace CRT objects.
let self_contained = crt_objects_fallback(sess, crate_type);
let self_contained = self_contained(sess, crate_type);
let opts = &sess.target;
let pre_objects = if self_contained {
&opts.pre_link_objects_fallback
&opts.pre_link_objects_self_contained
} else {
&opts.pre_link_objects
};
let post_objects = if self_contained {
&opts.post_link_objects_fallback
&opts.post_link_objects_self_contained
} else {
&opts.post_link_objects
};
Expand Down Expand Up @@ -1556,26 +1556,26 @@ fn detect_self_contained_mingw(sess: &Session) -> bool {
true
}

/// Whether we link to our own CRT objects instead of relying on gcc to pull them.
/// Various toolchain components used during linking are used from rustc distribution
/// instead of being found somewhere on the host system.
/// We only provide such support for a very limited number of targets.
fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
fn self_contained(sess: &Session, crate_type: CrateType) -> bool {
if let Some(self_contained) = sess.opts.cg.link_self_contained {
return self_contained;
}

match sess.target.crt_objects_fallback {
match sess.target.link_self_contained {
LinkSelfContainedDefault::False => false,
LinkSelfContainedDefault::True => true,
// FIXME: Find a better heuristic for "native musl toolchain is available",
// based on host and linker path, for example.
// (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
Some(CrtObjectsFallback::Musl) => sess.crt_static(Some(crate_type)),
Some(CrtObjectsFallback::Mingw) => {
LinkSelfContainedDefault::Musl => sess.crt_static(Some(crate_type)),
LinkSelfContainedDefault::Mingw => {
sess.host == sess.target
&& sess.target.vendor != "uwp"
&& detect_self_contained_mingw(&sess)
}
// FIXME: Figure out cases in which WASM needs to link with a native toolchain.
Some(CrtObjectsFallback::Wasm) => true,
None => false,
}
}

Expand All @@ -1592,7 +1592,7 @@ fn add_pre_link_objects(
let opts = &sess.target;
let empty = Default::default();
let objects = if self_contained {
&opts.pre_link_objects_fallback
&opts.pre_link_objects_self_contained
} else if !(sess.target.os == "fuchsia" && flavor == LinkerFlavor::Gcc) {
&opts.pre_link_objects
} else {
Expand All @@ -1610,9 +1610,11 @@ fn add_post_link_objects(
link_output_kind: LinkOutputKind,
self_contained: bool,
) {
let opts = &sess.target;
let objects =
if self_contained { &opts.post_link_objects_fallback } else { &opts.post_link_objects };
let objects = if self_contained {
&sess.target.post_link_objects_self_contained
} else {
&sess.target.post_link_objects
};
for obj in objects.get(&link_output_kind).iter().copied().flatten() {
cmd.add_object(&get_object_file_path(sess, obj, self_contained));
}
Expand Down Expand Up @@ -1891,12 +1893,12 @@ fn linker_with_args<'a>(
out_filename: &Path,
codegen_results: &CodegenResults,
) -> Result<Command, ErrorGuaranteed> {
let crt_objects_fallback = crt_objects_fallback(sess, crate_type);
let self_contained = self_contained(sess, crate_type);
let cmd = &mut *super::linker::get_linker(
sess,
path,
flavor,
crt_objects_fallback,
self_contained,
&codegen_results.crate_info.target_cpu,
);
let link_output_kind = link_output_kind(sess, crate_type);
Expand All @@ -1923,7 +1925,7 @@ fn linker_with_args<'a>(
// ------------ Object code and libraries, order-dependent ------------

// Pre-link CRT objects.
add_pre_link_objects(cmd, sess, flavor, link_output_kind, crt_objects_fallback);
add_pre_link_objects(cmd, sess, flavor, link_output_kind, self_contained);

add_linked_symbol_object(
cmd,
Expand Down Expand Up @@ -2033,7 +2035,7 @@ fn linker_with_args<'a>(
cmd,
sess,
link_output_kind,
crt_objects_fallback,
self_contained,
flavor,
crate_type,
codegen_results,
Expand All @@ -2049,7 +2051,7 @@ fn linker_with_args<'a>(
// ------------ Object code and libraries, order-dependent ------------

// Post-link CRT objects.
add_post_link_objects(cmd, sess, link_output_kind, crt_objects_fallback);
add_post_link_objects(cmd, sess, link_output_kind, self_contained);

// ------------ Late order-dependent options ------------

Expand All @@ -2066,7 +2068,7 @@ fn add_order_independent_options(
cmd: &mut dyn Linker,
sess: &Session,
link_output_kind: LinkOutputKind,
crt_objects_fallback: bool,
self_contained: bool,
flavor: LinkerFlavor,
crate_type: CrateType,
codegen_results: &CodegenResults,
Expand Down Expand Up @@ -2098,7 +2100,7 @@ fn add_order_independent_options(
// Make the binary compatible with data execution prevention schemes.
cmd.add_no_exec();

if crt_objects_fallback {
if self_contained {
cmd.no_crt_objects();
}

Expand Down Expand Up @@ -2127,7 +2129,7 @@ fn add_order_independent_options(

cmd.linker_plugin_lto();

add_library_search_dirs(cmd, sess, crt_objects_fallback);
add_library_search_dirs(cmd, sess, self_contained);

cmd.output_filename(out_filename);

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,10 @@ impl<'a> State<'a> {
if let Some(els) = els {
self.nbsp();
self.word_space("else");
// containing cbox, will be closed by print-block at `}`
self.cbox(0);
// head-box, will be closed by print-block after `{`
self.ibox(0);
self.print_block(els);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ impl<'a> Parser<'a> {
attrs: attrs.into(),
ty,
pat,
span: lo.to(this.token.span),
span: lo.to(this.prev_token.span),
id: DUMMY_NODE_ID,
is_placeholder: false,
},
Expand Down
53 changes: 37 additions & 16 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,27 +985,45 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
let ns = source.namespace();
let is_expected = &|res| source.is_expected(res);

let path_sep = |err: &mut Diagnostic, expr: &Expr| match expr.kind {
ExprKind::Field(_, ident) => {
let path_sep = |err: &mut Diagnostic, expr: &Expr, kind: DefKind| {
const MESSAGE: &str = "use the path separator to refer to an item";

let (lhs_span, rhs_span) = match &expr.kind {
ExprKind::Field(base, ident) => (base.span, ident.span),
ExprKind::MethodCall(_, receiver, _, span) => (receiver.span, *span),
_ => return false,
};

if lhs_span.eq_ctxt(rhs_span) {
err.span_suggestion(
expr.span,
"use the path separator to refer to an item",
format!("{}::{}", path_str, ident),
lhs_span.between(rhs_span),
MESSAGE,
"::",
Applicability::MaybeIncorrect,
);
true
}
ExprKind::MethodCall(ref segment, ..) => {
let span = expr.span.with_hi(segment.ident.span.hi());
err.span_suggestion(
span,
"use the path separator to refer to an item",
format!("{}::{}", path_str, segment.ident),
} else if kind == DefKind::Struct
&& let Some(lhs_source_span) = lhs_span.find_ancestor_inside(expr.span)
&& let Ok(snippet) = self.r.session.source_map().span_to_snippet(lhs_source_span)
{
// The LHS is a type that originates from a macro call.
// We have to add angle brackets around it.

err.span_suggestion_verbose(
lhs_source_span.until(rhs_span),
MESSAGE,
format!("<{snippet}>::"),
Applicability::MaybeIncorrect,
);
true
} else {
// Either we were unable to obtain the source span / the snippet or
// the LHS originates from a macro call and it is not a type and thus
// there is no way to replace `.` with `::` and still somehow suggest
// valid Rust code.

false
}
_ => false,
};

let find_span = |source: &PathSource<'_>, err: &mut Diagnostic| {
Expand All @@ -1027,7 +1045,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
match source {
PathSource::Expr(Some(
parent @ Expr { kind: ExprKind::Field(..) | ExprKind::MethodCall(..), .. },
)) if path_sep(err, &parent) => {}
)) if path_sep(err, &parent, DefKind::Struct) => {}
PathSource::Expr(
None
| Some(Expr {
Expand Down Expand Up @@ -1143,8 +1161,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
}
}
}
(Res::Def(DefKind::Mod, _), PathSource::Expr(Some(parent))) => {
if !path_sep(err, &parent) {
(
Res::Def(kind @ (DefKind::Mod | DefKind::Trait), _),
PathSource::Expr(Some(parent)),
) => {
if !path_sep(err, &parent, kind) {
return false;
}
}
Expand Down
40 changes: 22 additions & 18 deletions compiler/rustc_target/src/spec/crt_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(super) fn all(obj: &'static str) -> CrtObjects {
])
}

pub(super) fn pre_musl_fallback() -> CrtObjects {
pub(super) fn pre_musl_self_contained() -> CrtObjects {
new(&[
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
(LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o", "crtbeginS.o"]),
Expand All @@ -74,7 +74,7 @@ pub(super) fn pre_musl_fallback() -> CrtObjects {
])
}

pub(super) fn post_musl_fallback() -> CrtObjects {
pub(super) fn post_musl_self_contained() -> CrtObjects {
new(&[
(LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]),
(LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]),
Expand All @@ -85,7 +85,7 @@ pub(super) fn post_musl_fallback() -> CrtObjects {
])
}

pub(super) fn pre_mingw_fallback() -> CrtObjects {
pub(super) fn pre_mingw_self_contained() -> CrtObjects {
new(&[
(LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]),
(LinkOutputKind::DynamicPicExe, &["crt2.o", "rsbegin.o"]),
Expand All @@ -96,7 +96,7 @@ pub(super) fn pre_mingw_fallback() -> CrtObjects {
])
}

pub(super) fn post_mingw_fallback() -> CrtObjects {
pub(super) fn post_mingw_self_contained() -> CrtObjects {
all("rsend.o")
}

Expand All @@ -108,7 +108,7 @@ pub(super) fn post_mingw() -> CrtObjects {
all("rsend.o")
}

pub(super) fn pre_wasi_fallback() -> CrtObjects {
pub(super) fn pre_wasi_self_contained() -> CrtObjects {
// Use crt1-command.o instead of crt1.o to enable support for new-style
// commands. See https://reviews.llvm.org/D81689 for more info.
new(&[
Expand All @@ -120,37 +120,41 @@ pub(super) fn pre_wasi_fallback() -> CrtObjects {
])
}

pub(super) fn post_wasi_fallback() -> CrtObjects {
pub(super) fn post_wasi_self_contained() -> CrtObjects {
new(&[])
}

/// Which logic to use to determine whether to fall back to the "self-contained" mode or not.
/// Which logic to use to determine whether to use self-contained linking mode
/// if `-Clink-self-contained` is not specified explicitly.
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
pub enum CrtObjectsFallback {
pub enum LinkSelfContainedDefault {
False,
True,
Musl,
Mingw,
Wasm,
}

impl FromStr for CrtObjectsFallback {
impl FromStr for LinkSelfContainedDefault {
type Err = ();

fn from_str(s: &str) -> Result<CrtObjectsFallback, ()> {
fn from_str(s: &str) -> Result<LinkSelfContainedDefault, ()> {
Ok(match s {
"musl" => CrtObjectsFallback::Musl,
"mingw" => CrtObjectsFallback::Mingw,
"wasm" => CrtObjectsFallback::Wasm,
"false" => LinkSelfContainedDefault::False,
"true" | "wasm" => LinkSelfContainedDefault::True,
"musl" => LinkSelfContainedDefault::Musl,
"mingw" => LinkSelfContainedDefault::Mingw,
_ => return Err(()),
})
}
}

impl ToJson for CrtObjectsFallback {
impl ToJson for LinkSelfContainedDefault {
fn to_json(&self) -> Json {
match *self {
CrtObjectsFallback::Musl => "musl",
CrtObjectsFallback::Mingw => "mingw",
CrtObjectsFallback::Wasm => "wasm",
LinkSelfContainedDefault::False => "false",
LinkSelfContainedDefault::True => "true",
LinkSelfContainedDefault::Musl => "musl",
LinkSelfContainedDefault::Mingw => "mingw",
}
.to_json()
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_target/src/spec/linux_musl_base.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::spec::crt_objects::{self, CrtObjectsFallback};
use crate::spec::crt_objects::{self, LinkSelfContainedDefault};
use crate::spec::TargetOptions;

pub fn opts() -> TargetOptions {
let mut base = super::linux_base::opts();

base.env = "musl".into();
base.pre_link_objects_fallback = crt_objects::pre_musl_fallback();
base.post_link_objects_fallback = crt_objects::post_musl_fallback();
base.crt_objects_fallback = Some(CrtObjectsFallback::Musl);
base.pre_link_objects_self_contained = crt_objects::pre_musl_self_contained();
base.post_link_objects_self_contained = crt_objects::post_musl_self_contained();
base.link_self_contained = LinkSelfContainedDefault::Musl;

// These targets statically link libc by default
base.crt_static_default = true;
Expand Down
Loading