Skip to content

Commit 79f178b

Browse files
committed
Auto merge of rust-lang#95581 - Dylan-DPC:rollup-2suh5h1, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#95354 (Handle rustc_const_stable attribute in library feature collector) - rust-lang#95373 (invalid_value lint: detect invalid initialization of arrays) - rust-lang#95430 (Disable #[thread_local] support on i686-pc-windows-msvc) - rust-lang#95544 (Add error message suggestion for missing noreturn in naked function) - rust-lang#95556 (Implement provenance preserving methods on NonNull) - rust-lang#95557 (Fix `thread_local!` macro to be compatible with `no_implicit_prelude`) - rust-lang#95559 (small type system refactoring) - rust-lang#95560 (convert more `DefId`s to `LocalDefId`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c75909c + 1c82fac commit 79f178b

File tree

49 files changed

+389
-192
lines changed

Some content is hidden

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

49 files changed

+389
-192
lines changed

compiler/rustc_infer/src/infer/canonical/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
4949
/// At the end of processing, the substitution S (once
5050
/// canonicalized) then represents the values that you computed
5151
/// for each of the canonical inputs to your query.
52-
5352
pub fn instantiate_canonical_with_fresh_inference_vars<T>(
5453
&self,
5554
span: Span,

compiler/rustc_infer/src/infer/combine.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ use super::glb::Glb;
2727
use super::lub::Lub;
2828
use super::sub::Sub;
2929
use super::type_variable::TypeVariableValue;
30-
use super::unify_key::replace_if_possible;
31-
use super::unify_key::{ConstVarValue, ConstVariableValue};
32-
use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
3330
use super::{InferCtxt, MiscVariable, TypeTrace};
34-
3531
use crate::traits::{Obligation, PredicateObligations};
36-
3732
use rustc_data_structures::sso::SsoHashMap;
3833
use rustc_hir::def_id::DefId;
34+
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
35+
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
3936
use rustc_middle::traits::ObligationCause;
4037
use rustc_middle::ty::error::{ExpectedFound, TypeError};
4138
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
@@ -140,8 +137,8 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
140137
return Ok(a);
141138
}
142139

143-
let a = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table(), a);
144-
let b = replace_if_possible(&mut self.inner.borrow_mut().const_unification_table(), b);
140+
let a = self.shallow_resolve(a);
141+
let b = self.shallow_resolve(b);
145142

