Skip to content

Rollup of 7 pull requests #110704

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
99962a8
Refactor `SyntaxContext::ctxt` logic.
cjgillot Apr 18, 2023
1467877
Remove find_map_relevant_impl
compiler-errors Apr 19, 2023
a1780a7
Remove unnecessary `test_kind` field and `TestKind` struct
jyn514 Apr 20, 2023
d49c7d6
[wip] separate out a test_crate_args fn
jyn514 Apr 20, 2023
6348fac
switch Crate to run_cargo_test
jyn514 Apr 20, 2023
84e7253
Convert the rest of the `test` Steps to run_cargo_test
jyn514 Apr 20, 2023
c7ebddb
Combine several `Step`s into a single step with multiple paths
jyn514 Apr 20, 2023
b3ee81a
Fix `x test --no-deps`
jyn514 Apr 21, 2023
5cefe75
rustdoc: remove unneeded handleKey from settings.js
notriddle Apr 21, 2023
1d0f34f
rustdoc: remove unused CSS `color: inherit`
notriddle Apr 22, 2023
6ecdd03
Add note about change in bootstrap defaults
Mark-Simulacrum Apr 22, 2023
e9c52a5
stop `x fmt` formatting alt build dirs
Ezrashaw Apr 22, 2023
c8874e2
Don't infer fn return type to return itself
compiler-errors Apr 22, 2023
4158abf
Rollup merge of #110497 - cjgillot:span-ctxt, r=b-naber
compiler-errors Apr 22, 2023
95a6575
Rollup merge of #110514 - compiler-errors:remove-find_map_relevant_im…
compiler-errors Apr 22, 2023
ab1c930
Rollup merge of #110576 - jyn514:unify-test-args, r=ozkanonur
compiler-errors Apr 22, 2023
05ad133
Rollup merge of #110661 - notriddle:notriddle/settings-js-handlekey, …
compiler-errors Apr 22, 2023
ddf3932
Rollup merge of #110663 - Mark-Simulacrum:add-compat-note, r=cuviper
compiler-errors Apr 22, 2023
ad3d9bf
Rollup merge of #110664 - Ezrashaw:fix-bootstrap-build-format, r=jyn514
compiler-errors Apr 22, 2023
eb33b1d
Rollup merge of #110700 - compiler-errors:fn-ret-fn, r=oli-obk
compiler-errors Apr 22, 2023
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
6 changes: 5 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ Compatibility Notes
- [When `default-features` is set to false of a workspace dependency, and an inherited dependency of a member has `default-features = true`, Cargo will enable default features of that dependency.](https://github.com/rust-lang/cargo/pull/11409/)
- [Cargo denies `CARGO_HOME` in the `[env]` configuration table. Cargo itself doesn't pick up this value, but recursive calls to cargo would, which was not intended.](https://github.com/rust-lang/cargo/pull/11644/)
- [Debuginfo for build dependencies is now off if not explicitly set. This is expected to improve the overall build time.](https://github.com/rust-lang/cargo/pull/11252/)

- [The Rust distribution no longer always includes rustdoc](https://github.com/rust-lang/rust/pull/106886)
If `tools = [...]` is set in config.toml, we will respect a missing rustdoc in that list. By
default rustdoc remains included. To retain the prior behavior explicitly add `"rustdoc"` to the
list.

<a id="1.69.0-Internal-Changes"></a>

Internal Changes
Expand Down
31 changes: 20 additions & 11 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,24 +1146,22 @@ fn infer_return_ty_for_fn_sig<'tcx>(

let mut visitor = HirPlaceholderCollector::default();
visitor.visit_ty(ty);

let mut diag = bad_placeholder(tcx, visitor.0, "return type");
let ret_ty = fn_sig.output();
// Don't leak types into signatures unless they're nameable!
// For example, if a function returns itself, we don't want that
// recursive function definition to leak out into the fn sig.
let mut should_recover = false;

if let Some(ret_ty) = ret_ty.make_suggestable(tcx, false) {
diag.span_suggestion(
ty.span,
"replace with the correct return type",
ret_ty,
Applicability::MachineApplicable,
);
} else if matches!(ret_ty.kind(), ty::FnDef(..))
&& let Some(fn_sig) = ret_ty.fn_sig(tcx).make_suggestable(tcx, false)
{
diag.span_suggestion(
ty.span,
"replace with the correct return type",
fn_sig,
Applicability::MachineApplicable,
);
should_recover = true;
} else if let Some(sugg) = suggest_impl_trait(tcx, ret_ty, ty.span, def_id) {
diag.span_suggestion(
ty.span,
Expand All @@ -1181,9 +1179,20 @@ fn infer_return_ty_for_fn_sig<'tcx>(
https://doc.rust-lang.org/book/ch13-01-closures.html",
);
}
diag.emit();

ty::Binder::dummy(fn_sig)
let guar = diag.emit();

if should_recover {
ty::Binder::dummy(fn_sig)
} else {
ty::Binder::dummy(tcx.mk_fn_sig(
fn_sig.inputs().iter().copied(),
tcx.ty_error(guar),
fn_sig.c_variadic,
fn_sig.unsafety,
fn_sig.abi,
))
}
}
None => icx.astconv().ty_of_fn(
hir_id,
Expand Down
62 changes: 18 additions & 44 deletions compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,40 +139,6 @@ impl<'tcx> TyCtxt<'tcx> {
treat_projections: TreatProjections,
mut f: impl FnMut(DefId),
) {
let _: Option<()> =
self.find_map_relevant_impl(trait_def_id, self_ty, treat_projections, |did| {
f(did);
None
});
}

/// `trait_def_id` MUST BE the `DefId` of a trait.
pub fn non_blanket_impls_for_ty(
self,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
) -> impl Iterator<Item = DefId> + 'tcx {
let impls = self.trait_impls_of(trait_def_id);
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
return impls.iter().copied();
}
}

[].iter().copied()
}

/// Applies function to every impl that could possibly match the self type `self_ty` and returns
/// the first non-none value.
///
/// `trait_def_id` MUST BE the `DefId` of a trait.
pub fn find_map_relevant_impl<T>(
self,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
treat_projections: TreatProjections,
mut f: impl FnMut(DefId) -> Option<T>,
) -> Option<T> {
// FIXME: This depends on the set of all impls for the trait. That is
// unfortunate wrt. incremental compilation.
//
Expand All @@ -181,9 +147,7 @@ impl<'tcx> TyCtxt<'tcx> {
let impls = self.trait_impls_of(trait_def_id);

for &impl_def_id in impls.blanket_impls.iter() {
if let result @ Some(_) = f(impl_def_id) {
return result;
}
f(impl_def_id);
}

// Note that we're using `TreatParams::ForLookup` to query `non_blanket_impls` while using
Expand All @@ -199,20 +163,30 @@ impl<'tcx> TyCtxt<'tcx> {
if let Some(simp) = fast_reject::simplify_type(self, self_ty, treat_params) {
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
for &impl_def_id in impls {
if let result @ Some(_) = f(impl_def_id) {
return result;
}
f(impl_def_id);
}
}
} else {
for &impl_def_id in impls.non_blanket_impls.values().flatten() {
if let result @ Some(_) = f(impl_def_id) {
return result;
}
f(impl_def_id);
}
}
}

None
/// `trait_def_id` MUST BE the `DefId` of a trait.
pub fn non_blanket_impls_for_ty(
self,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
) -> impl Iterator<Item = DefId> + 'tcx {
let impls = self.trait_impls_of(trait_def_id);
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
return impls.iter().copied();
}
}

