Skip to content

Commit b08148f

Browse files
committed
Auto merge of rust-lang#111869 - Dylan-DPC:rollup-9pydw08, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#111461 (Fix symbol conflict diagnostic mistakenly being shown instead of missing crate diagnostic) - rust-lang#111579 (Also assume wrap-around discriminants in `as` MIR building) - rust-lang#111704 (Remove return type sized check hack from hir typeck) - rust-lang#111853 (Check opaques for mismatch during writeback) - rust-lang#111854 (rustdoc: clean up `settings.css`) - rust-lang#111860 (Don't ICE if method receiver fails to unify with `arbitrary_self_types`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f3d597b + c4f2a62 commit b08148f

File tree

46 files changed

+615
-567
lines changed

Some content is hidden

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

46 files changed

+615
-567
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
152152
let guar = ty.error_reported().err().unwrap_or_else(|| {
153153
prev.report_mismatch(
154154
&OpaqueHiddenType { ty, span: concrete_type.span },
155+
opaque_type_key.def_id,
155156
infcx.tcx,
156157
)
158+
.emit()
157159
});
158160
prev.ty = infcx.tcx.ty_error(guar);
159161
}

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ pub enum StashKey {
478478
MaybeFruTypo,
479479
CallAssocMethod,
480480
TraitMissingMethod,
481+
OpaqueHiddenTypeMismatch,
481482
}
482483

