Skip to content

Commit

Permalink
Auto merge of rust-lang#103998 - Dylan-DPC:rollup-2nbmtc9, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - rust-lang#103621 (Correctly resolve Inherent Associated Types)
 - rust-lang#103660 (improve `filesearch::get_or_default_sysroot`)
 - rust-lang#103866 (Remove some return-type diagnostic booleans from `FnCtxt`)
 - rust-lang#103867 (Remove `has_errors` from `FnCtxt`)
 - rust-lang#103994 (Specify that `break` cannot be used outside of loop *or* labeled block)
 - rust-lang#103995 (Small round of typo fixes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 5, 2022
2 parents 5b3e909 + 47e6304 commit 452cf4f
Show file tree
Hide file tree
Showing 52 changed files with 300 additions and 412 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3672,7 +3672,6 @@ dependencies = [
name = "rustc_interface"
version = "0.0.0"
dependencies = [
"libc",
"libloading",
"rustc-rayon",
"rustc-rayon-core",
Expand Down Expand Up @@ -3715,7 +3714,6 @@ dependencies = [
"rustc_ty_utils",
"smallvec",
"tracing",
"winapi",
]

[[package]]
Expand Down Expand Up @@ -4135,6 +4133,7 @@ name = "rustc_session"
version = "0.0.0"
dependencies = [
"getopts",
"libc",
"rustc_ast",
"rustc_data_structures",
"rustc_errors",
Expand All @@ -4146,7 +4145,9 @@ dependencies = [
"rustc_serialize",
"rustc_span",
"rustc_target",
"smallvec",
"tracing",
"winapi",
]

[[package]]
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,8 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
if path.exists() {
return session_tlib;
} else {
let default_sysroot = filesearch::get_or_default_sysroot();
let default_sysroot =
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
let default_tlib = filesearch::make_target_lib_path(
&default_sysroot,
sess.opts.target_triple.triple(),
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_error_messages/locales/en-US/passes.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,14 @@ passes_break_inside_async_block =
.async_block_label = enclosing `async` block
passes_outside_loop =
`{$name}` outside of a loop
.label = cannot `{$name}` outside of a loop
`{$name}` outside of a loop{$is_break ->
[true] {" or labeled block"}
*[false] {""}
}
.label = cannot `{$name}` outside of a loop{$is_break ->
[true] {" or labeled block"}
*[false] {""}
}
passes_unlabeled_in_labeled_block =
unlabeled `{$cf_type}` inside of a labeled block
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
}
}

// see if we can satisfy using an inherent associated type
for impl_ in tcx.inherent_impls(adt_def.did()) {
let assoc_ty = tcx.associated_items(impl_).find_by_name_and_kind(
tcx,
assoc_ident,
ty::AssocKind::Type,
*impl_,
);
if let Some(assoc_ty) = assoc_ty {
let ty = tcx.type_of(assoc_ty.def_id);
return Ok((ty, DefKind::AssocTy, assoc_ty.def_id));
}
}
}

// Find the type of the associated item, and the trait where the associated
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
..
} = self.type_var_origin(expected)? else { return None; };

let sig = *self
.typeck_results
.borrow()
.liberated_fn_sigs()
.get(hir::HirId::make_owner(self.body_id.owner.def_id))?;
let sig = self.body_fn_sig()?;

let substs = sig.output().walk().find_map(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_hir_typeck/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ pub(super) fn check_fn<'a, 'tcx>(
fn_id: hir::HirId,
body: &'tcx hir::Body<'tcx>,
can_be_generator: Option<hir::Movability>,
return_type_pre_known: bool,
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
// Create the function context. This is either derived from scratch or,
// in the case of closures, based on the outer context.
let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id);
fcx.ps.set(UnsafetyState::function(fn_sig.unsafety, fn_id));
fcx.return_type_pre_known = return_type_pre_known;

let tcx = fcx.tcx;
let hir = tcx.hir();
Expand All @@ -51,9 +49,6 @@ pub(super) fn check_fn<'a, 'tcx>(
decl.output.span(),
param_env,
));
// If we replaced declared_ret_ty with infer vars, then we must be inferring
// an opaque type, so set a flag so we can improve diagnostics.
fcx.return_type_has_opaque = ret_ty != declared_ret_ty;

fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));

Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

debug!(?bound_sig, ?liberated_sig);

let return_type_pre_known = !liberated_sig.output().is_ty_infer();

