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 #68330

Merged
merged 28 commits into from
Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
12f029b
Fix deref impl on type alias
GuillaumeGomez Jan 10, 2020
fd4a88f
Add test for typedef deref
GuillaumeGomez Jan 10, 2020
81a5b94
formatting
GuillaumeGomez Jan 10, 2020
6e79146
remove unneeded code from cache.rs
GuillaumeGomez Jan 15, 2020
e6ad49a
Include type alias implementations
GuillaumeGomez Jan 15, 2020
d755238
Simplify deref impls for type aliases
GuillaumeGomez Jan 15, 2020
8a9b951
Fix rendering on sidebar and update tests
GuillaumeGomez Jan 15, 2020
ea64a33
Update sanitizer tests
tmiasko Jan 16, 2020
25a8f94
Don't warn about snake case for field puns that don't introduce a new…
jumbatm Nov 23, 2019
3094c37
Improve code readability
GuillaumeGomez Jan 16, 2020
10a9ea4
Do not ICE on malformed suggestion spans
estebank Jan 15, 2020
03240e1
review comments
estebank Jan 17, 2020
cdc828e
Stop treating `FalseEdges` and `FalseUnwind` as having semantic value…
oli-obk Jan 17, 2020
a91f77c
Add regression test for integer literals in generic arguments in wher…
varkor Jan 17, 2020
9c6c2f1
Clean up E0198 explanation
GuillaumeGomez Jan 16, 2020
482dc77
formatting
GuillaumeGomez Jan 17, 2020
e8a4b93
Clean up E0199 explanation
GuillaumeGomez Jan 17, 2020
d461e6d
Use named fields for `ast::ItemKind::Impl`
ecstatic-morse Jan 14, 2020
4743995
Use named fields for `hir::ItemKind::Impl`
ecstatic-morse Jan 18, 2020
c854aec
Rollup merge of #66660 - jumbatm:dont_warn_about_snake_case_in_patter…
tmandry Jan 18, 2020
bafe089
Rollup merge of #68093 - GuillaumeGomez:fix-deref-impl-typedef, r=oli…
tmandry Jan 18, 2020
fca3264
Rollup merge of #68204 - ecstatic-morse:item-kind-impl, r=oli-obk
tmandry Jan 18, 2020
7f6fdef
Rollup merge of #68256 - estebank:bad-sugg-span, r=petrochenkov
tmandry Jan 18, 2020
2a1ab29
Rollup merge of #68279 - GuillaumeGomez:clean-up-e0198, r=Dylan-DPC
tmandry Jan 18, 2020
87293cd
Rollup merge of #68291 - tmiasko:sanitizer-tests, r=nikomatsakis
tmandry Jan 18, 2020
9d9c8c6
Rollup merge of #68312 - varkor:issue-67753-regression, r=Centril
tmandry Jan 18, 2020
dd6a838
Rollup merge of #68314 - oli-obk:true_unwind, r=eddyb
tmandry Jan 18, 2020
14d779c
Rollup merge of #68317 - GuillaumeGomez:clean-up-e0199, r=Dylan-DPC
tmandry Jan 18, 2020
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
4 changes: 2 additions & 2 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Target {
ItemKind::Union(..) => Target::Union,
ItemKind::Trait(..) => Target::Trait,
ItemKind::TraitAlias(..) => Target::TraitAlias,
ItemKind::Impl(..) => Target::Impl,
ItemKind::Impl { .. } => Target::Impl,
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ impl Target {
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
let containing_item = tcx.hir().expect_item(parent_hir_id);
let containing_impl_is_for_trait = match &containing_item.kind {
hir::ItemKind::Impl(_, _, _, _, tr, _, _) => tr.is_some(),
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.is_some(),
_ => bug!("parent of an ImplItem must be an Impl"),
};
if containing_impl_is_for_trait {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl<'hir> Map<'hir> {
| ItemKind::Use(..)
| ItemKind::ForeignMod(..)
| ItemKind::GlobalAsm(..)
| ItemKind::Impl(..) => return None,
| ItemKind::Impl { .. } => return None,
},
Node::ForeignItem(item) => match item.kind {
ForeignItemKind::Fn(..) => DefKind::Fn,
Expand Down Expand Up @@ -604,7 +604,7 @@ impl<'hir> Map<'hir> {
| ItemKind::Union(_, ref generics)
| ItemKind::Trait(_, _, ref generics, ..)
| ItemKind::TraitAlias(ref generics, _)
| ItemKind::Impl(_, _, _, ref generics, ..) => Some(generics),
| ItemKind::Impl { ref generics, .. } => Some(generics),
_ => None,
},
_ => None,
Expand Down Expand Up @@ -821,7 +821,7 @@ impl<'hir> Map<'hir> {
| ItemKind::Struct(..)
| ItemKind::Union(..)
| ItemKind::Trait(..)
| ItemKind::Impl(..) => true,
| ItemKind::Impl { .. } => true,
_ => false,
},
Node::ForeignItem(fi) => match fi.kind {
Expand Down Expand Up @@ -1332,7 +1332,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl(..) => "impl",
ItemKind::Impl { .. } => "impl",
};
format!("{} {}{}", item_str, path_str(), id_str)
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn emit_msg_span(

fn item_scope_tag(item: &hir::Item<'_>) -> &'static str {
match item.kind {
hir::ItemKind::Impl(..) => "impl",
hir::ItemKind::Impl { .. } => "impl",
hir::ItemKind::Struct(..) => "struct",
hir::ItemKind::Union(..) => "union",
hir::ItemKind::Enum(..) => "enum",
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/traits/error_reporting/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
..
})
| hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(_, _, _, generics, ..),
..
kind: hir::ItemKind::Impl { generics, .. }, ..
}) if projection.is_some() => {
// Missing associated type bound.
suggest_restriction(&generics, "the associated type", err);
Expand All @@ -115,7 +114,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
..
})
| hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(_, _, _, generics, ..),
kind: hir::ItemKind::Impl { generics, .. },
span,
..
})
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ pub fn impl_is_default(tcx: TyCtxt<'_>, node_item_def_id: DefId) -> bool {
match tcx.hir().as_local_hir_id(node_item_def_id) {
Some(hir_id) => {
let item = tcx.hir().expect_item(hir_id);
if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.kind {
if let hir::ItemKind::Impl { defaultness, .. } = item.kind {
defaultness.is_default()
} else {
false
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
// |
// = note: expected type `u32`
// found type `()`
if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
if let Some(hir::ItemKind::Impl { items, .. }) = item.map(|i| &i.kind) {
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
if let Some(impl_item) = impl_items
if let Some(impl_item) = items
.iter()
.filter(|item| item.ident == trait_assoc_item.ident)
.next()
Expand Down Expand Up @@ -279,14 +279,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
// | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
if let (
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
Some(hir::ItemKind::Impl(.., impl_items)),
Some(hir::ItemKind::Impl { items, .. }),
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind))
{
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
.filter(|i| i.def_id == *item_def_id)
.next()
.and_then(|trait_assoc_item| {
impl_items
items
.iter()
.filter(|i| i.ident == trait_assoc_item.ident)
.next()
Expand Down
35 changes: 18 additions & 17 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
if let Some(hir_id) = item_hir_id {
self.lctx.with_parent_item_lifetime_defs(hir_id, |this| {
let this = &mut ItemLowerer { lctx: this };
if let ItemKind::Impl(.., ref opt_trait_ref, _, _) = item.kind {
if opt_trait_ref.as_ref().map(|tr| tr.constness.is_some()).unwrap_or(false) {
if let ItemKind::Impl { ref of_trait, .. } = item.kind {
if of_trait.as_ref().map(|tr| tr.constness.is_some()).unwrap_or(false) {
this.with_trait_impl_ref(of_trait, |this| visit::walk_item(this, item));
this.lctx
.diagnostic()
.span_err(item.span, "const trait impls are not yet implemented");
}

this.with_trait_impl_ref(opt_trait_ref, |this| visit::walk_item(this, item));
this.with_trait_impl_ref(of_trait, |this| visit::walk_item(this, item));
} else {
visit::walk_item(this, item);
}
Expand Down Expand Up @@ -118,7 +119,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let old_len = self.in_scope_lifetimes.len();

let parent_generics = match self.items.get(&parent_hir_id).unwrap().kind {
hir::ItemKind::Impl(_, _, _, ref generics, ..)
hir::ItemKind::Impl { ref generics, .. }
| hir::ItemKind::Trait(_, _, ref generics, ..) => &generics.params[..],
_ => &[],
};
Expand Down Expand Up @@ -173,7 +174,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
vec
}
ItemKind::MacroDef(..) => SmallVec::new(),
ItemKind::Fn(..) | ItemKind::Impl(.., None, _, _) => smallvec![i.id],
ItemKind::Fn(..) | ItemKind::Impl { of_trait: None, .. } => smallvec![i.id],
ItemKind::Static(ref ty, ..) => {
let mut ids = smallvec![i.id];
if self.sess.features_untracked().impl_trait_in_bindings {
Expand Down Expand Up @@ -361,15 +362,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_generics(generics, ImplTraitContext::disallowed()),
)
}
ItemKind::Impl(
ItemKind::Impl {
unsafety,
polarity,
defaultness,
ref ast_generics,
ref trait_ref,
ref ty,
ref impl_items,
) => {
generics: ref ast_generics,
of_trait: ref trait_ref,
self_ty: ref ty,
items: ref impl_items,
} => {
let def_id = self.resolver.definitions().local_def_id(id);

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

hir::ItemKind::Impl(
hir::ItemKind::Impl {
unsafety,
polarity,
self.lower_defaultness(defaultness, true /* [1] */),
defaultness: self.lower_defaultness(defaultness, true /* [1] */),
generics,
trait_ref,
lowered_ty,
new_impl_items,
)
of_trait: trait_ref,
self_ty: lowered_ty,
items: new_impl_items,
}
}
ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref items) => {
let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed());
Expand Down
24 changes: 20 additions & 4 deletions src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,17 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

match item.kind {
ItemKind::Impl(unsafety, polarity, _, _, Some(..), ref ty, ref impl_items) => {
ItemKind::Impl {
unsafety,
polarity,
defaultness: _,
generics: _,
of_trait: Some(_),
ref self_ty,
ref items,
} => {
self.invalid_visibility(&item.vis, None);
if let TyKind::Err = ty.kind {
if let TyKind::Err = self_ty.kind {
self.err_handler()
.struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
.help("use `auto trait Trait {}` instead")
Expand All @@ -629,15 +637,23 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
)
.emit();
}
for impl_item in impl_items {
for impl_item in items {
self.invalid_visibility(&impl_item.vis, None);
if let AssocItemKind::Fn(ref sig, _) = impl_item.kind {
self.check_trait_fn_not_const(sig.header.constness);
self.check_trait_fn_not_async(impl_item.span, sig.header.asyncness.node);
}
}
}
ItemKind::Impl(unsafety, polarity, defaultness, _, None, _, _) => {
ItemKind::Impl {
unsafety,
polarity,
defaultness,
generics: _,
of_trait: None,
self_ty: _,
items: _,
} => {
self.invalid_visibility(
&item.vis,
Some("place qualifiers on individual impl items instead"),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}

ast::ItemKind::Impl(_, polarity, defaultness, ..) => {
ast::ItemKind::Impl { polarity, defaultness, .. } => {
if polarity == ast::ImplPolarity::Negative {
gate_feature_post!(
&self,
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_builtin_macros/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,15 +705,15 @@ impl<'a> TraitDef<'a> {
self.span,
Ident::invalid(),
a,
ast::ItemKind::Impl(
ast::ItemKind::Impl {
unsafety,
ast::ImplPolarity::Positive,
ast::Defaultness::Final,
trait_generics,
opt_trait_ref,
self_type,
methods.into_iter().chain(associated_types).collect(),
),
polarity: ast::ImplPolarity::Positive,
defaultness: ast::Defaultness::Final,
generics: trait_generics,
of_trait: opt_trait_ref,
self_ty: self_type,
items: methods.into_iter().chain(associated_types).collect(),
},
)
}

Expand Down
16 changes: 8 additions & 8 deletions src/librustc_builtin_macros/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ fn inject_impl_of_structural_trait(
span,
ast::Ident::invalid(),
attrs,
ItemKind::Impl(
ast::Unsafety::Normal,
ast::ImplPolarity::Positive,
ast::Defaultness::Final,
ItemKind::Impl {
unsafety: ast::Unsafety::Normal,
polarity: ast::ImplPolarity::Positive,
defaultness: ast::Defaultness::Final,
generics,
Some(trait_ref),
self_type,
Vec::new(),
),
of_trait: Some(trait_ref),
self_ty: self_type,
items: Vec::new(),
},
);

push(Annotatable::Item(newitem));
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_error_codes/error_codes/E0198.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
A negative implementation is one that excludes a type from implementing a
particular trait. Not being able to use a trait is always a safe operation,
so negative implementations are always safe and never need to be marked as
unsafe.
A negative implementation was marked as unsafe.

```compile_fail
#![feature(optin_builtin_traits)]
Erroneous code example:

```compile_fail
struct Foo;

// unsafe is unnecessary
unsafe impl !Clone for Foo { }
unsafe impl !Clone for Foo { } // error!
```

A negative implementation is one that excludes a type from implementing a
particular trait. Not being able to use a trait is always a safe operation,
so negative implementations are always safe and never need to be marked as
unsafe.

This will compile:

```ignore (ignore auto_trait future compatibility warning)
Expand Down
21 changes: 15 additions & 6 deletions src/librustc_error_codes/error_codes/E0199.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
A trait implementation was marked as unsafe while the trait is safe.

Erroneous code example:

```compile_fail,E0199
struct Foo;

trait Bar { }

unsafe impl Bar for Foo { } // error!
```

Safe traits should not have unsafe implementations, therefore marking an
implementation for a safe trait unsafe will cause a compiler error. Removing
the unsafe marker on the trait noted in the error will resolve this problem.
the unsafe marker on the trait noted in the error will resolve this problem:

```compile_fail,E0199
```
struct Foo;

trait Bar { }

// this won't compile because Bar is safe
unsafe impl Bar for Foo { }
// this will compile
impl Bar for Foo { }
impl Bar for Foo { } // ok!
```
16 changes: 12 additions & 4 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,15 @@ impl EmitterWriter {
None => return Ok(()),
};

// Render the replacements for each suggestion
let suggestions = suggestion.splice_lines(&**sm);

if suggestions.is_empty() {
// Suggestions coming from macros can have malformed spans. This is a heavy handed
// approach to avoid ICEs by ignoring the suggestion outright.
return Ok(());
}

let mut buffer = StyledBuffer::new();

// Render the suggestion message
Expand All @@ -1492,9 +1501,6 @@ impl EmitterWriter {
Some(Style::HeaderMsg),
);

// Render the replacements for each suggestion
let suggestions = suggestion.splice_lines(&**sm);

let mut row_num = 2;
let mut notice_capitalization = false;
for (complete, parts, only_capitalization) in suggestions.iter().take(MAX_SUGGESTIONS) {
Expand All @@ -1505,7 +1511,9 @@ impl EmitterWriter {
let show_underline = !(parts.len() == 1 && parts[0].snippet.trim() == complete.trim())
&& complete.lines().count() == 1;

let lines = sm.span_to_lines(parts[0].span).unwrap();
let lines = sm
.span_to_lines(parts[0].span)
.expect("span_to_lines failed when emitting suggestion");

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

Expand Down
Loading