Skip to content

Commit 2251766

Browse files
committed
Auto merge of #77517 - JohnTitor:rollup-msbd49e, r=JohnTitor
Rollup of 11 pull requests Successful merges: - #75143 (Use `tracing` spans to trace the entire MIR interp stack) - #75699 (Uplift drop-bounds lint from clippy) - #76768 (Test and reject out-of-bounds shuffle vectors) - #77190 (updated p! macro to accept literals) - #77388 (Add some regression tests) - #77419 (Create E0777 error code for invalid argument in derive) - #77447 (BTreeMap: document DrainFilterInner better) - #77468 (Fix test name) - #77469 (Improve rustdoc error for failed intra-doc link resolution) - #77473 (Make --all-targets in x.py check opt-in) - #77508 (Fix capitalization in blog post name) Failed merges: r? `@ghost`
2 parents 4cf3dc1 + f5db166 commit 2251766

Some content is hidden

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

53 files changed

+866
-331
lines changed

Cargo.lock

+3-12
Original file line numberDiff line numberDiff line change
@@ -1726,15 +1726,6 @@ dependencies = [
17261726
"cfg-if",
17271727
]
17281728

1729-
[[package]]
1730-
name = "log_settings"
1731-
version = "0.1.2"
1732-
source = "registry+https://github.com/rust-lang/crates.io-index"
1733-
checksum = "19af41f0565d7c19b2058153ad0b42d4d5ce89ec4dbf06ed6741114a8b63e7cd"
1734-
dependencies = [
1735-
"lazy_static",
1736-
]
1737-
17381729
[[package]]
17391730
name = "lsp-codec"
17401731
version = "0.1.2"
@@ -3523,6 +3514,7 @@ dependencies = [
35233514
"rustc_target",
35243515
"tracing",
35253516
"tracing-subscriber",
3517+
"tracing-tree",
35263518
"winapi 0.3.9",
35273519
]
35283520

