Skip to content

Commit

Permalink
Auto merge of rust-lang#106656 - JohnTitor:rollup-rk2qltg, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - rust-lang#105034 (Add example for iterator_flatten)
 - rust-lang#105708 (Enable atomic cas for bpf targets)
 - rust-lang#106175 (Fix bad import suggestion with nested `use` tree)
 - rust-lang#106204 (No need to take opaques in `check_type_bounds`)
 - rust-lang#106387 (Revert "bootstrap: Get rid of `tail_args` in `stream_cargo`")
 - rust-lang#106636 (Accept old spelling of Fuchsia target triples)
 - rust-lang#106639 (update Miri)
 - rust-lang#106640 (update test for inductive canonical cycles)
 - rust-lang#106647 (rustdoc: merge common CSS for `a`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 10, 2023
2 parents d53924d + ed840a6 commit deba5dd
Show file tree
Hide file tree
Showing 48 changed files with 553 additions and 177 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {

// This is still required for many(half of the tests in ui/type-alias-impl-trait)
// tests to pass
let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
let _ = infcx.take_opaque_types();

if errors.is_empty() {
definition_ty
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
);

translate_outlives_facts(&mut checker);
let opaque_type_values = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
let opaque_type_values = infcx.take_opaque_types();

let opaque_type_values = opaque_type_values
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/util/compare_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ pub fn is_subtype<'tcx>(
// even if they're constrained in our current function.
//
// It seems very unlikely that this hides any bugs.
let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
let _ = infcx.take_opaque_types();
errors.is_empty()
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn check_opaque_meets_bounds<'tcx>(
}
}
// Clean up after ourselves
let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
let _ = infcx.take_opaque_types();
}

fn is_enum_of_nonnullable_ptr<'tcx>(
Expand Down
18 changes: 1 addition & 17 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ fn compare_asyncness<'tcx>(
ty::Alias(ty::Opaque, ..) => {
// allow both `async fn foo()` and `fn foo() -> impl Future`
}
ty::Error(rustc_errors::ErrorGuaranteed { .. }) => {
ty::Error(_) => {
// We don't know if it's ok, but at least it's already an error.
}
_ => {
Expand Down Expand Up @@ -1972,22 +1972,6 @@ pub(super) fn check_type_bounds<'tcx>(
&outlives_environment,
)?;

let constraints = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
for (key, value) in constraints {
infcx
.err_ctxt()
.report_mismatched_types(
&ObligationCause::misc(
value.hidden_type.span,
tcx.hir().local_def_id_to_hir_id(impl_ty.def_id.expect_local()),
),
tcx.mk_opaque(key.def_id.to_def_id(), key.substs),
value.hidden_type.ty,
TypeError::Mismatch,
)
.emit();
}

Ok(())
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {

#[instrument(skip(self), level = "debug")]
fn visit_opaque_types(&mut self) {
let opaque_types =
self.fcx.infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
let opaque_types = self.fcx.infcx.take_opaque_types();
for (opaque_type_key, decl) in opaque_types {
let hidden_type = self.resolve(decl.hidden_type, &decl.hidden_type.span);
let opaque_type_key = self.resolve(opaque_type_key, &decl.hidden_type.span);
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// As the new solver does canonicalization slightly differently, this is also used there
/// for now. This should hopefully change fairly soon.
pub fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
self.inner
.borrow_mut()
.opaque_type_storage
.take_opaque_types()
std::mem::take(&mut self.inner.borrow_mut().opaque_type_storage.opaque_types)
.into_iter()
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty))
.collect()
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,12 @@ impl<'tcx> InferCtxt<'tcx> {
var_infos
}

#[instrument(level = "debug", skip(self), ret)]
pub fn take_opaque_types(&self) -> opaque_types::OpaqueTypeMap<'tcx> {
debug_assert_ne!(self.defining_use_anchor, DefiningAnchor::Error);
std::mem::take(&mut self.inner.borrow_mut().opaque_type_storage.opaque_types)
}

pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
self.resolve_vars_if_possible(t).to_string()
}
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_infer/src/infer/opaque_types/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ impl<'tcx> OpaqueTypeStorage<'tcx> {
}
}

#[instrument(level = "debug", ret)]
pub fn take_opaque_types(&mut self) -> OpaqueTypeMap<'tcx> {
std::mem::take(&mut self.opaque_types)
}

