Skip to content

Commit 9e34664

Browse files
committed
Auto merge of #66225 - Centril:rollup-it0t5tk, r=Centril
Rollup of 5 pull requests Successful merges: - #65785 (Transition future compat lints to {ERROR, DENY} - Take 2) - #66007 (Remove "here" from "expected one of X here") - #66043 (rename Memory::get methods to get_raw to indicate their unchecked nature) - #66154 (miri: Rename to_{u,i}size to to_machine_{u,i}size) - #66188 (`MethodSig` -> `FnSig` & Use it in `ItemKind::Fn`) Failed merges: r? @ghost
2 parents 76ade3e + 65c77bc commit 9e34664

File tree

224 files changed

+643
-1199
lines changed

Some content is hidden

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

224 files changed

+643
-1199
lines changed

src/doc/rustc/src/lints/listing/deny-by-default.md

+27-64
Original file line numberDiff line numberDiff line change
@@ -45,53 +45,6 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
4545
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
4646
```
4747

48-
## legacy-constructor-visibility
49-
50-
[RFC 1506](https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md) modified some
51-
visibility rules, and changed the visibility of struct constructors. Some
52-
example code that triggers this lint:
53-
54-
```rust,ignore
55-
mod m {
56-
pub struct S(u8);
57-
58-
fn f() {
59-
// this is trying to use S from the 'use' line, but because the `u8` is
60-
// not pub, it is private
61-
::S;
62-
}
63-
}
64-
65-
use m::S;
66-
```
67-
68-
This will produce:
69-
70-
```text
71-
error: private struct constructors are not usable through re-exports in outer modules
72-
--> src/main.rs:5:9
73-
|
74-
5 | ::S;
75-
| ^^^
76-
|
77-
= note: `#[deny(legacy_constructor_visibility)]` on by default
78-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
79-
= note: for more information, see issue #39207 <https://github.com/rust-lang/rust/issues/39207>
80-
```
81-
82-
83-
## legacy-directory-ownership
84-
85-
The legacy_directory_ownership warning is issued when
86-
87-
* There is a non-inline module with a `#[path]` attribute (e.g. `#[path = "foo.rs"] mod bar;`),
88-
* The module's file ("foo.rs" in the above example) is not named "mod.rs", and
89-
* The module's file contains a non-inline child module without a `#[path]` attribute.
90-
91-
The warning can be fixed by renaming the parent module to "mod.rs" and moving
92-
it into its own directory if appropriate.
93-
94-
9548
## missing-fragment-specifier
9649

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

172-
## parenthesized-params-in-types-and-modules
125+
## patterns-in-fns-without-body
173126

174-
This lint detects incorrect parentheses. Some example code that triggers this
175-
lint:
127+
This lint detects patterns in functions without body were that were
128+
previously erroneously allowed. Some example code that triggers this lint:
176129

177-
```rust,ignore
178-
let x = 5 as usize();
130+
```rust,compile_fail
131+
trait Trait {
132+
fn foo(mut arg: u8);
133+
}
179134
```
180135

181136
This will produce:
182137

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

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

197-
## pub-use-of-private-extern-crate
153+
```rust
154+
trait Trait {
155+
fn foo(arg: u8);
156+
}
198157

199-
This lint detects a specific situation of re-exporting a private `extern crate`;
158+
impl Trait for i32 {
159+
fn foo(mut arg: u8) {
160+
161+
}
162+
}
163+
```
200164

201-
## safe-extern-statics
165+
## pub-use-of-private-extern-crate
202166

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

206169
## unknown-crate-types
207170

src/doc/rustc/src/lints/listing/warn-by-default.md

-40
Original file line numberDiff line numberDiff line change
@@ -307,46 +307,6 @@ warning: path statement with no effect
307307
|
308308
```
309309

