1
Fork 0

Auto merge of #114181 - matthiaskrgr:rollup-14m8s7f, r=matthiaskrgr

Rollup of 7 pull requests

Successful merges:

 - #114099 (privacy: no nominal visibility for assoc fns )
 - #114128 (When flushing delayed span bugs, write to the ICE dump file even if it doesn't exist)
 - #114138 (Adjust spans correctly for fn -> method suggestion)
 - #114146 (Skip reporting item name when checking RPITIT GAT's associated type bounds hold)
 - #114147 (Insert RPITITs that were shadowed by missing ADTs that resolve to [type error])
 - #114155 (Replace a lazy `RefCell<Option<T>>` with `OnceCell<T>`)
 - #114164 (Add regression test for `--cap-lints allow` and trait bounds warning)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-07-28 23:53:12 +00:00
commit ca1f813cc3
23 changed files with 413 additions and 23 deletions

View file

@ -1655,11 +1655,11 @@ impl HandlerInner {
let backtrace = std::env::var_os("RUST_BACKTRACE").map_or(true, |x| &x != "0"); let backtrace = std::env::var_os("RUST_BACKTRACE").map_or(true, |x| &x != "0");
for bug in bugs { for bug in bugs {
if let Some(file) = self.ice_file.as_ref() if let Some(file) = self.ice_file.as_ref()
&& let Ok(mut out) = std::fs::File::options().append(true).open(file) && let Ok(mut out) = std::fs::File::options().create(true).append(true).open(file)
{ {
let _ = write!( let _ = write!(
&mut out, &mut out,
"\n\ndelayed span bug: {}\n{}", "delayed span bug: {}\n{}\n",
bug.inner.styled_message().iter().filter_map(|(msg, _)| msg.as_str()).collect::<String>(), bug.inner.styled_message().iter().filter_map(|(msg, _)| msg.as_str()).collect::<String>(),
&bug.note &bug.note
); );

View file

@ -754,7 +754,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
); );
ocx.resolve_regions_and_report_errors(impl_m_def_id, &outlives_env)?; ocx.resolve_regions_and_report_errors(impl_m_def_id, &outlives_env)?;
let mut collected_tys = FxHashMap::default(); let mut remapped_types = FxHashMap::default();
for (def_id, (ty, args)) in collected_types { for (def_id, (ty, args)) in collected_types {
match infcx.fully_resolve((ty, args)) { match infcx.fully_resolve((ty, args)) {
Ok((ty, args)) => { Ok((ty, args)) => {
@ -804,19 +804,37 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
Ok(ty) => ty, Ok(ty) => ty,
Err(guar) => Ty::new_error(tcx, guar), Err(guar) => Ty::new_error(tcx, guar),
}; };
collected_tys.insert(def_id, ty::EarlyBinder::bind(ty)); remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
} }
Err(err) => { Err(err) => {
let reported = tcx.sess.delay_span_bug( let reported = tcx.sess.delay_span_bug(
return_span, return_span,
format!("could not fully resolve: {ty} => {err:?}"), format!("could not fully resolve: {ty} => {err:?}"),
); );
collected_tys.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported))); remapped_types.insert(def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, reported)));
} }
} }
} }
Ok(&*tcx.arena.alloc(collected_tys)) // We may not collect all RPITITs that we see in the HIR for a trait signature
// because an RPITIT was located within a missing item. Like if we have a sig
// returning `-> Missing<impl Sized>`, that gets converted to `-> [type error]`,
// and when walking through the signature we end up never collecting the def id
// of the `impl Sized`. Insert that here, so we don't ICE later.
for assoc_item in tcx.associated_types_for_impl_traits_in_associated_fn(trait_m.def_id) {
if !remapped_types.contains_key(assoc_item) {
remapped_types.insert(
*assoc_item,
ty::EarlyBinder::bind(Ty::new_error_with_message(
tcx,
return_span,
"missing synthetic item for RPITIT",
)),
);
}
}
Ok(&*tcx.arena.alloc(remapped_types))
} }
struct ImplTraitInTraitCollector<'a, 'tcx> { struct ImplTraitInTraitCollector<'a, 'tcx> {

View file

@ -531,8 +531,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return; return;
} }
let up_to_rcvr_span = segment.ident.span.until(callee_expr.span); let Some(callee_expr_span) = callee_expr.span.find_ancestor_inside(call_expr.span)
let rest_span = callee_expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi()); else {
return;
};
let up_to_rcvr_span = segment.ident.span.until(callee_expr_span);
let rest_span = callee_expr_span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
let rest_snippet = if let Some(first) = rest.first() { let rest_snippet = if let Some(first) = rest.first() {
self.tcx self.tcx
.sess .sess

View file

@ -243,12 +243,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
infer::CheckAssociatedTypeBounds { impl_item_def_id, trait_item_def_id, parent } => { infer::CheckAssociatedTypeBounds { impl_item_def_id, trait_item_def_id, parent } => {
let mut err = self.report_concrete_failure(*parent, sub, sup); let mut err = self.report_concrete_failure(*parent, sub, sup);
// Don't mention the item name if it's an RPITIT, since that'll just confuse
// folks.
if !self.tcx.is_impl_trait_in_trait(impl_item_def_id.to_def_id()) {
let trait_item_span = self.tcx.def_span(trait_item_def_id); let trait_item_span = self.tcx.def_span(trait_item_def_id);
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id()); let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
err.span_label( err.span_label(
trait_item_span, trait_item_span,
format!("definition of `{}` from trait", item_name), format!("definition of `{}` from trait", item_name),
); );
}
self.suggest_copy_trait_method_bounds( self.suggest_copy_trait_method_bounds(
trait_item_def_id, trait_item_def_id,
impl_item_def_id, impl_item_def_id,

View file

@ -178,7 +178,12 @@ impl EffectiveVisibilities {
// All effective visibilities except `reachable_through_impl_trait` are limited to // All effective visibilities except `reachable_through_impl_trait` are limited to
// nominal visibility. For some items nominal visibility doesn't make sense so we // nominal visibility. For some items nominal visibility doesn't make sense so we
// don't check this condition for them. // don't check this condition for them.
if !matches!(tcx.def_kind(def_id), DefKind::Impl { .. }) { let is_impl = matches!(tcx.def_kind(def_id), DefKind::Impl { .. });
let is_associated_item_in_trait_impl = tcx
.impl_of_method(def_id.to_def_id())
.and_then(|impl_id| tcx.trait_id_of_impl(impl_id))
.is_some();
if !is_impl && !is_associated_item_in_trait_impl {
let nominal_vis = tcx.visibility(def_id); let nominal_vis = tcx.visibility(def_id);
if !nominal_vis.is_at_least(ev.reachable, tcx) { if !nominal_vis.is_at_least(ev.reachable, tcx) {
span_bug!( span_bug!(
@ -186,7 +191,7 @@ impl EffectiveVisibilities {
"{:?}: reachable {:?} > nominal {:?}", "{:?}: reachable {:?} > nominal {:?}",
def_id, def_id,
ev.reachable, ev.reachable,
nominal_vis nominal_vis,
); );
} }
} }

View file

@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_span::source_map::original_sp; use rustc_span::source_map::original_sp;
use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol}; use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol};
use std::cell::RefCell; use std::cell::OnceCell;
use std::cmp::Ordering; use std::cmp::Ordering;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
@ -67,7 +67,7 @@ impl CoverageStatement {
pub(super) struct CoverageSpan { pub(super) struct CoverageSpan {
pub span: Span, pub span: Span,
pub expn_span: Span, pub expn_span: Span,
pub current_macro_or_none: RefCell<Option<Option<Symbol>>>, pub current_macro_or_none: OnceCell<Option<Symbol>>,
pub bcb: BasicCoverageBlock, pub bcb: BasicCoverageBlock,
pub coverage_statements: Vec<CoverageStatement>, pub coverage_statements: Vec<CoverageStatement>,
pub is_closure: bool, pub is_closure: bool,
@ -175,8 +175,7 @@ impl CoverageSpan {
/// If the span is part of a macro, returns the macro name symbol. /// If the span is part of a macro, returns the macro name symbol.
pub fn current_macro(&self) -> Option<Symbol> { pub fn current_macro(&self) -> Option<Symbol> {
self.current_macro_or_none self.current_macro_or_none
.borrow_mut() .get_or_init(|| {
.get_or_insert_with(|| {
if let ExpnKind::Macro(MacroKind::Bang, current_macro) = if let ExpnKind::Macro(MacroKind::Bang, current_macro) =
self.expn_span.ctxt().outer_expn_data().kind self.expn_span.ctxt().outer_expn_data().kind
{ {

View file

@ -346,8 +346,16 @@ fn associated_type_for_impl_trait_in_impl(
) -> LocalDefId { ) -> LocalDefId {
let impl_local_def_id = tcx.local_parent(impl_fn_def_id); let impl_local_def_id = tcx.local_parent(impl_fn_def_id);
// FIXME fix the span, we probably want the def_id of the return type of the function let decl = tcx
let span = tcx.def_span(impl_fn_def_id); .hir()
.find_by_def_id(impl_fn_def_id)
.expect("expected item")
.fn_decl()
.expect("expected decl");
let span = match decl.output {
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(impl_fn_def_id),
hir::FnRetTy::Return(ty) => ty.span,
};
let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, DefPathData::ImplTraitAssocTy); let impl_assoc_ty = tcx.at(span).create_def(impl_local_def_id, DefPathData::ImplTraitAssocTy);
let local_def_id = impl_assoc_ty.def_id(); let local_def_id = impl_assoc_ty.def_id();

View file

@ -300,7 +300,7 @@ pub fn panic_hook_with_disk_dump(info: &PanicInfo<'_>, path: Option<&crate::path
}; };
if let Some(path) = path if let Some(path) = path
&& let Ok(mut out) = crate::fs::File::options().create(true).write(true).open(&path) && let Ok(mut out) = crate::fs::File::options().create(true).append(true).open(&path)
{ {
write(&mut out, BacktraceStyle::full()); write(&mut out, BacktraceStyle::full());
} }

View file

@ -0,0 +1,11 @@
// issue: 114146
#![feature(return_position_impl_trait_in_trait)]
trait Foo {
fn bar<'other: 'a>() -> impl Sized + 'a {}
//~^ ERROR use of undeclared lifetime name `'a`
//~| ERROR use of undeclared lifetime name `'a`
}
fn main() {}

View file

@ -0,0 +1,33 @@
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/bad-item-bound-within-rpitit-2.rs:6:20
|
LL | fn bar<'other: 'a>() -> impl Sized + 'a {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn bar<'a, 'other: 'a>() -> impl Sized + 'a {}
| +++
help: consider introducing lifetime `'a` here
|
LL | trait Foo<'a> {
| ++++
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/bad-item-bound-within-rpitit-2.rs:6:42
|
LL | fn bar<'other: 'a>() -> impl Sized + 'a {}
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | fn bar<'a, 'other: 'a>() -> impl Sized + 'a {}
| +++
help: consider introducing lifetime `'a` here
|
LL | trait Foo<'a> {
| ++++
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0261`.

View file

@ -0,0 +1,25 @@
// issue: 114145
#![feature(return_position_impl_trait_in_trait)]
trait Iterable {
type Item<'a>
where
Self: 'a;
fn iter(&self) -> impl '_ + Iterator<Item = Self::Item<'_>>;
}
impl<'a, I: 'a + Iterable> Iterable for &'a I {
type Item<'b> = I::Item<'a>
where
'b: 'a;
//~^ ERROR impl has stricter requirements than trait
fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> {
//~^ ERROR the type `&'a I` does not fulfill the required lifetime
(*self).iter()
}
}
fn main() {}

View file

@ -0,0 +1,30 @@
error[E0276]: impl has stricter requirements than trait
--> $DIR/bad-item-bound-within-rpitit.rs:16:13
|
LL | type Item<'a>
| ------------- definition of `Item` from trait
...
LL | 'b: 'a;
| ^^ impl has extra requirement `'b: 'a`
|
help: copy the `where` clause predicates from the trait
|
LL | where Self: 'b;
| ~~~~~~~~~~~~~~
error[E0477]: the type `&'a I` does not fulfill the required lifetime
--> $DIR/bad-item-bound-within-rpitit.rs:19:23
|
LL | fn iter(&self) -> impl 'a + Iterator<Item = I::Item<'a>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: type must outlive the anonymous lifetime as defined here
--> $DIR/bad-item-bound-within-rpitit.rs:10:28
|
LL | fn iter(&self) -> impl '_ + Iterator<Item = Self::Item<'_>>;
| ^^
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0276, E0477.
For more information about an error, try `rustc --explain E0276`.

View file

@ -0,0 +1,18 @@
// issue: 113903
#![feature(return_position_impl_trait_in_trait)]
use std::ops::Deref;
pub trait Tr {
fn w() -> impl Deref<Target = Missing<impl Sized>>;
//~^ ERROR cannot find type `Missing` in this scope
}
impl Tr for () {
fn w() -> &'static () {
&()
}
}
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0412]: cannot find type `Missing` in this scope
--> $DIR/rpitit-shadowed-by-missing-adt.rs:8:35
|
LL | fn w() -> impl Deref<Target = Missing<impl Sized>>;
| ^^^^^^^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0412`.

View file

@ -0,0 +1,8 @@
// Regression test for https://github.com/rust-lang/rust/issues/43134
// check-pass
// compile-flags: --cap-lints allow
type Foo<T: Clone> = Option<T>;
fn main() {}

View file

@ -0,0 +1,6 @@
// issue: 114131
fn main() {
let hello = len(vec![]);
//~^ ERROR cannot find function `len` in this scope
}

View file

@ -0,0 +1,15 @@
error[E0425]: cannot find function `len` in this scope
--> $DIR/suggest-method-on-call-with-macro-rcvr.rs:4:17
|
LL | let hello = len(vec![]);
| ^^^ not found in this scope
|
help: use the `.` operator to call the method `len` on `&Vec<_>`
|
LL - let hello = len(vec![]);
LL + let hello = vec![].len();
|
error: aborting due to previous error
For more information about this error, try `rustc --explain E0425`.

View file

@ -0,0 +1,16 @@
#![feature(staged_api)]
//~^ ERROR module has missing stability attribute
pub trait Trait {
//~^ ERROR trait has missing stability attribute
fn fun() {}
//~^ ERROR associated function has missing stability attribute
}
impl Trait for u8 {
//~^ ERROR implementation has missing stability attribute
pub(self) fn fun() {}
//~^ ERROR visibility qualifiers are not permitted here [E0449]
}
fn main() {}

View file

@ -0,0 +1,49 @@
error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-113860-1.rs:12:5
|
LL | pub(self) fn fun() {}
| ^^^^^^^^^
|
= note: trait items always share the visibility of their trait
error: module has missing stability attribute
--> $DIR/issue-113860-1.rs:1:1
|
LL | / #![feature(staged_api)]
LL | |
LL | |
LL | | pub trait Trait {
... |
LL | |
LL | | fn main() {}
| |____________^
error: trait has missing stability attribute
--> $DIR/issue-113860-1.rs:4:1
|
LL | / pub trait Trait {
LL | |
LL | | fn fun() {}
LL | |
LL | | }
| |_^
error: implementation has missing stability attribute
--> $DIR/issue-113860-1.rs:10:1
|
LL | / impl Trait for u8 {
LL | |
LL | | pub(self) fn fun() {}
LL | |
LL | | }
| |_^
error: associated function has missing stability attribute
--> $DIR/issue-113860-1.rs:6:5
|
LL | fn fun() {}
| ^^^^^^^^^^^
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0449`.

View file

@ -0,0 +1,16 @@
#![feature(staged_api)]
//~^ ERROR module has missing stability attribute
pub trait Trait {
//~^ ERROR trait has missing stability attribute
type X;
//~^ ERROR associated type has missing stability attribute
}
impl Trait for u8 {
//~^ ERROR implementation has missing stability attribute
pub(self) type X = Self;
//~^ ERROR visibility qualifiers are not permitted here [E0449]
}
fn main() {}

View file

@ -0,0 +1,49 @@
error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-113860-2.rs:12:5
|
LL | pub(self) type X = Self;
| ^^^^^^^^^
|
= note: trait items always share the visibility of their trait
error: module has missing stability attribute
--> $DIR/issue-113860-2.rs:1:1
|
LL | / #![feature(staged_api)]
LL | |
LL | |
LL | | pub trait Trait {
... |
LL | |
LL | | fn main() {}
| |____________^
error: trait has missing stability attribute
--> $DIR/issue-113860-2.rs:4:1
|
LL | / pub trait Trait {
LL | |
LL | | type X;
LL | |
LL | | }
| |_^
error: implementation has missing stability attribute
--> $DIR/issue-113860-2.rs:10:1
|
LL | / impl Trait for u8 {
LL | |
LL | | pub(self) type X = Self;
LL | |
LL | | }
| |_^
error: associated type has missing stability attribute
--> $DIR/issue-113860-2.rs:6:5
|
LL | type X;
| ^^^^^^^
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0449`.

View file

@ -0,0 +1,16 @@
#![feature(staged_api)]
//~^ ERROR module has missing stability attribute
pub trait Trait {
//~^ ERROR trait has missing stability attribute
const X: u32;
//~^ ERROR associated constant has missing stability attribute
}
impl Trait for u8 {
//~^ ERROR implementation has missing stability attribute
pub(self) const X: u32 = 3;
//~^ ERROR visibility qualifiers are not permitted here [E0449]
}
fn main() {}

View file

@ -0,0 +1,49 @@
error[E0449]: visibility qualifiers are not permitted here
--> $DIR/issue-113860.rs:12:5
|
LL | pub(self) const X: u32 = 3;
| ^^^^^^^^^
|
= note: trait items always share the visibility of their trait
error: module has missing stability attribute
--> $DIR/issue-113860.rs:1:1
|
LL | / #![feature(staged_api)]
LL | |
LL | |
LL | | pub trait Trait {
... |
LL | |
LL | | fn main() {}
| |____________^
error: trait has missing stability attribute
--> $DIR/issue-113860.rs:4:1
|
LL | / pub trait Trait {
LL | |
LL | | const X: u32;
LL | |
LL | | }
| |_^
error: implementation has missing stability attribute
--> $DIR/issue-113860.rs:10:1
|
LL | / impl Trait for u8 {
LL | |
LL | | pub(self) const X: u32 = 3;
LL | |
LL | | }
| |_^
error: associated constant has missing stability attribute
--> $DIR/issue-113860.rs:6:5
|
LL | const X: u32;
| ^^^^^^^^^^^^^
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0449`.