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 #110976

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4f7b895
Tweak borrow suggestion
compiler-errors Apr 18, 2023
ab99cdf
Rename some suggestion/note functions
compiler-errors Apr 18, 2023
cf24419
Make suggest_deref_or_ref return a multipart suggestion
compiler-errors Apr 18, 2023
2bf5f77
treat the dev channel as nightly in compiletest
pietroalbini Apr 17, 2023
4edba55
add support for `// unset-exec-env` in compiletest
pietroalbini Apr 17, 2023
eb00459
update tests for the test harness's json formatting
pietroalbini Apr 17, 2023
5fa8209
Clear response values for overflow in new solver
compiler-errors Apr 19, 2023
ee89421
Split out make_ambiguous_response_no_constraints
compiler-errors Apr 26, 2023
c7b7248
Bump libffi-sys to 2.3.0
heiher Apr 27, 2023
21ae5bd
Add support for LibreSSL 3.7.x
mixi Apr 28, 2023
24adb1f
include source error for LoadLibraryExW
Apr 28, 2023
dc94522
bless line changes in tests-listing-format-json.run.stdout
cuviper Apr 28, 2023
33871c9
Make sure that signatures aren't accidental refinements
compiler-errors Apr 28, 2023
7f26191
Make drop_flags an IndexVec.
cjgillot Apr 28, 2023
4e05cfb
Don't duplicate anonymous lifetimes for async fn in traits
compiler-errors Apr 28, 2023
2f33a82
Rollup merge of #110504 - compiler-errors:tweak-borrow-sugg, r=cjgillot
matthiaskrgr Apr 29, 2023
9546b11
Rollup merge of #110614 - compiler-errors:new-solver-overflow-respons…
matthiaskrgr Apr 29, 2023
f2b2737
Rollup merge of #110644 - pietroalbini:pa-json-formatting-tests, r=Ma…
matthiaskrgr Apr 29, 2023
f0ebc03
Rollup merge of #110894 - loongarch-rs:bump-libffi-sys, r=Mark-Simula…
matthiaskrgr Apr 29, 2023
153ccd2
Rollup merge of #110932 - sameer:master, r=michaelwoerister
matthiaskrgr Apr 29, 2023
f381756
Rollup merge of #110951 - mixi:libressl-3.7.x, r=Mark-Simulacrum
matthiaskrgr Apr 29, 2023
6e76497
Rollup merge of #110958 - compiler-errors:stdlib-refinement, r=cuviper
matthiaskrgr Apr 29, 2023
862d50c
Rollup merge of #110962 - cjgillot:no-hash-drops, r=compiler-errors
matthiaskrgr Apr 29, 2023
e8a3d8c
Rollup merge of #110965 - compiler-errors:anon-lt-dupe-oops, r=cjgillot
matthiaskrgr Apr 29, 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
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1956,9 +1956,9 @@ dependencies = [

[[package]]
name = "libffi-sys"
version = "2.2.1"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc65067b78c0fc069771e8b9a9e02df71e08858bec92c1f101377c67b9dca7c7"
checksum = "f36115160c57e8529781b4183c2bb51fdc1f6d6d1ed345591d84be7703befb3c"
dependencies = [
"cc",
]
Expand Down Expand Up @@ -2370,9 +2370,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"

[[package]]
name = "openssl-sys"
version = "0.9.84"
version = "0.9.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a20eace9dc2d82904039cb76dcf50fb1a0bba071cfd1629720b5d6f1ddba0fa"
checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e"
dependencies = [
"cc",
"libc",
Expand Down
198 changes: 102 additions & 96 deletions compiler/rustc_hir_typeck/src/demand.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
) -> bool {
let expr = expr.peel_blocks();
if let Some((sp, msg, suggestion, applicability, verbose, annotation)) =
self.check_ref(expr, found, expected)
if let Some((suggestion, msg, applicability, verbose, annotation)) =
self.suggest_deref_or_ref(expr, found, expected)
{
if verbose {
err.span_suggestion_verbose(sp, &msg, suggestion, applicability);
err.multipart_suggestion_verbose(&msg, suggestion, applicability);
} else {
err.span_suggestion(sp, &msg, suggestion, applicability);
err.multipart_suggestion(&msg, suggestion, applicability);
}
if annotation {
let suggest_annotation = match expr.peel_drop_temps().kind {
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_label(sp, format!("{descr} `{name}` defined here"));
}
return true;
} else if self.check_for_cast(err, expr, found, expected, expected_ty_expr) {
} else if self.suggest_cast(err, expr, found, expected, expected_ty_expr) {
return true;
} else {
let methods = self.get_conversion_methods(expr.span, expected, found, expr.hir_id);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}

self.check_for_inner_self(&mut err, source, rcvr_ty, item_name);
self.suggest_unwrapping_inner_self(&mut err, source, rcvr_ty, item_name);

bound_spans.sort();
bound_spans.dedup();
Expand Down Expand Up @@ -1131,7 +1131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

self.check_for_deref_method(&mut err, source, rcvr_ty, item_name, expected);
self.note_derefed_ty_has_method(&mut err, source, rcvr_ty, item_name, expected);
return Some(err);
}

Expand Down Expand Up @@ -1804,7 +1804,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

fn check_for_inner_self(
fn suggest_unwrapping_inner_self(
&self,
err: &mut Diagnostic,
source: SelfSource<'tcx>,
Expand Down Expand Up @@ -2174,7 +2174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

fn check_for_deref_method(
fn note_derefed_ty_has_method(
&self,
err: &mut Diagnostic,
self_source: SelfSource<'tcx>,
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use rustc_span::{Span, DUMMY_SP};
use rustc_target::spec::{PanicStrategy, TargetTriple};

use proc_macro::bridge::client::ProcMacro;
use std::error::Error;
use std::ops::Fn;
use std::path::Path;
use std::time::Duration;
Expand Down Expand Up @@ -1094,5 +1095,12 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
}

debug!("Failed to load proc-macro `{}` even after {} attempts.", path.display(), max_attempts);
Err(format!("{} (retried {} times)", last_error.unwrap(), max_attempts))

let last_error = last_error.unwrap();
let message = if let Some(src) = last_error.source() {
format!("{last_error} ({src}) (retried {max_attempts} times)")
} else {
format!("{last_error} (retried {max_attempts} times)")
};
Err(message)
}
15 changes: 8 additions & 7 deletions compiler/rustc_mir_transform/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::deref_separator::deref_finder;
use crate::MirPass;
use rustc_data_structures::fx::FxHashMap;
use rustc_index::bit_set::BitSet;
use rustc_index::IndexVec;
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt};
Expand Down Expand Up @@ -84,12 +84,13 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {

let reachable = traversal::reachable_as_bitset(body);

let drop_flags = IndexVec::from_elem(None, &env.move_data.move_paths);
ElaborateDropsCtxt {
tcx,
body,
env: &env,
init_data: InitializationData { inits, uninits },
drop_flags: Default::default(),
drop_flags,
patch: MirPatch::new(body),
un_derefer: un_derefer,
reachable,
Expand Down Expand Up @@ -293,7 +294,7 @@ struct ElaborateDropsCtxt<'a, 'tcx> {
body: &'a Body<'tcx>,
env: &'a MoveDataParamEnv<'tcx>,
init_data: InitializationData<'a, 'tcx>,
drop_flags: FxHashMap<MovePathIndex, Local>,
drop_flags: IndexVec<MovePathIndex, Option<Local>>,
patch: MirPatch<'tcx>,
un_derefer: UnDerefer<'tcx>,
reachable: BitSet<BasicBlock>,
Expand All @@ -312,11 +313,11 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
let tcx = self.tcx;
let patch = &mut self.patch;
debug!("create_drop_flag({:?})", self.body.span);
self.drop_flags.entry(index).or_insert_with(|| patch.new_internal(tcx.types.bool, span));
self.drop_flags[index].get_or_insert_with(|| patch.new_internal(tcx.types.bool, span));
}

fn drop_flag(&mut self, index: MovePathIndex) -> Option<Place<'tcx>> {
self.drop_flags.get(&index).map(|t| Place::from(*t))
self.drop_flags[index].map(Place::from)
}

/// create a patch that elaborates all drops in the input
Expand Down Expand Up @@ -463,7 +464,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
}

fn set_drop_flag(&mut self, loc: Location, path: MovePathIndex, val: DropFlagState) {
if let Some(&flag) = self.drop_flags.get(&path) {
if let Some(flag) = self.drop_flags[path] {
let span = self.patch.source_info_for_location(self.body, loc).span;
let val = self.constant_bool(span, val.value());
self.patch.add_assign(loc, Place::from(flag), val);
Expand All @@ -474,7 +475,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
let loc = Location::START;
let span = self.patch.source_info_for_location(self.body, loc).span;
let false_ = self.constant_bool(span, false);
for flag in self.drop_flags.values() {
for flag in self.drop_flags.iter().flatten() {
self.patch.add_assign(loc, Place::from(*flag), false_.clone());
}
}
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,13 +859,9 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)),
&sig.decl.output,
);

this.record_lifetime_params_for_async(
fn_id,
sig.header.asyncness.opt_return_id(),
);
},
);
self.record_lifetime_params_for_async(fn_id, sig.header.asyncness.opt_return_id());
return;
}
FnKind::Fn(..) => {
Expand Down
19 changes: 13 additions & 6 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rustc_infer::infer::at::ToTrace;
use rustc_infer::infer::canonical::CanonicalVarValues;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::infer::{
DefineOpaqueTypes, InferCtxt, InferOk, LateBoundRegionConversionTime, TyCtxtInferExt,
DefineOpaqueTypes, InferCtxt, InferOk, LateBoundRegionConversionTime, RegionVariableOrigin,
TyCtxtInferExt,
};
use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::ObligationCause;
Expand Down Expand Up @@ -223,18 +224,20 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
{
debug!("rerunning goal to check result is stable");
let (_orig_values, canonical_goal) = self.canonicalize_goal(goal);
let canonical_response =
let new_canonical_response =
EvalCtxt::evaluate_canonical_goal(self.tcx(), self.search_graph, canonical_goal)?;
if !canonical_response.value.var_values.is_identity() {
if !new_canonical_response.value.var_values.is_identity() {
bug!(
"unstable result: re-canonicalized goal={canonical_goal:#?} \
response={canonical_response:#?}"
first_response={canonical_response:#?} \
second_response={new_canonical_response:#?}"
);
}
if certainty != canonical_response.value.certainty {
if certainty != new_canonical_response.value.certainty {
bug!(
"unstable certainty: {certainty:#?} re-canonicalized goal={canonical_goal:#?} \
response={canonical_response:#?}"
first_response={canonical_response:#?} \
second_response={new_canonical_response:#?}"
);
}
}
Expand Down Expand Up @@ -434,6 +437,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
})
}

pub(super) fn next_region_infer(&self) -> ty::Region<'tcx> {
self.infcx.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
}

pub(super) fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
self.infcx.next_const_var(
ty,
Expand Down
58 changes: 55 additions & 3 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_infer::infer::canonical::query_response::make_query_region_constraints
use rustc_infer::infer::canonical::CanonicalVarValues;
use rustc_infer::infer::canonical::{CanonicalExt, QueryRegionConstraints};
use rustc_middle::traits::query::NoSolution;
use rustc_middle::traits::solve::{ExternalConstraints, ExternalConstraintsData};
use rustc_middle::traits::solve::{ExternalConstraints, ExternalConstraintsData, MaybeCause};
use rustc_middle::ty::{self, BoundVar, GenericArgKind};
use rustc_span::DUMMY_SP;
use std::iter;
Expand Down Expand Up @@ -60,9 +60,27 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {

let certainty = certainty.unify_with(goals_certainty);

let external_constraints = self.compute_external_query_constraints()?;
let response = match certainty {
Certainty::Yes | Certainty::Maybe(MaybeCause::Ambiguity) => {
let external_constraints = self.compute_external_query_constraints()?;
Response { var_values: self.var_values, external_constraints, certainty }
}
Certainty::Maybe(MaybeCause::Overflow) => {
// If we have overflow, it's probable that we're substituting a type
// into itself infinitely and any partial substitutions in the query
// response are probably not useful anyways, so just return an empty
// query response.
//
// This may prevent us from potentially useful inference, e.g.
// 2 candidates, one ambiguous and one overflow, which both
// have the same inference constraints.
//
// Changing this to retain some constraints in the future
// won't be a breaking change, so this is good enough for now.
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Overflow));
}
};

let response = Response { var_values: self.var_values, external_constraints, certainty };
let canonical = Canonicalizer::canonicalize(
self.infcx,
CanonicalizeMode::Response { max_input_universe: self.max_input_universe },
Expand All @@ -72,6 +90,40 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
Ok(canonical)
}

/// Constructs a totally unconstrained, ambiguous response to a goal.
///
/// Take care when using this, since often it's useful to respond with
/// ambiguity but return constrained variables to guide inference.
pub(in crate::solve) fn make_ambiguous_response_no_constraints(
&self,
maybe_cause: MaybeCause,
) -> CanonicalResponse<'tcx> {
let unconstrained_response = Response {
var_values: CanonicalVarValues {
var_values: self.tcx().mk_substs_from_iter(self.var_values.var_values.iter().map(
|arg| -> ty::GenericArg<'tcx> {
match arg.unpack() {
GenericArgKind::Lifetime(_) => self.next_region_infer().into(),
GenericArgKind::Type(_) => self.next_ty_infer().into(),
GenericArgKind::Const(ct) => self.next_const_infer(ct.ty()).into(),
}
},
)),
},
external_constraints: self
.tcx()
.mk_external_constraints(ExternalConstraintsData::default()),
certainty: Certainty::Maybe(maybe_cause),
};

Canonicalizer::canonicalize(
self.infcx,
CanonicalizeMode::Response { max_input_universe: self.max_input_universe },
&mut Default::default(),
unconstrained_response,
)
}

#[instrument(level = "debug", skip(self), ret)]
fn compute_external_query_constraints(&self) -> Result<ExternalConstraints<'tcx>, NoSolution> {
// Cannot use `take_registered_region_obligations` as we may compute the response
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_trait_selection/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,17 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
if responses.is_empty() {
return Err(NoSolution);
}
let certainty = responses.iter().fold(Certainty::AMBIGUOUS, |certainty, response| {
certainty.unify_with(response.value.certainty)
});

let response = self.evaluate_added_goals_and_make_canonical_response(certainty);
if let Ok(response) = response {
assert!(response.has_no_inference_or_external_constraints());
Ok(response)
} else {
bug!("failed to make floundered response: {responses:?}");
}

let Certainty::Maybe(maybe_cause) = responses.iter().fold(
Certainty::AMBIGUOUS,
|certainty, response| {
certainty.unify_with(response.value.certainty)
},
) else {
bug!("expected flounder response to be ambiguous")
};

Ok(self.make_ambiguous_response_no_constraints(maybe_cause))
}
}

Expand Down
Loading