[].iter().copied()
}

/// Returns an iterator containing all impls for `trait_def_id`.
Expand Down
37 changes: 22 additions & 15 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::mir;
use crate::ty::fast_reject::TreatProjections;
use crate::ty::layout::IntegerExt;
use crate::ty::{
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
Expand Down Expand Up @@ -359,21 +358,29 @@ impl<'tcx> TyCtxt<'tcx> {
self.ensure().coherent_trait(drop_trait);

let ty = self.type_of(adt_did).subst_identity();
let (did, constness) = self.find_map_relevant_impl(
drop_trait,
ty,
// FIXME: This could also be some other mode, like "unexpected"
TreatProjections::ForLookup,
|impl_did| {
if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
if validate(self, impl_did).is_ok() {
return Some((*item_id, self.constness(impl_did)));
}
}
None
},
)?;
let mut dtor_candidate = None;
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
return;
};

if validate(self, impl_did).is_err() {
// Already `ErrorGuaranteed`, no need to delay a span bug here.
return;
}

if let Some((old_item_id, _)) = dtor_candidate {
self.sess
.struct_span_err(self.def_span(item_id), "multiple drop impls found")
.span_note(self.def_span(old_item_id), "other impl here")
.delay_as_bug();
}

dtor_candidate = Some((*item_id, self.constness(impl_did)));
});

let (did, constness) = dtor_candidate?;
Some(ty::Destructor { did, constness })
}

Expand Down
24 changes: 14 additions & 10 deletions compiler/rustc_span/src/span_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,23 @@ impl Span {
#[inline]
pub fn ctxt(self) -> SyntaxContext {
let ctxt_or_tag = self.ctxt_or_tag as u32;
if ctxt_or_tag <= MAX_CTXT {
if self.len_or_tag == LEN_TAG || self.len_or_tag & PARENT_MASK == 0 {
// Inline format or interned format with inline ctxt.
SyntaxContext::from_u32(ctxt_or_tag)
// Check for interned format.
if self.len_or_tag == LEN_TAG {
if ctxt_or_tag == CTXT_TAG {
// Fully interned format.
let index = self.base_or_index;
with_span_interner(|interner| interner.spans[index as usize].ctxt)
} else {
// Inline format or interned format with inline parent.
// We know that the SyntaxContext is root.
SyntaxContext::root()
// Interned format with inline ctxt.
SyntaxContext::from_u32(ctxt_or_tag)
}
} else if self.len_or_tag & PARENT_MASK == 0 {
// Inline format with inline ctxt.
SyntaxContext::from_u32(ctxt_or_tag)
} else {
// Interned format.
let index = self.base_or_index;
with_span_interner(|interner| interner.spans[index as usize].ctxt)
// Inline format with inline parent.
// We know that the SyntaxContext is root.
SyntaxContext::root()
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_trait_selection/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,16 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
// FIXME: Handling opaques here is kinda sus. Especially because we
// simplify them to PlaceholderSimplifiedType.
| ty::Alias(ty::Opaque, _) => {
if let Some(def_id) = self.tcx().find_map_relevant_impl(
let mut disqualifying_impl = None;
self.tcx().for_each_relevant_impl_treating_projections(
goal.predicate.def_id(),
goal.predicate.self_ty(),
TreatProjections::NextSolverLookup,
Some,
) {
|impl_def_id| {
disqualifying_impl = Some(impl_def_id);
},
);
if let Some(def_id) = disqualifying_impl {
debug!(?def_id, ?goal, "disqualified auto-trait implementation");
// No need to actually consider the candidate here,
// since we do that in `consider_impl_candidate`.
Expand Down
Loading