Skip to content

Commit 699a862

Browse files
committed
Auto merge of rust-lang#111489 - compiler-errors:rollup-g3vgzss, r=compiler-errors
Rollup of 7 pull requests Successful merges: - rust-lang#106038 (use implied bounds when checking opaque types) - rust-lang#111366 (Make `NonUseContext::AscribeUserTy` carry `ty::Variance`) - rust-lang#111375 (CFI: Fix SIGILL reached via trait objects) - rust-lang#111439 (Fix backtrace normalization in ice-bug-report-url.rs) - rust-lang#111444 (Only warn single-use lifetime when the binders match.) - rust-lang#111459 (Update browser-ui-test version to 0.16.0) - rust-lang#111460 (Improve suggestion for `self: Box<self>`) Failed merges: - rust-lang#110454 (Require impl Trait in associated types to appear in method signatures) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 26e0c57 + 6641b49 commit 699a862

Some content is hidden

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

50 files changed

+591
-152
lines changed

compiler/rustc_borrowck/src/def_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
5555
// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
5656
// contain dangling references.
5757
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) |
58-
PlaceContext::NonUse(NonUseContext::AscribeUserTy) |
58+
PlaceContext::NonUse(NonUseContext::AscribeUserTy(_)) |
5959

6060
PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |
6161
PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf) |

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
777777
Inspect | Copy | Move | PlaceMention | SharedBorrow | ShallowBorrow | UniqueBorrow
778778
| AddressOf | Projection,
779779
) => ty::Covariant,
780-
PlaceContext::NonUse(AscribeUserTy) => ty::Covariant,
780+
PlaceContext::NonUse(AscribeUserTy(variance)) => variance,
781781
}
782782
}
783783

compiler/rustc_codegen_llvm/src/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
9494
// LLVM will prefix the name with `__imp_`. Ideally, we'd like the
9595
// existing logic below to set the Storage Class, but it has an
9696
// exemption for MinGW for backwards compatability.
97-
let llfn = cx.declare_fn(&common::i686_decorated_name(&dllimport, common::is_mingw_gnu_toolchain(&tcx.sess.target), true), fn_abi);
97+
let llfn = cx.declare_fn(&common::i686_decorated_name(&dllimport, common::is_mingw_gnu_toolchain(&tcx.sess.target), true), fn_abi, Some(instance));
9898
unsafe { llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport); }
9999
llfn
100100
} else {
101-
cx.declare_fn(sym, fn_abi)
101+
cx.declare_fn(sym, fn_abi, Some(instance))
102102
};
103103
debug!("get_fn: not casting pointer!");
104104

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<
207207
)),
208208
ty::List::empty(),
209209
),
210+
None,
210211
);
211212

212213
llvm::set_linkage(llfn, llvm::Linkage::PrivateLinkage);

compiler/rustc_codegen_llvm/src/declare.rs

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ use crate::llvm::AttributePlace::Function;
1919
use crate::type_::Type;
2020
use crate::value::Value;
2121
use rustc_codegen_ssa::traits::TypeMembershipMethods;
22-
use rustc_middle::ty::Ty;
23-
use rustc_symbol_mangling::typeid::{kcfi_typeid_for_fnabi, typeid_for_fnabi, TypeIdOptions};
22+
use rustc_middle::ty::{Instance, Ty};
23+
use rustc_symbol_mangling::typeid::{
24+
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
25+
TypeIdOptions,
26+
};
2427
use smallvec::SmallVec;
2528

