Skip to content

Commit 8c28fe8

Browse files
committed
Auto merge of #68330 - tmandry:rollup-5v29y9r, r=tmandry
Rollup of 9 pull requests Successful merges: - #66660 (Don't warn about snake case for field puns.) - #68093 (Fix deref impl typedef) - #68204 (Use named fields for `{ast,hir}::ItemKind::Impl`) - #68256 (Do not ICE on malformed suggestion spans) - #68279 (Clean up E0198 explanation) - #68291 (Update sanitizer tests) - #68312 (Add regression test for integer literals in generic arguments in where clauses) - #68314 (Stop treating `FalseEdges` and `FalseUnwind` as having semantic value for const eval) - #68317 (Clean up E0199 explanation) Failed merges: r? @ghost
2 parents d8dcb63 + 14d779c commit 8c28fe8

File tree

78 files changed

+642
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+642
-392
lines changed

src/librustc/hir/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Target {
112112
ItemKind::Union(..) => Target::Union,
113113
ItemKind::Trait(..) => Target::Trait,
114114
ItemKind::TraitAlias(..) => Target::TraitAlias,
115-
ItemKind::Impl(..) => Target::Impl,
115+
ItemKind::Impl { .. } => Target::Impl,
116116
}
117117
}
118118

@@ -144,7 +144,7 @@ impl Target {
144144
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
145145
let containing_item = tcx.hir().expect_item(parent_hir_id);
146146
let containing_impl_is_for_trait = match &containing_item.kind {
147-
hir::ItemKind::Impl(_, _, _, _, tr, _, _) => tr.is_some(),
147+
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.is_some(),
148148
_ => bug!("parent of an ImplItem must be an Impl"),
149149
};
150150
if containing_impl_is_for_trait {

src/librustc/hir/map/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'hir> Map<'hir> {
341341
| ItemKind::Use(..)
342342
| ItemKind::ForeignMod(..)
343343
| ItemKind::GlobalAsm(..)
344-
| ItemKind::Impl(..) => return None,
344+
| ItemKind::Impl { .. } => return None,
345345
},
346346
Node::ForeignItem(item) => match item.kind {
347347
ForeignItemKind::Fn(..) => DefKind::Fn,
@@ -604,7 +604,7 @@ impl<'hir> Map<'hir> {
604604
| ItemKind::Union(_, ref generics)
605605
| ItemKind::Trait(_, _, ref generics, ..)
606606
| ItemKind::TraitAlias(ref generics, _)
607-
| ItemKind::Impl(_, _, _, ref generics, ..) => Some(generics),
607+
| ItemKind::Impl { ref generics, .. } => Some(generics),
608608
_ => None,
609609
},
610610
_ => None,
@@ -821,7 +821,7 @@ impl<'hir> Map<'hir> {
821821
| ItemKind::Struct(..)
822822
| ItemKind::Union(..)
823823
| ItemKind::Trait(..)
824-
| ItemKind::Impl(..) => true,
824+
| ItemKind::Impl { .. } => true,
825825
_ => false,
826826
},
827827
Node::ForeignItem(fi) => match fi.kind {
@@ -1332,7 +1332,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
13321332
ItemKind::Union(..) => "union",
13331333
ItemKind::Trait(..) => "trait",
13341334
ItemKind::TraitAlias(..) => "trait alias",
1335-
ItemKind::Impl(..) => "impl",
1335+
ItemKind::Impl { .. } => "impl",
13361336
};
13371337
format!("{} {}{}", item_str, path_str(), id_str)
13381338
}

src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn emit_msg_span(
254254

255255
fn item_scope_tag(item: &hir::Item<'_>) -> &'static str {
256256
match item.kind {
257-
hir::ItemKind::Impl(..) => "impl",
257+
hir::ItemKind::Impl { .. } => "impl",
258258
hir::ItemKind::Struct(..) => "struct",
259259
hir::ItemKind::Union(..) => "union",
260260
hir::ItemKind::Enum(..) => "enum",

src/librustc/traits/error_reporting/suggestions.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
8888
..
8989
})
9090
| hir::Node::Item(hir::Item {
91-
kind: hir::ItemKind::Impl(_, _, _, generics, ..),
92-
..
91+
kind: hir::ItemKind::Impl { generics, .. }, ..
9392
}) if projection.is_some() => {
9493
// Missing associated type bound.
9594
suggest_restriction(&generics, "the associated type", err);
@@ -115,7 +114,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
115114
..
116115
})
117116
| hir::Node::Item(hir::Item {
118-
kind: hir::ItemKind::Impl(_, _, _, generics, ..),
117+
kind: hir::ItemKind::Impl { generics, .. },
119118
span,
120119
..
121120
})

src/librustc/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ pub fn impl_is_default(tcx: TyCtxt<'_>, node_item_def_id: DefId) -> bool {
651651
match tcx.hir().as_local_hir_id(node_item_def_id) {
652652
Some(hir_id) => {
653653
let item = tcx.hir().expect_item(hir_id);
654-
if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.kind {
654+
if let hir::ItemKind::Impl { defaultness, .. } = item.kind {
655655
defaultness.is_default()
656656
} else {
657657
false

src/librustc/traits/wf.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
229229
// |
230230
// = note: expected type `u32`
231231
// found type `()`
232-
if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
232+
if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
233233
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
234-
if let Some(impl_item) = impl_items
234+
if let Some(impl_item) = items
235235
.iter()
236236
.filter(|item| item.ident == trait_assoc_item.ident)
237237
.next()
@@ -279,14 +279,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
279279
// | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
280280
if let (
281281
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
282-
Some(hir::ItemKind::Impl(.., impl_items)),
282+
Some(hir::ItemKind::Impl { items, .. }),
283283
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind))
284284
{
285285
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
286286
.filter(|i| i.def_id == *item_def_id)
287287
.next()
288288
.and_then(|trait_assoc_item| {
289-
impl_items
289+
items
290290
.iter()
291291
.filter(|i| i.ident == trait_assoc_item.ident)
292292
.next()

src/librustc_ast_lowering/item.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
6767
if let Some(hir_id) = item_hir_id {
6868
self.lctx.with_parent_item_lifetime_defs(hir_id, |this| {
6969
let this = &mut ItemLowerer { lctx: this };
70-
if let ItemKind::Impl(.., ref opt_trait_ref, _, _) = item.kind {
71-
if opt_trait_ref.as_ref().map(|tr| tr.constness.is_some()).unwrap_or(false) {
70+
if let ItemKind::Impl { ref of_trait, .. } = item.kind {
71+
if of_trait.as_ref().map(|tr| tr.constness.is_some()).unwrap_or(false) {
72+
this.with_trait_impl_ref(of_trait, |this| visit::walk_item(this, item));
7273
this.lctx
7374
.diagnostic()
7475
.span_err(item.span, "const trait impls are not yet implemented");
7576
}
7677

77-
this.with_trait_impl_ref(opt_trait_ref, |this| visit::walk_item(this, item));
78+
this.with_trait_impl_ref(of_trait, |this| visit::walk_item(this, item));
7879
} else {
7980
visit::walk_item(this, item);
8081
}
@@ -118,7 +119,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
118119
let old_len = self.in_scope_lifetimes.len();
119120

120121
let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind {
121-
hir::ItemKind::Impl(_, _, _, ref generics, ..)
122+
hir::ItemKind::Impl { ref generics, .. }
122123
| hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..],
123124
_ => &[],
124125
};
@@ -173,7 +174,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
173174
vec
174175
}
175176
ItemKind::MacroDef(..) => SmallVec::new(),
176-
ItemKind::Fn(..) | ItemKind::Impl(.., None, _, _) => smallvec![i.id],
177+
ItemKind::Fn(..) | ItemKind::Impl { of_trait: None, .. } => smallvec![i.id],
177178
ItemKind::Static(ref ty, ..) => {
178179
let mut ids = smallvec![i.id];
179180
if self.sess.features_untracked().impl_trait_in_bindings {
@@ -361,15 +362,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
361362
self.lower_generics(generics, ImplTraitContext::disallowed()),
362363
)
363364
}
364-
ItemKind::Impl(
365+
ItemKind::Impl {
365366
unsafety,
366367
polarity,
367368
defaultness,
368-
ref ast_generics,
369-
ref trait_ref,
370-
ref ty,
371-
ref impl_items,
372-
) => {
369+
generics: ref ast_generics,
370+
of_trait: ref trait_ref,
371+
self_ty: ref ty,
372+
items: ref impl_items,
373+
} => {
373374
let def_id = self.resolver.definitions().local_def_id(id);
374375

375376
// Lower the "impl header" first. This ordering is important
@@ -417,15 +418,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
417418
)
418419
});
419420

420-
hir::ItemKind::Impl(
421+
hir::ItemKind::Impl {
421422
unsafety,
422423
polarity,
423-
self.lower_defaultness(defaultness, true /* [1] */),
424+
defaultness: self.lower_defaultness(defaultness, true /* [1] */),
424425
generics,
425-
trait_ref,
426-
lowered_ty,
427-
new_impl_items,
428-
)
426+
of_trait: trait_ref,
427+
self_ty: lowered_ty,
428+
items: new_impl_items,
429+
}
429430
}
430431
ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref items) => {
431432
let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed());

src/librustc_ast_passes/ast_validation.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,17 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
612612
}
613613

614614
match item.kind {
615-
ItemKind::Impl(unsafety, polarity, _, _, Some(..), ref ty, ref impl_items) => {
615+
ItemKind::Impl {
616+
unsafety,
617+
polarity,
618+
defaultness: _,
619+
generics: _,
620+
of_trait: Some(_),
621+
ref self_ty,
622+
ref items,
623+
} => {
616624
self.invalid_visibility(&item.vis, None);
617-
if let TyKind::Err = ty.kind {
625+
if let TyKind::Err = self_ty.kind {
618626
self.err_handler()
619627
.struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
620628
.help("use `auto trait Trait {}` instead")
@@ -629,15 +637,23 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
629637
)
630638
.emit();
631639
}
632-
for impl_item in impl_items {
640+
for impl_item in items {
633641
self.invalid_visibility(&impl_item.vis, None);
634642
if let AssocItemKind::Fn(ref sig, _) = impl_item.kind {
635643
self.check_trait_fn_not_const(sig.header.constness);
636644
self.check_trait_fn_not_async(impl_item.span, sig.header.asyncness.node);
637645
}
638646
}
639647
}
640-
ItemKind::Impl(unsafety, polarity, defaultness, _, None, _, _) => {
648+
ItemKind::Impl {
649+
unsafety,
650+
polarity,
651+
defaultness,
652+
generics: _,
653+
of_trait: None,
654+
self_ty: _,
655+
items: _,
656+
} => {
641657
self.invalid_visibility(
642658
&item.vis,
643659
Some("place qualifiers on individual impl items instead"),

src/librustc_ast_passes/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
339339
}
340340
}
341341

342-
ast::ItemKind::Impl(_, polarity, defaultness, ..) => {
342+
ast::ItemKind::Impl { polarity, defaultness, .. } => {
343343
if polarity == ast::ImplPolarity::Negative {
344344
gate_feature_post!(
345345
&self,

src/librustc_builtin_macros/deriving/generic/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -705,15 +705,15 @@ impl<'a> TraitDef<'a> {
705705
self.span,
706706
Ident::invalid(),
707707
a,
708-
ast::ItemKind::Impl(
708+
ast::ItemKind::Impl {
709709
unsafety,
710-
ast::ImplPolarity::Positive,
711-
ast::Defaultness::Final,
712-
trait_generics,
713-
opt_trait_ref,
714-
self_type,
715-
methods.into_iter().chain(associated_types).collect(),
716-
),
710+
polarity: ast::ImplPolarity::Positive,
711+
defaultness: ast::Defaultness::Final,
712+
generics: trait_generics,
713+
of_trait: opt_trait_ref,
714+
self_ty: self_type,
715+
items: methods.into_iter().chain(associated_types).collect(),
716+
},
717717
)
718718
}
719719

src/librustc_builtin_macros/deriving/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ fn inject_impl_of_structural_trait(
156156
span,
157157
ast::Ident::invalid(),
158158
attrs,
159-
ItemKind::Impl(
160-
ast::Unsafety::Normal,
161-
ast::ImplPolarity::Positive,
162-
ast::Defaultness::Final,
159+
ItemKind::Impl {
160+
unsafety: ast::Unsafety::Normal,
161+
polarity: ast::ImplPolarity::Positive,
162+
defaultness: ast::Defaultness::Final,
163163
generics,
164-
Some(trait_ref),
165-
self_type,
166-
Vec::new(),
167-
),
164+
of_trait: Some(trait_ref),
165+
self_ty: self_type,
166+
items: Vec::new(),
167+
},
168168
);
169169

170170
push(Annotatable::Item(newitem));

src/librustc_error_codes/error_codes/E0198.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
A negative implementation is one that excludes a type from implementing a
2-
particular trait. Not being able to use a trait is always a safe operation,
3-
so negative implementations are always safe and never need to be marked as
4-
unsafe.
1+
A negative implementation was marked as unsafe.
52

6-
```compile_fail
7-
#![feature(optin_builtin_traits)]
3+
Erroneous code example:
84

5+
```compile_fail
96
struct Foo;
107
11-
// unsafe is unnecessary
12-
unsafe impl !Clone for Foo { }
8+
unsafe impl !Clone for Foo { } // error!
139
```
1410

11+
A negative implementation is one that excludes a type from implementing a
12+
particular trait. Not being able to use a trait is always a safe operation,
13+
so negative implementations are always safe and never need to be marked as
14+
unsafe.
15+
1516
This will compile:
1617

1718
```ignore (ignore auto_trait future compatibility warning)
+15-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
A trait implementation was marked as unsafe while the trait is safe.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0199
6+
struct Foo;
7+
8+
trait Bar { }
9+
10+
unsafe impl Bar for Foo { } // error!
11+
```
12+
113
Safe traits should not have unsafe implementations, therefore marking an
214
implementation for a safe trait unsafe will cause a compiler error. Removing
3-
the unsafe marker on the trait noted in the error will resolve this problem.
15+
the unsafe marker on the trait noted in the error will resolve this problem:
416

5-
```compile_fail,E0199
17+
```
618
struct Foo;
719
820
trait Bar { }
921
10-
// this won't compile because Bar is safe
11-
unsafe impl Bar for Foo { }
12-
// this will compile
13-
impl Bar for Foo { }
22+
impl Bar for Foo { } // ok!
1423
```

src/librustc_errors/emitter.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,15 @@ impl EmitterWriter {
14761476
None => return Ok(()),
14771477
};
14781478

1479+
// Render the replacements for each suggestion
1480+
let suggestions = suggestion.splice_lines(&**sm);
1481+
1482+
if suggestions.is_empty() {
1483+
// Suggestions coming from macros can have malformed spans. This is a heavy handed
1484+
// approach to avoid ICEs by ignoring the suggestion outright.
1485+
return Ok(());
1486+
}
1487+
14791488
let mut buffer = StyledBuffer::new();
14801489

14811490
// Render the suggestion message
@@ -1492,9 +1501,6 @@ impl EmitterWriter {
14921501
Some(Style::HeaderMsg),
14931502
);
14941503

1495-
// Render the replacements for each suggestion
1496-
let suggestions = suggestion.splice_lines(&**sm);
1497-
14981504
let mut row_num = 2;
14991505
let mut notice_capitalization = false;
15001506
for (complete, parts, only_capitalization) in suggestions.iter().take(MAX_SUGGESTIONS) {
@@ -1505,7 +1511,9 @@ impl EmitterWriter {
15051511
let show_underline = !(parts.len() == 1 && parts[0].snippet.trim() == complete.trim())
15061512
&& complete.lines().count() == 1;
15071513

1508-
let lines = sm.span_to_lines(parts[0].span).unwrap();
1514+
let lines = sm
1515+
.span_to_lines(parts[0].span)
1516+
.expect("span_to_lines failed when emitting suggestion");
15091517

15101518
assert!(!lines.lines.is_empty());
15111519

0 commit comments

Comments
 (0)