Skip to content

Commit 612a33f

Browse files
committed
Auto merge of rust-lang#128350 - matthiaskrgr:rollup-bcuhts8, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#127882 (Don't elaborate associated types with Sized bounds in `trait_object_ty` in cfi) - rust-lang#128174 (Don't record trait aliases as marker traits) - rust-lang#128202 (Tell users not to file a bug when using internal library features) - rust-lang#128239 (Don't ICE when encountering error regions when confirming object method candidate) - rust-lang#128337 (skip assoc type during infer source visitor) - rust-lang#128341 (Make `rustc_attr::parse_version` pub) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 66e5852 + 83734f2 commit 612a33f

File tree

19 files changed

+228
-77
lines changed

19 files changed

+228
-77
lines changed

compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &Session, features: &Fea
578578
/// Parse a rustc version number written inside string literal in an attribute,
579579
/// like appears in `since = "1.0.0"`. Suffixes like "-dev" and "-nightly" are
580580
/// not accepted in this position, unlike when parsing CFG_RELEASE.
581-
fn parse_version(s: Symbol) -> Option<RustcVersion> {
581+
pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
582582
let mut components = s.as_str().split('-');
583583
let d = components.next()?;
584584
if components.next().is_some() {

compiler/rustc_expand/src/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
117117
// Otherwise, the feature is unknown. Record it as a lib feature.
118118
// It will be checked later.
119119
features.set_declared_lib_feature(name, mi.span());
120+
121+
// Similar to above, detect internal lib features to suppress
122+
// the ICE message that asks for a report.
123+
if features.internal(name) && ![sym::core, sym::alloc, sym::std].contains(&crate_name) {
124+
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
125+
}
120126
}
121127
}
122128

compiler/rustc_hir_analysis/src/collect.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1207,25 +1207,29 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
12071207
fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
12081208
let item = tcx.hir().expect_item(def_id);
12091209

