Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a5a60d7
Add `size_of`, `size_of_val`, `align_of`, and `align_of_val` to the p…
joshtriplett Mar 28, 2024
b4834a1
rewrite resolve-rename in rmake
Oneirical May 28, 2024
d553d5b
rewrite incr-prev-body-beyond-eof in rmake
Oneirical May 28, 2024
8530285
rustc_span: Inline some hot functions
petrochenkov Jun 2, 2024
07dc3eb
Allow static mut definitions with #[linkage]
bjorn3 Jun 3, 2024
8f08625
Remove a bunch of redundant args from report_method_error
compiler-errors Jun 3, 2024
e9957b9
Stop passing empty args to check_expr_path
compiler-errors Jun 3, 2024
8f677e8
bootstrap: implement new feature `bootstrap-self-test`
onur-ozkan May 19, 2024
2bad3d1
Make deleting on LinkedList aware of the allocator
xTachyon Jun 4, 2024
59e2074
rewrite suspicious-library in rmake
Oneirical May 28, 2024
5d26f58
Closures are recursively reachable
tmiasko Jun 4, 2024
ac96fa4
Use inline const instead of unsafe to construct arrays in `MaybeUnini…
kpreid May 13, 2024
ec8fa17
Use inline const instead of unsafe to implement `MaybeUninit::uninit_…
kpreid May 13, 2024
2a21937
Add a co-maintainer for the two ARMv4T targets
Lokathor Jun 4, 2024
e1ae0fa
`UNICODE_ARRAY` and `ASCII_ARRAY` fixes.
nnethercote May 29, 2024
d1215da
Don't use the word "parse" for lexing operations.
nnethercote May 30, 2024
f657624
Inline and remove `error_malformed_cfg_attr_missing`.
nnethercote May 31, 2024
769ca3f
Rename `maybe_file_to_stream` as `maybe_source_file_to_stream`.
nnethercote May 31, 2024
3c321b9
Remove `stream_to_parser`.
nnethercote May 31, 2024
af13b48
Improve `panictry_buffer!`.
nnethercote May 31, 2024
29e6e28
Remove low-value comments.
nnethercote May 31, 2024
191b76e
Rename `maybe_source_file_to_parser` as `maybe_new_parser_from_source…
nnethercote May 31, 2024
8964106
Use `source_str_to_stream` in a test file.
nnethercote May 31, 2024
25972ae
Inline and remove `parse_crate{,_attrs}_from_{file,source_str}`.
nnethercote May 31, 2024
ab192a0
Reorder `source_str_to_stream` arguments.
nnethercote May 31, 2024
264dbe4
Inline and remove `source_file_to_stream`.
nnethercote May 31, 2024
b903733
Make top-level `rustc_parse` functions fallible.
nnethercote May 31, 2024
2d4e7df
rustfmt: Remove an unnecessary `catch_unwind` use.
nnethercote Jun 3, 2024
dd6bca5
Add another test for hidden types capturing lifetimes that outlive bu…
compiler-errors Jun 5, 2024
9ccc7b7
Rollup merge of #123168 - joshtriplett:size-of-prelude, r=Amanieu
workingjubilee Jun 5, 2024
0f86182
Rollup merge of #125273 - onur-ozkan:bootstrap-self-test, r=albertlar…
workingjubilee Jun 5, 2024
0f2b34a
Rollup merge of #125683 - Oneirical:patience-testing-test, r=jieyouxu
workingjubilee Jun 5, 2024
05b4674
Rollup merge of #125815 - nnethercote:rustc_parse-top-level-cleanups,…
workingjubilee Jun 5, 2024
0096138
Rollup merge of #125903 - petrochenkov:upctxt3, r=nnethercote
workingjubilee Jun 5, 2024
78d9a7e
Rollup merge of #125906 - compiler-errors:simplify-method-error-args,…
workingjubilee Jun 5, 2024
2b89c1b
Rollup merge of #125920 - bjorn3:allow_static_mut_linkage_def, r=Urgau
workingjubilee Jun 5, 2024
448159c
Rollup merge of #125982 - xTachyon:fix-linked-list, r=jhpratt
workingjubilee Jun 5, 2024
6b6b698
Rollup merge of #125995 - kpreid:const-uninit-stable, r=Nilstrieb
workingjubilee Jun 5, 2024
eb2819e
Rollup merge of #125996 - tmiasko:closure-recursively-reachable, r=ol…
workingjubilee Jun 5, 2024
669935e
Rollup merge of #126003 - Lokathor:new-co-maintainer, r=compiler-errors
workingjubilee Jun 5, 2024
f12fe3a
Rollup merge of #126004 - compiler-errors:captures-soundness-test, r=…
workingjubilee Jun 5, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove a bunch of redundant args from report_method_error
  • Loading branch information
compiler-errors committed Jun 4, 2024
commit 8f0862544327d5419a158c9483ed905d3fb55bf2
31 changes: 14 additions & 17 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::errors::{
YieldExprOutsideOfCoroutine,
};
use crate::fatally_break_rust;
use crate::method::SelfSource;
use crate::type_error_struct;
use crate::CoroutineTypes;
use crate::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExpectation};
Expand Down Expand Up @@ -507,7 +506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> Ty<'tcx> {
let tcx = self.tcx;
let (res, opt_ty, segs) =
self.resolve_ty_and_res_fully_qualified_call(qpath, expr.hir_id, expr.span, Some(args));
self.resolve_ty_and_res_fully_qualified_call(qpath, expr.hir_id, expr.span);
let ty = match res {
Res::Err => {
self.suggest_assoc_method_call(segs);
Expand Down Expand Up @@ -1331,9 +1330,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let rcvr_t = self.check_expr(rcvr);
// no need to check for bot/err -- callee does that
let rcvr_t = self.structurally_resolve_type(rcvr.span, rcvr_t);
let span = segment.ident.span;

let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr, args) {
let method = match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args)
{
Ok(method) => {
// We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
// trigger this codepath causing `structurally_resolve_type` to emit an error.
Expand All @@ -1342,18 +1341,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
Err(error) => {
if segment.ident.name != kw::Empty {
if let Some(err) = self.report_method_error(
span,
Some(rcvr),
rcvr_t,
segment.ident,
expr.hir_id,
SelfSource::MethodCall(rcvr),
error,
Some(args),
expected,
false,
) {
if let Some(err) =
self.report_method_error(expr.hir_id, rcvr_t, error, expected, false)
{
err.emit();
}
}
Expand All @@ -1362,7 +1352,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

// Call the generic checker.
self.check_method_argument_types(span, expr, method, args, DontTupleArguments, expected)
self.check_method_argument_types(
segment.ident.span,
expr,
method,
args,
DontTupleArguments,
expected,
)
}

fn check_expr_cast(
Expand Down
10 changes: 2 additions & 8 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::callee::{self, DeferredCallResolution};
use crate::errors::{self, CtorIsPrivate};
use crate::method::{self, MethodCallee, SelfSource};
use crate::method::{self, MethodCallee};
use crate::rvalue_scopes;
use crate::{BreakableCtxt, Diverges, Expectation, FnCtxt, LoweredTy};
use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -735,7 +735,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
qpath: &'tcx QPath<'tcx>,
hir_id: HirId,
span: Span,
args: Option<&'tcx [hir::Expr<'tcx>]>,
) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
debug!(
"resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}",
Expand Down Expand Up @@ -828,14 +827,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if item_name.name != kw::Empty {
if let Some(e) = self.report_method_error(
span,
None,
ty.normalized,
item_name,
hir_id,
SelfSource::QPath(qself),
ty.normalized,
error,
args,
Expectation::NoExpectation,
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
) {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod prelude_edition_lints;
pub mod probe;
mod suggest;

pub use self::suggest::SelfSource;
pub use self::MethodError::*;

use crate::FnCtxt;
Expand Down
58 changes: 38 additions & 20 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use rustc_data_structures::unord::UnordSet;
use rustc_errors::{
codes::*, pluralize, struct_span_code_err, Applicability, Diag, MultiSpan, StashKey,
};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_hir::PathSegment;
use rustc_hir::{self as hir, HirId};
use rustc_hir::{ExprKind, Node, QPath};
use rustc_infer::infer::{self, RegionVariableOrigin};
use rustc_middle::bug;
Expand Down Expand Up @@ -187,37 +187,56 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(level = "debug", skip(self))]
pub fn report_method_error(
&self,
span: Span,
rcvr_opt: Option<&'tcx hir::Expr<'tcx>>,
call_id: HirId,
rcvr_ty: Ty<'tcx>,
item_name: Ident,
expr_id: hir::HirId,
source: SelfSource<'tcx>,
error: MethodError<'tcx>,
args: Option<&'tcx [hir::Expr<'tcx>]>,
expected: Expectation<'tcx>,
trait_missing_method: bool,
) -> Option<Diag<'_>> {
let (span, sugg_span, source, item_name, args) = match self.tcx.hir_node(call_id) {
hir::Node::Expr(&hir::Expr {
kind: hir::ExprKind::MethodCall(segment, rcvr, args, _),
span,
..
}) => {
(segment.ident.span, span, SelfSource::MethodCall(rcvr), segment.ident, Some(args))
}
hir::Node::Expr(&hir::Expr {
kind: hir::ExprKind::Path(QPath::TypeRelative(rcvr, segment)),
span,
..
})
| hir::Node::Pat(&hir::Pat {
kind:
hir::PatKind::Path(QPath::TypeRelative(rcvr, segment))
| hir::PatKind::Struct(QPath::TypeRelative(rcvr, segment), ..)
| hir::PatKind::TupleStruct(QPath::TypeRelative(rcvr, segment), ..),
span,
..
}) => {
let args = match self.tcx.parent_hir_node(call_id) {
hir::Node::Expr(&hir::Expr {
kind: hir::ExprKind::Call(callee, args), ..
}) if callee.hir_id == call_id => Some(args),
_ => None,
};
(segment.ident.span, span, SelfSource::QPath(rcvr), segment.ident, args)
}
node => unreachable!("{node:?}"),
};

// Avoid suggestions when we don't know what's going on.
if rcvr_ty.references_error() {
return None;
}

let sugg_span = if let SelfSource::MethodCall(expr) = source {
// Given `foo.bar(baz)`, `expr` is `bar`, but we want to point to the whole thing.
self.tcx.hir().expect_expr(self.tcx.parent_hir_id(expr.hir_id)).span
} else {
span
};

match error {
MethodError::NoMatch(mut no_match_data) => {
return self.report_no_match_method_error(
span,
rcvr_opt,
rcvr_ty,
item_name,
expr_id,
call_id,
source,
args,
sugg_span,
Expand Down Expand Up @@ -362,7 +381,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

pub fn suggest_use_shadowed_binding_with_method(
&self,
rcvr_opt: Option<&'tcx hir::Expr<'tcx>>,
self_source: SelfSource<'tcx>,
method_name: Ident,
ty_str_reported: &str,
err: &mut Diag<'_>,
Expand Down Expand Up @@ -502,7 +521,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

if let Some(rcvr) = rcvr_opt
if let SelfSource::MethodCall(rcvr) = self_source
&& let hir::ExprKind::Path(QPath::Resolved(_, path)) = rcvr.kind
&& let hir::def::Res::Local(recv_id) = path.res
&& let Some(segment) = path.segments.first()
Expand Down Expand Up @@ -548,7 +567,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn report_no_match_method_error(
&self,
mut span: Span,
rcvr_opt: Option<&'tcx hir::Expr<'tcx>>,
rcvr_ty: Ty<'tcx>,
item_name: Ident,
expr_id: hir::HirId,
Expand Down Expand Up @@ -658,7 +676,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if is_method {
self.suggest_use_shadowed_binding_with_method(
rcvr_opt,
source,
item_name,
&ty_str_reported,
&mut err,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let PatInfo { binding_mode, max_ref_mutbl, top_info: ti, current_depth, .. } = pat_info;

let path_res = match &pat.kind {
PatKind::Path(qpath) => Some(
self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span, None),
),
PatKind::Path(qpath) => {
Some(self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span))
}
_ => None,
};
let adjust_mode = self.calc_adjust_mode(pat, path_res.map(|(res, ..)| res));
Expand Down Expand Up @@ -1184,7 +1184,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Resolve the path and check the definition for errors.
let (res, opt_ty, segments) =
self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span, None);
self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span);
if res == Res::Err {
let e = tcx.dcx().span_delayed_bug(pat.span, "`Res::Err` but no error emitted");
self.set_tainted_by_errors(e);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-28344.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ error[E0599]: no function or associated item named `bitor` found for trait objec
LL | let g = BitXor::bitor;
| ^^^^^ function or associated item not found in `dyn BitXor<_>`
|
help: there is a method `bitxor` with a similar name, but with different arguments
help: there is a method `bitxor` with a similar name
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL

error: aborting due to 4 previous errors; 2 warnings emitted
Expand Down
7 changes: 0 additions & 7 deletions tests/ui/resolve/issue-82865.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ LL | Box::z
LL | mac!();
| ------ in this macro invocation
|
note: if you're trying to build a new `Box<_, _>` consider using one of the following associated functions:
Box::<T>::new
Box::<T>::new_uninit
Box::<T>::new_zeroed
Box::<T>::try_new
and 18 others
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors
Expand Down
9 changes: 5 additions & 4 deletions tests/ui/traits/item-privacy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ LL | S::B;
| ^ associated item not found in `S`
|
= help: items from traits can only be used if the trait is in scope
help: there is a method `b` with a similar name
--> $DIR/item-privacy.rs:11:9
|
LL | fn b(&self) { }
| ^^^^^^^^^^^
help: trait `B` which provides `B` is implemented but not in scope; perhaps you want to import it
|
LL + use assoc_const::B;
|
help: there is a method `b` with a similar name
|
LL | S::b;
| ~

error[E0624]: associated constant `A` is private
--> $DIR/item-privacy.rs:101:14
Expand Down