let generator_types = check_fn(
self,
self.param_env.without_const(),
Expand All @@ -93,7 +91,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr.hir_id,
body,
gen,
return_type_pre_known,
)
.1;

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
// may occur at the first return expression we see in the closure
// (if it conflicts with the declared return type). Skip adding a
// note in this case, since it would be incorrect.
&& !fcx.return_type_pre_known
&& let Some(fn_sig) = fcx.body_fn_sig()
&& fn_sig.output().is_ty_var()
{
err.span_note(
sp,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Hide the outer diverging and has_errors flags.
let old_diverges = self.diverges.replace(Diverges::Maybe);
let old_has_errors = self.has_errors.replace(false);

let ty = ensure_sufficient_stack(|| match &expr.kind {
hir::ExprKind::Path(
Expand Down Expand Up @@ -259,7 +258,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Combine the diverging and has_error flags.
self.diverges.set(self.diverges.get() | old_diverges);
self.has_errors.set(self.has_errors.get() | old_has_errors);

debug!("type of {} is...", self.tcx.hir().node_to_string(expr.hir_id));
debug!("... {:?}, expected is {:?}", ty, expected);
Expand Down Expand Up @@ -840,7 +838,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return_expr_ty,
);

if self.return_type_has_opaque {
if let Some(fn_sig) = self.body_fn_sig()
&& fn_sig.output().has_opaque_types()
{
// Point any obligations that were registered due to opaque type
// inference at the return expression.
self.select_obligations_where_possible(false, |errors| {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.typeck_results.borrow_mut().node_types_mut().insert(id, ty);

if ty.references_error() {
self.has_errors.set(true);
self.set_tainted_by_errors();
}
}
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Hide the outer diverging and `has_errors` flags.
let old_diverges = self.diverges.replace(Diverges::Maybe);
let old_has_errors = self.has_errors.replace(false);

match stmt.kind {
hir::StmtKind::Local(l) => {
Expand Down Expand Up @@ -1364,7 +1363,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Combine the diverging and `has_error` flags.
self.diverges.set(self.diverges.get() | old_diverges);
self.has_errors.set(self.has_errors.get() | old_has_errors);
}

pub fn check_block_no_value(&self, blk: &'tcx hir::Block<'tcx>) {
Expand Down Expand Up @@ -1544,11 +1542,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.diverges.set(prev_diverges);
}

let mut ty = ctxt.coerce.unwrap().complete(self);

if self.has_errors.get() || ty.references_error() {
ty = self.tcx.ty_error()
}
let ty = ctxt.coerce.unwrap().complete(self);

self.write_ty(blk.hir_id, ty);

Expand Down
15 changes: 0 additions & 15 deletions compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,9 @@ pub struct FnCtxt<'a, 'tcx> {
/// the diverges flag is set to something other than `Maybe`.
pub(super) diverges: Cell<Diverges>,

/// Whether any child nodes have any type errors.
pub(super) has_errors: Cell<bool>,

pub(super) enclosing_breakables: RefCell<EnclosingBreakables<'tcx>>,

pub(super) inh: &'a Inherited<'tcx>,

/// True if the function or closure's return type is known before
/// entering the function/closure, i.e. if the return type is
/// either given explicitly or inferred from, say, an `Fn*` trait
/// bound. Used for diagnostic purposes only.
pub(super) return_type_pre_known: bool,

/// True if the return type has an Opaque type
pub(super) return_type_has_opaque: bool,
}

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Expand All @@ -145,14 +133,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
resume_yield_tys: None,
ps: Cell::new(UnsafetyState::function(hir::Unsafety::Normal, hir::CRATE_HIR_ID)),
diverges: Cell::new(Diverges::Maybe),
has_errors: Cell::new(false),
enclosing_breakables: RefCell::new(EnclosingBreakables {
stack: Vec::new(),
by_id: Default::default(),
}),
inh,
return_type_pre_known: true,
return_type_has_opaque: false,
}
}

Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ use rustc_trait_selection::traits::error_reporting::DefIdOrName;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(crate) fn body_fn_sig(&self) -> Option<ty::FnSig<'tcx>> {
self.typeck_results
.borrow()
.liberated_fn_sigs()
.get(self.tcx.hir().get_parent_node(self.body_id))
.copied()
}

pub(in super::super) fn suggest_semicolon_at_end(&self, span: Span, err: &mut Diagnostic) {
err.span_suggestion_short(
span.shrink_to_hi(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn typeck_with_fallback<'tcx>(
param_env,
fn_sig,
);
check_fn(&inh, param_env, fn_sig, decl, id, body, None, true).0
check_fn(&inh, param_env, fn_sig, decl, id, body, None).0
} else {
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
let expected_type = body_ty
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ rustc_resolve = { path = "../rustc_resolve" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_ty_utils = { path = "../rustc_ty_utils" }

[target.'cfg(unix)'.dependencies]
libc = "0.2"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["libloaderapi"] }

[dev-dependencies]
rustc_target = { path = "../rustc_target" }

Expand Down
Loading

0 comments on commit 452cf4f

Please sign in to comment.