1210-
let (is_auto, safety, items) = match item.kind {
1210+
let (is_alias, is_auto, safety, items) = match item.kind {
12111211
hir::ItemKind::Trait(is_auto, safety, .., items) => {
1212-
(is_auto == hir::IsAuto::Yes, safety, items)
1212+
(false, is_auto == hir::IsAuto::Yes, safety, items)
12131213
}
1214-
hir::ItemKind::TraitAlias(..) => (false, hir::Safety::Safe, &[][..]),
1214+
hir::ItemKind::TraitAlias(..) => (true, false, hir::Safety::Safe, &[][..]),
12151215
_ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"),
12161216
};
12171217

1218-
let constness = if tcx.has_attr(def_id, sym::const_trait) {
1218+
// Only regular traits can be const.
1219+
let constness = if !is_alias && tcx.has_attr(def_id, sym::const_trait) {
12191220
hir::Constness::Const
12201221
} else {
12211222
hir::Constness::NotConst
12221223
};
1224+
12231225
let paren_sugar = tcx.has_attr(def_id, sym::rustc_paren_sugar);
12241226
if paren_sugar && !tcx.features().unboxed_closures {
12251227
tcx.dcx().emit_err(errors::ParenSugarAttribute { span: item.span });
12261228
}
12271229

1228-
let is_marker = tcx.has_attr(def_id, sym::marker);
1230+
// Only regular traits can be marker.
1231+
let is_marker = !is_alias && tcx.has_attr(def_id, sym::marker);
1232+
12291233
let rustc_coinductive = tcx.has_attr(def_id, sym::rustc_coinductive);
12301234
let is_fundamental = tcx.has_attr(def_id, sym::fundamental);
12311235

compiler/rustc_hir_typeck/src/method/confirm.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use rustc_middle::ty::adjustment::{
1616
};
1717
use rustc_middle::ty::fold::TypeFoldable;
1818
use rustc_middle::ty::{
19-
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, UserArgs, UserType,
19+
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, UserArgs,
20+
UserType,
2021
};
2122
use rustc_middle::{bug, span_bug};
2223
use rustc_span::{Span, DUMMY_SP};
@@ -269,6 +270,17 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
269270

270271
probe::ObjectPick => {
271272
let trait_def_id = pick.item.container_id(self.tcx);
273+
274+
// This shouldn't happen for non-region error kinds, but may occur
275+
// when we have error regions. Specifically, since we canonicalize
276+
// during method steps, we may successfully deref when we assemble
277+
// the pick, but fail to deref when we try to extract the object
278+
// type from the pick during confirmation. This is fine, we're basically
279+
// already doomed by this point.
280+
if self_ty.references_error() {
281+
return ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]);
282+
}
283+
272284
self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| {
273285
// The object data has no entry for the Self
274286
// Type. For the purposes of this method call, we

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ fn trait_object_ty<'tcx>(tcx: TyCtxt<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tc
232232
tcx.associated_items(super_poly_trait_ref.def_id())
233233
.in_definition_order()
234234
.filter(|item| item.kind == ty::AssocKind::Type)
235+
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
235236
.map(move |assoc_ty| {
236237
super_poly_trait_ref.map_bound(|super_trait_ref| {
237238
let alias_ty =

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -934,13 +934,13 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
934934
// which makes this somewhat difficult and prevents us from just
935935
// using `self.path_inferred_arg_iter` here.
936936
hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _)
937-
// FIXME(TaKO8Ki): Ideally we should support this. For that
938-
// we have to map back from the self type to the
939-
// type alias though. That's difficult.
937+
// FIXME(TaKO8Ki): Ideally we should support other kinds,
938+
// such as `TyAlias` or `AssocTy`. For that we have to map
939+
// back from the self type to the type alias though. That's difficult.
940940
//
941941
// See the `need_type_info/issue-103053.rs` test for
942942
// a example.
943-
if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => {
943+
if matches!(path.res, Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, _)) => {
944944
if let Some(ty) = self.opt_node_type(expr.hir_id)
945945
&& let ty::Adt(_, args) = ty.kind()
946946
{

tests/crashes/121613-2.rs

-28
This file was deleted.

tests/crashes/121613.rs

-24
This file was deleted.

tests/crashes/122914.rs

-11
This file was deleted.

tests/crashes/127222.rs

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// issue#121613
2+
3+
#![feature(more_qualified_paths)]
4+
5+
struct S {}
6+
7+
struct Foo;
8+
9+
trait A {
10+
type Assoc;
11+
}
12+
13+
impl A for Foo {
14+
type Assoc = S;
15+
}
16+
17+
fn f() {}
18+
19+
fn main() {
20+
<Foo as A>::Assoc {};
21+
f(|a, b| a.cmp(b));
22+
//~^ ERROR: type annotations needed
23+
//~| ERROR: this function takes 0 arguments but 1 argument was supplied
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/incompat-call-after-qualified-path-0.rs:21:6
3+
|
4+
LL | f(|a, b| a.cmp(b));
5+
| ^ - type must be known at this point
6+
|
7+
help: consider giving this closure parameter an explicit type
8+
|
9+
LL | f(|a: /* Type */, b| a.cmp(b));
10+
| ++++++++++++
11+
12+
error[E0061]: this function takes 0 arguments but 1 argument was supplied
13+
--> $DIR/incompat-call-after-qualified-path-0.rs:21:3
14+
|
15+
LL | f(|a, b| a.cmp(b));
16+
| ^ --------------- unexpected argument
17+
|
18+
note: function defined here
19+
--> $DIR/incompat-call-after-qualified-path-0.rs:17:4
20+
|
21+
LL | fn f() {}
22+
| ^
23+
help: remove the extra argument
24+
|
25+
LL - f(|a, b| a.cmp(b));
26+
LL + f();
27+
|
28+
29+
error: aborting due to 2 previous errors
30+
31+
Some errors have detailed explanations: E0061, E0282.
32+
For more information about an error, try `rustc --explain E0061`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// issue#121613
2+
3+
#![feature(more_qualified_paths)]
4+
5+
struct S<T> {
6+
a: T
7+
}
8+
9+
struct Foo;
10+
11+
trait A {
12+
type Assoc<T>;
13+
}
14+
15+
impl A for Foo {
16+
type Assoc<T> = S<T>;
17+
}
18+
19+
fn f() {}
20+
21+
fn main() {
22+
<Foo as A>::Assoc::<i32> {
23+
a: 1
24+
};
25+
f(|a, b| a.cmp(b));
26+
//~^ ERROR: type annotations needed
27+
//~| ERROR: this function takes 0 arguments but 1 argument was supplied
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/incompat-call-after-qualified-path-1.rs:25:6
3+
|
4+
LL | f(|a, b| a.cmp(b));
5+
| ^ - type must be known at this point
6+
|
7+
help: consider giving this closure parameter an explicit type
8+
|
9+
LL | f(|a: /* Type */, b| a.cmp(b));
10+
| ++++++++++++
11+
12+
error[E0061]: this function takes 0 arguments but 1 argument was supplied
13+
--> $DIR/incompat-call-after-qualified-path-1.rs:25:3
14+
|
15+
LL | f(|a, b| a.cmp(b));
16+
| ^ --------------- unexpected argument
17+
|
18+
note: function defined here
19+
--> $DIR/incompat-call-after-qualified-path-1.rs:19:4
20+
|
21+
LL | fn f() {}
22+
| ^
23+
help: remove the extra argument
24+
|
25+
LL - f(|a, b| a.cmp(b));
26+
LL + f();
27+
|
28+
29+
error: aborting due to 2 previous errors
30+
31+
Some errors have detailed explanations: E0061, E0282.
32+
For more information about an error, try `rustc --explain E0061`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Fix for issue: #122914
2+
3+
use std::future::Future;
4+
use std::pin::Pin;
5+
6+
fn project(x: Pin<&'missing mut dyn Future<Output = ()>>) {
7+
//~^ ERROR use of undeclared lifetime name `'missing`
8+
let _ = x.poll(todo!());
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0261]: use of undeclared lifetime name `'missing`
2+
--> $DIR/dont-ice-on-object-lookup-w-error-region.rs:6:20
3+
|
4+
LL | fn project(x: Pin<&'missing mut dyn Future<Output = ()>>) {
5+
| - ^^^^^^^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'missing` here: `<'missing>`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0261`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Check that we only elaborate non-`Self: Sized` associated types when
2+
// erasing the receiver from trait ref.
3+
4+
//@ revisions: cfi kcfi
5+
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
6+
//@ only-linux
7+
//@ [cfi] needs-sanitizer-cfi
8+
//@ [kcfi] needs-sanitizer-kcfi
9+
//@ compile-flags: -C target-feature=-crt-static
10+
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
11+
//@ [cfi] compile-flags: -Z sanitizer=cfi
12+
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
13+
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
14+
//@ run-pass
15+
16+
trait Foo {
17+
type Bar<'a>
18+
where
19+
Self: Sized;
20+
21+
fn test(&self);
22+
}
23+
24+
impl Foo for () {
25+
type Bar<'a> = ()
26+
where
27+
Self: Sized;
28+
29+
fn test(&self) {}
30+
}
31+
32+
fn test(x: &dyn Foo) {
33+
x.test();
34+
}
35+
36+
fn main() {
37+
test(&());
38+
}

tests/ui/traits/alias/not-a-marker.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(trait_alias, marker_trait_attr)]
2+
3+
#[marker]
4+
//~^ ERROR attribute should be applied to a trait
5+
trait Foo = Send;
6+
7+
fn main() {}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: attribute should be applied to a trait
2+
--> $DIR/not-a-marker.rs:3:1
3+
|
4+
LL | #[marker]
5+
| ^^^^^^^^^
6+
LL |
7+
LL | trait Foo = Send;
8+
| ----------------- not a trait
9+
10+
error: aborting due to 1 previous error
11+

0 commit comments

Comments
 (0)