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 8 pull requests #133296

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
78bbc64
Fix closure arg extraction in extract_callable_info
compiler-errors Nov 2, 2024
cbacb6d
Use extract_callable_info, generalize it to async closure
compiler-errors Nov 2, 2024
44933b5
Print env var in --print=deployment-target
madsmtm Nov 14, 2024
98ab898
tests: ui/inline-consts: add issue number to a test, rename other tes…
matthiaskrgr Nov 15, 2024
030ddee
don't require const stability for const impls
fee1-dead Nov 20, 2024
91be815
ci: Disable full `debuginfo-level=2` in windows alt job
marcoieni Nov 20, 2024
d318878
Reduce integer `Display` implementation size
GuillaumeGomez Nov 20, 2024
0465f71
Stop being so bail-y in candidate assembly
compiler-errors Nov 21, 2024
61a03fa
Don't exclude relnotes from `needs-triage` label
jieyouxu Nov 21, 2024
514ef18
constify `Add`
fee1-dead Nov 20, 2024
ab38c6d
Improve code by using `wrapping_neg`
GuillaumeGomez Nov 20, 2024
3a1d498
Rollup merge of #132090 - compiler-errors:baily, r=lcnr
GuillaumeGomez Nov 21, 2024
ed91963
Rollup merge of #132489 - compiler-errors:fn-sugg-tweaks, r=BoxyUwU
GuillaumeGomez Nov 21, 2024
cacd4a0
Rollup merge of #133041 - madsmtm:print-deployment-target-env-var, r=…
GuillaumeGomez Nov 21, 2024
9aa63c7
Rollup merge of #133078 - matthiaskrgr:uiuiui, r=davidtwco
GuillaumeGomez Nov 21, 2024
09bc5fa
Rollup merge of #133237 - fee1-dead-contrib:constadd, r=compiler-errors
GuillaumeGomez Nov 21, 2024
7396c94
Rollup merge of #133246 - MarcoIeni:debug-info-2-windows-disable, r=K…
GuillaumeGomez Nov 21, 2024
7554f9f
Rollup merge of #133247 - GuillaumeGomez:reduce-integer-display-impl,…
GuillaumeGomez Nov 21, 2024
aeb9f6d
Rollup merge of #133283 - jieyouxu:triage-relnotes, r=BoxyUwU
GuillaumeGomez Nov 21, 2024
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
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/apple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn minimum_deployment_target(target: &Target) -> OSVersion {
}

