Skip to content

Commit

Permalink
Auto merge of rust-lang#128350 - matthiaskrgr:rollup-bcuhts8, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Jul 29, 2024
2 parents 4db3d12 + 83734f2 commit 1cea7fc
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 77 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &Session, features: &Fea
/// Parse a rustc version number written inside string literal in an attribute,
/// like appears in `since = "1.0.0"`. Suffixes like "-dev" and "-nightly" are
/// not accepted in this position, unlike when parsing CFG_RELEASE.
fn parse_version(s: Symbol) -> Option<RustcVersion> {
pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
let mut components = s.as_str().split('-');
let d = components.next()?;
if components.next().is_some() {
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
// Otherwise, the feature is unknown. Record it as a lib feature.
// It will be checked later.
features.set_declared_lib_feature(name, mi.span());

// Similar to above, detect internal lib features to suppress
// the ICE message that asks for a report.
if features.internal(name) && ![sym::core, sym::alloc, sym::std].contains(&crate_name) {
sess.using_internal_features.store(true, std::sync::atomic::Ordering::Relaxed);
}
}
}

Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,25 +1207,29 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
let item = tcx.hir().expect_item(def_id);

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

let constness = if tcx.has_attr(def_id, sym::const_trait) {
// Only regular traits can be const.
let constness = if !is_alias && tcx.has_attr(def_id, sym::const_trait) {
hir::Constness::Const
} else {
hir::Constness::NotConst
};

let paren_sugar = tcx.has_attr(def_id, sym::rustc_paren_sugar);
if paren_sugar && !tcx.features().unboxed_closures {
tcx.dcx().emit_err(errors::ParenSugarAttribute { span: item.span });
}

let is_marker = tcx.has_attr(def_id, sym::marker);
// Only regular traits can be marker.
let is_marker = !is_alias && tcx.has_attr(def_id, sym::marker);

let rustc_coinductive = tcx.has_attr(def_id, sym::rustc_coinductive);
let is_fundamental = tcx.has_attr(def_id, sym::fundamental);

Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use rustc_middle::ty::adjustment::{
};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, UserArgs, UserType,
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, UserArgs,
UserType,
};
use rustc_middle::{bug, span_bug};
use rustc_span::{Span, DUMMY_SP};
Expand Down Expand Up @@ -269,6 +270,17 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {

probe::ObjectPick => {
let trait_def_id = pick.item.container_id(self.tcx);

// This shouldn't happen for non-region error kinds, but may occur
// when we have error regions. Specifically, since we canonicalize
// during method steps, we may successfully deref when we assemble
// the pick, but fail to deref when we try to extract the object
// type from the pick during confirmation. This is fine, we're basically
// already doomed by this point.
if self_ty.references_error() {
return ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]);
}

