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 7 pull requests #118434

Merged
merged 21 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8490b8e
Dont suggest `!` for path in function call if it has generic args
compiler-errors Nov 27, 2023
fd37da7
Remove a comment.
nnethercote Nov 28, 2023
3570468
Remove unused feature.
nnethercote Nov 24, 2023
dbaa786
Reduce exposure of some things.
nnethercote Nov 25, 2023
b12851c
Avoid an unnecessary `by_ref`.
nnethercote Nov 27, 2023
ed2868e
Create `LoweringContext::lower_assoc_item`.
nnethercote Nov 28, 2023
3bae927
Add `LoweringContext::new`.
nnethercote Nov 28, 2023
5c680e1
Remove unnecessary `Option` from `LoweringContext::allow_{try_trait,g…
nnethercote Nov 28, 2023
de13a38
unwrap return Option value, as it always returns Some for some fns
klensy Nov 28, 2023
9386e14
fix the issue of suggest unwrap/expect for shorthand field
chenyukang Nov 28, 2023
115eac0
Address unused tuple struct fields in the standard library
shepmaster Nov 25, 2023
9b85fc0
Update cargo
weihanglo Nov 28, 2023
3a4edf0
More fix on mismatched type suggestion for shorthand fields
chenyukang Nov 29, 2023
b8cdd43
Fix a typo in a `format_args!` note
cuviper Nov 29, 2023
5e7f770
Rollup merge of #118342 - compiler-errors:macro-generic-bang, r=estebank
matthiaskrgr Nov 29, 2023
f8628a1
Rollup merge of #118383 - shepmaster:unused-tuple-struct-field-cleanu…
matthiaskrgr Nov 29, 2023
82eda58
Rollup merge of #118401 - nnethercote:rustc_ast_lowering, r=compiler-…
matthiaskrgr Nov 29, 2023
69e48d0
Rollup merge of #118409 - klensy:position-opt, r=compiler-errors
matthiaskrgr Nov 29, 2023
8727538
Rollup merge of #118413 - chenyukang:yukang-fix-118145-unwrap-for-sho…
matthiaskrgr Nov 29, 2023
9c93eff
Rollup merge of #118425 - weihanglo:update-cargo, r=weihanglo
matthiaskrgr Nov 29, 2023
0687dcb
Rollup merge of #118429 - cuviper:its-arguments, r=compiler-errors
matthiaskrgr Nov 29, 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
21 changes: 12 additions & 9 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.mark_span_with_reason(
DesugaringKind::TryBlock,
expr.span,
this.allow_try_trait.clone(),
Some(this.allow_try_trait.clone()),
),
expr,
)
} else {
let try_span = this.mark_span_with_reason(
DesugaringKind::TryBlock,
this.tcx.sess.source_map().end_point(body.span),
this.allow_try_trait.clone(),
Some(this.allow_try_trait.clone()),
);

(try_span, this.expr_unit(try_span))
Expand Down Expand Up @@ -618,8 +618,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));

// Resume argument type: `ResumeTy`
let unstable_span =
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
let unstable_span = self.mark_span_with_reason(
DesugaringKind::Async,
span,
Some(self.allow_gen_future.clone()),
);
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
let input_ty = hir::Ty {
hir_id: self.next_id(),
Expand Down Expand Up @@ -741,7 +744,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let unstable_span = self.mark_span_with_reason(
DesugaringKind::Async,
span,
self.allow_gen_future.clone(),
Some(self.allow_gen_future.clone()),
);
self.lower_attrs(
inner_hir_id,
Expand Down Expand Up @@ -788,7 +791,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let gen_future_span = self.mark_span_with_reason(
DesugaringKind::Await,
full_span,
self.allow_gen_future.clone(),
Some(self.allow_gen_future.clone()),
);
let expr = self.lower_expr_mut(expr);
let expr_hir_id = expr.hir_id;
Expand Down Expand Up @@ -1646,13 +1649,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let unstable_span = self.mark_span_with_reason(
DesugaringKind::QuestionMark,
span,
self.allow_try_trait.clone(),
Some(self.allow_try_trait.clone()),
);
let try_span = self.tcx.sess.source_map().end_point(span);
let try_span = self.mark_span_with_reason(
DesugaringKind::QuestionMark,
try_span,
self.allow_try_trait.clone(),
Some(self.allow_try_trait.clone()),
);

// `Try::branch(<expr>)`
Expand Down Expand Up @@ -1745,7 +1748,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let unstable_span = self.mark_span_with_reason(
DesugaringKind::YeetExpr,
span,
self.allow_try_trait.clone(),
Some(self.allow_try_trait.clone()),
);

let from_yeet_expr = self.wrap_in_try_constructor(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_span::{Span, DUMMY_SP};

/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
pub(super) struct NodeCollector<'a, 'hir> {
struct NodeCollector<'a, 'hir> {
tcx: TyCtxt<'hir>,

bodies: &'a SortedMap<ItemLocalId, &'hir Body<'hir>>,
Expand Down
106 changes: 38 additions & 68 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use hir::definitions::DefPathData;
use rustc_ast::ptr::P;
use rustc_ast::visit::AssocCtxt;
use rustc_ast::*;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
Expand Down Expand Up @@ -55,42 +54,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
owner: NodeId,
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
) {
let allow_gen_future = Some(if self.tcx.features().async_fn_track_caller {
[sym::gen_future, sym::closure_track_caller][..].into()
} else {
[sym::gen_future][..].into()
});
let mut lctx = LoweringContext {
// Pseudo-globals.
tcx: self.tcx,
resolver: self.resolver,
arena: self.tcx.hir_arena,

// HirId handling.
bodies: Vec::new(),
attrs: SortedMap::default(),
children: Vec::default(),
current_hir_id_owner: hir::CRATE_OWNER_ID,
item_local_id_counter: hir::ItemLocalId::new(0),
node_id_to_local_id: Default::default(),
trait_map: Default::default(),

// Lowering state.
catch_scope: None,
loop_scope: None,
is_in_loop_condition: false,
is_in_trait_impl: false,
is_in_dyn_type: false,
coroutine_kind: None,
task_context: None,
current_item: None,
impl_trait_defs: Vec::new(),
impl_trait_bounds: Vec::new(),
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
allow_gen_future,
generics_def_id_map: Default::default(),
host_param_id: None,
};
let mut lctx = LoweringContext::new(self.tcx, self.resolver);
lctx.with_hir_id_owner(owner, |lctx| f(lctx));

for (def_id, info) in lctx.children {
Expand Down Expand Up @@ -136,39 +100,9 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {

fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
let def_id = self.resolver.node_id_to_def_id[&item.id];

let parent_id = self.tcx.local_parent(def_id);
let parent_hir = self.lower_node(parent_id).unwrap();
self.with_lctx(item.id, |lctx| {
// Evaluate with the lifetimes in `params` in-scope.
// This is used to track which lifetimes have already been defined,
// and which need to be replicated when lowering an async fn.

match parent_hir.node().expect_item().kind {
hir::ItemKind::Impl(impl_) => {
lctx.is_in_trait_impl = impl_.of_trait.is_some();
}
hir::ItemKind::Trait(_, _, generics, _, _) if lctx.tcx.features().effects => {
lctx.host_param_id = generics
.params
.iter()
.find(|param| {
parent_hir
.attrs
.get(param.hir_id.local_id)
.iter()
.any(|attr| attr.has_name(sym::rustc_host))
})
.map(|param| param.def_id);
}
_ => {}
}

match ctxt {
AssocCtxt::Trait => hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)),
AssocCtxt::Impl => hir::OwnerNode::ImplItem(lctx.lower_impl_item(item)),
}
})
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt, parent_hir))
}

fn lower_foreign_item(&mut self, item: &ForeignItem) {
Expand Down Expand Up @@ -611,6 +545,42 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

fn lower_assoc_item(
&mut self,
item: &AssocItem,
ctxt: AssocCtxt,
parent_hir: &'hir hir::OwnerInfo<'hir>,
) -> hir::OwnerNode<'hir> {
// Evaluate with the lifetimes in `params` in-scope.
// This is used to track which lifetimes have already been defined,
// and which need to be replicated when lowering an async fn.

match parent_hir.node().expect_item().kind {
hir::ItemKind::Impl(impl_) => {
self.is_in_trait_impl = impl_.of_trait.is_some();
}
hir::ItemKind::Trait(_, _, generics, _, _) if self.tcx.features().effects => {
self.host_param_id = generics
.params
.iter()
.find(|param| {
parent_hir
.attrs
.get(param.hir_id.local_id)
.iter()
.any(|attr| attr.has_name(sym::rustc_host))
})
.map(|param| param.def_id);
}
_ => {}
}

match ctxt {
AssocCtxt::Trait => hir::OwnerNode::TraitItem(self.lower_trait_item(item)),
AssocCtxt::Impl => hir::OwnerNode::ImplItem(self.lower_impl_item(item)),
}
}

fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
let hir_id = self.lower_node_id(i.id);
let owner_id = hir_id.expect_owner();
Expand Down
45 changes: 42 additions & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#![doc(rust_logo)]
#![feature(box_patterns)]
#![feature(let_chains)]
#![feature(never_type)]
#![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
Expand Down Expand Up @@ -132,8 +131,8 @@ struct LoweringContext<'a, 'hir> {
/// NodeIds that are lowered inside the current HIR owner.
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,

allow_try_trait: Option<Lrc<[Symbol]>>,
allow_gen_future: Option<Lrc<[Symbol]>>,
allow_try_trait: Lrc<[Symbol]>,
allow_gen_future: Lrc<[Symbol]>,

/// Mapping from generics `def_id`s to TAIT generics `def_id`s.
/// For each captured lifetime (e.g., 'a), we create a new lifetime parameter that is a generic
Expand All @@ -144,6 +143,46 @@ struct LoweringContext<'a, 'hir> {
host_param_id: Option<LocalDefId>,
}

impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn new(tcx: TyCtxt<'hir>, resolver: &'a mut ResolverAstLowering) -> Self {
Self {
// Pseudo-globals.
tcx,
resolver: resolver,
arena: tcx.hir_arena,

// HirId handling.
bodies: Vec::new(),
attrs: SortedMap::default(),
children: Vec::default(),
current_hir_id_owner: hir::CRATE_OWNER_ID,
item_local_id_counter: hir::ItemLocalId::new(0),
node_id_to_local_id: Default::default(),
trait_map: Default::default(),

// Lowering state.
catch_scope: None,
loop_scope: None,
is_in_loop_condition: false,
is_in_trait_impl: false,
is_in_dyn_type: false,
coroutine_kind: None,
task_context: None,
current_item: None,
impl_trait_defs: Vec::new(),
impl_trait_bounds: Vec::new(),
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
allow_gen_future: if tcx.features().async_fn_track_caller {
[sym::gen_future, sym::closure_track_caller].into()
} else {
[sym::gen_future].into()
},
generics_def_id_map: Default::default(),
host_param_id: None,
}
}
}

trait ResolverAstLoweringExt {
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>>;
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lifetime_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
}
}

pub fn lifetimes_in_bounds(
pub(crate) fn lifetimes_in_bounds(
resolver: &ResolverAstLowering,
bounds: &GenericBounds,
) -> Vec<Lifetime> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.arena.alloc(self.lower_pat_mut(pattern))
}

pub(crate) fn lower_pat_mut(&mut self, mut pattern: &Pat) -> hir::Pat<'hir> {
fn lower_pat_mut(&mut self, mut pattern: &Pat) -> hir::Pat<'hir> {
ensure_sufficient_stack(|| {
// loop here to avoid recursion
let node = loop {
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 @@ -2352,7 +2352,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Applicability::MaybeIncorrect,
);
} else {
err.note("the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used");
err.note("the result of `format_args!` can only be assigned directly if no placeholders in its arguments are used");
err.note("to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html>");
}
suggested = true;
Expand Down
24 changes: 8 additions & 16 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,30 +672,22 @@ fn report_missing_placeholders(
if explained.contains(&sub) {
continue;
}
explained.insert(sub.clone());
explained.insert(sub);

if !found_foreign {
found_foreign = true;
show_doc_note = true;
}

if let Some(inner_sp) = pos {
let sp = fmt_span.from_inner(inner_sp);
let sp = fmt_span.from_inner(pos);

if success {
suggestions.push((sp, trn));
} else {
diag.span_note(
sp,
format!("format specifiers use curly braces, and {}", trn),
);
}
if success {
suggestions.push((sp, trn));
} else {
if success {
diag.help(format!("`{}` should be written as `{}`", sub, trn));
} else {
diag.note(format!("`{}` should use curly braces, and {}", sub, trn));
}
diag.span_note(
sp,
format!("format specifiers use curly braces, and {}", trn),
);
}
}

Expand Down
Loading
Loading