2629
/// Declare a function.
@@ -116,7 +119,12 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
116119
///
117120
/// If there’s a value with the same name already declared, the function will
118121
/// update the declaration and return existing Value instead.
119-
pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Value {
122+
pub fn declare_fn(
123+
&self,
124+
name: &str,
125+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
126+
instance: Option<Instance<'tcx>>,
127+
) -> &'ll Value {
120128
debug!("declare_rust_fn(name={:?}, fn_abi={:?})", name, fn_abi);
121129

122130
// Function addresses in Rust are never significant, allowing functions to
@@ -132,18 +140,35 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
132140
fn_abi.apply_attrs_llfn(self, llfn);
133141

134142
if self.tcx.sess.is_sanitizer_cfi_enabled() {
135-
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::empty());
136-
self.set_type_metadata(llfn, typeid);
137-
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::GENERALIZE_POINTERS);
138-
self.add_type_metadata(llfn, typeid);
139-
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::NORMALIZE_INTEGERS);
140-
self.add_type_metadata(llfn, typeid);
141-
let typeid = typeid_for_fnabi(
142-
self.tcx,
143-
fn_abi,
144-
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
145-
);
146-
self.add_type_metadata(llfn, typeid);
143+
if let Some(instance) = instance {
144+
let typeid = typeid_for_instance(self.tcx, &instance, TypeIdOptions::empty());
145+
self.set_type_metadata(llfn, typeid);
146+
let typeid =
147+
typeid_for_instance(self.tcx, &instance, TypeIdOptions::GENERALIZE_POINTERS);
148+
self.add_type_metadata(llfn, typeid);
149+
let typeid =
150+
typeid_for_instance(self.tcx, &instance, TypeIdOptions::NORMALIZE_INTEGERS);
151+
self.add_type_metadata(llfn, typeid);
152+
let typeid = typeid_for_instance(
153+
self.tcx,
154+
&instance,
155+
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
156+
);
157+
self.add_type_metadata(llfn, typeid);
158+
} else {
159+
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::empty());
160+
self.set_type_metadata(llfn, typeid);
161+
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::GENERALIZE_POINTERS);
162+
self.add_type_metadata(llfn, typeid);
163+
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::NORMALIZE_INTEGERS);
164+
self.add_type_metadata(llfn, typeid);
165+
let typeid = typeid_for_fnabi(
166+
self.tcx,
167+
fn_abi,
168+
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
169+
);
170+
self.add_type_metadata(llfn, typeid);
171+
}
147172
}
148173

149174
if self.tcx.sess.is_sanitizer_kcfi_enabled() {
@@ -156,8 +181,13 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
156181
options.insert(TypeIdOptions::NORMALIZE_INTEGERS);
157182
}
158183

159-
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);
160-
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
184+
if let Some(instance) = instance {
185+
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, &instance, options);
186+
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
187+
} else {
188+
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);
189+
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
190+
}
161191
}
162192

163193
llfn

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ fn gen_fn<'ll, 'tcx>(
772772
) -> (&'ll Type, &'ll Value) {
773773
let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty());
774774
let llty = fn_abi.llvm_type(cx);
775-
let llfn = cx.declare_fn(name, fn_abi);
775+
let llfn = cx.declare_fn(name, fn_abi, None);
776776
cx.set_frame_pointer_type(llfn);
777777
cx.apply_target_cpu_attr(llfn);
778778
// FIXME(eddyb) find a nicer way to do this.

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> {
5151
assert!(!instance.substs.has_infer());
5252

5353
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
54-
let lldecl = self.declare_fn(symbol_name, fn_abi);
54+
let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance));
5555
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
5656
let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
5757
base::set_link_section(lldecl, attrs);

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_target::abi::FieldIdx;
3131
use rustc_target::spec::abi::Abi;
3232
use rustc_trait_selection::traits::error_reporting::on_unimplemented::OnUnimplementedDirective;
3333
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
34+
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
3435
use rustc_trait_selection::traits::{self, ObligationCtxt, TraitEngine, TraitEngineExt as _};
3536

3637
use std::ops::ControlFlow;
@@ -222,7 +223,7 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
222223
if check_opaque_for_cycles(tcx, item.owner_id.def_id, substs, span, &origin).is_err() {
223224
return;
224225
}
225-
check_opaque_meets_bounds(tcx, item.owner_id.def_id, substs, span, &origin);
226+
check_opaque_meets_bounds(tcx, item.owner_id.def_id, span, &origin);
226227
}
227228