310-
## patterns-in-fns-without-body
311-
312-
This lint detects patterns in functions without body were that were
313-
previously erroneously allowed. Some example code that triggers this lint:
314-
315-
```rust
316-
trait Trait {
317-
fn foo(mut arg: u8);
318-
}
319-
```
320-
321-
This will produce:
322-
323-
```text
324-
warning: patterns aren't allowed in methods without bodies
325-
--> src/main.rs:2:12
326-
|
327-
2 | fn foo(mut arg: u8);
328-
| ^^^^^^^
329-
|
330-
= note: `#[warn(patterns_in_fns_without_body)]` on by default
331-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
332-
= note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203>
333-
```
334-
335-
To fix this, remove the pattern; it can be used in the implementation without
336-
being used in the definition. That is:
337-
338-
```rust
339-
trait Trait {
340-
fn foo(arg: u8);
341-
}
342-
343-
impl Trait for i32 {
344-
fn foo(mut arg: u8) {
345-
346-
}
347-
}
348-
```
349-
350310
## plugin-as-library
351311

352312
This lint detects when compiler plugins are used as ordinary library in

src/librustc/hir/intravisit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum FnKind<'a> {
4545
ItemFn(Ident, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]),
4646

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

5050
/// `|x, y| {}`
5151
Closure(&'a [Attribute]),
@@ -481,13 +481,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
481481
visitor.visit_ty(typ);
482482
visitor.visit_nested_body(body);
483483
}
484-
ItemKind::Fn(ref declaration, header, ref generics, body_id) => {
484+
ItemKind::Fn(ref sig, ref generics, body_id) => {
485485
visitor.visit_fn(FnKind::ItemFn(item.ident,
486486
generics,
487-
header,
487+
sig.header,
488488
&item.vis,
489489
&item.attrs),
490-
declaration,
490+
&sig.decl,
491491
body_id,
492492
item.span,
493493
item.hir_id)

src/librustc/hir/lowering.rs

+9-30
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ use crate::hir::def::{Namespace, Res, DefKind, PartialRes, PerNS};
4444
use crate::hir::{GenericArg, ConstArg};
4545
use crate::hir::ptr::P;
4646
use crate::lint;
47-
use crate::lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
48-
ELIDED_LIFETIMES_IN_PATHS};
47+
use crate::lint::builtin::{self, ELIDED_LIFETIMES_IN_PATHS};
4948
use crate::middle::cstore::CrateStore;
5049
use crate::session::Session;
5150
use crate::session::config::nightly_options;
@@ -298,7 +297,6 @@ enum ParamMode {
298297

299298
enum ParenthesizedGenericArgs {
300299
Ok,
301-
Warn,
302300
Err,
303301
}
304302

@@ -1701,29 +1699,19 @@ impl<'a> LoweringContext<'a> {
17011699
};
17021700
let parenthesized_generic_args = match partial_res.base_res() {
17031701
// `a::b::Trait(Args)`
1704-
Res::Def(DefKind::Trait, _)
1705-
if i + 1 == proj_start => ParenthesizedGenericArgs::Ok,
1702+
Res::Def(DefKind::Trait, _) if i + 1 == proj_start => {
1703+
ParenthesizedGenericArgs::Ok
1704+
}
17061705
// `a::b::Trait(Args)::TraitItem`
1707-
Res::Def(DefKind::Method, _)
1708-
| Res::Def(DefKind::AssocConst, _)
1709-
| Res::Def(DefKind::AssocTy, _)
1710-
if i + 2 == proj_start =>
1711-
{
1706+
Res::Def(DefKind::Method, _) |
1707+
Res::Def(DefKind::AssocConst, _) |
1708+
Res::Def(DefKind::AssocTy, _) if i + 2 == proj_start => {
17121709
ParenthesizedGenericArgs::Ok
17131710
}
17141711
// Avoid duplicated errors.
17151712
Res::Err => ParenthesizedGenericArgs::Ok,
17161713
// An error
1717-
Res::Def(DefKind::Struct, _)
1718-
| Res::Def(DefKind::Enum, _)
1719-
| Res::Def(DefKind::Union, _)
1720-
| Res::Def(DefKind::TyAlias, _)
1721-
| Res::Def(DefKind::Variant, _) if i + 1 == proj_start =>
1722-
{
1723-
ParenthesizedGenericArgs::Err
1724-
}
1725-
// A warning for now, for compatibility reasons.
1726-
_ => ParenthesizedGenericArgs::Warn,
1714+
_ => ParenthesizedGenericArgs::Err,
17271715
};
17281716

17291717
let num_lifetimes = type_def_id.map_or(0, |def_id| {
@@ -1786,7 +1774,7 @@ impl<'a> LoweringContext<'a> {
17861774
segment,
17871775
param_mode,
17881776
0,
1789-
ParenthesizedGenericArgs::Warn,
1777+
ParenthesizedGenericArgs::Err,
17901778
itctx.reborrow(),
17911779
None,
17921780
));
@@ -1862,15 +1850,6 @@ impl<'a> LoweringContext<'a> {
18621850
}
18631851
GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args {
18641852
ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data),
1865-
ParenthesizedGenericArgs::Warn => {
1866-
self.resolver.lint_buffer().buffer_lint(
1867-
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
1868-
CRATE_NODE_ID,
1869-
data.span,
1870-
msg.into(),
1871-
);
1872-
(hir::GenericArgs::none(), true)
1873-
}
18741853
ParenthesizedGenericArgs::Err => {
18751854
let mut err = struct_span_err!(self.sess, data.span, E0214, "{}", msg);
18761855
err.span_label(data.span, "only `Fn` traits may use parentheses");

src/librustc/hir/lowering/item.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl LoweringContext<'_> {
306306
self.lower_const_body(e)
307307
)
308308
}
309-
ItemKind::Fn(ref decl, header, ref generics, ref body) => {
309+
ItemKind::Fn(FnSig { ref decl, header }, ref generics, ref body) => {
310310
let fn_def_id = self.resolver.definitions().local_def_id(id);
311311
self.with_new_scopes(|this| {
312312
this.current_item = Some(ident.span);
@@ -317,7 +317,7 @@ impl LoweringContext<'_> {
317317
// declaration (decl), not the return types.
318318
let body_id = this.lower_maybe_async_body(&decl, header.asyncness.node, body);
319319

320-
let (generics, fn_decl) = this.add_in_band_defs(
320+
let (generics, decl) = this.add_in_band_defs(
321321
generics,
322322
fn_def_id,
323323
AnonymousLifetimeMode::PassThrough,
@@ -328,13 +328,8 @@ impl LoweringContext<'_> {
328328
header.asyncness.node.opt_return_id()
329329
),
330330
);
331-
332-
hir::ItemKind::Fn(
333-
fn_decl,
334-
this.lower_fn_header(header),
335-
generics,
336-
body_id,
337-
)
331+
let sig = hir::FnSig { decl, header: this.lower_fn_header(header) };
332+
hir::ItemKind::Fn(sig, generics, body_id)
338333
})
339334
}
340335
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
@@ -1260,11 +1255,11 @@ impl LoweringContext<'_> {
12601255
fn lower_method_sig(
12611256
&mut self,
12621257
generics: &Generics,
1263-
sig: &MethodSig,
1258+
sig: &FnSig,
12641259
fn_def_id: DefId,
12651260
impl_trait_return_allow: bool,
12661261
is_async: Option<NodeId>,
1267-
) -> (hir::Generics, hir::MethodSig) {
1262+
) -> (hir::Generics, hir::FnSig) {
12681263
let header = self.lower_fn_header(sig.header);
12691264
let (generics, decl) = self.add_in_band_defs(
12701265
generics,
@@ -1277,7 +1272,7 @@ impl LoweringContext<'_> {
12771272
is_async,
12781273
),
12791274
);
1280-
(generics, hir::MethodSig { header, decl })
1275+
(generics, hir::FnSig { header, decl })
12811276
}
12821277

12831278
fn lower_is_auto(&mut self, a: IsAuto) -> hir::IsAuto {

src/librustc/hir/map/blocks.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,25 @@ impl<'a> FnLikeNode<'a> {
158158

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

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

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

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

@@ -199,7 +199,7 @@ impl<'a> FnLikeNode<'a> {
199199
let closure = |c: ClosureParts<'a>| {
200200
FnKind::Closure(c.attrs)
201201
};
202-
let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| {
202+
let method = |_, ident: Ident, sig: &'a ast::FnSig, vis, _, _, attrs| {
203203
FnKind::Method(ident, sig, vis, attrs)
204204
};
205205
self.handle(item, method, closure)
@@ -209,7 +209,7 @@ impl<'a> FnLikeNode<'a> {
209209
I: FnOnce(ItemFnParts<'a>) -> A,
210210
M: FnOnce(ast::HirId,
211211
Ident,
212-
&'a ast::MethodSig,
212+
&'a ast::FnSig,
213213
Option<&'a ast::Visibility>,
214214
ast::BodyId,
215215
Span,
@@ -219,16 +219,16 @@ impl<'a> FnLikeNode<'a> {
219219
{
220220
match self.node {
221221
map::Node::Item(i) => match i.kind {
222-
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
222+
ast::ItemKind::Fn(ref sig, ref generics, block) =>
223223
item_fn(ItemFnParts {
224224
id: i.hir_id,
225225
ident: i.ident,
226-
decl: &decl,
226+
decl: &sig.decl,
227227
body: block,
228228
vis: &i.vis,
229229
span: i.span,
230230
attrs: &i.attrs,
231-
header,
231+
header: sig.header,
232232
generics,
233233
}),
234234
_ => bug!("item FnLikeNode that is not fn-like"),

0 commit comments

Comments
 (0)