@@ -3810,7 +3802,6 @@ version = "0.0.0"
38103802
dependencies = [
38113803
"either",
38123804
"itertools 0.9.0",
3813-
"log_settings",
38143805
"polonius-engine",
38153806
"regex",
38163807
"rustc_apfloat",
@@ -5105,9 +5096,9 @@ dependencies = [
51055096

51065097
[[package]]
51075098
name = "tracing-tree"
5108-
version = "0.1.5"
5099+
version = "0.1.6"
51095100
source = "registry+https://github.com/rust-lang/crates.io-index"
5110-
checksum = "e1a3dc4774db3a6b2d66a4f8d8de670e874ec3ed55615860c994927419b32c5f"
5101+
checksum = "43aac8afb493b08e1e1904956f7407c1e671b9c83b26a17e1bd83d6a3520e350"
51115102
dependencies = [
51125103
"ansi_term 0.12.1",
51135104
"atty",

RELEASES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Compatibility Notes
9090

9191
Internal Only
9292
--------
93-
- [Improved default settings for bootstrapping in `x.py`.][73964] You can read details about this change in the ["Changes To `x.py` Defaults"](https://blog.rust-lang.org/inside-rust/2020/08/30/changes-to-x-py-defaults.html) post on the Inside Rust blog.
93+
- [Improved default settings for bootstrapping in `x.py`.][73964] You can read details about this change in the ["Changes to `x.py` defaults"](https://blog.rust-lang.org/inside-rust/2020/08/30/changes-to-x-py-defaults.html) post on the Inside Rust blog.
9494

9595
[1.47.0-cfg]: https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard
9696
[75048]: https://github.com/rust-lang/rust/pull/75048/

compiler/rustc_driver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ crate-type = ["dylib"]
1111
libc = "0.2"
1212
tracing = { version = "0.1.18" }
1313
tracing-subscriber = { version = "0.2.10", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
14+
tracing-tree = "0.1.6"
1415
rustc_middle = { path = "../rustc_middle" }
1516
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1617
rustc_target = { path = "../rustc_target" }

compiler/rustc_driver/src/lib.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -1251,11 +1251,21 @@ pub fn init_env_logger(env: &str) {
12511251
Ok(s) if s.is_empty() => return,
12521252
Ok(_) => {}
12531253
}
1254-
let builder = tracing_subscriber::FmtSubscriber::builder();
1255-
1256-
let builder = builder.with_env_filter(tracing_subscriber::EnvFilter::from_env(env));
1257-
1258-
builder.init()
1254+
let filter = tracing_subscriber::EnvFilter::from_env(env);
1255+
let layer = tracing_tree::HierarchicalLayer::default()
1256+
.with_indent_lines(true)
1257+
.with_ansi(true)
1258+
.with_targets(true)
1259+
.with_thread_ids(true)
1260+
.with_thread_names(true)
1261+
.with_wraparound(10)
1262+
.with_verbose_exit(true)
1263+
.with_verbose_entry(true)
1264+
.with_indent_amount(2);
1265+
1266+
use tracing_subscriber::layer::SubscriberExt;
1267+
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
1268+
tracing::subscriber::set_global_default(subscriber).unwrap();
12591269
}
12601270

12611271
pub fn main() -> ! {

compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ E0773: include_str!("./error_codes/E0773.md"),
459459
E0774: include_str!("./error_codes/E0774.md"),
460460
E0775: include_str!("./error_codes/E0775.md"),
461461
E0776: include_str!("./error_codes/E0776.md"),
462+
E0777: include_str!("./error_codes/E0777.md"),
462463
;
463464
// E0006, // merged with E0005
464465
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
A literal value was used inside `#[derive]`.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0777
6+
#[derive("Clone")] // error!
7+
struct Foo;
8+
```
9+
10+
Only paths to traits are allowed as argument inside `#[derive]`. You can find
11+
more information about the `#[derive]` attribute in the [Rust Book].
12+
13+
14+
```
15+
#[derive(Clone)] // ok!
16+
struct Foo;
17+
```
18+
19+
[Rust Book]: https://doc.rust-lang.org/book/appendix-03-derivable-traits.html

compiler/rustc_expand/src/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_ast_pretty::pprust;
1818
use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
1919
use rustc_data_structures::map_in_place::MapInPlace;
2020
use rustc_data_structures::stack::ensure_sufficient_stack;
21-
use rustc_errors::{Applicability, PResult};
21+
use rustc_errors::{struct_span_err, Applicability, PResult};
2222
use rustc_feature::Features;
2323
use rustc_parse::parser::Parser;
2424
use rustc_parse::validate_attr;
@@ -542,7 +542,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
542542
fn error_derive_forbidden_on_non_adt(&self, derives: &[Path], item: &Annotatable) {
543543
let attr = self.cx.sess.find_by_name(item.attrs(), sym::derive);
544544
let span = attr.map_or(item.span(), |attr| attr.span);
545-
let mut err = rustc_errors::struct_span_err!(
545+
let mut err = struct_span_err!(
546546
self.cx.sess,
547547
span,
548548
E0774,

compiler/rustc_expand/src/proc_macro.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use rustc_ast::token;
55
use rustc_ast::tokenstream::{TokenStream, TokenTree};
66
use rustc_ast::{self as ast, *};
77
use rustc_data_structures::sync::Lrc;
8-
use rustc_errors::{Applicability, ErrorReported};
8+
use rustc_errors::{struct_span_err, Applicability, ErrorReported};
9+
use rustc_lexer::is_ident;
910
use rustc_parse::nt_to_tokenstream;
1011
use rustc_span::symbol::sym;
1112
use rustc_span::{Span, DUMMY_SP};
@@ -182,9 +183,22 @@ crate fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>)
182183
.filter_map(|nmi| match nmi {
183184
NestedMetaItem::Literal(lit) => {
184185
error_reported_filter_map = true;
185-
cx.struct_span_err(lit.span, "expected path to a trait, found literal")
186-
.help("for example, write `#[derive(Debug)]` for `Debug`")
187-
.emit();
186+
let mut err = struct_span_err!(
187+
cx.sess,
188+
lit.span,
189+
E0777,
190+
"expected path to a trait, found literal",
191+
);
192+
let token = lit.token.to_string();
193+
if token.starts_with('"')
194+
&& token.len() > 2
195+
&& is_ident(&token[1..token.len() - 1])
196+
{
197+
err.help(&format!("try using `#[derive({})]`", &token[1..token.len() - 1]));
198+
} else {
199+
err.help("for example, write `#[derive(Debug)]` for `Debug`");
200+
}
201+
err.emit();
188202
None
189203
}
190204
NestedMetaItem::MetaItem(mi) => Some(mi),

compiler/rustc_lint/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ mod non_ascii_idents;
5353
mod nonstandard_style;
5454
mod passes;
5555
mod redundant_semicolon;
56+
mod traits;
5657
mod types;
5758
mod unused;
5859

@@ -75,6 +76,7 @@ use internal::*;
7576
use non_ascii_idents::*;
7677
use nonstandard_style::*;
7778
use redundant_semicolon::*;
79+
use traits::*;
7880
use types::*;
7981
use unused::*;
8082

@@ -157,6 +159,7 @@ macro_rules! late_lint_passes {
157159
MissingDebugImplementations: MissingDebugImplementations::default(),
158160
ArrayIntoIter: ArrayIntoIter,
159161
ClashingExternDeclarations: ClashingExternDeclarations::new(),
162+
DropTraitConstraints: DropTraitConstraints,
160163
]
161164
);
162165
};

compiler/rustc_lint/src/traits.rs

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use crate::LateContext;
2+
use crate::LateLintPass;
3+
use crate::LintContext;
4+
use rustc_hir as hir;
5+
use rustc_span::symbol::sym;
6+
7+
declare_lint! {
8+
/// The `drop_bounds` lint checks for generics with `std::ops::Drop` as
9+
/// bounds.
10+
///
11+
/// ### Example
12+
///
13+
/// ```rust
14+
/// fn foo<T: Drop>() {}
15+
/// ```
16+
///
17+
/// {{produces}}
18+
///
19+
/// ### Explanation
20+
///
21+
/// `Drop` bounds do not really accomplish anything. A type may have
22+
/// compiler-generated drop glue without implementing the `Drop` trait
23+
/// itself. The `Drop` trait also only has one method, `Drop::drop`, and
24+
/// that function is by fiat not callable in user code. So there is really
25+
/// no use case for using `Drop` in trait bounds.
26+
///
27+
/// The most likely use case of a drop bound is to distinguish between
28+
/// types that have destructors and types that don't. Combined with
29+
/// specialization, a naive coder would write an implementation that
30+
/// assumed a type could be trivially dropped, then write a specialization
31+
/// for `T: Drop` that actually calls the destructor. Except that doing so
32+
/// is not correct; String, for example, doesn't actually implement Drop,
33+
/// but because String contains a Vec, assuming it can be trivially dropped
34+
/// will leak memory.
35+
pub DROP_BOUNDS,
36+
Warn,
37+
"bounds of the form `T: Drop` are useless"
38+
}
39+
40+
declare_lint_pass!(
41+
/// Lint for bounds of the form `T: Drop`, which usually
42+
/// indicate an attempt to emulate `std::mem::needs_drop`.
43+
DropTraitConstraints => [DROP_BOUNDS]
44+
);
45+
46+
impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
47+
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
48+
use rustc_middle::ty::PredicateAtom::*;
49+
50+
let def_id = cx.tcx.hir().local_def_id(item.hir_id);
51+
let predicates = cx.tcx.explicit_predicates_of(def_id);
52+
for &(predicate, span) in predicates.predicates {
53+
let trait_predicate = match predicate.skip_binders() {
54+
Trait(trait_predicate, _constness) => trait_predicate,
55+
_ => continue,
56+
};
57+
let def_id = trait_predicate.trait_ref.def_id;
58+
if cx.tcx.lang_items().drop_trait() == Some(def_id) {
59+
// Explicitly allow `impl Drop`, a drop-guards-as-Voldemort-type pattern.
60+
if trait_predicate.trait_ref.self_ty().is_impl_trait() {
61+
continue;
62+
}
63+
cx.struct_span_lint(DROP_BOUNDS, span, |lint| {
64+
let needs_drop = match cx.tcx.get_diagnostic_item(sym::needs_drop) {
65+
Some(needs_drop) => needs_drop,
66+
None => return,
67+
};
68+
let msg = format!(
69+
"bounds on `{}` are useless, consider instead \
70+
using `{}` to detect if a type has a destructor",
71+
predicate,
72+
cx.tcx.def_path_str(needs_drop)
73+
);
74+
lint.build(&msg).emit()
75+
});
76+
}
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)