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 5 pull requests #66225

Merged
merged 20 commits into from
Nov 8, 2019
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
91 changes: 27 additions & 64 deletions src/doc/rustc/src/lints/listing/deny-by-default.md
Original file line number Diff line number Diff line change
@@ -45,53 +45,6 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
```

## legacy-constructor-visibility

[RFC 1506](https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md) modified some
visibility rules, and changed the visibility of struct constructors. Some
example code that triggers this lint:

```rust,ignore
mod m {
pub struct S(u8);

fn f() {
// this is trying to use S from the 'use' line, but because the `u8` is
// not pub, it is private
::S;
}
}

use m::S;
```

This will produce:

```text
error: private struct constructors are not usable through re-exports in outer modules
--> src/main.rs:5:9
|
5 | ::S;
| ^^^
|
= note: `#[deny(legacy_constructor_visibility)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #39207 <https://github.com/rust-lang/rust/issues/39207>
```


## legacy-directory-ownership

The legacy_directory_ownership warning is issued when

* There is a non-inline module with a `#[path]` attribute (e.g. `#[path = "foo.rs"] mod bar;`),
* The module's file ("foo.rs" in the above example) is not named "mod.rs", and
* The module's file contains a non-inline child module without a `#[path]` attribute.

The warning can be fixed by renaming the parent module to "mod.rs" and moving
it into its own directory if appropriate.


## missing-fragment-specifier

The missing_fragment_specifier warning is issued when an unused pattern in a
@@ -169,39 +122,49 @@ error: literal out of range for u8
|
```

## parenthesized-params-in-types-and-modules
## patterns-in-fns-without-body

This lint detects incorrect parentheses. Some example code that triggers this
lint:
This lint detects patterns in functions without body were that were
previously erroneously allowed. Some example code that triggers this lint:

```rust,ignore
let x = 5 as usize();
```rust,compile_fail
trait Trait {
fn foo(mut arg: u8);
}
```

This will produce:

```text
error: parenthesized parameters may only be used with a trait
--> src/main.rs:2:21
warning: patterns aren't allowed in methods without bodies
--> src/main.rs:2:12
|
2 | let x = 5 as usize();
| ^^
2 | fn foo(mut arg: u8);
| ^^^^^^^
|
= note: `#[deny(parenthesized_params_in_types_and_modules)]` on by default
= note: `#[warn(patterns_in_fns_without_body)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42238 <https://github.com/rust-lang/rust/issues/42238>
= note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203>
```

To fix it, remove the `()`s.
To fix this, remove the pattern; it can be used in the implementation without
being used in the definition. That is:

## pub-use-of-private-extern-crate
```rust
trait Trait {
fn foo(arg: u8);
}

This lint detects a specific situation of re-exporting a private `extern crate`;
impl Trait for i32 {
fn foo(mut arg: u8) {

}
}
```

## safe-extern-statics
## pub-use-of-private-extern-crate

In older versions of Rust, there was a soundness issue where `extern static`s were allowed
to be accessed in safe code. This lint now catches and denies this kind of code.
This lint detects a specific situation of re-exporting a private `extern crate`;

## unknown-crate-types

40 changes: 0 additions & 40 deletions src/doc/rustc/src/lints/listing/warn-by-default.md
Original file line number Diff line number Diff line change
@@ -307,46 +307,6 @@ warning: path statement with no effect
|
```

## patterns-in-fns-without-body

This lint detects patterns in functions without body were that were
previously erroneously allowed. Some example code that triggers this lint:

```rust
trait Trait {
fn foo(mut arg: u8);
}
```

This will produce:

```text
warning: patterns aren't allowed in methods without bodies
--> src/main.rs:2:12
|
2 | fn foo(mut arg: u8);
| ^^^^^^^
|
= note: `#[warn(patterns_in_fns_without_body)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203>
```

To fix this, remove the pattern; it can be used in the implementation without
being used in the definition. That is:

```rust
trait Trait {
fn foo(arg: u8);
}

impl Trait for i32 {
fn foo(mut arg: u8) {

}
}
```

## plugin-as-library

This lint detects when compiler plugins are used as ordinary library in
8 changes: 4 additions & 4 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ pub enum FnKind<'a> {
ItemFn(Ident, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),

