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 9 pull requests #107308

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
656db98
Tweak E0597
estebank Jan 15, 2023
e4f61af
Fix fulldeps-ui tests
estebank Jan 15, 2023
be2ec32
Account for `*` when looking for inner-most path in expression
estebank Jan 17, 2023
c6111e8
Account for field access when looking for inner-most path in expression
estebank Jan 17, 2023
7b8251e
Account for method call and indexing when looking for inner-most path…
estebank Jan 17, 2023
e1f630f
Add `OnceCell<T>: !Sync` impl for diagnostics
Noratrieb Jan 16, 2023
6d0c91f
Add `rustc_on_unimplemented` on `Sync` for cell types
Noratrieb Jan 16, 2023
62a1e76
Add hint for missing lifetime bound on trait object when type alias i…
Dec 6, 2022
7f5ce94
Bring tests back into rustc source tarball
tmiasko Jan 23, 2023
e6e93e0
add test where we ignore hr implied bounds
lcnr Jan 24, 2023
ad73936
Delete `SimplifyArmIdentity` and `SimplifyBranchSame` mir opts
JakobDegen Jan 24, 2023
11a94f2
rustdoc: prevent scroll bar on source viewer
kadiwa4 Jan 24, 2023
430dab0
implement builtin candidate
BoxyUwU Jan 24, 2023
2f924b0
sorry erica
BoxyUwU Jan 24, 2023
a418e39
no without_constness
BoxyUwU Jan 24, 2023
273254e
rustdoc: use smarter encoding for playground URL
notriddle Jan 24, 2023
e500c44
rustdoc: update tests for smarter playground url encoding
notriddle Jan 25, 2023
0db0419
rustdoc: add comment for why playground URLs have unencoded angle bra…
notriddle Jan 25, 2023
0c9d9e5
Rollup merge of #105345 - yanchen4791:issue-103582-fix, r=jackh726
matthiaskrgr Jan 25, 2023
4d0e6aa
Rollup merge of #106897 - estebank:issue-99430, r=davidtwco
matthiaskrgr Jan 25, 2023
11b227a
Rollup merge of #106944 - Nilstrieb:there-once-was-a-diagnostic, r=Wa…
matthiaskrgr Jan 25, 2023
a1dcdea
Rollup merge of #107239 - tmiasko:tests, r=Mark-Simulacrum
matthiaskrgr Jan 25, 2023
7cebffe
Rollup merge of #107255 - lcnr:implied-b-hr, r=oli-obk
matthiaskrgr Jan 25, 2023
82ea29c
Rollup merge of #107256 - JakobDegen:delete-sai, r=cjgillot
matthiaskrgr Jan 25, 2023
7cede15
Rollup merge of #107266 - kadiwa4:source_viewer_scrollbar, r=notriddle
matthiaskrgr Jan 25, 2023
32eca9f
Rollup merge of #107282 - BoxyUwU:erica_builtin_pointee_impls, r=comp…
matthiaskrgr Jan 25, 2023
0168598
Rollup merge of #107284 - notriddle:notriddle/plus, r=jsha
matthiaskrgr Jan 25, 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
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
desc,
);

err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_desc));
err.span_label(borrow_span, format!("{} is borrowed here", borrow_desc));
err.span_label(span, format!("use of borrowed {}", borrow_desc));
err
}
Expand Down Expand Up @@ -250,8 +250,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
desc,
);

err.span_label(borrow_span, format!("borrow of {} occurs here", desc));
err.span_label(span, format!("assignment to borrowed {} occurs here", desc));
err.span_label(borrow_span, format!("{} is borrowed here", desc));
err.span_label(span, format!("{} is assigned to here but it was already borrowed", desc));
err
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&self.local_names,
&mut err,
"",
None,
Some(borrow_span),
None,
);
}
Expand Down
33 changes: 33 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Print diagnostics to explain why values are borrowed.