483484
fn default_track_diagnostic(d: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) {

compiler/rustc_hir_analysis/src/collect/type_of.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
584584
debug!(?concrete_type, "found constraint");
585585
if let Some(prev) = &mut self.found {
586586
if concrete_type.ty != prev.ty && !(concrete_type, prev.ty).references_error() {
587-
let guar = prev.report_mismatch(&concrete_type, self.tcx);
587+
let guar =
588+
prev.report_mismatch(&concrete_type, self.def_id, self.tcx).emit();
588589
prev.ty = self.tcx.ty_error(guar);
589590
}
590591
} else {
@@ -678,10 +679,10 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
678679
// Only check against typeck if we didn't already error
679680
if !hidden.ty.references_error() {
680681
for concrete_type in locator.typeck_types {
681-
if tcx.erase_regions(concrete_type.ty) != tcx.erase_regions(hidden.ty)
682+
if concrete_type.ty != tcx.erase_regions(hidden.ty)
682683
&& !(concrete_type, hidden).references_error()
683684
{
684-
hidden.report_mismatch(&concrete_type, tcx);
685+
hidden.report_mismatch(&concrete_type, def_id, tcx).emit();
685686
}
686687
}
687688
}
@@ -722,7 +723,7 @@ fn find_opaque_ty_constraints_for_rpit(
722723
if concrete_type.ty != self.found.ty
723724
&& !(concrete_type, self.found).references_error()
724725
{
725-
self.found.report_mismatch(&concrete_type, self.tcx);
726+
self.found.report_mismatch(&concrete_type, self.def_id, self.tcx).emit();
726727
}
727728
}
728729
}

compiler/rustc_hir_typeck/src/check.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,8 @@ pub(super) fn check_fn<'a, 'tcx>(
103103

104104
fcx.typeck_results.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig);
105105

106-
if let ty::Dynamic(_, _, ty::Dyn) = declared_ret_ty.kind() {
107-
// FIXME: We need to verify that the return type is `Sized` after the return expression has
108-
// been evaluated so that we have types available for all the nodes being returned, but that
109-
// requires the coerced evaluated type to be stored. Moving `check_return_expr` before this
110-
// causes unsized errors caused by the `declared_ret_ty` to point at the return expression,
111-
// while keeping the current ordering we will ignore the tail expression's type because we
112-
// don't know it yet. We can't do `check_expr_kind` while keeping `check_return_expr`
113-
// because we will trigger "unreachable expression" lints unconditionally.
114-
// Because of all of this, we perform a crude check to know whether the simplest `!Sized`
115-
// case that a newcomer might make, returning a bare trait, and in that case we populate
116-
// the tail expression's type so that the suggestion will be correct, but ignore all other
117-
// possible cases.
118-
fcx.check_expr(&body.value);
119-
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
120-
} else {
121-
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
122-
fcx.check_return_expr(&body.value, false);
123-
}
106+
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
107+
fcx.check_return_expr(&body.value, false);
124108

125109
// We insert the deferred_generator_interiors entry after visiting the body.
126110
// This ensures that all nested generators appear before the entry of this generator.

compiler/rustc_hir_typeck/src/method/confirm.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
471471
self_ty, method_self_ty, self.span, pick
472472
);
473473
let cause = self.cause(
474-
self.span,
474+
self.self_expr.span,
475475
ObligationCauseCode::UnifyReceiver(Box::new(UnifyReceiverContext {
476476
assoc_item: pick.item,
477477
param_env: self.param_env,
@@ -482,13 +482,22 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
482482
Ok(InferOk { obligations, value: () }) => {
483483
self.register_predicates(obligations);
484484
}
485-
Err(_) => {
486-
span_bug!(
487-
self.span,
488-
"{} was a subtype of {} but now is not?",
489-
self_ty,
490-
method_self_ty
491-
);
485+
Err(terr) => {
486+
// FIXME(arbitrary_self_types): We probably should limit the
487+
// situations where this can occur by adding additional restrictions
488+
// to the feature, like the self type can't reference method substs.
489+
if self.tcx.features().arbitrary_self_types {
490+
self.err_ctxt()
491+
.report_mismatched_types(&cause, method_self_ty, self_ty, terr)
492+
.emit();
493+
} else {
494+
span_bug!(
495+
self.span,
496+
"{} was a subtype of {} but now is not?",
497+
self_ty,
498+
method_self_ty
499+
);
500+
}
492501
}
493502
}
494503
}

compiler/rustc_hir_typeck/src/writeback.rs

+31-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::FnCtxt;
66
use hir::def_id::LocalDefId;
77
use rustc_data_structures::fx::FxHashMap;
8-
use rustc_errors::ErrorGuaranteed;
8+
use rustc_errors::{ErrorGuaranteed, StashKey};
99
use rustc_hir as hir;
1010
use rustc_hir::intravisit::{self, Visitor};
1111
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
@@ -82,10 +82,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8282
wbcx.typeck_results.treat_byte_string_as_slice =
8383
mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice);
8484

85-
if let Some(e) = self.tainted_by_errors() {
86-
wbcx.typeck_results.tainted_by_errors = Some(e);
87-
}
88-
8985
debug!("writeback: typeck results for {:?} are {:#?}", item_def_id, wbcx.typeck_results);
9086

9187
self.tcx.arena.alloc(wbcx.typeck_results)
@@ -118,12 +114,21 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
118114
) -> WritebackCx<'cx, 'tcx> {
119115
let owner = body.id().hir_id.owner;
120116

121-
WritebackCx {
117+
let mut wbcx = WritebackCx {
122118
fcx,
123119
typeck_results: ty::TypeckResults::new(owner),
124120
body,
125121
rustc_dump_user_substs,
122+
};
123+
124+
// HACK: We specifically don't want the (opaque) error from tainting our
125+
// inference context. That'll prevent us from doing opaque type inference
126+
// later on in borrowck, which affects diagnostic spans pretty negatively.
127+
if let Some(e) = fcx.tainted_by_errors() {
128+
wbcx.typeck_results.tainted_by_errors = Some(e);
126129
}
130+
131+
wbcx
127132
}
128133

129134
fn tcx(&self) -> TyCtxt<'tcx> {
@@ -578,13 +583,26 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
578583
continue;
579584
}
580585

581-
let hidden_type = hidden_type.remap_generic_params_to_declaration_params(
582-
opaque_type_key,
583-
self.fcx.infcx.tcx,
584-
true,
585-
);
586-
587-
self.typeck_results.concrete_opaque_types.insert(opaque_type_key.def_id, hidden_type);
586+
let hidden_type =
587+
self.tcx().erase_regions(hidden_type.remap_generic_params_to_declaration_params(
588+
opaque_type_key,
589+
self.tcx(),
590+
true,
591+
));
592+
593+
if let Some(last_opaque_ty) = self
594+
.typeck_results
595+
.concrete_opaque_types
596+
.insert(opaque_type_key.def_id, hidden_type)
597+
&& last_opaque_ty.ty != hidden_type.ty
598+
{
599+
hidden_type
600+
.report_mismatch(&last_opaque_ty, opaque_type_key.def_id, self.tcx())
601+
.stash(
602+
self.tcx().def_span(opaque_type_key.def_id),
603+
StashKey::OpaqueHiddenTypeMismatch,
604+
);
605+
}
588606
}
589607
}
590608