/// Name of the environment variable used to fetch the deployment target on the given OS.
fn deployment_target_env_var(os: &str) -> &'static str {
pub fn deployment_target_env_var(os: &str) -> &'static str {
match os {
"macos" => "MACOSX_DEPLOYMENT_TARGET",
"ios" => "IPHONEOS_DEPLOYMENT_TARGET",
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,9 @@ fn print_crate_info(
DeploymentTarget => {
if sess.target.is_like_osx {
println_info!(
"deployment_target={}",
apple::pretty_version(apple::deployment_target(sess))
"{}={}",
apple::deployment_target_env_var(&sess.target.os),
apple::pretty_version(apple::deployment_target(sess)),
)
} else {
#[allow(rustc::diagnostic_outside_of_impl)]
Expand Down
55 changes: 8 additions & 47 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use rustc_span::symbol::{Ident, kw, sym};
use rustc_span::{
DUMMY_SP, ErrorGuaranteed, ExpnKind, FileName, MacroKind, Span, Symbol, edit_distance,
};
use rustc_trait_selection::error_reporting::traits::DefIdOrName;
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedNote;
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
Expand All @@ -45,50 +46,6 @@ use crate::errors::{self, CandidateTraitNote, NoAssociatedItem};
use crate::{Expectation, FnCtxt};

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
let tcx = self.tcx;
match ty.kind() {
// Not all of these (e.g., unsafe fns) implement `FnOnce`,
// so we look for these beforehand.
// FIXME(async_closures): These don't impl `FnOnce` by default.
ty::Closure(..) | ty::FnDef(..) | ty::FnPtr(..) => true,
// If it's not a simple function, look for things which implement `FnOnce`.
_ => {
let Some(fn_once) = tcx.lang_items().fn_once_trait() else {
return false;
};

// This conditional prevents us from asking to call errors and unresolved types.
// It might seem that we can use `predicate_must_hold_modulo_regions`,
// but since a Dummy binder is used to fill in the FnOnce trait's arguments,
// type resolution always gives a "maybe" here.
if self.autoderef(span, ty).silence_errors().any(|(ty, _)| {
info!("check deref {:?} error", ty);
matches!(ty.kind(), ty::Error(_) | ty::Infer(_))
}) {
return false;
}

self.autoderef(span, ty).silence_errors().any(|(ty, _)| {
info!("check deref {:?} impl FnOnce", ty);
self.probe(|_| {
let trait_ref =
ty::TraitRef::new(tcx, fn_once, [ty, self.next_ty_var(span)]);
let poly_trait_ref = ty::Binder::dummy(trait_ref);
let obligation = Obligation::misc(
tcx,
span,
self.body_id,
self.param_env,
poly_trait_ref,
);
self.predicate_may_hold(&obligation)
})
})
}
}
}

fn is_slice_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
self.autoderef(span, ty)
.silence_errors()
Expand Down Expand Up @@ -2367,12 +2324,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let is_accessible = field.vis.is_accessible_from(scope, tcx);

if is_accessible {
if self.is_fn_ty(field_ty, span) {
if let Some((what, _, _)) = self.extract_callable_info(field_ty) {
let what = match what {
DefIdOrName::DefId(def_id) => self.tcx.def_descr(def_id),
DefIdOrName::Name(what) => what,
};
let expr_span = expr.span.to(item_name.span);
err.multipart_suggestion(
format!(
"to call the function stored in `{item_name}`, \
surround the field access with parentheses",
"to call the {what} stored in `{item_name}`, \
surround the field access with parentheses",
),
vec![
(expr_span.shrink_to_lo(), '('.to_string()),
Expand Down
11 changes: 1 addition & 10 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,16 +590,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
}

fn check_missing_const_stability(&self, def_id: LocalDefId, span: Span) {
// if the const impl is derived using the `derive_const` attribute,
// then it would be "stable" at least for the impl.
// We gate usages of it using `feature(const_trait_impl)` anyways
// so there is no unstable leakage
if self.tcx.is_automatically_derived(def_id.to_def_id()) {
return;
}

let is_const = self.tcx.is_const_fn(def_id.to_def_id())
|| self.tcx.is_const_trait_impl(def_id.to_def_id());
let is_const = self.tcx.is_const_fn(def_id.to_def_id());

// Reachable const fn must have a stability attribute.
if is_const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1075,93 +1075,110 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)> {
// Autoderef is useful here because sometimes we box callables, etc.
let Some((def_id_or_name, output, inputs)) =
(self.autoderef_steps)(found).into_iter().find_map(|(found, _)| {
match *found.kind() {
ty::FnPtr(sig_tys, _) => Some((
DefIdOrName::Name("function pointer"),
sig_tys.output(),
sig_tys.inputs(),
)),
ty::FnDef(def_id, _) => {
let fn_sig = found.fn_sig(self.tcx);
Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs()))
}
ty::Closure(def_id, args) => {
let fn_sig = args.as_closure().sig();
Some((
DefIdOrName::DefId(def_id),
fn_sig.output(),
fn_sig.inputs().map_bound(|inputs| &inputs[1..]),
))
}
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
self.tcx
.item_super_predicates(def_id)
.instantiate(self.tcx, args)
.iter()
.find_map(|pred| {
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
&& self.tcx.is_lang_item(proj.projection_term.def_id,LangItem::FnOnceOutput)
// args tuple will always be args[1]
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
{
Some((
DefIdOrName::DefId(def_id),
pred.kind().rebind(proj.term.expect_type()),
pred.kind().rebind(args.as_slice()),
))
} else {
None
}
})
}
ty::Dynamic(data, _, ty::Dyn) => {
data.iter().find_map(|pred| {
if let ty::ExistentialPredicate::Projection(proj) = pred.skip_binder()
(self.autoderef_steps)(found).into_iter().find_map(|(found, _)| match *found.kind() {
ty::FnPtr(sig_tys, _) => Some((
DefIdOrName::Name("function pointer"),
sig_tys.output(),
sig_tys.inputs(),
)),
ty::FnDef(def_id, _) => {
let fn_sig = found.fn_sig(self.tcx);
Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs()))
}
ty::Closure(def_id, args) => {
let fn_sig = args.as_closure().sig();
Some((
DefIdOrName::DefId(def_id),
fn_sig.output(),
fn_sig.inputs().map_bound(|inputs| inputs[0].tuple_fields().as_slice()),
))
}
ty::CoroutineClosure(def_id, args) => {
let sig_parts = args.as_coroutine_closure().coroutine_closure_sig();
Some((
DefIdOrName::DefId(def_id),
sig_parts.map_bound(|sig| {
sig.to_coroutine(
self.tcx,
args.as_coroutine_closure().parent_args(),
// Just use infer vars here, since we don't really care
// what these types are, just that we're returning a coroutine.
self.next_ty_var(DUMMY_SP),
self.tcx.coroutine_for_closure(def_id),
self.next_ty_var(DUMMY_SP),
)
}),
sig_parts.map_bound(|sig| sig.tupled_inputs_ty.tuple_fields().as_slice()),
))
}
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self
.tcx
.item_super_predicates(def_id)
.instantiate(self.tcx, args)
.iter()
.find_map(|pred| {
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
&& self
.tcx
.is_lang_item(proj.projection_term.def_id, LangItem::FnOnceOutput)
// args tuple will always be args[1]
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
{
Some((
DefIdOrName::DefId(def_id),
pred.kind().rebind(proj.term.expect_type()),
pred.kind().rebind(args.as_slice()),
))
} else {
None
}
}),
ty::Dynamic(data, _, ty::Dyn) => data.iter().find_map(|pred| {
if let ty::ExistentialPredicate::Projection(proj) = pred.skip_binder()
&& self.tcx.is_lang_item(proj.def_id, LangItem::FnOnceOutput)
// for existential projection, args are shifted over by 1
&& let ty::Tuple(args) = proj.args.type_at(0).kind()
{
Some((
DefIdOrName::Name("trait object"),
pred.rebind(proj.term.expect_type()),
pred.rebind(args.as_slice()),
))
} else {
None
}
})
{
Some((
DefIdOrName::Name("trait object"),
pred.rebind(proj.term.expect_type()),
pred.rebind(args.as_slice()),
))
} else {
None
}
ty::Param(param) => {
let generics = self.tcx.generics_of(body_id);
let name = if generics.count() > param.index as usize
&& let def = generics.param_at(param.index as usize, self.tcx)
&& matches!(def.kind, ty::GenericParamDefKind::Type { .. })
&& def.name == param.name
}),
ty::Param(param) => {
let generics = self.tcx.generics_of(body_id);
let name = if generics.count() > param.index as usize
&& let def = generics.param_at(param.index as usize, self.tcx)
&& matches!(def.kind, ty::GenericParamDefKind::Type { .. })
&& def.name == param.name
{
DefIdOrName::DefId(def.def_id)
} else {
DefIdOrName::Name("type parameter")
};
param_env.caller_bounds().iter().find_map(|pred| {
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
&& self
.tcx
.is_lang_item(proj.projection_term.def_id, LangItem::FnOnceOutput)
&& proj.projection_term.self_ty() == found
// args tuple will always be args[1]
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
{
DefIdOrName::DefId(def.def_id)
Some((
name,
pred.kind().rebind(proj.term.expect_type()),
pred.kind().rebind(args.as_slice()),
))
} else {
DefIdOrName::Name("type parameter")
};
param_env.caller_bounds().iter().find_map(|pred| {
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
&& self.tcx.is_lang_item(proj.projection_term.def_id, LangItem::FnOnceOutput)
&& proj.projection_term.self_ty() == found
// args tuple will always be args[1]
&& let ty::Tuple(args) = proj.projection_term.args.type_at(1).kind()
{
Some((
name,
pred.kind().rebind(proj.term.expect_type()),
pred.kind().rebind(args.as_slice()),
))
} else {
None
}
})
}
_ => None,
None
}
})
}
_ => None,
})
else {
return None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
} else if tcx.is_lang_item(def_id, LangItem::Sized) {
// Sized is never implementable by end-users, it is
// always automatically computed.

// FIXME: Consider moving this check to the top level as it
// may also be useful for predicates other than `Sized`
// Error type cannot possibly implement `Sized` (fixes #123154)
if let Err(e) = obligation.predicate.skip_binder().self_ty().error_reported() {
return Err(SelectionError::Overflow(e.into()));
}

let sized_conditions = self.sized_conditions(obligation);
self.assemble_builtin_bound_candidates(sized_conditions, &mut candidates);
} else if tcx.is_lang_item(def_id, LangItem::Unsize) {
Expand Down Expand Up @@ -230,13 +222,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) -> Result<(), SelectionError<'tcx>> {
debug!(?stack.obligation);

// An error type will unify with anything. So, avoid
// matching an error type with `ParamCandidate`.
// This helps us avoid spurious errors like issue #121941.
if stack.obligation.predicate.references_error() {
return Ok(());
}

let bounds = stack
.obligation
.param_env
Expand Down Expand Up @@ -563,19 +548,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &PolyTraitObligation<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) {
// Essentially any user-written impl will match with an error type,
// so creating `ImplCandidates` isn't useful. However, we might
// end up finding a candidate elsewhere (e.g. a `BuiltinCandidate` for `Sized`)
// This helps us avoid overflow: see issue #72839
// Since compilation is already guaranteed to fail, this is just
// to try to show the 'nicest' possible errors to the user.
// We don't check for errors in the `ParamEnv` - in practice,
// it seems to cause us to be overly aggressive in deciding
// to give up searching for candidates, leading to spurious errors.
if obligation.predicate.references_error() {
return;
}

let drcx = DeepRejectCtxt::relate_rigid_infer(self.tcx());
let obligation_args = obligation.predicate.skip_binder().trait_ref.args;
self.tcx().for_each_relevant_impl(
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2487,10 +2487,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);

let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
if trait_ref.references_error() {
return Err(());
}

debug!(?impl_trait_header);

let Normalized { value: impl_trait_ref, obligations: mut nested_obligations } =
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use rustc_index::bit_set::BitSet;
use rustc_middle::bug;
use rustc_middle::query::Providers;
use rustc_middle::ty::{
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
TypeVisitor, Upcast,
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Upcast,
};
use rustc_span::DUMMY_SP;
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
Expand Down Expand Up @@ -95,9 +94,6 @@ fn adt_sized_constraint<'tcx>(
let tail_ty = tcx.type_of(tail_def.did).instantiate_identity();

let constraint_ty = sized_constraint_for_ty(tcx, tail_ty)?;
if let Err(guar) = constraint_ty.error_reported() {
return Some(ty::EarlyBinder::bind(Ty::new_error(tcx, guar)));
}

// perf hack: if there is a `constraint_ty: Sized` bound, then we know
// that the type is sized and do not need to check it on the impl.
Expand Down
Loading
Loading