228229
/// Checks that an opaque type does not use `Self` or `T::Foo` projections that would result
@@ -391,7 +392,6 @@ pub(super) fn check_opaque_for_cycles<'tcx>(
391392
fn check_opaque_meets_bounds<'tcx>(
392393
tcx: TyCtxt<'tcx>,
393394
def_id: LocalDefId,
394-
substs: SubstsRef<'tcx>,
395395
span: Span,
396396
origin: &hir::OpaqueTyOrigin,
397397
) {
@@ -406,6 +406,8 @@ fn check_opaque_meets_bounds<'tcx>(
406406
.with_opaque_type_inference(DefiningAnchor::Bind(defining_use_anchor))
407407
.build();
408408
let ocx = ObligationCtxt::new(&infcx);
409+
410+
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
409411
let opaque_ty = tcx.mk_opaque(def_id.to_def_id(), substs);
410412

411413
// `ReErased` regions appear in the "parent_substs" of closures/generators.
@@ -448,9 +450,18 @@ fn check_opaque_meets_bounds<'tcx>(
448450
match origin {
449451
// Checked when type checking the function containing them.
450452
hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..) => {}
453+
// Nested opaque types occur only in associated types:
454+
// ` type Opaque<T> = impl Trait<&'static T, AssocTy = impl Nested>; `
455+
// They can only be referenced as `<Opaque<T> as Trait<&'static T>>::AssocTy`.
456+
// We don't have to check them here because their well-formedness follows from the WF of
457+
// the projection input types in the defining- and use-sites.
458+
hir::OpaqueTyOrigin::TyAlias
459+
if tcx.def_kind(tcx.parent(def_id.to_def_id())) == DefKind::OpaqueTy => {}
451460
// Can have different predicates to their defining use
452461
hir::OpaqueTyOrigin::TyAlias => {
453-
let outlives_env = OutlivesEnvironment::new(param_env);
462+
let wf_tys = ocx.assumed_wf_types(param_env, span, def_id);
463+
let implied_bounds = infcx.implied_bounds_tys(param_env, def_id, wf_tys);
464+
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
454465
let _ = ocx.resolve_regions_and_report_errors(defining_use_anchor, &outlives_env);
455466
}
456467
}

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
6565
use crate::mir::*;
6666
use crate::ty::subst::SubstsRef;
67-
use crate::ty::{CanonicalUserTypeAnnotation, Ty};
67+
use crate::ty::{self, CanonicalUserTypeAnnotation, Ty};
6868
use rustc_span::Span;
6969

7070
macro_rules! make_mir_visitor {
@@ -782,12 +782,12 @@ macro_rules! make_mir_visitor {
782782

783783
fn super_ascribe_user_ty(&mut self,
784784
place: & $($mutability)? Place<'tcx>,
785-
_variance: $(& $mutability)? ty::Variance,
785+
variance: $(& $mutability)? ty::Variance,
786786
user_ty: & $($mutability)? UserTypeProjection,
787787
location: Location) {
788788
self.visit_place(
789789
place,
790-
PlaceContext::NonUse(NonUseContext::AscribeUserTy),
790+
PlaceContext::NonUse(NonUseContext::AscribeUserTy($(* &$mutability *)? variance)),
791791
location
792792
);
793793
self.visit_user_type_projection(user_ty);
@@ -1320,7 +1320,7 @@ pub enum NonUseContext {
13201320
/// Ending a storage live range.
13211321
StorageDead,
13221322
/// User type annotation assertions for NLL.
1323-
AscribeUserTy,
1323+
AscribeUserTy(ty::Variance),
13241324
/// The data of a user variable, for debug info.
13251325
VarDebugInfo,
13261326
}

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ pub enum ExplicitSelf<'tcx> {
12531253

12541254
impl<'tcx> ExplicitSelf<'tcx> {
12551255
/// Categorizes an explicit self declaration like `self: SomeType`
1256-
/// into either `self`, `&self`, `&mut self`, `Box<self>`, or
1256+
/// into either `self`, `&self`, `&mut self`, `Box<Self>`, or
12571257
/// `Other`.
12581258
/// This is mainly used to require the arbitrary_self_types feature
12591259
/// in the case of `Other`, to improve error messages in the common cases,

0 commit comments

Comments
 (0)