Skip to content

Commit 05f2326

Browse files
committed
Auto merge of #87347 - GuillaumeGomez:rollup-ke92xxc, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - #87187 (Fix NixOS detection) - #87206 (avoid temporary vectors/reuse iterators) - #87230 (Fix docblock <table> overflow) - #87273 (Recognize bounds on impls as const bounds) - #87279 (Add comments explaining the unix command-line argument support.) - #87301 (Fix typo in compile.rs) - #87311 (Get back the more precise suggestion spans of old regionck) - #87321 (Add long explanation for E0722) - #87342 (Add long explanation for E0757) Failed merges: - #87270 (Don't display <table> in item summary) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cf932aa + 3a8bc0d commit 05f2326

File tree

28 files changed

+184
-61
lines changed

28 files changed

+184
-61
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ impl Path {
7272
) -> ast::Path {
7373
let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect();
7474
let lt = mk_lifetimes(cx, span, &self.lifetime);
75-
let tys: Vec<P<ast::Ty>> =
76-
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
77-
let params = lt
78-
.into_iter()
79-
.map(GenericArg::Lifetime)
80-
.chain(tys.into_iter().map(GenericArg::Type))
81-
.collect();
75+
let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics));
76+
let params =
77+
lt.into_iter().map(GenericArg::Lifetime).chain(tys.map(GenericArg::Type)).collect();
8278