/// `fn foo(&self)`
Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]),
Method(Ident, &'a FnSig, Option<&'a Visibility>, &'a [Attribute]),

/// `|x, y| {}`
Closure(&'a [Attribute]),
@@ -481,13 +481,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor.visit_ty(typ);
visitor.visit_nested_body(body);
}
ItemKind::Fn(ref declaration, header, ref generics, body_id) => {
ItemKind::Fn(ref sig, ref generics, body_id) => {
visitor.visit_fn(FnKind::ItemFn(item.ident,
generics,
header,
sig.header,
&item.vis,
&item.attrs),
declaration,
&sig.decl,
body_id,
item.span,
item.hir_id)
39 changes: 9 additions & 30 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
@@ -44,8 +44,7 @@ use crate::hir::def::{Namespace, Res, DefKind, PartialRes, PerNS};
use crate::hir::{GenericArg, ConstArg};
use crate::hir::ptr::P;
use crate::lint;
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
ELIDED_LIFETIMES_IN_PATHS};
use crate::lint::builtin::{self, ELIDED_LIFETIMES_IN_PATHS};
use crate::middle::cstore::CrateStore;
use crate::session::Session;
use crate::session::config::nightly_options;
@@ -298,7 +297,6 @@ enum ParamMode {

enum ParenthesizedGenericArgs {
Ok,
Warn,
Err,
}

@@ -1701,29 +1699,19 @@ impl<'a> LoweringContext<'a> {
};
let parenthesized_generic_args = match partial_res.base_res() {
// `a::b::Trait(Args)`
Res::Def(DefKind::Trait, _)
if i + 1 == proj_start => ParenthesizedGenericArgs::Ok,
Res::Def(DefKind::Trait, _) if i + 1 == proj_start => {
ParenthesizedGenericArgs::Ok
}
// `a::b::Trait(Args)::TraitItem`
Res::Def(DefKind::Method, _)
| Res::Def(DefKind::AssocConst, _)
| Res::Def(DefKind::AssocTy, _)
if i + 2 == proj_start =>
{
Res::Def(DefKind::Method, _) |
Res::Def(DefKind::AssocConst, _) |
Res::Def(DefKind::AssocTy, _) if i + 2 == proj_start => {
ParenthesizedGenericArgs::Ok
}
// Avoid duplicated errors.
Res::Err => ParenthesizedGenericArgs::Ok,
// An error
Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Enum, _)
| Res::Def(DefKind::Union, _)
| Res::Def(DefKind::TyAlias, _)
| Res::Def(DefKind::Variant, _) if i + 1 == proj_start =>
{
ParenthesizedGenericArgs::Err
}
// A warning for now, for compatibility reasons.
_ => ParenthesizedGenericArgs::Warn,
_ => ParenthesizedGenericArgs::Err,
};

let num_lifetimes = type_def_id.map_or(0, |def_id| {
@@ -1786,7 +1774,7 @@ impl<'a> LoweringContext<'a> {
segment,
param_mode,
0,
ParenthesizedGenericArgs::Warn,
ParenthesizedGenericArgs::Err,
itctx.reborrow(),
None,
));
@@ -1862,15 +1850,6 @@ impl<'a> LoweringContext<'a> {
}
GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args {
ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data),
ParenthesizedGenericArgs::Warn => {
self.resolver.lint_buffer().buffer_lint(
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
CRATE_NODE_ID,
data.span,
msg.into(),
);
(hir::GenericArgs::none(), true)
}
ParenthesizedGenericArgs::Err => {
let mut err = struct_span_err!(self.sess, data.span, E0214, "{}", msg);
err.span_label(data.span, "only `Fn` traits may use parentheses");
19 changes: 7 additions & 12 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
@@ -306,7 +306,7 @@ impl LoweringContext<'_> {
self.lower_const_body(e)
)
}
ItemKind::Fn(ref decl, header, ref generics, ref body) => {
ItemKind::Fn(FnSig { ref decl, header }, ref generics, ref body) => {
let fn_def_id = self.resolver.definitions().local_def_id(id);
self.with_new_scopes(|this| {
this.current_item = Some(ident.span);
@@ -317,7 +317,7 @@ impl LoweringContext<'_> {
// declaration (decl), not the return types.
let body_id = this.lower_maybe_async_body(&decl, header.asyncness.node, body);

let (generics, fn_decl) = this.add_in_band_defs(
let (generics, decl) = this.add_in_band_defs(
generics,
fn_def_id,
AnonymousLifetimeMode::PassThrough,
@@ -328,13 +328,8 @@ impl LoweringContext<'_> {
header.asyncness.node.opt_return_id()
),
);

hir::ItemKind::Fn(
fn_decl,
this.lower_fn_header(header),
generics,
body_id,
)
let sig = hir::FnSig { decl, header: this.lower_fn_header(header) };
hir::ItemKind::Fn(sig, generics, body_id)
})
}
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
@@ -1260,11 +1255,11 @@ impl LoweringContext<'_> {
fn lower_method_sig(
&mut self,
generics: &Generics,
sig: &MethodSig,
sig: &FnSig,
fn_def_id: DefId,
impl_trait_return_allow: bool,
is_async: Option<NodeId>,
) -> (hir::Generics, hir::MethodSig) {
) -> (hir::Generics, hir::FnSig) {
let header = self.lower_fn_header(sig.header);
let (generics, decl) = self.add_in_band_defs(
generics,
@@ -1277,7 +1272,7 @@ impl LoweringContext<'_> {
is_async,
),
);
(generics, hir::MethodSig { header, decl })
(generics, hir::FnSig { header, decl })
}

fn lower_is_auto(&mut self, a: IsAuto) -> hir::IsAuto {
18 changes: 9 additions & 9 deletions src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
@@ -158,25 +158,25 @@ impl<'a> FnLikeNode<'a> {

pub fn body(self) -> ast::BodyId {
self.handle(|i: ItemFnParts<'a>| i.body,
|_, _, _: &'a ast::MethodSig, _, body: ast::BodyId, _, _| body,
|_, _, _: &'a ast::FnSig, _, body: ast::BodyId, _, _| body,
|c: ClosureParts<'a>| c.body)
}

pub fn decl(self) -> &'a FnDecl {
self.handle(|i: ItemFnParts<'a>| &*i.decl,
|_, _, sig: &'a ast::MethodSig, _, _, _, _| &sig.decl,
|_, _, sig: &'a ast::FnSig, _, _, _, _| &sig.decl,
|c: ClosureParts<'a>| c.decl)
}

pub fn span(self) -> Span {
self.handle(|i: ItemFnParts<'_>| i.span,
|_, _, _: &'a ast::MethodSig, _, _, span, _| span,
|_, _, _: &'a ast::FnSig, _, _, span, _| span,
|c: ClosureParts<'_>| c.span)
}

pub fn id(self) -> ast::HirId {
self.handle(|i: ItemFnParts<'_>| i.id,
|id, _, _: &'a ast::MethodSig, _, _, _, _| id,
|id, _, _: &'a ast::FnSig, _, _, _, _| id,
|c: ClosureParts<'_>| c.id)
}

@@ -199,7 +199,7 @@ impl<'a> FnLikeNode<'a> {
let closure = |c: ClosureParts<'a>| {
FnKind::Closure(c.attrs)
};
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| {
let method = |_, ident: Ident, sig: &'a ast::FnSig, vis, _, _, attrs| {
FnKind::Method(ident, sig, vis, attrs)
};
self.handle(item, method, closure)
@@ -209,7 +209,7 @@ impl<'a> FnLikeNode<'a> {
I: FnOnce(ItemFnParts<'a>) -> A,
M: FnOnce(ast::HirId,
Ident,
&'a ast::MethodSig,
&'a ast::FnSig,
Option<&'a ast::Visibility>,
ast::BodyId,
Span,
@@ -219,16 +219,16 @@ impl<'a> FnLikeNode<'a> {
{
match self.node {
map::Node::Item(i) => match i.kind {
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
ast::ItemKind::Fn(ref sig, ref generics, block) =>
item_fn(ItemFnParts {
id: i.hir_id,
ident: i.ident,
decl: &decl,
decl: &sig.decl,
body: block,
vis: &i.vis,
span: i.span,
attrs: &i.attrs,
header,
header: sig.header,
generics,
}),
_ => bug!("item FnLikeNode that is not fn-like"),
Loading