compiler/rustc_metadata/src/creader.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,15 @@ impl CStore {
148148
assert_eq!(self.metas.len(), self.stable_crate_ids.len());
149149
let num = CrateNum::new(self.stable_crate_ids.len());
150150
if let Some(&existing) = self.stable_crate_ids.get(&root.stable_crate_id()) {
151-
let crate_name0 = root.name();
152-
if let Some(crate_name1) = self.metas[existing].as_ref().map(|data| data.name()) {
151+
// Check for (potential) conflicts with the local crate
152+
if existing == LOCAL_CRATE {
153+
Err(CrateError::SymbolConflictsCurrent(root.name()))
154+
} else if let Some(crate_name1) = self.metas[existing].as_ref().map(|data| data.name())
155+
{
156+
let crate_name0 = root.name();
153157
Err(CrateError::StableCrateIdCollision(crate_name0, crate_name1))
154158
} else {
155-
Err(CrateError::SymbolConflictsCurrent(crate_name0))
159+
Err(CrateError::NotFound(root.name()))
156160
}
157161
} else {
158162
self.metas.push(None);

compiler/rustc_metadata/src/locator.rs

+13
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ pub(crate) enum CrateError {
961961
DlSym(String),
962962
LocatorCombined(Box<CombinedLocatorError>),
963963
NonDylibPlugin(Symbol),
964+
NotFound(Symbol),
964965
}
965966

966967
enum MetadataError<'a> {
@@ -1131,6 +1132,18 @@ impl CrateError {
11311132
CrateError::NonDylibPlugin(crate_name) => {
11321133
sess.emit_err(errors::NoDylibPlugin { span, crate_name });
11331134
}
1135+
CrateError::NotFound(crate_name) => {
1136+
sess.emit_err(errors::CannotFindCrate {
1137+
span,
1138+
crate_name,
1139+
add_info: String::new(),
1140+
missing_core,
1141+
current_crate: sess.opts.crate_name.clone().unwrap_or("<unknown>".to_string()),
1142+
is_nightly_build: sess.is_nightly_build(),
1143+
profiler_runtime: Symbol::intern(&sess.opts.unstable_opts.profiler_runtime),
1144+
locator_triple: sess.opts.target_triple.clone(),
1145+
});
1146+
}
11341147
}
11351148
}
11361149
}

compiler/rustc_middle/src/ty/mod.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_data_structures::intern::Interned;
3737
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3838
use rustc_data_structures::steal::Steal;
3939
use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
40-
use rustc_errors::ErrorGuaranteed;
40+
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, StashKey};
4141
use rustc_hir as hir;
4242
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
4343
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
@@ -1439,14 +1439,26 @@ pub struct OpaqueHiddenType<'tcx> {
14391439
}
14401440

14411441
impl<'tcx> OpaqueHiddenType<'tcx> {
1442-
pub fn report_mismatch(&self, other: &Self, tcx: TyCtxt<'tcx>) -> ErrorGuaranteed {
1442+
pub fn report_mismatch(
1443+
&self,
1444+
other: &Self,
1445+
opaque_def_id: LocalDefId,
1446+
tcx: TyCtxt<'tcx>,
1447+
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
1448+
if let Some(diag) = tcx
1449+
.sess
1450+
.diagnostic()
1451+
.steal_diagnostic(tcx.def_span(opaque_def_id), StashKey::OpaqueHiddenTypeMismatch)
1452+
{
1453+
diag.cancel();
1454+
}
14431455
// Found different concrete types for the opaque type.
14441456
let sub_diag = if self.span == other.span {
14451457
TypeMismatchReason::ConflictType { span: self.span }
14461458
} else {
14471459
TypeMismatchReason::PreviousUse { span: self.span }
14481460
};
1449-
tcx.sess.emit_err(OpaqueHiddenTypeMismatch {
1461+
tcx.sess.create_err(OpaqueHiddenTypeMismatch {
14501462
self_ty: self.ty,
14511463
other_ty: other.ty,
14521464
other_span: other.span,

compiler/rustc_middle/src/ty/typeck_results.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,14 @@ pub struct TypeckResults<'tcx> {
151151
/// this field will be set to `Some(ErrorGuaranteed)`.
152152
pub tainted_by_errors: Option<ErrorGuaranteed>,
153153

154-
/// All the opaque types that have hidden types set
155-
/// by this function. We also store the
156-
/// type here, so that mir-borrowck can use it as a hint for figuring out hidden types,
157-
/// even if they are only set in dead code (which doesn't show up in MIR).
154+
/// All the opaque types that have hidden types set by this function.
155+
/// We also store the type here, so that the compiler can use it as a hint
156+
/// for figuring out hidden types, even if they are only set in dead code
157+
/// (which doesn't show up in MIR).
158+
///
159+
/// These types are mapped back to the opaque's identity substitutions
160+
/// (with erased regions), which is why we don't associated substs with any
161+
/// of these usages.
158162
pub concrete_opaque_types: FxIndexMap<LocalDefId, ty::OpaqueHiddenType<'tcx>>,
159163

160164
/// Tracks the minimum captures required for a closure;

0 commit comments

Comments
 (0)