8379
match self.kind {
8480
PathKind::Global => cx.path_all(span, true, idents, params),

compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ E0716: include_str!("./error_codes/E0716.md"),
418418
E0718: include_str!("./error_codes/E0718.md"),
419419
E0719: include_str!("./error_codes/E0719.md"),
420420
E0720: include_str!("./error_codes/E0720.md"),
421+
E0722: include_str!("./error_codes/E0722.md"),
421422
E0724: include_str!("./error_codes/E0724.md"),
422423
E0725: include_str!("./error_codes/E0725.md"),
423424
E0727: include_str!("./error_codes/E0727.md"),
@@ -449,6 +450,7 @@ E0753: include_str!("./error_codes/E0753.md"),
449450
E0754: include_str!("./error_codes/E0754.md"),
450451
E0755: include_str!("./error_codes/E0755.md"),
451452
E0756: include_str!("./error_codes/E0756.md"),
453+
E0757: include_str!("./error_codes/E0757.md"),
452454
E0758: include_str!("./error_codes/E0758.md"),
453455
E0759: include_str!("./error_codes/E0759.md"),
454456
E0760: include_str!("./error_codes/E0760.md"),
@@ -634,10 +636,8 @@ E0783: include_str!("./error_codes/E0783.md"),
634636
E0711, // a feature has been declared with conflicting stability attributes
635637
E0717, // rustc_promotable without stability attribute
636638
// E0721, // `await` keyword
637-
E0722, // Malformed `#[optimize]` attribute
638639
// E0723, unstable feature in `const` context
639640
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
640641
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
641-
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
642642
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
643643
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
The `optimize` attribute was malformed.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0722
6+
#![feature(optimize_attribute)]
7+
8+
#[optimize(something)] // error: invalid argument
9+
pub fn something() {}
10+
```
11+
12+
The `#[optimize]` attribute should be used as follows:
13+
14+
- `#[optimize(size)]` -- instructs the optimization pipeline to generate code
15+
that's smaller rather than faster
16+
17+
- `#[optimize(speed)]` -- instructs the optimization pipeline to generate code
18+
that's faster rather than smaller
19+
20+
For example:
21+
22+
```
23+
#![feature(optimize_attribute)]
24+
25+
#[optimize(size)]
26+
pub fn something() {}
27+
```
28+
29+
See [RFC 2412] for more details.
30+
31+
[RFC 2412]: https://rust-lang.github.io/rfcs/2412-optimize-attr.html
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
A function was given both the `ffi_const` and `ffi_pure` attributes.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0757
6+
#![feature(ffi_const, ffi_pure)]
7+
8+
extern "C" {
9+
#[ffi_const]
10+
#[ffi_pure] // error: `#[ffi_const]` function cannot be `#[ffi_pure]`
11+
pub fn square(num: i32) -> i32;
12+
}
13+
```
14+
15+
As `ffi_const` provides stronger guarantees than `ffi_pure`, remove the
16+
`ffi_pure` attribute:
17+
18+
```
19+
#![feature(ffi_const)]
20+
21+
extern "C" {
22+
#[ffi_const]
23+
pub fn square(num: i32) -> i32;
24+
}
25+
```
26+
27+
You can get more information about `const` and `pure` in the [GCC documentation
28+
on Common Function Attributes]. The unstable Rust Book has more information
29+
about [`ffi_const`] and [`ffi_pure`].
30+
31+
[GCC documentation on Common Function Attributes]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html
32+
[`ffi_const`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html
33+
[`ffi_pure`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-pure.html

compiler/rustc_hir/src/hir.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,6 +3060,27 @@ impl<'hir> Node<'hir> {
30603060
Node::Crate(_) | Node::Visibility(_) => None,
30613061
}
30623062
}
3063+
3064+
/// Returns `Constness::Const` when this node is a const fn/impl.
3065+
pub fn constness(&self) -> Constness {
3066+
match self {
3067+
Node::Item(Item {
3068+
kind: ItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3069+
..
3070+
})
3071+
| Node::TraitItem(TraitItem {
3072+
kind: TraitItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3073+
..
3074+
})
3075+
| Node::ImplItem(ImplItem {
3076+
kind: ImplItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..),
3077+
..
3078+
})
3079+
| Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness,
3080+
3081+
_ => Constness::NotConst,
3082+
}
3083+
}
30633084
}
30643085

30653086
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21302130
let new_lt = generics
21312131
.as_ref()
21322132
.and_then(|(parent_g, g)| {
2133-
let possible: Vec<_> = (b'a'..=b'z').map(|c| format!("'{}", c as char)).collect();
2133+
let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char));
21342134
let mut lts_names = g
21352135
.params
21362136
.iter()
@@ -2146,7 +2146,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21462146
);
21472147
}
21482148
let lts = lts_names.iter().map(|s| -> &str { &*s }).collect::<Vec<_>>();
2149-
possible.into_iter().find(|candidate| !lts.contains(&candidate.as_str()))
2149+
possible.find(|candidate| !lts.contains(&candidate.as_str()))
21502150
})
21512151
.unwrap_or("'lt".to_string());
21522152
let add_lt_sugg = generics

compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
99
use rustc_middle::ty::subst::Subst;
1010
use rustc_middle::ty::{self, RegionVid, Ty};
1111
use rustc_span::symbol::{kw, sym};
12-
use rustc_span::Span;
12+
use rustc_span::{BytePos, Span};
1313

1414
use crate::util::borrowck_errors;
1515

@@ -641,12 +641,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
641641
} else {
642642
"'_".to_string()
643643
};
644-
let suggestion = if snippet.ends_with(';') {
644+
let span = if snippet.ends_with(';') {
645645
// `type X = impl Trait;`
646-
format!("{} + {};", &snippet[..snippet.len() - 1], suggestable_fr_name)
646+
span.with_hi(span.hi() - BytePos(1))
647647
} else {
648-
format!("{} + {}", snippet, suggestable_fr_name)
648+
span
649649
};
650+
let suggestion = format!(" + {}", suggestable_fr_name);
651+
let span = span.shrink_to_hi();
650652
diag.span_suggestion(
651653
span,
652654
&format!(

compiler/rustc_mir/src/transform/check_consts/validation.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -897,16 +897,19 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
897897
permitted = true;
898898
}
899899
}
900-
let mut const_impls = true;
901-
tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| {
902-
if const_impls {
903-
if let hir::Constness::NotConst = tcx.impl_constness(imp) {
904-
const_impls = false;
900+
if !permitted {
901+
// if trait's impls are all const, permit the call.
902+
let mut const_impls = true;
903+
tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| {
904+
if const_impls {
905+
if let hir::Constness::NotConst = tcx.impl_constness(imp) {
906+
const_impls = false;
907+
}
905908
}
909+
});
910+
if const_impls {
911+
permitted = true;
906912
}
907-
});
908-
if const_impls {
909-
permitted = true;
910913
}
911914
}
912915

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_hir::def_id::DefId;
1515
use rustc_infer::infer;
1616
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1717
use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
18-
use rustc_middle::hir::map::blocks::FnLikeNode;
1918
use rustc_middle::ty::fold::TypeFoldable;
2019
use rustc_middle::ty::subst::GenericArgKind;
2120
use rustc_middle::ty::{self, Const, Ty, TyCtxt};
@@ -175,13 +174,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
175174
}
176175

177176
fn default_constness_for_trait_bounds(&self) -> hir::Constness {
178-
// FIXME: refactor this into a method
179-
let node = self.tcx.hir().get(self.body_id);
180-
if let Some(fn_like) = FnLikeNode::from_node(node) {
181-
fn_like.constness()
182-
} else {
183-
hir::Constness::NotConst
184-
}
177+
self.tcx.hir().get(self.body_id).constness()
185178
}
186179

187180
fn get_type_parameter_bounds(

compiler/rustc_typeck/src/collect.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
3535
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
3636
use rustc_hir::weak_lang_items;
3737
use rustc_hir::{GenericParamKind, HirId, Node};
38-
use rustc_middle::hir::map::blocks::FnLikeNode;
3938
use rustc_middle::hir::map::Map;
4039
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
4140
use rustc_middle::mir::mono::Linkage;
@@ -358,11 +357,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
358357
}
359358

360359
fn default_constness_for_trait_bounds(&self) -> hir::Constness {
361-
if let Some(fn_like) = FnLikeNode::from_node(self.node()) {
362-
fn_like.constness()
363-
} else {
364-
hir::Constness::NotConst
365-
}
360+
self.node().constness()
366361
}
367362

368363
fn get_type_parameter_bounds(

0 commit comments

Comments
 (0)