146143
let a_is_expected = relation.a_is_expected();
147144

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,15 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
237237
ObligationCauseCode::MatchImpl(parent, ..) => parent.code(),
238238
_ => cause.code(),
239239
}
240-
&& let (ObligationCauseCode::ItemObligation(item_def_id), None) = (code, override_error_code)
240+
&& let (&ObligationCauseCode::ItemObligation(item_def_id), None) = (code, override_error_code)
241241
{
242242
// Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static`
243243
// lifetime as above, but called using a fully-qualified path to the method:
244244
// `Foo::qux(bar)`.
245245
let mut v = TraitObjectVisitor(FxHashSet::default());
246246
v.visit_ty(param.param_ty);
247247
if let Some((ident, self_ty)) =
248-
self.get_impl_ident_and_self_ty_from_trait(*item_def_id, &v.0)
248+
self.get_impl_ident_and_self_ty_from_trait(item_def_id, &v.0)
249249
&& self.suggest_constrain_dyn_trait_in_impl(&mut err, &v.0, ident, self_ty)
250250
{
251251
override_error_code = Some(ident.name);

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
77
use rustc_errors::ErrorGuaranteed;
88
use rustc_hir as hir;
99
use rustc_hir::def::Res;
10-
use rustc_hir::def_id::DefId;
10+
use rustc_hir::def_id::{DefId, LocalDefId};
1111
use rustc_hir::intravisit::Visitor;
1212
use rustc_middle::hir::nested_filter;
1313
use rustc_middle::ty::print::RegionHighlightMode;
@@ -51,7 +51,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5151
{
5252
let guar = self.emit_associated_type_err(
5353
span,
54-
self.infcx.tcx.item_name(impl_item_def_id),
54+
self.infcx.tcx.item_name(impl_item_def_id.to_def_id()),
5555
impl_item_def_id,
5656
trait_item_def_id,
5757
);
@@ -155,7 +155,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
155155
&self,
156156
span: Span,
157157
item_name: Symbol,
158-
impl_item_def_id: DefId,
158+
impl_item_def_id: LocalDefId,
159159
trait_item_def_id: DefId,
160160
) -> ErrorGuaranteed {
161161
let impl_sp = self.tcx().def_span(impl_item_def_id);

compiler/rustc_infer/src/infer/error_reporting/note.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
348348
let mut err = self.report_concrete_failure(*parent, sub, sup);
349349

350350
let trait_item_span = self.tcx.def_span(trait_item_def_id);
351-
let item_name = self.tcx.item_name(impl_item_def_id);
351+
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
352352
err.span_label(
353353
trait_item_span,
354354
format!("definition of `{}` from trait", item_name),
@@ -370,7 +370,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
370370
let where_clause_span = self
371371
.tcx
372372
.hir()
373-
.get_generics(impl_item_def_id.expect_local())
373+
.get_generics(impl_item_def_id)
374374
.unwrap()
375375
.where_clause
376376
.tail_span_for_suggestion();

compiler/rustc_infer/src/infer/freshen.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@
3030
//! solving a set of constraints. In contrast, the type inferencer assigns a value to each type
3131
//! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type
3232
//! inferencer knows "so far".
33-
33+
use super::InferCtxt;
34+
use rustc_data_structures::fx::FxHashMap;
35+
use rustc_middle::infer::unify_key::ToType;
3436
use rustc_middle::ty::fold::TypeFolder;
3537
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
36-
37-
use rustc_data_structures::fx::FxHashMap;
38-
3938
use std::collections::hash_map::Entry;
4039

41-
use super::unify_key::ToType;
42-
use super::InferCtxt;
43-
4440
pub struct TypeFreshener<'a, 'tcx> {
4541
infcx: &'a InferCtxt<'a, 'tcx>,
4642
ty_freshen_count: u32,

compiler/rustc_infer/src/infer/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ mod sub;
7070
pub mod type_variable;
7171
mod undo_log;
7272

73-
pub use rustc_middle::infer::unify_key;
74-
7573
#[must_use]
7674
#[derive(Debug)]
7775
pub struct InferOk<'tcx, T> {
@@ -425,16 +423,20 @@ pub enum SubregionOrigin<'tcx> {
425423

426424
/// Comparing the signature and requirements of an impl method against
427425
/// the containing trait.
428-
CompareImplMethodObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
426+
CompareImplMethodObligation {
427+
span: Span,
428+
impl_item_def_id: LocalDefId,
429+
trait_item_def_id: DefId,
430+
},
429431

430432
/// Comparing the signature and requirements of an impl associated type
431433
/// against the containing trait
432-
CompareImplTypeObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
434+
CompareImplTypeObligation { span: Span, impl_item_def_id: LocalDefId, trait_item_def_id: DefId },
433435

434436
/// Checking that the bounds of a trait's associated type hold for a given impl
435437
CheckAssociatedTypeBounds {
436438
parent: Box<SubregionOrigin<'tcx>>,
437-
impl_item_def_id: DefId,
439+
impl_item_def_id: LocalDefId,
438440
trait_item_def_id: DefId,
439441
},
440442
}
@@ -558,9 +560,9 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
558560
}
559561
}
560562

561-
/// Helper type of a temporary returned by `tcx.infer_ctxt()`.
562-
/// Necessary because we can't write the following bound:
563-
/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`.
563+
/// A temporary returned by `tcx.infer_ctxt()`. This is necessary
564+
/// for multiple `InferCtxt` to share the same `in_progress_typeck_results`
565+
/// without using `Rc` or something similar.
564566
pub struct InferCtxtBuilder<'tcx> {
565567
tcx: TyCtxt<'tcx>,
566568
fresh_typeck_results: Option<RefCell<ty::TypeckResults<'tcx>>>,

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::infer::InferCtxt;
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed};
66
use rustc_hir as hir;
7-
use rustc_hir::def_id::DefId;
7+
use rustc_hir::def_id::{DefId, LocalDefId};
88
use rustc_middle::ty::TyCtxt;
99
use rustc_span::{MultiSpan, Span};
1010
use std::fmt;
@@ -14,7 +14,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1414
pub fn report_extra_impl_obligation(
1515
&self,
1616
error_span: Span,
17-
impl_item_def_id: DefId,
17+
impl_item_def_id: LocalDefId,
1818
trait_item_def_id: DefId,
1919
requirement: &dyn fmt::Display,
2020
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
@@ -25,7 +25,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2525

2626
if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
2727
let span = self.tcx.sess.source_map().guess_head_span(trait_item_span);
28-
let item_name = self.tcx.item_name(impl_item_def_id);
28+
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
2929
err.span_label(span, format!("definition of `{}` from trait", item_name));
3030
}
3131

compiler/rustc_lint/src/builtin.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
25482548
/// Return `Some` only if we are sure this type does *not*
25492549
/// allow zero initialization.
25502550
fn ty_find_init_error<'tcx>(
2551-
tcx: TyCtxt<'tcx>,
2551+
cx: &LateContext<'tcx>,
25522552
ty: Ty<'tcx>,
25532553
init: InitKind,
25542554
) -> Option<InitError> {
@@ -2575,7 +2575,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
25752575
Adt(adt_def, substs) if !adt_def.is_union() => {
25762576
// First check if this ADT has a layout attribute (like `NonNull` and friends).
25772577
use std::ops::Bound;
2578-
match tcx.layout_scalar_valid_range(adt_def.did()) {
2578+
match cx.tcx.layout_scalar_valid_range(adt_def.did()) {
25792579
// We exploit here that `layout_scalar_valid_range` will never
25802580
// return `Bound::Excluded`. (And we have tests checking that we
25812581
// handle the attribute correctly.)
@@ -2603,12 +2603,12 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26032603
// Proceed recursively, check all fields.
26042604
let variant = &adt_def.variant(VariantIdx::from_u32(0));
26052605
variant.fields.iter().find_map(|field| {
2606-
ty_find_init_error(tcx, field.ty(tcx, substs), init).map(
2606+
ty_find_init_error(cx, field.ty(cx.tcx, substs), init).map(
26072607
|(mut msg, span)| {
26082608
if span.is_none() {
26092609
// Point to this field, should be helpful for figuring
26102610
// out where the source of the error is.
2611-
let span = tcx.def_span(field.did);
2611+
let span = cx.tcx.def_span(field.did);
26122612
write!(
26132613
&mut msg,
26142614
" (in this {} field)",
@@ -2627,7 +2627,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26272627
// Multi-variant enum.
26282628
_ => {
26292629
if init == InitKind::Uninit && is_multi_variant(*adt_def) {
2630-
let span = tcx.def_span(adt_def.did());
2630+
let span = cx.tcx.def_span(adt_def.did());
26312631
Some((
26322632
"enums have to be initialized to a variant".to_string(),
26332633
Some(span),
@@ -2642,7 +2642,16 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26422642
}
26432643
Tuple(..) => {
26442644
// Proceed recursively, check all fields.
2645-
ty.tuple_fields().iter().find_map(|field| ty_find_init_error(tcx, field, init))
2645+
ty.tuple_fields().iter().find_map(|field| ty_find_init_error(cx, field, init))
2646+
}
2647+
Array(ty, len) => {
2648+
if matches!(len.try_eval_usize(cx.tcx, cx.param_env), Some(v) if v > 0) {
2649+
// Array length known at array non-empty -- recurse.
2650+
ty_find_init_error(cx, *ty, init)
2651+
} else {
2652+
// Empty array or size unknown.
2653+
None
2654+
}
26462655
}
26472656
// Conservative fallback.
26482657
_ => None,
@@ -2655,7 +2664,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26552664
// We are extremely conservative with what we warn about.
26562665
let conjured_ty = cx.typeck_results().expr_ty(expr);
26572666
if let Some((msg, span)) =
2658-
with_no_trimmed_paths!(ty_find_init_error(cx.tcx, conjured_ty, init))
2667+
with_no_trimmed_paths!(ty_find_init_error(cx, conjured_ty, init))
26592668
{
26602669
cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| {
26612670
let mut err = lint.build(&format!(

compiler/rustc_middle/src/infer/unify_key.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
use crate::ty::{self, InferConst, Ty, TyCtxt};
2-
use rustc_data_structures::snapshot_vec;
3-
use rustc_data_structures::undo_log::UndoLogs;
4-
use rustc_data_structures::unify::{
5-
self, EqUnifyValue, InPlace, NoError, UnificationTable, UnifyKey, UnifyValue,
6-
};
1+
use crate::ty::{self, Ty, TyCtxt};
2+
use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue};
73
use rustc_span::def_id::DefId;
84
use rustc_span::symbol::Symbol;
95
use rustc_span::Span;
10-
116
use std::cmp;
127
use std::marker::PhantomData;
138

@@ -165,23 +160,3 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
165160
})
166161
}
167162
}
168-
169-
impl<'tcx> EqUnifyValue for ty::Const<'tcx> {}
170-
171-
pub fn replace_if_possible<'tcx, V, L>(
172-
table: &mut UnificationTable<InPlace<ty::ConstVid<'tcx>, V, L>>,
173-
c: ty::Const<'tcx>,
174-
) -> ty::Const<'tcx>
175-
where
176-
V: snapshot_vec::VecLike<unify::Delegate<ty::ConstVid<'tcx>>>,
177-
L: UndoLogs<snapshot_vec::UndoLog<unify::Delegate<ty::ConstVid<'tcx>>>>,
178-
{
179-
if let ty::ConstKind::Infer(InferConst::Var(vid)) = c.val() {
180-
match table.probe_value(vid).val.known() {
181-
Some(c) => c,
182-
None => c,
183-
}
184-
} else {
185-
c
186-
}
187-
}

compiler/rustc_middle/src/traits/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -276,24 +276,23 @@ pub enum ObligationCauseCode<'tcx> {
276276

277277
/// Error derived when matching traits/impls; see ObligationCause for more details
278278
CompareImplMethodObligation {
279-
impl_item_def_id: DefId,
279+
impl_item_def_id: LocalDefId,
280280
trait_item_def_id: DefId,
281281
},
282282

283283
/// Error derived when matching traits/impls; see ObligationCause for more details
284284
CompareImplTypeObligation {
285-
impl_item_def_id: DefId,
285+
impl_item_def_id: LocalDefId,
286286
trait_item_def_id: DefId,
287287
},
288288

289289
/// Checking that the bounds of a trait's associated type hold for a given impl
290290
CheckAssociatedTypeBounds {
291-
impl_item_def_id: DefId,
291+
impl_item_def_id: LocalDefId,
292292
trait_item_def_id: DefId,
293293
},
294294

295-
/// Checking that this expression can be assigned where it needs to be
296-
// FIXME(eddyb) #11161 is the original Expr required?
295+
/// Checking that this expression can be assigned to its target.
297296
ExprAssignable,
298297

299298
/// Computing common supertype in the arms of a match expression

compiler/rustc_passes/src/lib_features.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ impl<'tcx> LibFeatureCollector<'tcx> {
2929
}
3030

3131
fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option<Symbol>, Span)> {
32-
let stab_attrs = [sym::stable, sym::unstable, sym::rustc_const_unstable];
32+
let stab_attrs =
33+
[sym::stable, sym::unstable, sym::rustc_const_stable, sym::rustc_const_unstable];
3334

34-
// Find a stability attribute (i.e., `#[stable (..)]`, `#[unstable (..)]`,
35-
// `#[rustc_const_unstable (..)]`).
35+
// Find a stability attribute: one of #[stable(…)], #[unstable(…)],
36+
// #[rustc_const_stable(…)], or #[rustc_const_unstable(…)].
3637
if let Some(stab_attr) = stab_attrs.iter().find(|stab_attr| attr.has_name(**stab_attr)) {
3738
let meta_kind = attr.meta_kind();
3839
if let Some(MetaItemKind::List(ref metas)) = meta_kind {
@@ -52,7 +53,9 @@ impl<'tcx> LibFeatureCollector<'tcx> {
5253
// This additional check for stability is to make sure we
5354
// don't emit additional, irrelevant errors for malformed
5455
// attributes.
55-
if *stab_attr != sym::stable || since.is_some() {
56+
let is_unstable =
57+
matches!(*stab_attr, sym::unstable | sym::rustc_const_unstable);
58+
if since.is_some() || is_unstable {
5659
return Some((feature, since, attr.span));
5760
}
5861
}

compiler/rustc_passes/src/naked_functions.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Checks validity of naked functions.
22
33
use rustc_ast::{Attribute, InlineAsmOptions};
4-
use rustc_errors::struct_span_err;
4+
use rustc_errors::{struct_span_err, Applicability};
55
use rustc_hir as hir;
66
use rustc_hir::def_id::LocalDefId;
77
use rustc_hir::intravisit::{FnKind, Visitor};
@@ -274,12 +274,25 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
274274
}
275275

276276
if !asm.options.contains(InlineAsmOptions::NORETURN) {
277+
let last_span = asm
278+
.operands
279+
.last()
280+
.map_or_else(|| asm.template_strs.last().unwrap().2, |op| op.1)
281+
.shrink_to_hi();
282+
277283
struct_span_err!(
278284
self.tcx.sess,
279285
span,
280286
E0787,
281287
"asm in naked functions must use `noreturn` option"
282288
)
289+
.span_suggestion(
290+
last_span,
291+
"consider specifying that the asm block is responsible \
292+
for returning from the function",
293+
String::from(", options(noreturn)"),
294+
Applicability::MachineApplicable,
295+
)
283296
.emit();
284297
}
285298
}

0 commit comments

Comments
 (0)