Skip to content

Commit 452cf4f

Browse files
committed
Auto merge of #103998 - Dylan-DPC:rollup-2nbmtc9, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #103621 (Correctly resolve Inherent Associated Types) - #103660 (improve `filesearch::get_or_default_sysroot`) - #103866 (Remove some return-type diagnostic booleans from `FnCtxt`) - #103867 (Remove `has_errors` from `FnCtxt`) - #103994 (Specify that `break` cannot be used outside of loop *or* labeled block) - #103995 (Small round of typo fixes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5b3e909 + 47e6304 commit 452cf4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+300
-412
lines changed

Cargo.lock

+3-2
Original file line numberDiff line numberDiff line change
@@ -3672,7 +3672,6 @@ dependencies = [
36723672
name = "rustc_interface"
36733673
version = "0.0.0"
36743674
dependencies = [
3675-
"libc",
36763675
"libloading",
36773676
"rustc-rayon",
36783677
"rustc-rayon-core",
@@ -3715,7 +3714,6 @@ dependencies = [
37153714
"rustc_ty_utils",
37163715
"smallvec",
37173716
"tracing",
3718-
"winapi",
37193717
]
37203718

37213719
[[package]]
@@ -4135,6 +4133,7 @@ name = "rustc_session"
41354133
version = "0.0.0"
41364134
dependencies = [
41374135
"getopts",
4136+
"libc",
41384137
"rustc_ast",
41394138
"rustc_data_structures",
41404139
"rustc_errors",
@@ -4146,7 +4145,9 @@ dependencies = [
41464145
"rustc_serialize",
41474146
"rustc_span",
41484147
"rustc_target",
4148+
"smallvec",
41494149
"tracing",
4150+
"winapi",
41504151
]
41514152

41524153
[[package]]

compiler/rustc_codegen_ssa/src/back/link.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,8 @@ fn link_sanitizer_runtime(sess: &Session, linker: &mut dyn Linker, name: &str) {
11231123
if path.exists() {
11241124
return session_tlib;
11251125
} else {
1126-
let default_sysroot = filesearch::get_or_default_sysroot();
1126+
let default_sysroot =
1127+
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
11271128
let default_tlib = filesearch::make_target_lib_path(
11281129
&default_sysroot,
11291130
sess.opts.target_triple.triple(),

compiler/rustc_error_messages/locales/en-US/passes.ftl

+8-2
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,14 @@ passes_break_inside_async_block =
451451
.async_block_label = enclosing `async` block
452452
453453
passes_outside_loop =
454-
`{$name}` outside of a loop
455-
.label = cannot `{$name}` outside of a loop
454+
`{$name}` outside of a loop{$is_break ->
455+
[true] {" or labeled block"}
456+
*[false] {""}
457+
}
458+
.label = cannot `{$name}` outside of a loop{$is_break ->
459+
[true] {" or labeled block"}
460+
*[false] {""}
461+
}
456462
457463
passes_unlabeled_in_labeled_block =
458464
unlabeled `{$cf_type}` inside of a labeled block

compiler/rustc_hir_analysis/src/astconv/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19101910
}
19111911
}
19121912
}
1913+
1914+
// see if we can satisfy using an inherent associated type
1915+
for impl_ in tcx.inherent_impls(adt_def.did()) {
1916+
let assoc_ty = tcx.associated_items(impl_).find_by_name_and_kind(
1917+
tcx,
1918+
assoc_ident,
1919+
ty::AssocKind::Type,
1920+
*impl_,
1921+
);
1922+
if let Some(assoc_ty) = assoc_ty {
1923+
let ty = tcx.type_of(assoc_ty.def_id);
1924+
return Ok((ty, DefKind::AssocTy, assoc_ty.def_id));
1925+
}
1926+
}
19131927
}
19141928

19151929
// Find the type of the associated item, and the trait where the associated

compiler/rustc_hir_typeck/src/_match.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
491491
..
492492
} = self.type_var_origin(expected)? else { return None; };
493493

494-
let sig = *self
495-
.typeck_results
496-
.borrow()
497-
.liberated_fn_sigs()
498-
.get(hir::HirId::make_owner(self.body_id.owner.def_id))?;
494+
let sig = self.body_fn_sig()?;
499495

500496
let substs = sig.output().walk().find_map(|arg| {
501497
if let ty::GenericArgKind::Type(ty) = arg.unpack()

compiler/rustc_hir_typeck/src/check.rs

-5
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ pub(super) fn check_fn<'a, 'tcx>(
3131
fn_id: hir::HirId,
3232
body: &'tcx hir::Body<'tcx>,
3333
can_be_generator: Option<hir::Movability>,
34-
return_type_pre_known: bool,
3534
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
3635
// Create the function context. This is either derived from scratch or,
3736
// in the case of closures, based on the outer context.
3837
let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id);
3938
fcx.ps.set(UnsafetyState::function(fn_sig.unsafety, fn_id));
40-
fcx.return_type_pre_known = return_type_pre_known;
4139

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

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

compiler/rustc_hir_typeck/src/closure.rs

-3
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8383

8484
debug!(?bound_sig, ?liberated_sig);
8585

86-
let return_type_pre_known = !liberated_sig.output().is_ty_infer();
87-
8886
let generator_types = check_fn(
8987
self,
9088
self.param_env.without_const(),
@@ -93,7 +91,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9391
expr.hir_id,
9492
body,
9593
gen,
96-
return_type_pre_known,
9794
)
9895
.1;
9996

compiler/rustc_hir_typeck/src/coercion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17821782
// may occur at the first return expression we see in the closure
17831783
// (if it conflicts with the declared return type). Skip adding a
17841784
// note in this case, since it would be incorrect.
1785-
&& !fcx.return_type_pre_known
1785+
&& let Some(fn_sig) = fcx.body_fn_sig()
1786+
&& fn_sig.output().is_ty_var()
17861787
{
17871788
err.span_note(
17881789
sp,

compiler/rustc_hir_typeck/src/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
220220

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

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

260259
// Combine the diverging and has_error flags.
261260
self.diverges.set(self.diverges.get() | old_diverges);
262-
self.has_errors.set(self.has_errors.get() | old_has_errors);
263261

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

843-
if self.return_type_has_opaque {
841+
if let Some(fn_sig) = self.body_fn_sig()
842+
&& fn_sig.output().has_opaque_types()
843+
{
844844
// Point any obligations that were registered due to opaque type
845845
// inference at the return expression.
846846
self.select_obligations_where_possible(false, |errors| {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
143143
self.typeck_results.borrow_mut().node_types_mut().insert(id, ty);
144144

145145
if ty.references_error() {
146-
self.has_errors.set(true);
147146
self.set_tainted_by_errors();
148147
}
149148
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13341334

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

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

13651364
// Combine the diverging and `has_error` flags.
13661365
self.diverges.set(self.diverges.get() | old_diverges);
1367-
self.has_errors.set(self.has_errors.get() | old_has_errors);
13681366
}
13691367

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

1547-
let mut ty = ctxt.coerce.unwrap().complete(self);
1548-
1549-
if self.has_errors.get() || ty.references_error() {
1550-
ty = self.tcx.ty_error()
1551-
}
1545+
let ty = ctxt.coerce.unwrap().complete(self);
15521546

15531547
self.write_ty(blk.hir_id, ty);
15541548

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

-15
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,9 @@ pub struct FnCtxt<'a, 'tcx> {
112112
/// the diverges flag is set to something other than `Maybe`.
113113
pub(super) diverges: Cell<Diverges>,
114114

115-
/// Whether any child nodes have any type errors.
116-
pub(super) has_errors: Cell<bool>,
117-
118115
pub(super) enclosing_breakables: RefCell<EnclosingBreakables<'tcx>>,
119116

120117
pub(super) inh: &'a Inherited<'tcx>,
121-
122-
/// True if the function or closure's return type is known before
123-
/// entering the function/closure, i.e. if the return type is
124-
/// either given explicitly or inferred from, say, an `Fn*` trait
125-
/// bound. Used for diagnostic purposes only.
126-
pub(super) return_type_pre_known: bool,
127-
128-
/// True if the return type has an Opaque type
129-
pub(super) return_type_has_opaque: bool,
130118
}
131119

132120
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -145,14 +133,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
145133
resume_yield_tys: None,
146134
ps: Cell::new(UnsafetyState::function(hir::Unsafety::Normal, hir::CRATE_HIR_ID)),
147135
diverges: Cell::new(Diverges::Maybe),
148-
has_errors: Cell::new(false),
149136
enclosing_breakables: RefCell::new(EnclosingBreakables {
150137
stack: Vec::new(),
151138
by_id: Default::default(),
152139
}),
153140
inh,
154-
return_type_pre_known: true,
155-
return_type_has_opaque: false,
156141
}
157142
}
158143

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ use rustc_trait_selection::traits::error_reporting::DefIdOrName;
2222
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
2323

2424
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25+
pub(crate) fn body_fn_sig(&self) -> Option<ty::FnSig<'tcx>> {
26+
self.typeck_results
27+
.borrow()
28+
.liberated_fn_sigs()
29+
.get(self.tcx.hir().get_parent_node(self.body_id))
30+
.copied()
31+
}
32+
2533
pub(in super::super) fn suggest_semicolon_at_end(&self, span: Span, err: &mut Diagnostic) {
2634
err.span_suggestion_short(
2735
span.shrink_to_hi(),

compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ fn typeck_with_fallback<'tcx>(
250250
param_env,
251251
fn_sig,
252252
);
253-
check_fn(&inh, param_env, fn_sig, decl, id, body, None, true).0
253+
check_fn(&inh, param_env, fn_sig, decl, id, body, None).0
254254
} else {
255255
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
256256
let expected_type = body_ty

compiler/rustc_interface/Cargo.toml

-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ rustc_resolve = { path = "../rustc_resolve" }
4848
rustc_trait_selection = { path = "../rustc_trait_selection" }
4949
rustc_ty_utils = { path = "../rustc_ty_utils" }
5050

51-
[target.'cfg(unix)'.dependencies]
52-
libc = "0.2"
53-
54-
[target.'cfg(windows)'.dependencies]
55-
winapi = { version = "0.3", features = ["libloaderapi"] }
56-
5751
[dev-dependencies]
5852
rustc_target = { path = "../rustc_target" }
5953

0 commit comments

Comments
 (0)