Skip to content

Commit 7df6f4a

Browse files
committed
Auto merge of rust-lang#120417 - matthiaskrgr:rollup-5rszkmd, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#118182 (Properly recover from trailing attr in body) - rust-lang#119641 (Remove feature not required by `Ipv6Addr::to_cononical` doctest) - rust-lang#119957 (fix: correct suggestion arg for impl trait) - rust-lang#120386 (ScopeTree: remove destruction_scopes as unused) - rust-lang#120398 (Improve handling of numbers in `IntoDiagnosticArg`) - rust-lang#120399 (Remove myself from review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8b6a431 + 574d35f commit 7df6f4a

11 files changed

+213
-47
lines changed

compiler/rustc_errors/src/diagnostic_impls.rs

+22-25
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,29 @@ macro_rules! into_diagnostic_arg_using_display {
5858
}
5959
}
6060

61+
macro_rules! into_diagnostic_arg_for_number {
62+
($( $ty:ty ),+ $(,)?) => {
63+
$(
64+
impl IntoDiagnosticArg for $ty {
65+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
66+
// HACK: `FluentNumber` the underline backing struct represent
67+
// numbers using a f64 which can't represent all the i128 numbers
68+
// So in order to be able to use fluent selectors and still
69+
// have all the numbers representable we only convert numbers
70+
// below a certain threshold.
71+
if let Ok(n) = TryInto::<i128>::try_into(self) && n >= -100 && n <= 100 {
72+
DiagnosticArgValue::Number(n)
73+
} else {
74+
self.to_string().into_diagnostic_arg()
75+
}
76+
}
77+
}
78+
)+
79+
}
80+
}
81+
6182
into_diagnostic_arg_using_display!(
6283
ast::ParamKindOrd,
63-
i8,
64-
u8,
65-
i16,
66-
u16,
67-
u32,
68-
i64,
69-
i128,
70-
u128,
7184
std::io::Error,
7285
Box<dyn std::error::Error>,
7386
std::num::NonZeroU32,
@@ -82,17 +95,7 @@ into_diagnostic_arg_using_display!(
8295
ExitStatus,
8396
);
8497

85-
impl IntoDiagnosticArg for i32 {
86-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
87-
DiagnosticArgValue::Number(self.into())
88-
}
89-
}
90-
91-
impl IntoDiagnosticArg for u64 {
92-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
93-
DiagnosticArgValue::Number(self.into())
94-
}
95-
}
98+
into_diagnostic_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
9699

97100
impl IntoDiagnosticArg for bool {
98101
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
@@ -154,12 +157,6 @@ impl IntoDiagnosticArg for PathBuf {
154157
}
155158
}
156159

157-
impl IntoDiagnosticArg for usize {
158-
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
159-
DiagnosticArgValue::Number(self as i128)
160-
}
161-
}
162-
163160
impl IntoDiagnosticArg for PanicStrategy {
164161
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
165162
DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string()))

