Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #109428

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
01d6c04
Link to Option/Result for `Iterator::sum/product`
clubby789 Jan 4, 2023
9261fd0
Nested impl traits trigger opaque_hidden_inferred_bound too much
compiler-errors Feb 27, 2023
ed63201
replace usage of `evaluate_goal` with a new `add_goal`
BoxyUwU Mar 16, 2023
ee31e5f
review nits
BoxyUwU Mar 17, 2023
ea08d3a
add assert
BoxyUwU Mar 17, 2023
ce14a1e
add comments
BoxyUwU Mar 17, 2023
e06c62c
UNACEPTABLE
BoxyUwU Mar 17, 2023
aa8de17
fix let else unformatting
BoxyUwU Mar 17, 2023
e624ef4
replace chain with two `add_goal`
BoxyUwU Mar 17, 2023
9df35a5
fix bad assertion
BoxyUwU Mar 17, 2023
b85bc19
move `compute_goal` and `evaluate_x` methods to inner module
BoxyUwU Mar 17, 2023
27e9ee9
move Option::as_slice to intrinsic
llogiq Mar 15, 2023
f7a9702
rustdoc: Cleanup parent module tracking for doc links
petrochenkov Mar 18, 2023
ae47810
rustdoc: Factor out some doc link resolution code into a separate fun…
petrochenkov Mar 19, 2023
1f67949
Lint ambiguous glob re-exports
jieyouxu Mar 19, 2023
9f80c75
Walk un-shifted nested `impl Trait` in trait when setting up default …
compiler-errors Mar 16, 2023
239ec6c
drive-by: Fix a comment in TyCtxt::fold_regions and remove an unused …
compiler-errors Mar 17, 2023
20dc532
Remove Ty::is_region_ptr
mu001999 Mar 20, 2023
5b4fa5b
fix typo
lcnr Mar 20, 2023
f321144
Add example for `Option::product` and `Result::product`
clubby789 Jan 4, 2023
720cc40
Enforce non-lifetime-binders in supertrait preds are not object safe
compiler-errors Mar 7, 2023
7a8384b
Rollup merge of #106434 - clubby789:document-sum-result, r=the8472
Dylan-DPC Mar 21, 2023
89c28bd
Rollup merge of #107880 - jieyouxu:issue-107563, r=petrochenkov
Dylan-DPC Mar 21, 2023
2838b80
Rollup merge of #108541 - compiler-errors:lol-nested-rpits, r=oli-obk
Dylan-DPC Mar 21, 2023
dffc706
Rollup merge of #108842 - compiler-errors:non_lifetime_binders-object…
Dylan-DPC Mar 21, 2023
fea32d4
Rollup merge of #108896 - BoxyUwU:new_solver_add_goal_fn, r=lcnr
Dylan-DPC Mar 21, 2023
6dbd539
Rollup merge of #109179 - llogiq:intrinsically-option-as-slice, r=eholk
Dylan-DPC Mar 21, 2023
ac9d9e7
Rollup merge of #109240 - compiler-errors:dont-binder-twice, r=oli-obk
Dylan-DPC Mar 21, 2023
61df888
Rollup merge of #109312 - petrochenkov:docice5, r=GuillaumeGomez
Dylan-DPC Mar 21, 2023
4159409
Rollup merge of #109378 - MU001999:master, r=scottmcm
Dylan-DPC Mar 21, 2023
a5442d2
Rollup merge of #109385 - lcnr:typo, r=Dylan-DPC
Dylan-DPC Mar 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
&& !self.upvars.is_empty()
{
item_msg = access_place_desc;
debug_assert!(
self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_region_ptr()
);
debug_assert!(self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_ref());
debug_assert!(is_closure_or_generator(
Place::ty_from(
the_place_err.local,
Expand Down Expand Up @@ -470,11 +468,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
{
let local_decl = &self.body.local_decls[local];

let (pointer_sigil, pointer_desc) = if local_decl.ty.is_region_ptr() {
("&", "reference")
} else {
("*const", "pointer")
};
let (pointer_sigil, pointer_desc) =
if local_decl.ty.is_ref() { ("&", "reference") } else { ("*const", "pointer") };

match self.local_names[local] {
Some(name) if !local_decl.from_compiler_desugaring() => {
Expand Down Expand Up @@ -1258,7 +1253,7 @@ fn suggest_ampmut<'tcx>(
(
suggestability,
highlight_span,
if local_decl.ty.is_region_ptr() {
if local_decl.ty.is_ref() {
format!("&mut {}", ty_mut.ty)
} else {
format!("*mut {}", ty_mut.ty)
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_cranelift/src/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
) -> (Pointer, Value) {
let (ptr, vtable) = 'block: {
if let Abi::Scalar(_) = arg.layout().abi {
'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr()
&& !arg.layout().ty.is_region_ptr()
{
'descend_newtypes: while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() {
for i in 0..arg.layout().fields.count() {
let field = arg.value_field(fx, mir::Field::new(i));
if !field.layout().is_zst() {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
//
// This is also relevant for `Pin<&mut Self>`, where we need to peel the `Pin`.
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
&& !op.layout.ty.is_region_ptr()
&& !op.layout.ty.is_ref()
{
for i in 0..op.layout.fields.count() {
let field = op.extract_field(bx, i);
Expand Down Expand Up @@ -959,7 +959,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
Immediate(_) => {
// See comment above explaining why we peel these newtypes
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
&& !op.layout.ty.is_region_ptr()
&& !op.layout.ty.is_ref()
{
for i in 0..op.layout.fields.count() {
let field = op.extract_field(bx, i);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ language_item_table! {
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

Option, sym::Option, option_type, Target::Enum, GenericRequirement::None;
OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None;
OptionNone, sym::None, option_none_variant, Target::Variant, GenericRequirement::None;

Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
],
tcx.mk_ptr(ty::TypeAndMut { ty: param(0), mutbl: hir::Mutability::Not }),
),
sym::option_payload_ptr => {
let option_def_id = tcx.require_lang_item(hir::LangItem::Option, None);
let p0 = param(0);
(
1,
vec![tcx.mk_ptr(ty::TypeAndMut {
ty: tcx.mk_adt(
tcx.adt_def(option_def_id),
tcx.mk_substs_from_iter([ty::GenericArg::from(p0)].into_iter()),
),
mutbl: hir::Mutability::Not,
})],
tcx.mk_ptr(ty::TypeAndMut { ty: p0, mutbl: hir::Mutability::Not }),
)
}
sym::ptr_mask => (
1,
vec![
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
found: Option<ty::OpaqueHiddenType<'tcx>>,

/// In the presence of dead code, typeck may figure out a hidden type
/// while borrowck will now. We collect these cases here and check at
/// while borrowck will not. We collect these cases here and check at
/// the end that we actually found a type that matches (modulo regions).
typeck_types: Vec<ty::OpaqueHiddenType<'tcx>>,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
let deref_kind = if checked_ty.is_box() {
"unboxing the value"
} else if checked_ty.is_region_ptr() {
} else if checked_ty.is_ref() {
"dereferencing the borrow"
} else {
"dereferencing the type"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.inputs()
.skip_binder()
.get(0)
.filter(|ty| ty.is_region_ptr() && !rcvr_ty.is_region_ptr())
.filter(|ty| ty.is_ref() && !rcvr_ty.is_ref())
.copied()
.unwrap_or(rcvr_ty),
};
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,10 @@ pub trait LintContext: Sized {
Applicability::MachineApplicable,
);
}
BuiltinLintDiagnostics::AmbiguousGlobReexports { name, namespace, first_reexport_span, duplicate_reexport_span } => {
db.span_label(first_reexport_span, format!("the name `{}` in the {} namespace is first re-exported here", name, namespace));
db.span_label(duplicate_reexport_span, format!("but the name `{}` in the {} namespace is also re-exported here", name, namespace));
}
}
// Rewrap `db`, and pass control to the user.
decorate(db)
Expand Down
23 changes: 19 additions & 4 deletions compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_hir as hir;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::{
self, fold::BottomUpFolder, print::TraitPredPrintModifiersAndPath, Ty, TypeFoldable,
self, fold::BottomUpFolder, print::TraitPredPrintModifiersAndPath, DefIdTree, Ty, TypeFoldable,
};
use rustc_span::Span;
use rustc_trait_selection::traits;
Expand All @@ -27,6 +27,8 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(type_alias_impl_trait)]
///
/// trait Duh {}
///
/// impl Duh for i32 {}
Expand All @@ -41,7 +43,9 @@ declare_lint! {
/// type Assoc = F;
/// }
///
/// fn test() -> impl Trait<Assoc = impl Sized> {
/// type Tait = impl Sized;
///
/// fn test() -> impl Trait<Assoc = Tait> {
/// 42
/// }
/// ```
Expand All @@ -54,7 +58,7 @@ declare_lint! {
///
/// Although the hidden type, `i32` does satisfy this bound, we do not
/// consider the return type to be well-formed with this lint. It can be
/// fixed by changing `impl Sized` into `impl Sized + Send`.
/// fixed by changing `Tait = impl Sized` into `Tait = impl Sized + Send`.
pub OPAQUE_HIDDEN_INFERRED_BOUND,
Warn,
"detects the use of nested `impl Trait` types in associated type bounds that are not general enough"
Expand All @@ -64,7 +68,7 @@ declare_lint_pass!(OpaqueHiddenInferredBound => [OPAQUE_HIDDEN_INFERRED_BOUND]);

impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
let hir::ItemKind::OpaqueTy(_) = &item.kind else { return; };
let hir::ItemKind::OpaqueTy(opaque) = &item.kind else { return; };
let def_id = item.owner_id.def_id.to_def_id();
let infcx = &cx.tcx.infer_ctxt().build();
// For every projection predicate in the opaque type's explicit bounds,
Expand All @@ -81,6 +85,17 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// have opaques in them anyways.
let Some(proj_term) = proj.term.ty() else { continue };

// HACK: `impl Trait<Assoc = impl Trait2>` from an RPIT is "ok"...
if let ty::Alias(ty::Opaque, opaque_ty) = *proj_term.kind()
&& cx.tcx.parent(opaque_ty.def_id) == def_id
&& matches!(
opaque.origin,
hir::OpaqueTyOrigin::FnReturn(_) | hir::OpaqueTyOrigin::AsyncFn(_)
)
{
continue;
}

let proj_ty =
cx.tcx.mk_projection(proj.projection_ty.def_id, proj.projection_ty.substs);
// For every instance of the projection type in the bounds,
Expand Down
40 changes: 40 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,45 @@ declare_lint! {
};
}

declare_lint! {
/// The `ambiguous_glob_reexports` lint detects cases where names re-exported via globs
/// collide. Downstream users trying to use the same name re-exported from multiple globs
/// will receive a warning pointing out redefinition of the same name.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(ambiguous_glob_reexports)]
/// pub mod foo {
/// pub type X = u8;
/// }
///
/// pub mod bar {
/// pub type Y = u8;
/// pub type X = u8;
/// }
///
/// pub use foo::*;
/// pub use bar::*;
///
///
/// pub fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This was previously accepted but it could silently break a crate's downstream users code.
/// For example, if `foo::*` and `bar::*` were re-exported before `bar::X` was added to the
/// re-exports, down stream users could use `this_crate::X` without problems. However, adding
/// `bar::X` would cause compilation errors in downstream crates because `X` is defined
/// multiple times in the same namespace of `this_crate`.
pub AMBIGUOUS_GLOB_REEXPORTS,
Warn,
"ambiguous glob re-exports",
}

declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
Expand Down Expand Up @@ -3337,6 +3376,7 @@ declare_lint_pass! {
NAMED_ARGUMENTS_USED_POSITIONALLY,
IMPLIED_BOUNDS_ENTAILMENT,
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
AMBIGUOUS_GLOB_REEXPORTS,
]
}

Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,16 @@ pub enum BuiltinLintDiagnostics {
vis_span: Span,
ident_span: Span,
},
AmbiguousGlobReexports {
/// The name for which collision(s) have occurred.
name: String,
/// The name space for whihc the collision(s) occurred in.
namespace: String,
/// Span where the name is first re-exported.
first_reexport_span: Span,
/// Span where the same name is also re-exported.
duplicate_reexport_span: Span,
},
}

/// Lints that are buffered up early on in the `Session` before the
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,9 @@ pub enum ObjectSafetyViolation {
/// (e.g., `trait Foo : Bar<Self>`).
SupertraitSelf(SmallVec<[Span; 1]>),

// Supertrait has a non-lifetime `for<T>` binder.
SupertraitNonLifetimeBinder(SmallVec<[Span; 1]>),

/// Method has something illegal.
Method(Symbol, MethodViolationCode, Span),

Expand All @@ -919,6 +922,9 @@ impl ObjectSafetyViolation {
.into()
}
}
ObjectSafetyViolation::SupertraitNonLifetimeBinder(_) => {
format!("where clause cannot reference non-lifetime `for<...>` variables").into()
}
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod(_), _) => {
format!("associated function `{}` has no `self` parameter", name).into()
}
Expand Down Expand Up @@ -969,7 +975,9 @@ impl ObjectSafetyViolation {

pub fn solution(&self, err: &mut Diagnostic) {
match self {
ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => {}
ObjectSafetyViolation::SizedSelf(_)
| ObjectSafetyViolation::SupertraitSelf(_)
| ObjectSafetyViolation::SupertraitNonLifetimeBinder(..) => {}
ObjectSafetyViolation::Method(
name,
MethodViolationCode::StaticMethod(Some((add_self_sugg, make_sized_sugg))),
Expand Down Expand Up @@ -1023,7 +1031,8 @@ impl ObjectSafetyViolation {
// diagnostics use a `note` instead of a `span_label`.
match self {
ObjectSafetyViolation::SupertraitSelf(spans)
| ObjectSafetyViolation::SizedSelf(spans) => spans.clone(),
| ObjectSafetyViolation::SizedSelf(spans)
| ObjectSafetyViolation::SupertraitNonLifetimeBinder(spans) => spans.clone(),
ObjectSafetyViolation::AssocConst(_, span)
| ObjectSafetyViolation::GAT(_, span)
| ObjectSafetyViolation::Method(_, _, span)
Expand Down
15 changes: 1 addition & 14 deletions compiler/rustc_middle/src/ty/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ where
// Region folder

impl<'tcx> TyCtxt<'tcx> {
/// Folds the escaping and free regions in `value` using `f`, and
/// sets `skipped_regions` to true if any late-bound region was found
/// and skipped.
/// Folds the escaping and free regions in `value` using `f`.
pub fn fold_regions<T>(
self,
value: T,
Expand All @@ -64,17 +62,6 @@ impl<'tcx> TyCtxt<'tcx> {
{
value.fold_with(&mut RegionFolder::new(self, &mut f))
}

pub fn super_fold_regions<T>(
self,
value: T,
mut f: impl FnMut(ty::Region<'tcx>, ty::DebruijnIndex) -> ty::Region<'tcx>,
) -> T
where
T: TypeSuperFoldable<TyCtxt<'tcx>>,
{
value.super_fold_with(&mut RegionFolder::new(self, &mut f))
}
}

/// Folds over the substructure of a type, visiting its component
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,11 +1913,6 @@ impl<'tcx> Ty<'tcx> {
}
}

#[inline]
pub fn is_region_ptr(self) -> bool {
matches!(self.kind(), Ref(..))
}

#[inline]
pub fn is_mutable_ptr(self) -> bool {
matches!(
Expand All @@ -1944,7 +1939,7 @@ impl<'tcx> Ty<'tcx> {
/// Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).
#[inline]
pub fn is_any_ptr(self) -> bool {
self.is_region_ptr() || self.is_unsafe_ptr() || self.is_fn_ptr()
self.is_ref() || self.is_unsafe_ptr() || self.is_fn_ptr()
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl<'tcx> Cx<'tcx> {
if self.typeck_results().is_coercion_cast(source.hir_id) {
// Convert the lexpr to a vexpr.
ExprKind::Use { source: self.mirror_expr(source) }
} else if self.typeck_results().expr_ty(source).is_region_ptr() {
} else if self.typeck_results().expr_ty(source).is_ref() {
// Special cased so that we can type check that the element
// type of the source matches the pointed to type of the
// destination.
Expand Down
Loading