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

Diff for: compiler/rustc_borrowck/src/def_use.rs

+1-1
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) |

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
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

Diff for: compiler/rustc_codegen_llvm/src/callee.rs

+2-2
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

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1
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);

Diff for: compiler/rustc_codegen_llvm/src/declare.rs

+47-17
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

Diff for: compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
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.

Diff for: compiler/rustc_codegen_llvm/src/mono_item.rs

+1-1
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);

Diff for: compiler/rustc_hir_analysis/src/check/check.rs

+14-3
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
}

Diff for: compiler/rustc_middle/src/mir/visit.rs

+4-4
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
}

Diff for: compiler/rustc_middle/src/ty/util.rs

+1-1
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,

Diff for: compiler/rustc_resolve/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ resolve_invalid_asm_sym =
199199
.label = is a local variable
200200
.help = `sym` operands must refer to either a function or a static
201201
202+
resolve_lowercase_self =
203+
attempt to use a non-constant value in a constant
204+
.suggestion = try using `Self`
205+
202206
resolve_trait_impl_duplicate =
203207
duplicate definitions with name `{$name}`:
204208
.label = duplicate definition

Diff for: compiler/rustc_resolve/src/diagnostics.rs

+3
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
948948
ResolutionError::InvalidAsmSym => {
949949
self.tcx.sess.create_err(errs::InvalidAsmSym { span })
950950
}
951+
ResolutionError::LowercaseSelf => {
952+
self.tcx.sess.create_err(errs::LowercaseSelf { span })
953+
}
951954
}
952955
}
953956

Diff for: compiler/rustc_resolve/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,14 @@ pub(crate) struct InvalidAsmSym {
442442
pub(crate) span: Span,
443443
}
444444

445+
#[derive(Diagnostic)]
446+
#[diag(resolve_lowercase_self)]
447+
pub(crate) struct LowercaseSelf {
448+
#[primary_span]
449+
#[suggestion(code = "Self", applicability = "maybe-incorrect", style = "short")]
450+
pub(crate) span: Span,
451+
}
452+
445453
#[derive(Diagnostic)]
446454
#[diag(resolve_trait_impl_duplicate, code = "E0201")]
447455
pub(crate) struct TraitImplDuplicate {

Diff for: compiler/rustc_resolve/src/ident.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use std::ptr;
1515

1616
use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
1717
use crate::late::{
18-
ConstantHasGenerics, ConstantItemKind, HasGenericParams, NoConstantGenericsReason, PathSource,
19-
Rib, RibKind,
18+
ConstantHasGenerics, HasGenericParams, NoConstantGenericsReason, PathSource, Rib, RibKind,
2019
};
2120
use crate::macros::{sub_namespace_match, MacroRulesScope};
2221
use crate::{errors, AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize};
@@ -1127,28 +1126,25 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
11271126
RibKind::ConstantItem(_, item) => {
11281127
// Still doesn't deal with upvars
11291128
if let Some(span) = finalize {
1130-
let (span, resolution_error) =
1131-
if let Some((ident, constant_item_kind)) = item {
1132-
let kind_str = match constant_item_kind {
1133-
ConstantItemKind::Const => "const",
1134-
ConstantItemKind::Static => "static",
1135-
};
1136-
(
1137-
span,
1138-
AttemptToUseNonConstantValueInConstant(
1139-
ident, "let", kind_str,
1140-
),
1141-
)
1142-
} else {
1143-
(
1144-
rib_ident.span,
1145-
AttemptToUseNonConstantValueInConstant(
1146-
original_rib_ident_def,
1147-
"const",
1148-
"let",
1149-
),
1150-
)
1151-
};
1129+
let (span, resolution_error) = match item {
1130+
None if rib_ident.as_str() == "self" => (span, LowercaseSelf),
1131+
None => (
1132+
rib_ident.span,
1133+
AttemptToUseNonConstantValueInConstant(
1134+
original_rib_ident_def,
1135+
"const",
1136+
"let",
1137+
),
1138+
),
1139+
Some((ident, kind)) => (
1140+
span,
1141+
AttemptToUseNonConstantValueInConstant(
1142+
ident,
1143+
"let",
1144+
kind.as_str(),
1145+
),
1146+
),
1147+
};
11521148
self.report_error(span, resolution_error);
11531149
}
11541150
return Res::Err;

Diff for: compiler/rustc_resolve/src/late.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ pub(crate) enum ConstantItemKind {
150150
Static,
151151
}
152152

153+
impl ConstantItemKind {
154+
pub(crate) fn as_str(&self) -> &'static str {
155+
match self {
156+
Self::Const => "const",
157+
Self::Static => "static",
158+
}
159+
}
160+
}
161+
153162
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
154163
enum RecordPartialRes {
155164
Yes,
@@ -1482,7 +1491,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
14821491
if let Some(&(_, res)) = rib.bindings.get(&normalized_ident) {
14831492
self.record_lifetime_res(lifetime.id, res, LifetimeElisionCandidate::Named);
14841493

1485-
if let LifetimeRes::Param { param, .. } = res {
1494+
if let LifetimeRes::Param { param, binder } = res {
14861495
match self.lifetime_uses.entry(param) {
14871496
Entry::Vacant(v) => {
14881497
debug!("First use of {:?} at {:?}", res, ident.span);
@@ -1496,10 +1505,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
14961505
LifetimeRibKind::Item
14971506
| LifetimeRibKind::AnonymousReportError
14981507
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
1499-
// An anonymous lifetime is legal here, go ahead.
1500-
LifetimeRibKind::AnonymousCreateParameter { .. } => {
1501-
Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt })
1502-
}
1508+
// An anonymous lifetime is legal here, and bound to the right
1509+
// place, go ahead.
1510+
LifetimeRibKind::AnonymousCreateParameter {
1511+
binder: anon_binder,
1512+
..
1513+
} => Some(if binder == anon_binder {
1514+
LifetimeUseSet::One { use_span: ident.span, use_ctxt }
1515+
} else {
1516+
LifetimeUseSet::Many
1517+
}),
15031518
// Only report if eliding the lifetime would have the same
15041519
// semantics.
15051520
LifetimeRibKind::Elided(r) => Some(if res == r {

Diff for: compiler/rustc_resolve/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ enum ResolutionError<'a> {
251251
TraitImplDuplicate { name: Symbol, trait_item_span: Span, old_span: Span },
252252
/// Inline asm `sym` operand must refer to a `fn` or `static`.
253253
InvalidAsmSym,
254+
/// `self` used instead of `Self` in a generic parameter
255+
LowercaseSelf,
254256
}
255257

256258
enum VisResolutionError<'a> {

0 commit comments

Comments
 (0)