compiler/rustc_hir_typeck/src/method/suggest.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -1601,23 +1601,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16011601
self.ty_to_value_string(rcvr_ty.peel_refs())
16021602
};
16031603
if let SelfSource::MethodCall(_) = source {
1604-
let first_arg = if let Some(CandidateSource::Impl(impl_did)) = static_candidates.get(0)
1605-
&& let Some(assoc) = self.associated_value(*impl_did, item_name)
1606-
&& assoc.kind == ty::AssocKind::Fn
1607-
{
1604+
let first_arg = static_candidates.get(0).and_then(|candidate_source| {
1605+
let (assoc_did, self_ty) = match candidate_source {
1606+
CandidateSource::Impl(impl_did) => {
1607+
(*impl_did, self.tcx.type_of(*impl_did).instantiate_identity())
1608+
}
1609+
CandidateSource::Trait(trait_did) => (*trait_did, rcvr_ty),
1610+
};
1611+
1612+
let assoc = self.associated_value(assoc_did, item_name)?;
1613+
if assoc.kind != ty::AssocKind::Fn {
1614+
return None;
1615+
}
1616+
1617+
// for CandidateSource::Impl, `Self` will be instantiated to a concrete type
1618+
// but for CandidateSource::Trait, `Self` is still `Self`
16081619
let sig = self.tcx.fn_sig(assoc.def_id).instantiate_identity();
16091620
sig.inputs().skip_binder().get(0).and_then(|first| {
1610-
let impl_ty = self.tcx.type_of(*impl_did).instantiate_identity();
16111621
// if the type of first arg is the same as the current impl type, we should take the first arg into assoc function
1612-
if first.peel_refs() == impl_ty {
1622+
let first_ty = first.peel_refs();
1623+
if first_ty == self_ty || first_ty == self.tcx.types.self_param {
16131624
Some(first.ref_mutability().map_or("", |mutbl| mutbl.ref_prefix_str()))
16141625
} else {
16151626
None
16161627
}
16171628
})
1618-
} else {
1619-
None
1620-
};
1629+
});
1630+
16211631
let mut applicability = Applicability::MachineApplicable;
16221632
let args = if let SelfSource::MethodCall(receiver) = source
16231633
&& let Some(args) = args

compiler/rustc_middle/src/middle/region.rs

-8
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ pub struct ScopeTree {
221221
/// variable is declared.
222222
var_map: FxIndexMap<hir::ItemLocalId, Scope>,
223223

224-
/// Maps from a `NodeId` to the associated destruction scope (if any).
225-
destruction_scopes: FxIndexMap<hir::ItemLocalId, Scope>,
226-
227224
/// Identifies expressions which, if captured into a temporary, ought to
228225
/// have a temporary whose lifetime extends to the end of the enclosing *block*,
229226
/// and not the enclosing *statement*. Expressions that are not present in this
@@ -336,11 +333,6 @@ impl ScopeTree {
336333
let prev = self.parent_map.insert(child, p);
337334
assert!(prev.is_none());
338335
}
339-
340-
// Record the destruction scopes for later so we can query them.
341-
if let ScopeData::Destruction = child.data {
342-
self.destruction_scopes.insert(child.item_local_id(), child);
343-
}
344336
}
345337

346338
pub fn record_var_scope(&mut self, var: hir::ItemLocalId, lifetime: Scope) {

compiler/rustc_parse/src/parser/diagnostics.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,28 @@ impl<'a> Parser<'a> {
791791
&& let [segment] = &attr_kind.item.path.segments[..]
792792
&& segment.ident.name == sym::cfg
793793
&& let Some(args_span) = attr_kind.item.args.span()
794-
&& let Ok(next_attr) = snapshot.parse_attribute(InnerAttrPolicy::Forbidden(None))
794+
&& let next_attr = match snapshot.parse_attribute(InnerAttrPolicy::Forbidden(None))
795+
{
796+
Ok(next_attr) => next_attr,
797+
Err(inner_err) => {
798+
err.cancel();
799+
inner_err.cancel();
800+
return;
801+
}
802+
}
795803
&& let ast::AttrKind::Normal(next_attr_kind) = next_attr.kind
796804
&& let Some(next_attr_args_span) = next_attr_kind.item.args.span()
797805
&& let [next_segment] = &next_attr_kind.item.path.segments[..]
798806
&& segment.ident.name == sym::cfg
799-
&& let Ok(next_expr) = snapshot.parse_expr()
800807
{
808+
let next_expr = match snapshot.parse_expr() {
809+
Ok(next_expr) => next_expr,
810+
Err(inner_err) => {
811+
err.cancel();
812+
inner_err.cancel();
813+
return;
814+
}
815+
};
801816
// We have for sure
802817
// #[cfg(..)]
803818
// expr

library/core/src/net/ip_addr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,6 @@ impl Ipv6Addr {
18931893
/// # Examples
18941894
///
18951895
/// ```
1896-
/// #![feature(ip)]
18971896
/// use std::net::Ipv6Addr;
18981897
///
18991898
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).is_loopback(), false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Issue #118164: recovery path leaving unemitted error behind
2+
fn bar() -> String {
3+
#[cfg(feature = )]
4+
[1, 2, 3].iter().map().collect::<String>() //~ ERROR expected `;`, found `#`
5+
#[attr] //~ ERROR expected statement after outer attribute
6+
}
7+
fn main() {
8+
let _ = bar();
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: expected `;`, found `#`
2+
--> $DIR/properly-recover-from-trailing-outer-attribute-in-body.rs:4:47
3+
|
4+
LL | #[cfg(feature = )]
5+
| ------------------ only `;` terminated statements or tail expressions are allowed after this attribute
6+
LL | [1, 2, 3].iter().map().collect::<String>()
7+
| ^ expected `;` here
8+
LL | #[attr]
9+
| - unexpected token
10+
|
11+
help: add `;` here
12+
|
13+
LL | [1, 2, 3].iter().map().collect::<String>();
14+
| +
15+
help: alternatively, consider surrounding the expression with a block
16+
|
17+
LL | { [1, 2, 3].iter().map().collect::<String>() }
18+
| + +
19+
20+
error: expected statement after outer attribute
21+
--> $DIR/properly-recover-from-trailing-outer-attribute-in-body.rs:5:5
22+
|
23+
LL | #[attr]
24+
| ^^^^^^^
25+
26+
error: aborting due to 2 previous errors
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-rustfix
2+
3+
struct A {
4+
5+
}
6+
7+
trait M {
8+
fn foo(_a: Self);
9+
fn bar(_a: Self);
10+
fn baz(_a: i32);
11+
}
12+
13+
impl M for A {
14+
fn foo(_a: Self) {}
15+
fn bar(_a: A) {}
16+
fn baz(_a: i32) {}
17+
}
18+
19+
fn main() {
20+
let _a = A {};
21+
A::foo(_a);
22+
//~^ ERROR no method named `foo` found
23+
A::baz(0);
24+
//~^ ERROR no method named `baz` found
25+
26+
let _b = A {};
27+
A::bar(_b);
28+
//~^ ERROR no method named `bar` found
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-rustfix
2+
3+
struct A {
4+
5+
}
6+
7+
trait M {
8+
fn foo(_a: Self);
9+
fn bar(_a: Self);
10+
fn baz(_a: i32);
11+
}
12+
13+
impl M for A {
14+
fn foo(_a: Self) {}
15+
fn bar(_a: A) {}
16+
fn baz(_a: i32) {}
17+
}
18+
19+
fn main() {
20+
let _a = A {};
21+
_a.foo();
22+
//~^ ERROR no method named `foo` found
23+
_a.baz(0);
24+
//~^ ERROR no method named `baz` found
25+
26+
let _b = A {};
27+
_b.bar();
28+
//~^ ERROR no method named `bar` found
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error[E0599]: no method named `foo` found for struct `A` in the current scope
2+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:21:8
3+
|
4+
LL | struct A {
5+
| -------- method `foo` not found for this struct
6+
...
7+
LL | _a.foo();
8+
| ---^^^--
9+
| | |
10+
| | this is an associated function, not a method
11+
| help: use associated function syntax instead: `A::foo(_a)`
12+
|
13+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
14+
note: the candidate is defined in the trait `M`
15+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:8:5
16+
|
17+
LL | fn foo(_a: Self);
18+
| ^^^^^^^^^^^^^^^^^
19+
20+
error[E0599]: no method named `baz` found for struct `A` in the current scope
21+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:23:8
22+
|
23+
LL | struct A {
24+
| -------- method `baz` not found for this struct
25+
...
26+
LL | _a.baz(0);
27+
| ---^^^---
28+
| | |
29+
| | this is an associated function, not a method
30+
| help: use associated function syntax instead: `A::baz(0)`
31+
|
32+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
33+
note: the candidate is defined in the trait `M`
34+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:10:5
35+
|
36+
LL | fn baz(_a: i32);
37+
| ^^^^^^^^^^^^^^^^
38+
39+
error[E0599]: no method named `bar` found for struct `A` in the current scope
40+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:27:8
41+
|
42+
LL | struct A {
43+
| -------- method `bar` not found for this struct
44+
...
45+
LL | _b.bar();
46+
| ---^^^--
47+
| | |
48+
| | this is an associated function, not a method
49+
| help: use associated function syntax instead: `A::bar(_b)`
50+
|
51+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
52+
note: the candidate is defined in the trait `M`
53+
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:9:5
54+
|
55+
LL | fn bar(_a: Self);
56+
| ^^^^^^^^^^^^^^^^^
57+
58+
error: aborting due to 3 previous errors
59+
60+
For more information about this error, try `rustc --explain E0599`.

triagebot.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ libs = [
663663
"@joshtriplett",
664664
"@Mark-Simulacrum",
665665
"@m-ou-se",
666-
"@thomcc",
667666
]
668667
bootstrap = [
669668
"@Mark-Simulacrum",
@@ -803,7 +802,7 @@ project-stable-mir = [
803802
"/library/panic_unwind" = ["libs"]
804803
"/library/proc_macro" = ["@petrochenkov"]
805804
"/library/std" = ["libs"]
806-
"/library/std/src/sys/pal/windows" = ["@ChrisDenton", "@thomcc"]
805+
"/library/std/src/sys/pal/windows" = ["@ChrisDenton"]
807806
"/library/stdarch" = ["libs"]
808807
"/library/test" = ["libs"]
809808
"/src/bootstrap" = ["bootstrap"]

0 commit comments

Comments
 (0)