use rustc_errors::{Applicability, Diagnostic};
use rustc_hir as hir;
use rustc_hir::intravisit::Visitor;
use rustc_index::vec::IndexVec;
use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::{
Expand All @@ -11,6 +13,7 @@ use rustc_middle::ty::adjustment::PointerCast;
use rustc_middle::ty::{self, RegionVid, TyCtxt};
use rustc_span::symbol::{kw, Symbol};
use rustc_span::{sym, DesugaringKind, Span};
use rustc_trait_selection::traits::error_reporting::FindExprBySpan;

use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
use crate::{
Expand Down Expand Up @@ -63,6 +66,36 @@ impl<'tcx> BorrowExplanation<'tcx> {
borrow_span: Option<Span>,
multiple_borrow_span: Option<(Span, Span)>,
) {
if let Some(span) = borrow_span {
let def_id = body.source.def_id();
if let Some(node) = tcx.hir().get_if_local(def_id)
&& let Some(body_id) = node.body_id()
{
let body = tcx.hir().body(body_id);
let mut expr_finder = FindExprBySpan::new(span);
expr_finder.visit_expr(body.value);
if let Some(mut expr) = expr_finder.result {
while let hir::ExprKind::AddrOf(_, _, inner)
| hir::ExprKind::Unary(hir::UnOp::Deref, inner)
| hir::ExprKind::Field(inner, _)
| hir::ExprKind::MethodCall(_, inner, _, _)
| hir::ExprKind::Index(inner, _) = &expr.kind
{
expr = inner;
}
if let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind
&& let [hir::PathSegment { ident, args: None, .. }] = p.segments
&& let hir::def::Res::Local(hir_id) = p.res
&& let Some(hir::Node::Pat(pat)) = tcx.hir().find(hir_id)
{
err.span_label(
pat.span,
&format!("binding `{ident}` declared here"),
);
}
}
}
}
match *self {
BorrowExplanation::UsedLater(later_use_kind, var_or_use_span, path_span) => {
let message = match later_use_kind {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
};
self.note_type_does_not_implement_copy(err, &place_desc, place_ty, Some(span), "");

use_spans.args_span_label(err, format!("move out of {place_desc} occurs here"));
use_spans.args_span_label(err, format!("{place_desc} is moved here"));
}
}
}
Expand Down
59 changes: 40 additions & 19 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,17 +813,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if *outlived_f != ty::ReStatic {
return;
}
let suitable_region = self.infcx.tcx.is_suitable_region(f);
let Some(suitable_region) = suitable_region else { return; };

let fn_returns = self
.infcx
.tcx
.is_suitable_region(f)
.map(|r| self.infcx.tcx.return_type_impl_or_dyn_traits(r.def_id))
.unwrap_or_default();

if fn_returns.is_empty() {
return;
}
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.def_id);

let param = if let Some(param) = find_param_with_region(self.infcx.tcx, f, outlived_f) {
param
Expand All @@ -839,15 +832,43 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
};
let captures = format!("captures data from {arg}");

return nice_region_error::suggest_new_region_bound(
self.infcx.tcx,
diag,
fn_returns,
lifetime.to_string(),
Some(arg),
captures,
Some((param.param_ty_span, param.param_ty.to_string())),
self.infcx.tcx.is_suitable_region(f).map(|r| r.def_id),
if !fn_returns.is_empty() {
nice_region_error::suggest_new_region_bound(
self.infcx.tcx,
diag,
fn_returns,
lifetime.to_string(),
Some(arg),
captures,
Some((param.param_ty_span, param.param_ty.to_string())),
Some(suitable_region.def_id),
);
return;
}

let Some((alias_tys, alias_span)) = self
.infcx
.tcx
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.def_id) else { return; };

// in case the return type of the method is a type alias
let mut spans_suggs: Vec<_> = Vec::new();
for alias_ty in alias_tys {
if alias_ty.span.desugaring_kind().is_some() {
// Skip `async` desugaring `impl Future`.
()
}
if let TyKind::TraitObject(_, lt, _) = alias_ty.kind {
spans_suggs.push((lt.ident.span.shrink_to_hi(), " + 'a".to_string()));
}
}
spans_suggs.push((alias_span.shrink_to_hi(), "<'a>".to_string()));
diag.multipart_suggestion_verbose(
&format!(
"to declare that the trait object {captures}, you can add a lifetime parameter `'a` in the type alias"
),
spans_suggs,
Applicability::MaybeIncorrect,
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3524,6 +3524,13 @@ impl<'hir> Node<'hir> {
}
}

pub fn alias_ty(self) -> Option<&'hir Ty<'hir>> {
match self {
Node::Item(Item { kind: ItemKind::TyAlias(ty, ..), .. }) => Some(ty),
_ => None,
}
}

pub fn body_id(&self) -> Option<BodyId> {
match self {
Node::TraitItem(TraitItem {
Expand Down
24 changes: 24 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,30 @@ impl<'tcx> TyCtxt<'tcx> {
v.0
}

/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type and associated alias span when type alias is used
pub fn return_type_impl_or_dyn_traits_with_type_alias(
self,
scope_def_id: LocalDefId,
) -> Option<(Vec<&'tcx hir::Ty<'tcx>>, Span)> {
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
let mut v = TraitObjectVisitor(vec![], self.hir());
// when the return type is a type alias
if let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) = self.hir().fn_decl_by_hir_id(hir_id)
&& let hir::TyKind::Path(hir::QPath::Resolved(
None,
hir::Path { res: hir::def::Res::Def(DefKind::TyAlias, def_id), .. }, )) = hir_output.kind
&& let Some(local_id) = def_id.as_local()
&& let Some(alias_ty) = self.hir().get_by_def_id(local_id).alias_ty() // it is type alias
&& let Some(alias_generics) = self.hir().get_by_def_id(local_id).generics()
{
v.visit_ty(alias_ty);
if !v.0.is_empty() {
return Some((v.0, alias_generics.span));
}
}
return None;
}

pub fn return_type_impl_trait(self, scope_def_id: LocalDefId) -> Option<(Ty<'tcx>, Span)> {
// `type_of()` will fail on these (#55796, #86483), so only allow `fn`s or closures.
match self.hir().get_by_def_id(scope_def_id) {
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ mod shim;
pub mod simplify;
mod simplify_branches;
mod simplify_comparison_integral;
mod simplify_try;
mod sroa;
mod uninhabited_enum_branching;
mod unreachable_prop;
Expand Down Expand Up @@ -567,8 +566,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
&o1(simplify_branches::SimplifyConstCondition::new("after-const-prop")),
&early_otherwise_branch::EarlyOtherwiseBranch,
&simplify_comparison_integral::SimplifyComparisonIntegral,
&simplify_try::SimplifyArmIdentity,
&simplify_try::SimplifyBranchSame,
&dead_store_elimination::DeadStoreElimination,
&dest_prop::DestinationPropagation,
&o1(simplify_branches::SimplifyConstCondition::new("final")),
Expand Down
Loading