self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| {
// The object data has no entry for the Self
// Type. For the purposes of this method call, we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ fn trait_object_ty<'tcx>(tcx: TyCtxt<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tc
tcx.associated_items(super_poly_trait_ref.def_id())
.in_definition_order()
.filter(|item| item.kind == ty::AssocKind::Type)
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
.map(move |assoc_ty| {
super_poly_trait_ref.map_bound(|super_trait_ref| {
let alias_ty =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,13 +934,13 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
// which makes this somewhat difficult and prevents us from just
// using `self.path_inferred_arg_iter` here.
hir::ExprKind::Struct(&hir::QPath::Resolved(_self_ty, path), _, _)
// FIXME(TaKO8Ki): Ideally we should support this. For that
// we have to map back from the self type to the
// type alias though. That's difficult.
// FIXME(TaKO8Ki): Ideally we should support other kinds,
// such as `TyAlias` or `AssocTy`. For that we have to map
// back from the self type to the type alias though. That's difficult.
//
// See the `need_type_info/issue-103053.rs` test for
// a example.
if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => {
if matches!(path.res, Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, _)) => {
if let Some(ty) = self.opt_node_type(expr.hir_id)
&& let ty::Adt(_, args) = ty.kind()
{
Expand Down
28 changes: 0 additions & 28 deletions tests/crashes/121613-2.rs

This file was deleted.

24 changes: 0 additions & 24 deletions tests/crashes/121613.rs

This file was deleted.

11 changes: 0 additions & 11 deletions tests/crashes/122914.rs

This file was deleted.

3 changes: 0 additions & 3 deletions tests/crashes/127222.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// issue#121613

#![feature(more_qualified_paths)]

struct S {}

struct Foo;

trait A {
type Assoc;
}

impl A for Foo {
type Assoc = S;
}

fn f() {}

fn main() {
<Foo as A>::Assoc {};
f(|a, b| a.cmp(b));
//~^ ERROR: type annotations needed
//~| ERROR: this function takes 0 arguments but 1 argument was supplied
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error[E0282]: type annotations needed
--> $DIR/incompat-call-after-qualified-path-0.rs:21:6
|
LL | f(|a, b| a.cmp(b));
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
LL | f(|a: /* Type */, b| a.cmp(b));
| ++++++++++++

error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> $DIR/incompat-call-after-qualified-path-0.rs:21:3
|
LL | f(|a, b| a.cmp(b));
| ^ --------------- unexpected argument
|
note: function defined here
--> $DIR/incompat-call-after-qualified-path-0.rs:17:4
|
LL | fn f() {}
| ^
help: remove the extra argument
|
LL - f(|a, b| a.cmp(b));
LL + f();
|

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0061, E0282.
For more information about an error, try `rustc --explain E0061`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// issue#121613

#![feature(more_qualified_paths)]

struct S<T> {
a: T
}

struct Foo;

trait A {
type Assoc<T>;
}

impl A for Foo {
type Assoc<T> = S<T>;
}

fn f() {}

fn main() {
<Foo as A>::Assoc::<i32> {
a: 1
};
f(|a, b| a.cmp(b));
//~^ ERROR: type annotations needed
//~| ERROR: this function takes 0 arguments but 1 argument was supplied
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error[E0282]: type annotations needed
--> $DIR/incompat-call-after-qualified-path-1.rs:25:6
|
LL | f(|a, b| a.cmp(b));
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
LL | f(|a: /* Type */, b| a.cmp(b));
| ++++++++++++

error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> $DIR/incompat-call-after-qualified-path-1.rs:25:3
|
LL | f(|a, b| a.cmp(b));
| ^ --------------- unexpected argument
|
note: function defined here
--> $DIR/incompat-call-after-qualified-path-1.rs:19:4
|
LL | fn f() {}
| ^
help: remove the extra argument
|
LL - f(|a, b| a.cmp(b));
LL + f();
|

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0061, E0282.
For more information about an error, try `rustc --explain E0061`.
11 changes: 11 additions & 0 deletions tests/ui/methods/dont-ice-on-object-lookup-w-error-region.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Fix for issue: #122914

use std::future::Future;
use std::pin::Pin;

fn project(x: Pin<&'missing mut dyn Future<Output = ()>>) {
//~^ ERROR use of undeclared lifetime name `'missing`
let _ = x.poll(todo!());
}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/methods/dont-ice-on-object-lookup-w-error-region.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0261]: use of undeclared lifetime name `'missing`
--> $DIR/dont-ice-on-object-lookup-w-error-region.rs:6:20
|
LL | fn project(x: Pin<&'missing mut dyn Future<Output = ()>>) {
| - ^^^^^^^^ undeclared lifetime
| |
| help: consider introducing lifetime `'missing` here: `<'missing>`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0261`.
38 changes: 38 additions & 0 deletions tests/ui/sanitizer/cfi-sized-associated-ty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Check that we only elaborate non-`Self: Sized` associated types when
// erasing the receiver from trait ref.

//@ revisions: cfi kcfi
// FIXME(#122848) Remove only-linux once OSX CFI binaries work
//@ only-linux
//@ [cfi] needs-sanitizer-cfi
//@ [kcfi] needs-sanitizer-kcfi
//@ compile-flags: -C target-feature=-crt-static
//@ [cfi] compile-flags: -C codegen-units=1 -C lto -C prefer-dynamic=off -C opt-level=0
//@ [cfi] compile-flags: -Z sanitizer=cfi
//@ [kcfi] compile-flags: -Z sanitizer=kcfi
//@ [kcfi] compile-flags: -C panic=abort -C prefer-dynamic=off
//@ run-pass

trait Foo {
type Bar<'a>
where
Self: Sized;

fn test(&self);
}

impl Foo for () {
type Bar<'a> = ()
where
Self: Sized;

fn test(&self) {}
}

fn test(x: &dyn Foo) {
x.test();
}

fn main() {
test(&());
}
7 changes: 7 additions & 0 deletions tests/ui/traits/alias/not-a-marker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(trait_alias, marker_trait_attr)]

#[marker]
//~^ ERROR attribute should be applied to a trait
trait Foo = Send;

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/traits/alias/not-a-marker.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: attribute should be applied to a trait
--> $DIR/not-a-marker.rs:3:1
|
LL | #[marker]
| ^^^^^^^^^
LL |
LL | trait Foo = Send;
| ----------------- not a trait

error: aborting due to 1 previous error

0 comments on commit 1cea7fc

Please sign in to comment.