#[inline]
pub(crate) fn with_log<'a>(
&'a mut self,
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl<'a> Resolver<'a> {
found_use,
DiagnosticMode::Normal,
path,
"",
);
err.emit();
} else if let Some((span, msg, sugg, appl)) = suggestion {
Expand Down Expand Up @@ -690,6 +691,7 @@ impl<'a> Resolver<'a> {
FoundUse::Yes,
DiagnosticMode::Pattern,
vec![],
"",
);
}
err
Expand Down Expand Up @@ -1344,6 +1346,7 @@ impl<'a> Resolver<'a> {
FoundUse::Yes,
DiagnosticMode::Normal,
vec![],
"",
);

if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
Expand Down Expand Up @@ -2309,7 +2312,7 @@ enum FoundUse {
}

/// Whether a binding is part of a pattern or a use statement. Used for diagnostics.
enum DiagnosticMode {
pub(crate) enum DiagnosticMode {
Normal,
/// The binding is part of a pattern
Pattern,
Expand All @@ -2324,6 +2327,8 @@ pub(crate) fn import_candidates(
// This is `None` if all placement locations are inside expansions
use_placement_span: Option<Span>,
candidates: &[ImportSuggestion],
mode: DiagnosticMode,
append: &str,
) {
show_candidates(
session,
Expand All @@ -2333,8 +2338,9 @@ pub(crate) fn import_candidates(
candidates,
Instead::Yes,
FoundUse::Yes,
DiagnosticMode::Import,
mode,
vec![],
append,
);
}

Expand All @@ -2352,6 +2358,7 @@ fn show_candidates(
found_use: FoundUse,
mode: DiagnosticMode,
path: Vec<Segment>,
append: &str,
) {
if candidates.is_empty() {
return;
Expand Down Expand Up @@ -2416,7 +2423,7 @@ fn show_candidates(
// produce an additional newline to separate the new use statement
// from the directly following item.
let additional_newline = if let FoundUse::Yes = found_use { "" } else { "\n" };
candidate.0 = format!("{}{};\n{}", add_use, &candidate.0, additional_newline);
candidate.0 = format!("{add_use}{}{append};\n{additional_newline}", &candidate.0);
}

err.span_suggestions(
Expand Down
81 changes: 55 additions & 26 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A bunch of methods and structures more or less related to resolving imports.
use crate::diagnostics::{import_candidates, Suggestion};
use crate::diagnostics::{import_candidates, DiagnosticMode, Suggestion};
use crate::Determinacy::{self, *};
use crate::Namespace::*;
use crate::{module_to_string, names_to_string, ImportSuggestion};
Expand Down Expand Up @@ -402,7 +402,7 @@ struct UnresolvedImportError {
label: Option<String>,
note: Option<String>,
suggestion: Option<Suggestion>,
candidate: Option<Vec<ImportSuggestion>>,
candidates: Option<Vec<ImportSuggestion>>,
}

pub struct ImportResolver<'a, 'b> {
Expand Down Expand Up @@ -475,12 +475,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
errors = vec![];
}
if seen_spans.insert(err.span) {
let path = import_path_to_string(
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
&import.kind,
err.span,
);
errors.push((path, err));
errors.push((import, err));
prev_root_id = import.root_id;
}
} else if is_indeterminate {
Expand All @@ -494,10 +489,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
label: None,
note: None,
suggestion: None,
candidate: None,
candidates: None,
};
// FIXME: there should be a better way of doing this than
// formatting this as a string then checking for `::`
if path.contains("::") {
errors.push((path, err))
errors.push((import, err))
}
}
}
Expand All @@ -507,7 +504,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
}
}

fn throw_unresolved_import_error(&self, errors: Vec<(String, UnresolvedImportError)>) {
fn throw_unresolved_import_error(&self, errors: Vec<(&Import<'_>, UnresolvedImportError)>) {
if errors.is_empty() {
return;
}
Expand All @@ -516,7 +513,17 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
const MAX_LABEL_COUNT: usize = 10;

let span = MultiSpan::from_spans(errors.iter().map(|(_, err)| err.span).collect());
let paths = errors.iter().map(|(path, _)| format!("`{}`", path)).collect::<Vec<_>>();
let paths = errors
.iter()
.map(|(import, err)| {
let path = import_path_to_string(
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
&import.kind,
err.span,
);
format!("`{path}`")
})
.collect::<Vec<_>>();
let msg = format!("unresolved import{} {}", pluralize!(paths.len()), paths.join(", "),);

let mut diag = struct_span_err!(self.r.session, span, E0432, "{}", &msg);
Expand All @@ -525,7 +532,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
diag.note(note);
}

for (_, err) in errors.into_iter().take(MAX_LABEL_COUNT) {
for (import, err) in errors.into_iter().take(MAX_LABEL_COUNT) {
if let Some(label) = err.label {
diag.span_label(err.span, label);
}
Expand All @@ -538,14 +545,36 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
diag.multipart_suggestion(&msg, suggestions, applicability);
}

if let Some(candidate) = &err.candidate {
import_candidates(
self.r.session,
&self.r.untracked.source_span,
&mut diag,
Some(err.span),
&candidate,
)
if let Some(candidates) = &err.candidates {
match &import.kind {
ImportKind::Single { nested: false, source, target, .. } => import_candidates(
self.r.session,
&self.r.untracked.source_span,
&mut diag,
Some(err.span),
&candidates,
DiagnosticMode::Import,
(source != target)
.then(|| format!(" as {target}"))
.as_deref()
.unwrap_or(""),
),
ImportKind::Single { nested: true, source, target, .. } => {
import_candidates(
self.r.session,
&self.r.untracked.source_span,
&mut diag,
None,
&candidates,
DiagnosticMode::Normal,
(source != target)
.then(|| format!(" as {target}"))
.as_deref()
.unwrap_or(""),
);
}
_ => {}
}
}
}

Expand Down Expand Up @@ -707,14 +736,14 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
String::from("a similar path exists"),
Applicability::MaybeIncorrect,
)),
candidate: None,
candidates: None,
},
None => UnresolvedImportError {
span,
label: Some(label),
note: None,
suggestion,
candidate: None,
candidates: None,
},
};
return Some(err);
Expand Down Expand Up @@ -761,7 +790,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
)),
note: None,
suggestion: None,
candidate: None,
candidates: None,
});
}
}
Expand Down Expand Up @@ -873,7 +902,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let resolutions = resolutions.as_ref().into_iter().flat_map(|r| r.iter());
let names = resolutions
.filter_map(|(BindingKey { ident: i, .. }, resolution)| {
if *i == ident {
if i.name == ident.name {
return None;
} // Never suggest the same name
match *resolution.borrow() {
Expand Down Expand Up @@ -943,7 +972,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
label: Some(label),
note,
suggestion,
candidate: if !parent_suggestion.is_empty() {
candidates: if !parent_suggestion.is_empty() {
Some(parent_suggestion)
} else {
None
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/aarch64_fuchsia.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use crate::spec::aarch64_unknown_fuchsia::target;
6 changes: 5 additions & 1 deletion compiler/rustc_target/src/spec/bpf_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn opts(endian: Endian) -> TargetOptions {
allow_asm: true,
endian,
linker_flavor: LinkerFlavor::Bpf,
atomic_cas: false,
atomic_cas: true,
dynamic_linking: true,
no_builtins: true,
panic_strategy: PanicStrategy::Abort,
Expand All @@ -19,6 +19,10 @@ pub fn opts(endian: Endian) -> TargetOptions {
obj_is_bitcode: true,
requires_lto: false,
singlethread: true,
// When targeting the `v3` cpu in llvm, 32-bit atomics are also supported.
// But making this value change based on the target cpu can be mostly confusing
// and would require a bit of a refactor.
min_atomic_width: Some(64),
max_atomic_width: Some(64),
..Default::default()
}
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ impl fmt::Display for StackProtector {
}

macro_rules! supported_targets {
( $(($triple:literal, $module:ident ),)+ ) => {
( $(($triple:literal, $module:ident),)+ ) => {
$(mod $module;)+

/// List of supported targets
Expand Down Expand Up @@ -1109,7 +1109,11 @@ supported_targets! {
("x86_64-apple-darwin", x86_64_apple_darwin),
("i686-apple-darwin", i686_apple_darwin),

// FIXME(#106649): Remove aarch64-fuchsia in favor of aarch64-unknown-fuchsia
("aarch64-fuchsia", aarch64_fuchsia),
("aarch64-unknown-fuchsia", aarch64_unknown_fuchsia),
// FIXME(#106649): Remove x86_64-fuchsia in favor of x86_64-unknown-fuchsia
("x86_64-fuchsia", x86_64_fuchsia),
("x86_64-unknown-fuchsia", x86_64_unknown_fuchsia),

("avr-unknown-gnu-atmega328", avr_unknown_gnu_atmega328),
Expand Down
Loading

0 comments on commit deba5dd

Please sign in to comment.